@matheusbsbs / matheus-bagliano / commits / 94638f89f5
Fork 0

send-email: get all the quoting of realnames right

- when sending several mails I got a slightly different behaviour for the first mail compared to the second to last one. The reason is that $from was assigned in line 608 and was not reset when beginning to handle the next mail. - Email::Valid can only handle properly quoted real names, so quote arguments to extract_valid_address. This patch cleans up variable naming to better differentiate between sender of the mail and it's author. Signed-off-by: Uwe Kleine-König <ukleinek@informatik.uni-freiburg.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Uwe Kleine-König committed Aug 9, 2007 at 15:27 UTC 94638f89f5bcd1f92b86ebf988f7974167c3fd27
1 file changed +24 -26
git-send-email.perl
+24 -26
@@ -137,7 +137,7 @@ my $compose_filename = ".msg.$$";
137
138 # Variables we fill in automatically, or via prompting:
139 my (@to,@cc,@initial_cc,@bcclist,@xh,
140 - $initial_reply_to,$initial_subject,@files,$from,$compose,$time);
140 + $initial_reply_to,$initial_subject,@files,$author,$sender,$compose,$time);
141
142 my $smtp_server;
143 my $envelope_sender;
@@ -179,7 +179,7 @@ if (!@bcclist or !$bcclist[0]) {
179 # Begin by accumulating all the variables (defined above), that we will end up
180 # needing, first, from the command line:
181
182 -my $rc = GetOptions("from=s" => \$from,
182 +my $rc = GetOptions("sender|from=s" => \$sender,
183 "in-reply-to=s" => \$initial_reply_to,
184 "subject=s" => \$initial_subject,
185 "to=s" => \@to,
@@ -216,8 +216,8 @@ foreach my $entry (@bcclist) {
216
217 # Now, let's fill any that aren't set in with defaults:
218
219 -my ($author) = $repo->ident_person('author');
220 -my ($committer) = $repo->ident_person('committer');
219 +my ($repoauthor) = $repo->ident_person('author');
220 +my ($repocommitter) = $repo->ident_person('committer');
221
222 my %aliases;
223 my @alias_files = $repo->config('sendemail.aliasesfile');
@@ -254,17 +254,17 @@ if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {
254 }
255 }
256
257 -($from) = expand_aliases($from) if defined $from;
257 +($sender) = expand_aliases($sender) if defined $sender;
258
259 my $prompting = 0;
260 -if (!defined $from) {
261 - $from = $author || $committer;
260 +if (!defined $sender) {
261 + $sender = $repoauthor || $repocommitter;
262 do {
263 - $_ = $term->readline("Who should the emails appear to be from? [$from] ");
263 + $_ = $term->readline("Who should the emails appear to be from? [$sender] ");
264 } while (!defined $_);
265
266 - $from = $_ if ($_);
267 - print "Emails will be sent from: ", $from, "\n";
266 + $sender = $_ if ($_);
267 + print "Emails will be sent from: ", $sender, "\n";
268 $prompting++;
269 }
270
@@ -330,7 +330,7 @@ if ($compose) {
330 # effort to have it be unique
331 open(C,">",$compose_filename)
332 or die "Failed to open for writing $compose_filename: $!";
333 - print C "From $from # This line is ignored.\n";
333 + print C "From $sender # This line is ignored.\n";
334 printf C "Subject: %s\n\n", $initial_subject;
335 printf C <<EOT;
336 GIT: Please enter your email below.
@@ -433,11 +433,11 @@ sub make_message_id
433 my $date = time;
434 my $pseudo_rand = int (rand(4200));
435 my $du_part;
436 - for ($from, $committer, $author) {
437 - $du_part = extract_valid_address($_);
438 - last if ($du_part ne '');
436 + for ($sender, $repocommitter, $repoauthor) {
437 + $du_part = extract_valid_address(sanitize_address($_));
438 + last if (defined $du_part and $du_part ne '');
439 }
440 - if ($du_part eq '') {
440 + if (not defined $du_part or $du_part eq '') {
441 use Sys::Hostname qw();
442 $du_part = 'user@' . Sys::Hostname::hostname();
443 }
@@ -508,10 +508,10 @@ sub send_message
508 if ($cc ne '') {
509 $ccline = "\nCc: $cc";
510 }
511 - $from = sanitize_address($from);
511 + my $sanitized_sender = sanitize_address($sender);
512 make_message_id();
513
514 - my $header = "From: $from
514 + my $header = "From: $sanitized_sender
515 To: $to${ccline}
516 Subject: $subject
517 Date: $date
@@ -528,7 +528,7 @@ X-Mailer: git-send-email $gitversion
528 }
529
530 my @sendmail_parameters = ('-i', @recipients);
531 - my $raw_from = $from;
531 + my $raw_from = $sanitized_sender;
532 $raw_from = $envelope_sender if (defined $envelope_sender);
533 $raw_from = extract_valid_address($raw_from);
534 unshift (@sendmail_parameters,
@@ -565,7 +565,7 @@ X-Mailer: git-send-email $gitversion
565 } else {
566 print "Sendmail: $smtp_server ".join(' ',@sendmail_parameters)."\n";
567 }
568 - print "From: $from\nSubject: $subject\nCc: $cc\nTo: $to\n\n";
568 + print "From: $sanitized_sender\nSubject: $subject\nCc: $cc\nTo: $to\n\n";
569 if ($smtp) {
570 print "Result: ", $smtp->code, ' ',
571 ($smtp->message =~ /\n([^\n]+\n)$/s), "\n";
@@ -582,7 +582,7 @@ $subject = $initial_subject;
582 foreach my $t (@files) {
583 open(F,"<",$t) or die "can't open file $t";
584
585 - my $author_not_sender = undef;
585 + my $author = undef;
586 @cc = @initial_cc;
587 @xh = ();
588 my $input_format = undef;
@@ -604,12 +604,11 @@ foreach my $t (@files) {
604 $subject = $1;
605
606 } elsif (/^(Cc|From):\s+(.*)$/) {
607 - if (unquote_rfc2047($2) eq $from) {
608 - $from = $2;
607 + if (unquote_rfc2047($2) eq $sender) {
608 next if ($suppress_from);
609 }
610 elsif ($1 eq 'From') {
612 - $author_not_sender = $2;
611 + $author = unquote_rfc2047($2);
612 }
613 printf("(mbox) Adding cc: %s from line '%s'\n",
614 $2, $_) unless $quiet;
@@ -653,9 +652,8 @@ foreach my $t (@files) {
652 }
653 }
654 close F;
656 - if (defined $author_not_sender) {
657 - $author_not_sender = unquote_rfc2047($author_not_sender);
658 - $message = "From: $author_not_sender\n\n$message";
655 + if (defined $author) {
656 + $message = "From: $author\n\n$message";
657 }
658
659