From: Tom Russello <tom.russello@xxxxxxxxxxxxxxxxxxxxxxx> This new option takes an email message file, parses it, fills the "To", "Subject" and "Cc" fields appropriately and quote the message. This option involves the `--compose` mode to edit the cover letter quoting the given email. Signed-off-by: Tom Russello <tom.russello@xxxxxxxxxxxxxxxx> Signed-off-by: Samuel Groot <samuel.groot@xxxxxxxxxxxxxxxx> Signed-off-by: Matthieu Moy <matthieu.moy@xxxxxxxxxxxxxxx> --- diff --git a/git-send-email.perl b/git-send-email.perl index 6958785..784b8a6 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -55,6 +55,7 @@ git send-email --dump-aliases --[no-]bcc <str> * Email Bcc: --subject <str> * Email "Subject:" --in-reply-to <str> * Email "In-Reply-To:" + --quote-mail <str> * Email To, Cc and quote the message. --[no-]xmailer * Add "X-Mailer:" header (default). --[no-]annotate * Review each patch that will be sent in an editor. --compose * Open an editor for introduction. @@ -160,7 +161,7 @@ my $re_encoded_word = qr/=\?($re_token)\?($re_token)\?($re_encoded_text)\?=/; # Variables we fill in automatically, or via prompting: my (@to,$no_to,@initial_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh, - $initial_reply_to,$initial_subject,@files, + $initial_reply_to,$quote_mail,$initial_subject,@files, $author,$sender,$smtp_authpass,$annotate,$use_xmailer,$compose,$time); my $envelope_sender; @@ -304,6 +305,7 @@ $rc = GetOptions( "sender|from=s" => \$sender, "in-reply-to=s" => \$initial_reply_to, "subject=s" => \$initial_subject, + "quote-mail=s" => \$quote_mail, "to=s" => \@initial_to, "to-cmd=s" => \$to_cmd, "no-to" => \$no_to, @@ -638,6 +640,98 @@ if (@files) { print STDERR "\nNo patch files specified!\n\n"; usage(); } +my $message_quoted; +if ($quote_mail) { + $message_quoted = ""; + my $error = validate_patch($quote_mail); + $error and die "fatal: $quote_mail: $error\nwarning: no patches were sent\n"; + $compose = 1; + my @header = (); + open my $fh, "<", $quote_mail or die "can't open file $quote_mail"; + while(<$fh>) { + #for files containing crlf line endings + $_=~ s/\r//g; + last if /^\s*$/; + if (/^\s+\S/ and @header) { + chomp($header[$#header]); + s/^\s+/ /; + $header[$#header] .= $_; + } else { + push(@header, $_); + } + } + + foreach(@header) { + my $input_format; + my $initial_sender = $sender || $repoauthor || $repocommitter || ''; + if (/^From /) { + $input_format = 'mbox'; + next; + } + chomp; + if (!defined $input_format && /^[-A-Za-z]+:\s/) { + $input_format = 'mbox'; + } + + if (defined $input_format && $input_format eq 'mbox') { + if (/^Subject:\s+(.*)$/i) { + my $prefix_re = ""; + my $subject_re = $1; + if ($1=~/^[^Re:]/) { + $prefix_re = "Re: "; + } + $initial_subject = $prefix_re.$subject_re; + } + elsif (/^From:\s+(.*)$/i) { + push @initial_to, $1; + } + elsif (/^To:\s+(.*)$/i) { + foreach my $addr (parse_address_line($1)) { + if (!($addr eq $initial_sender)) { + push @initial_to, $addr; + } + } + } elsif (/^Cc:\s+(.*)$/i) { + foreach my $addr (parse_address_line($1)) { + my $qaddr = unquote_rfc2047($addr); + my $saddr = sanitize_address($qaddr); + if ($saddr eq $initial_sender) { + next if ($suppress_cc{'self'}); + } else { + next if ($suppress_cc{'cc'}); + } + push @initial_cc, $addr; + } + } elsif (/^Message-Id: (.*)/i) { + $initial_reply_to = $1; + } + } else { + # In the traditional + # "send lots of email" format, + # line 1 = cc + # line 2 = subject + # So let's support that, too. + $input_format = 'lots'; + if (@cc == 0 && !$suppress_cc{'cc'}) { + push @cc, $_; + } elsif (!defined $initial_subject) { + $initial_subject = $_; + } + } + } + + #Message body + while (<$fh>) { + #for files containing crlf line endings + $_=~ s/\r//g; + my $space=""; + if (/^[^>]/) { + $space = " "; + } + $message_quoted .= ">".$space.$_; + } + +} sub get_patch_subject { my $fn = shift; @@ -664,6 +758,7 @@ if ($compose) { my $tpl_sender = $sender || $repoauthor || $repocommitter || ''; my $tpl_subject = $initial_subject || ''; my $tpl_reply_to = $initial_reply_to || ''; + my $tpl_quote = $message_quoted || ''; print $c <<EOT; From $tpl_sender # This line is ignored. @@ -676,6 +771,8 @@ From: $tpl_sender Subject: $tpl_subject In-Reply-To: $tpl_reply_to +$tpl_quote + EOT for my $f (@files) { print $c get_patch_subject($f); -- 2.8.2 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html