Merge branch 'bc/send-email-use-port-as-separate-param'
authorJunio C Hamano <gitster@pobox.com>
Mon, 15 Jul 2013 17:28:50 +0000 (10:28 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Jul 2013 17:28:50 +0000 (10:28 -0700)
Pass port number as a separate argument when send-email initializes
Net::SMTP, instead of as a part of the hostname, i.e. host:port.
This allows GSSAPI codepath to match with the hostname given.

* bc/send-email-use-port-as-separate-param:
send-email: provide port separately from hostname

1  2 
git-send-email.perl
diff --combined git-send-email.perl
index ecbf56f693f7049fd87267ec1830f9020e60e720,ca86a1391d49397289e2d3f0fcb644f479070ac3..45c386337777460ed77fd71026fcfca678b18037
@@@ -203,9 -203,11 +203,9 @@@ my ($compose_encoding)
  
  my ($debug_net_smtp) = 0;             # Net::SMTP, see send_message()
  
 -my $not_set_by_user = "true but not set by the user";
 -
  my %config_bool_settings = (
      "thread" => [\$thread, 1],
 -    "chainreplyto" => [\$chain_reply_to, $not_set_by_user],
 +    "chainreplyto" => [\$chain_reply_to, 0],
      "suppressfrom" => [\$suppress_from, undef],
      "signedoffbycc" => [\$signed_off_by_cc, undef],
      "signedoffcc" => [\$signed_off_by_cc, undef],      # Deprecated
@@@ -239,6 -241,19 +239,6 @@@ my %config_path_settings = 
      "aliasesfile" => \@alias_files,
  );
  
 -# Help users prepare for 1.7.0
 -sub chain_reply_to {
 -      if (defined $chain_reply_to &&
 -          $chain_reply_to eq $not_set_by_user) {
 -              print STDERR
 -                  "In git 1.7.0, the default has changed to --no-chain-reply-to\n" .
 -                  "Set sendemail.chainreplyto configuration variable to true if\n" .
 -                  "you want to keep --chain-reply-to as your default.\n";
 -              $chain_reply_to = 0;
 -      }
 -      return $chain_reply_to;
 -}
 -
  # Handle Uncouth Termination
  sub signal_handler {
  
@@@ -745,11 -760,6 +745,11 @@@ if (!defined $sender) 
        $sender = $repoauthor || $repocommitter || '';
  }
  
 +# $sender could be an already sanitized address
 +# (e.g. sendemail.from could be manually sanitized by user).
 +# But it's a no-op to run sanitize_address on an already sanitized address.
 +$sender = sanitize_address($sender);
 +
  my $prompting = 0;
  if (!@initial_to && !defined $to_cmd) {
        my $to = ask("Who should the emails be sent to (if any)? ",
@@@ -1103,9 -1113,10 +1103,9 @@@ sub send_message 
        if ($cc ne '') {
                $ccline = "\nCc: $cc";
        }
 -      my $sanitized_sender = sanitize_address($sender);
        make_message_id() unless defined($message_id);
  
 -      my $header = "From: $sanitized_sender
 +      my $header = "From: $sender
  To: $to${ccline}
  Subject: $subject
  Date: $date
@@@ -1122,7 -1133,7 +1122,7 @@@ X-Mailer: git-send-email $gitversio
        }
  
        my @sendmail_parameters = ('-i', @recipients);
 -      my $raw_from = $sanitized_sender;
 +      my $raw_from = $sender;
        if (defined $envelope_sender && $envelope_sender ne "auto") {
                $raw_from = $envelope_sender;
        }
                else {
                        require Net::SMTP;
                        $smtp_domain ||= maildomain();
-                       $smtp ||= Net::SMTP->new(smtp_host_string(),
+                       $smtp_server_port ||= 25;
+                       $smtp ||= Net::SMTP->new($smtp_server,
                                                 Hello => $smtp_domain,
-                                                Debug => $debug_net_smtp);
+                                                Debug => $debug_net_smtp,
+                                                Port => $smtp_server_port);
                        if ($smtp_encryption eq 'tls' && $smtp) {
                                require Net::SMTP::SSL;
                                $smtp->command('STARTTLS');
@@@ -1259,7 -1272,6 +1261,7 @@@ foreach my $t (@files) 
        open my $fh, "<", $t or die "can't open file $t";
  
        my $author = undef;
 +      my $sauthor = undef;
        my $author_encoding;
        my $has_content_type;
        my $body_encoding;
                        }
                        elsif (/^From:\s+(.*)$/i) {
                                ($author, $author_encoding) = unquote_rfc2047($1);
 +                              $sauthor = sanitize_address($author);
                                next if $suppress_cc{'author'};
 -                              next if $suppress_cc{'self'} and $author eq $sender;
 +                              next if $suppress_cc{'self'} and $sauthor eq $sender;
                                printf("(mbox) Adding cc: %s from line '%s'\n",
                                        $1, $_) unless $quiet;
                                push @cc, $1;
                        }
                        elsif (/^Cc:\s+(.*)$/i) {
                                foreach my $addr (parse_address_line($1)) {
 -                                      if (unquote_rfc2047($addr) eq $sender) {
 +                                      my $qaddr = unquote_rfc2047($addr);
 +                                      my $saddr = sanitize_address($qaddr);
 +                                      if ($saddr eq $sender) {
                                                next if ($suppress_cc{'self'});
                                        } else {
                                                next if ($suppress_cc{'cc'});
                        chomp;
                        my ($what, $c) = ($1, $2);
                        chomp $c;
 -                      if ($c eq $sender) {
 +                      my $sc = sanitize_address($c);
 +                      if ($sc eq $sender) {
                                next if ($suppress_cc{'self'});
                        } else {
                                next if $suppress_cc{'sob'} and $what =~ /Signed-off-by/i;
                $subject = quote_subject($subject, $auto_8bit_encoding);
        }
  
 -      if (defined $author and $author ne $sender) {
 +      if (defined $sauthor and $sauthor ne $sender) {
                $message = "From: $author\n\n$message";
                if (defined $author_encoding) {
                        if ($has_content_type) {
  
        # set up for the next message
        if ($thread && $message_was_sent &&
 -              (chain_reply_to() || !defined $reply_to || length($reply_to) == 0 ||
 +              ($chain_reply_to || !defined $reply_to || length($reply_to) == 0 ||
                $message_num == 1)) {
                $reply_to = $message_id;
                if (length $references > 0) {
  sub recipients_cmd {
        my ($prefix, $what, $cmd, $file) = @_;
  
 -      my $sanitized_sender = sanitize_address($sender);
        my @addresses = ();
        open my $fh, "-|", "$cmd \Q$file\E"
            or die "($prefix) Could not execute '$cmd'";
                $address =~ s/^\s*//g;
                $address =~ s/\s*$//g;
                $address = sanitize_address($address);
 -              next if ($address eq $sanitized_sender and $suppress_from);
 +              next if ($address eq $sender and $suppress_cc{'self'});
                push @addresses, $address;
                printf("($prefix) Adding %s: %s from: '%s'\n",
                       $what, $address, $cmd) unless $quiet;