@@ -132,8 +132,6 @@ sub format_2822_time {
132
132
my $have_mail_address = eval { require Mail::Address; 1 };
133
133
my $smtp ;
134
134
my $auth ;
135
- my $mail_domain_default = " localhost.localdomain" ;
136
- my $mail_domain ;
137
135
138
136
sub unique_email_list (@);
139
137
sub cleanup_compose_files ();
@@ -190,7 +188,7 @@ sub do_edit {
190
188
# Variables with corresponding config settings
191
189
my ($thread , $chain_reply_to , $suppress_from , $signed_off_by_cc , $cc_cmd );
192
190
my ($smtp_server , $smtp_server_port , $smtp_authuser , $smtp_encryption );
193
- my ($identity , $aliasfiletype , @alias_files , @smtp_host_parts );
191
+ my ($identity , $aliasfiletype , @alias_files , @smtp_host_parts , $smtp_domain );
194
192
my ($validate , $confirm );
195
193
my (@suppress_cc );
196
194
@@ -212,6 +210,7 @@ sub do_edit {
212
210
" smtpserverport" => \$smtp_server_port ,
213
211
" smtpuser" => \$smtp_authuser ,
214
212
" smtppass" => \$smtp_authpass ,
213
+ " smtpdomain" => \$smtp_domain ,
215
214
" to" => \@to ,
216
215
" cc" => \@initial_cc ,
217
216
" cccmd" => \$cc_cmd ,
@@ -283,7 +282,7 @@ sub signal_handler {
283
282
" smtp-ssl" => sub { $smtp_encryption = ' ssl' },
284
283
" smtp-encryption=s" => \$smtp_encryption ,
285
284
" smtp-debug:i" => \$debug_net_smtp ,
286
- " smtp-domain:s" => \$mail_domain ,
285
+ " smtp-domain:s" => \$smtp_domain ,
287
286
" identity=s" => \$identity ,
288
287
" annotate" => \$annotate ,
289
288
" compose" => \$compose ,
@@ -761,8 +760,7 @@ sub extract_valid_address {
761
760
# We'll setup a template for the message id, using the "from" address:
762
761
763
762
my ($message_id_stamp , $message_id_serial );
764
- sub make_message_id
765
- {
763
+ sub make_message_id {
766
764
my $uniq ;
767
765
if (!defined $message_id_stamp ) {
768
766
$message_id_stamp = sprintf (" %s -%s " , time , $$ );
@@ -817,8 +815,7 @@ sub is_rfc2047_quoted {
817
815
}
818
816
819
817
# use the simplest quoting being able to handle the recipient
820
- sub sanitize_address
821
- {
818
+ sub sanitize_address {
822
819
my ($recipient ) = @_ ;
823
820
my ($recipient_name , $recipient_addr ) = ($recipient =~ / ^(.*?)\s *(<.*)/ );
824
821
@@ -863,21 +860,23 @@ sub sanitize_address
863
860
# This maildomain*() code is based on ideas in Perl library Test::Reporter
864
861
# /usr/share/perl5/Test/Reporter/Mail/Util.pm ==> sub _maildomain ()
865
862
866
- sub maildomain_net
867
- {
863
+ sub valid_fqdn {
864
+ my $domain = shift ;
865
+ return !($^O eq ' darwin' && $domain =~ / \. local$ / ) && $domain =~ / \. / ;
866
+ }
867
+
868
+ sub maildomain_net {
868
869
my $maildomain ;
869
870
870
871
if (eval { require Net::Domain; 1 }) {
871
872
my $domain = Net::Domain::domainname();
872
- $maildomain = $domain
873
- unless $^O eq ' darwin' && $domain =~ / \. local$ / ;
873
+ $maildomain = $domain if valid_fqdn($domain );
874
874
}
875
875
876
876
return $maildomain ;
877
877
}
878
878
879
- sub maildomain_mta
880
- {
879
+ sub maildomain_mta {
881
880
my $maildomain ;
882
881
883
882
if (eval { require Net::SMTP; 1 }) {
@@ -887,8 +886,7 @@ sub maildomain_mta
887
886
my $domain = $smtp -> domain;
888
887
$smtp -> quit;
889
888
890
- $maildomain = $domain
891
- unless $^O eq ' darwin' && $domain =~ / \. local$ / ;
889
+ $maildomain = $domain if valid_fqdn($domain );
892
890
893
891
last if $maildomain ;
894
892
}
@@ -898,17 +896,15 @@ sub maildomain_mta
898
896
return $maildomain ;
899
897
}
900
898
901
- sub maildomain
902
- {
903
- return maildomain_net() || maildomain_mta() || $mail_domain_default ;
899
+ sub maildomain {
900
+ return maildomain_net() || maildomain_mta() || ' localhost.localdomain' ;
904
901
}
905
902
906
903
# Returns 1 if the message was sent, and 0 otherwise.
907
904
# In actuality, the whole program dies when there
908
905
# is an error sending a message.
909
906
910
- sub send_message
911
- {
907
+ sub send_message {
912
908
my @recipients = unique_email_list(@to );
913
909
@cc = (grep { my $cc = extract_valid_address($_ );
914
910
not grep { $cc eq $_ } @recipients
@@ -1005,18 +1001,18 @@ sub send_message
1005
1001
if ($smtp_encryption eq ' ssl' ) {
1006
1002
$smtp_server_port ||= 465; # ssmtp
1007
1003
require Net::SMTP::SSL;
1008
- $mail_domain ||= maildomain();
1004
+ $smtp_domain ||= maildomain();
1009
1005
$smtp ||= Net::SMTP::SSL-> new($smtp_server ,
1010
- Hello => $mail_domain ,
1006
+ Hello => $smtp_domain ,
1011
1007
Port => $smtp_server_port );
1012
1008
}
1013
1009
else {
1014
1010
require Net::SMTP;
1015
- $mail_domain ||= maildomain();
1011
+ $smtp_domain ||= maildomain();
1016
1012
$smtp ||= Net::SMTP-> new((defined $smtp_server_port )
1017
1013
? " $smtp_server :$smtp_server_port "
1018
1014
: $smtp_server ,
1019
- Hello => $mail_domain ,
1015
+ Hello => $smtp_domain ,
1020
1016
Debug => $debug_net_smtp );
1021
1017
if ($smtp_encryption eq ' tls' && $smtp ) {
1022
1018
require Net::SMTP::SSL;
@@ -1039,7 +1035,7 @@ sub send_message
1039
1035
die " Unable to initialize SMTP properly. Check config and use --smtp-debug. " ,
1040
1036
" VALUES: server=$smtp_server " ,
1041
1037
" encryption=$smtp_encryption " ,
1042
- " maildomain= $mail_domain " ,
1038
+ " hello= $smtp_domain " ,
1043
1039
defined $smtp_server_port ? " port=$smtp_server_port " : " " ;
1044
1040
}
1045
1041
0 commit comments