@@ -132,8 +132,6 @@ sub format_2822_time {
132132my $have_mail_address = eval { require Mail::Address; 1 };
133133my $smtp ;
134134my $auth ;
135- my $mail_domain_default = " localhost.localdomain" ;
136- my $mail_domain ;
137135
138136sub unique_email_list (@);
139137sub cleanup_compose_files ();
@@ -190,7 +188,7 @@ sub do_edit {
190188# Variables with corresponding config settings
191189my ($thread , $chain_reply_to , $suppress_from , $signed_off_by_cc , $cc_cmd );
192190my ($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 );
194192my ($validate , $confirm );
195193my (@suppress_cc );
196194
@@ -212,6 +210,7 @@ sub do_edit {
212210 " smtpserverport" => \$smtp_server_port ,
213211 " smtpuser" => \$smtp_authuser ,
214212 " smtppass" => \$smtp_authpass ,
213+ " smtpdomain" => \$smtp_domain ,
215214 " to" => \@to ,
216215 " cc" => \@initial_cc ,
217216 " cccmd" => \$cc_cmd ,
@@ -283,7 +282,7 @@ sub signal_handler {
283282 " smtp-ssl" => sub { $smtp_encryption = ' ssl' },
284283 " smtp-encryption=s" => \$smtp_encryption ,
285284 " smtp-debug:i" => \$debug_net_smtp ,
286- " smtp-domain:s" => \$mail_domain ,
285+ " smtp-domain:s" => \$smtp_domain ,
287286 " identity=s" => \$identity ,
288287 " annotate" => \$annotate ,
289288 " compose" => \$compose ,
@@ -761,8 +760,7 @@ sub extract_valid_address {
761760# We'll setup a template for the message id, using the "from" address:
762761
763762my ($message_id_stamp , $message_id_serial );
764- sub make_message_id
765- {
763+ sub make_message_id {
766764 my $uniq ;
767765 if (!defined $message_id_stamp ) {
768766 $message_id_stamp = sprintf (" %s -%s " , time , $$ );
@@ -817,8 +815,7 @@ sub is_rfc2047_quoted {
817815}
818816
819817# use the simplest quoting being able to handle the recipient
820- sub sanitize_address
821- {
818+ sub sanitize_address {
822819 my ($recipient ) = @_ ;
823820 my ($recipient_name , $recipient_addr ) = ($recipient =~ / ^(.*?)\s *(<.*)/ );
824821
@@ -863,21 +860,23 @@ sub sanitize_address
863860# This maildomain*() code is based on ideas in Perl library Test::Reporter
864861# /usr/share/perl5/Test/Reporter/Mail/Util.pm ==> sub _maildomain ()
865862
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 {
868869 my $maildomain ;
869870
870871 if (eval { require Net::Domain; 1 }) {
871872 my $domain = Net::Domain::domainname();
872- $maildomain = $domain
873- unless $^O eq ' darwin' && $domain =~ / \. local$ / ;
873+ $maildomain = $domain if valid_fqdn($domain );
874874 }
875875
876876 return $maildomain ;
877877}
878878
879- sub maildomain_mta
880- {
879+ sub maildomain_mta {
881880 my $maildomain ;
882881
883882 if (eval { require Net::SMTP; 1 }) {
@@ -887,8 +886,7 @@ sub maildomain_mta
887886 my $domain = $smtp -> domain;
888887 $smtp -> quit;
889888
890- $maildomain = $domain
891- unless $^O eq ' darwin' && $domain =~ / \. local$ / ;
889+ $maildomain = $domain if valid_fqdn($domain );
892890
893891 last if $maildomain ;
894892 }
@@ -898,17 +896,15 @@ sub maildomain_mta
898896 return $maildomain ;
899897}
900898
901- sub maildomain
902- {
903- return maildomain_net() || maildomain_mta() || $mail_domain_default ;
899+ sub maildomain {
900+ return maildomain_net() || maildomain_mta() || ' localhost.localdomain' ;
904901}
905902
906903# Returns 1 if the message was sent, and 0 otherwise.
907904# In actuality, the whole program dies when there
908905# is an error sending a message.
909906
910- sub send_message
911- {
907+ sub send_message {
912908 my @recipients = unique_email_list(@to );
913909 @cc = (grep { my $cc = extract_valid_address($_ );
914910 not grep { $cc eq $_ } @recipients
@@ -1005,18 +1001,18 @@ sub send_message
10051001 if ($smtp_encryption eq ' ssl' ) {
10061002 $smtp_server_port ||= 465; # ssmtp
10071003 require Net::SMTP::SSL;
1008- $mail_domain ||= maildomain();
1004+ $smtp_domain ||= maildomain();
10091005 $smtp ||= Net::SMTP::SSL-> new($smtp_server ,
1010- Hello => $mail_domain ,
1006+ Hello => $smtp_domain ,
10111007 Port => $smtp_server_port );
10121008 }
10131009 else {
10141010 require Net::SMTP;
1015- $mail_domain ||= maildomain();
1011+ $smtp_domain ||= maildomain();
10161012 $smtp ||= Net::SMTP-> new((defined $smtp_server_port )
10171013 ? " $smtp_server :$smtp_server_port "
10181014 : $smtp_server ,
1019- Hello => $mail_domain ,
1015+ Hello => $smtp_domain ,
10201016 Debug => $debug_net_smtp );
10211017 if ($smtp_encryption eq ' tls' && $smtp ) {
10221018 require Net::SMTP::SSL;
@@ -1039,7 +1035,7 @@ sub send_message
10391035 die " Unable to initialize SMTP properly. Check config and use --smtp-debug. " ,
10401036 " VALUES: server=$smtp_server " ,
10411037 " encryption=$smtp_encryption " ,
1042- " maildomain= $mail_domain " ,
1038+ " hello= $smtp_domain " ,
10431039 defined $smtp_server_port ? " port=$smtp_server_port " : " " ;
10441040 }
10451041
0 commit comments