Merge branch 'master' of git://git.kernel.org/pub/scm/gitk/gitk
[gitweb.git] / git-send-email.perl
index 404095f258f1eafd8f247257c2416c9dba86364b..b8b8fe7ee35aaf7a0bb84ab59b619dc554ae4dc1 100755 (executable)
@@ -74,6 +74,9 @@ sub usage {
    --suppress-from Suppress sending emails to yourself if your address
                   appears in a From: line.
 
+    --threaded    Specify that the "In-Reply-To:" header should be set on all
+                  emails. Defaults to on.
+
    --quiet       Make git-send-email less verbose.  One line per email
                   should be all that is output.
 
@@ -138,8 +141,8 @@ sub format_2822_time {
        $initial_reply_to,$initial_subject,@files,$from,$compose,$time);
 
 # Behavior modification variables
-my ($chain_reply_to, $quiet, $suppress_from, $no_signed_off_cc,
-       $dry_run) = (1, 0, 0, 0, 0);
+my ($threaded, $chain_reply_to, $quiet, $suppress_from, $no_signed_off_cc,
+       $dry_run) = (1, 1, 0, 0, 0, 0);
 my $smtp_server;
 my $envelope_sender;
 
@@ -154,9 +157,16 @@ sub format_2822_time {
        $term = new FakeTerm "$@: going non-interactive";
 }
 
-my $def_chain = $repo->config_bool('sendemail.chainreplyto');
-if (defined $def_chain and not $def_chain) {
-    $chain_reply_to = 0;
+my %config_settings = (
+    "threaded" => \$threaded,
+    "chainreplyto" => \$chain_reply_to,
+);
+
+foreach my $setting (keys %config_settings) {
+    my $default = $repo->config_bool("sendemail.$setting");
+    if (defined $default) {
+        $config_settings{$setting} = $default ? 1 : 0;
+    }
 }
 
 @bcclist = $repo->config('sendemail.bcc');
@@ -181,6 +191,7 @@ sub format_2822_time {
                    "no-signed-off-cc|no-signed-off-by-cc" => \$no_signed_off_cc,
                    "dry-run" => \$dry_run,
                    "envelope-sender=s" => \$envelope_sender,
+                   "threaded!" => \$threaded,
         );
 
 unless ($rc) {
@@ -212,7 +223,7 @@ sub format_2822_time {
 my %parse_alias = (
        # multiline formats can be supported in the future
        mutt => sub { my $fh = shift; while (<$fh>) {
-               if (/^alias\s+(\S+)\s+(.*)$/) {
+               if (/^\s*alias\s+(\S+)\s+(.*)$/) {
                        my ($alias, $addr) = ($1, $2);
                        $addr =~ s/#.*$//; # mutt allows # comments
                         # commas delimit multiple addresses
@@ -287,7 +298,7 @@ sub expand_aliases {
        $prompting++;
 }
 
-if (!defined $initial_reply_to && $prompting) {
+if ($threaded && !defined $initial_reply_to && $prompting) {
        do {
                $_= $term->readline("Message-ID to be used as In-Reply-To for the first email? ",
                        $initial_reply_to);
@@ -412,13 +423,21 @@ sub extract_valid_address {
 # 1 second since the last time we were called.
 
 # We'll setup a template for the message id, using the "from" address:
-my $message_id_from = extract_valid_address($from);
-my $message_id_template = "<%s-git-send-email-$message_id_from>";
 
 sub make_message_id
 {
        my $date = time;
        my $pseudo_rand = int (rand(4200));
+       my $du_part;
+       for ($from, $committer, $author) {
+               $du_part = extract_valid_address($_);
+               last if ($du_part ne '');
+       }
+       if ($du_part eq '') {
+               use Sys::Hostname qw();
+               $du_part = 'user@' . Sys::Hostname::hostname();
+       }
+       my $message_id_template = "<%s-git-send-email-$du_part>";
        $message_id = sprintf $message_id_template, "$date$pseudo_rand";
        #print "new message id = $message_id\n"; # Was useful for debugging
 }
@@ -467,6 +486,8 @@ sub send_message
                $ccline = "\nCc: $cc";
        }
        $from = sanitize_address_rfc822($from);
+       make_message_id();
+
        my $header = "From: $from
 To: $to${ccline}
 Subject: $subject
@@ -474,7 +495,7 @@ sub send_message
 Message-Id: $message_id
 X-Mailer: git-send-email $gitversion
 ";
-       if ($reply_to) {
+       if ($threaded && $reply_to) {
 
                $header .= "In-Reply-To: $reply_to\n";
                $header .= "References: $references\n";
@@ -533,7 +554,6 @@ sub send_message
 
 $reply_to = $initial_reply_to;
 $references = $initial_reply_to || '';
-make_message_id();
 $subject = $initial_subject;
 
 foreach my $t (@files) {
@@ -561,7 +581,8 @@ sub send_message
                                        $subject = $1;
 
                                } elsif (/^(Cc|From):\s+(.*)$/) {
-                                       if ($2 eq $from) {
+                                       if (unquote_rfc2047($2) eq $from) {
+                                               $from = $2;
                                                next if ($suppress_from);
                                        }
                                        elsif ($1 eq 'From') {
@@ -626,7 +647,6 @@ sub send_message
                        $references = "$message_id";
                }
        }
-       make_message_id();
 }
 
 if ($compose) {