From 68ce93307fcc0364816664114a71c58f60bbad94 Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Sat, 10 Apr 2010 10:53:53 -0400 Subject: send-email: Cleanup { style As Jakub Narebski pointed out on the list, Perl code usually prefers sub func { } over sub func { } git-send-email.perl is somewhat inconsistent in its style, with 23 subroutines using the first style and 6 using the second. Convert the few odd subroutines so that the code matches normal Perl style. Signed-off-by: Brian Gernhardt Signed-off-by: Junio C Hamano --- git-send-email.perl | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'git-send-email.perl') diff --git a/git-send-email.perl b/git-send-email.perl index dba587601d..f8d86ea9a2 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -752,8 +752,7 @@ sub extract_valid_address { # We'll setup a template for the message id, using the "from" address: my ($message_id_stamp, $message_id_serial); -sub make_message_id -{ +sub make_message_id { my $uniq; if (!defined $message_id_stamp) { $message_id_stamp = sprintf("%s-%s", time, $$); @@ -808,8 +807,7 @@ sub is_rfc2047_quoted { } # use the simplest quoting being able to handle the recipient -sub sanitize_address -{ +sub sanitize_address { my ($recipient) = @_; my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)\s*(<.*)/); @@ -854,8 +852,7 @@ sub sanitize_address # This maildomain*() code is based on ideas in Perl library Test::Reporter # /usr/share/perl5/Test/Reporter/Mail/Util.pm ==> sub _maildomain () -sub maildomain_net -{ +sub maildomain_net { my $maildomain; if (eval { require Net::Domain; 1 }) { @@ -867,8 +864,7 @@ sub maildomain_net return $maildomain; } -sub maildomain_mta -{ +sub maildomain_mta { my $maildomain; if (eval { require Net::SMTP; 1 }) { @@ -889,8 +885,7 @@ sub maildomain_mta return $maildomain; } -sub maildomain -{ +sub maildomain { return maildomain_net() || maildomain_mta() || $mail_domain_default; } @@ -898,8 +893,7 @@ sub maildomain # In actuality, the whole program dies when there # is an error sending a message. -sub send_message -{ +sub send_message { my @recipients = unique_email_list(@to); @cc = (grep { my $cc = extract_valid_address($_); not grep { $cc eq $_ } @recipients -- cgit v1.2.3 From 59a8630338ea0173b9777eb9b3e3c9185643efb1 Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Sat, 10 Apr 2010 10:53:54 -0400 Subject: send-email: Don't use FQDNs without a '.' Although Net::Domain::domainname attempts to be very thorough, the host's configuration can still refuse to give a FQDN. Check to see if what we receive contains a dot as a basic sanity check. Since the same condition is used twice and getting complex, let's move it to a new function. Signed-off-by: Brian Gernhardt Signed-off-by: Junio C Hamano --- git-send-email.perl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'git-send-email.perl') diff --git a/git-send-email.perl b/git-send-email.perl index f8d86ea9a2..df83f0aa10 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -852,13 +852,17 @@ sub sanitize_address { # This maildomain*() code is based on ideas in Perl library Test::Reporter # /usr/share/perl5/Test/Reporter/Mail/Util.pm ==> sub _maildomain () +sub valid_fqdn { + my $domain = shift; + return !($^O eq 'darwin' && $domain =~ /\.local$/) && $domain =~ /\./; +} + sub maildomain_net { my $maildomain; if (eval { require Net::Domain; 1 }) { my $domain = Net::Domain::domainname(); - $maildomain = $domain - unless $^O eq 'darwin' && $domain =~ /\.local$/; + $maildomain = $domain if valid_fqdn($domain); } return $maildomain; @@ -874,8 +878,7 @@ sub maildomain_mta { my $domain = $smtp->domain; $smtp->quit; - $maildomain = $domain - unless $^O eq 'darwin' && $domain =~ /\.local$/; + $maildomain = $domain if valid_fqdn($domain); last if $maildomain; } -- cgit v1.2.3 From 69cf7bfd131ae6246931459a1e6513d51f0b0119 Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Sat, 10 Apr 2010 10:53:56 -0400 Subject: send-email: Cleanup smtp-domain and add config The way the code stored --smtp-domain was unlike its handling of other similar options. Bring it in line with the others by: - Renaming $mail_domain to $smtp_domain to match the command line option. Also move its declaration from near the top of the file to near other option variables. - Removing $mail_domain_default. The variable was used once and only served to move the default away from where it gets used. - Adding a sendemail.smtpdomain config option. smtp-domain was the only SMTP configuration option that couldn't be set in the user's .gitconfig. Signed-off-by: Brian Gernhardt Signed-off-by: Junio C Hamano --- git-send-email.perl | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'git-send-email.perl') diff --git a/git-send-email.perl b/git-send-email.perl index df83f0aa10..0f23ed380f 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -132,8 +132,6 @@ my $have_email_valid = eval { require Email::Valid; 1 }; my $have_mail_address = eval { require Mail::Address; 1 }; my $smtp; my $auth; -my $mail_domain_default = "localhost.localdomain"; -my $mail_domain; sub unique_email_list(@); sub cleanup_compose_files(); @@ -187,7 +185,7 @@ sub do_edit { # Variables with corresponding config settings my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd); my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption); -my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts); +my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts, $smtp_domain); my ($validate, $confirm); my (@suppress_cc); @@ -209,6 +207,7 @@ my %config_settings = ( "smtpserverport" => \$smtp_server_port, "smtpuser" => \$smtp_authuser, "smtppass" => \$smtp_authpass, + "smtpdomain" => \$smtp_domain, "to" => \@to, "cc" => \@initial_cc, "cccmd" => \$cc_cmd, @@ -277,7 +276,7 @@ my $rc = GetOptions("sender|from=s" => \$sender, "smtp-ssl" => sub { $smtp_encryption = 'ssl' }, "smtp-encryption=s" => \$smtp_encryption, "smtp-debug:i" => \$debug_net_smtp, - "smtp-domain:s" => \$mail_domain, + "smtp-domain:s" => \$smtp_domain, "identity=s" => \$identity, "annotate" => \$annotate, "compose" => \$compose, @@ -889,7 +888,7 @@ sub maildomain_mta { } sub maildomain { - return maildomain_net() || maildomain_mta() || $mail_domain_default; + return maildomain_net() || maildomain_mta() || 'localhost.localdomain'; } # Returns 1 if the message was sent, and 0 otherwise. @@ -993,18 +992,18 @@ X-Mailer: git-send-email $gitversion if ($smtp_encryption eq 'ssl') { $smtp_server_port ||= 465; # ssmtp require Net::SMTP::SSL; - $mail_domain ||= maildomain(); + $smtp_domain ||= maildomain(); $smtp ||= Net::SMTP::SSL->new($smtp_server, - Hello => $mail_domain, + Hello => $smtp_domain, Port => $smtp_server_port); } else { require Net::SMTP; - $mail_domain ||= maildomain(); + $smtp_domain ||= maildomain(); $smtp ||= Net::SMTP->new((defined $smtp_server_port) ? "$smtp_server:$smtp_server_port" : $smtp_server, - Hello => $mail_domain, + Hello => $smtp_domain, Debug => $debug_net_smtp); if ($smtp_encryption eq 'tls' && $smtp) { require Net::SMTP::SSL; @@ -1027,7 +1026,7 @@ X-Mailer: git-send-email $gitversion die "Unable to initialize SMTP properly. Check config and use --smtp-debug. ", "VALUES: server=$smtp_server ", "encryption=$smtp_encryption ", - "maildomain=$mail_domain", + "hello=$smtp_domain", defined $smtp_server_port ? "port=$smtp_server_port" : ""; } -- cgit v1.2.3