~ubuntu-branches/ubuntu/intrepid/git-core/intrepid-updates

« back to all changes in this revision

Viewing changes to git-send-email.perl

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-05-01 08:59:06 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20070501085906-n1e5qzoc00wvlzt3
Tags: 1:1.5.1.3-1
* new upstream point release.
  * git-add tried to optimize by finding common leading directories
    across its arguments but botched, causing very confused behaviour
    (closes: #420671).
  * Documentation/git-reset.txt: suggest git commit --amend in example
    (closes: #420112).
  * unofficial rpm.spec file shipped with git was letting ETC_GITCONFIG
    set to /usr/etc/gitconfig.  Tweak the official Makefile to make it
    harder for distro people to make the same mistake, by setting the
    variable to /etc/gitconfig if prefix is set to /usr (closes:
    #420675).
* debian/changelog.upstream: upstream changes taken from mailing list
  announcement.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
   --quiet        Make git-send-email less verbose.  One line per email
78
78
                  should be all that is output.
79
79
 
 
80
   --dry-run      Do everything except actually send the emails.
 
81
 
 
82
   --envelope-sender    Specify the envelope sender used to send the emails.
 
83
 
80
84
EOT
81
85
        exit(1);
82
86
}
137
141
my ($chain_reply_to, $quiet, $suppress_from, $no_signed_off_cc,
138
142
        $dry_run) = (1, 0, 0, 0, 0);
139
143
my $smtp_server;
 
144
my $envelope_sender;
140
145
 
141
146
# Example reply to:
142
147
#$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>';
175
180
                    "suppress-from" => \$suppress_from,
176
181
                    "no-signed-off-cc|no-signed-off-by-cc" => \$no_signed_off_cc,
177
182
                    "dry-run" => \$dry_run,
 
183
                    "envelope-sender=s" => \$envelope_sender,
178
184
         );
179
185
 
180
186
unless ($rc) {
268
274
}
269
275
 
270
276
@to = expand_aliases(@to);
 
277
@to = (map { sanitize_address_rfc822($_) } @to);
271
278
@initial_cc = expand_aliases(@initial_cc);
272
279
@bcclist = expand_aliases(@bcclist);
273
280
 
377
384
}
378
385
 
379
386
# Variables we set as part of the loop over files
380
 
our ($message_id, $cc, %mail, $subject, $reply_to, $references, $message);
 
387
our ($message_id, %mail, $subject, $reply_to, $references, $message);
381
388
 
382
389
sub extract_valid_address {
383
390
        my $address = shift;
418
425
 
419
426
 
420
427
 
421
 
$cc = "";
422
428
$time = time - scalar $#files;
423
429
 
424
430
sub unquote_rfc2047 {
430
436
        return "$_";
431
437
}
432
438
 
 
439
# If an address contains a . in the name portion, the name must be quoted.
 
440
sub sanitize_address_rfc822
 
441
{
 
442
        my ($recipient) = @_;
 
443
        my ($recipient_name) = ($recipient =~ /^(.*?)\s+</);
 
444
        if ($recipient_name && $recipient_name =~ /\./ && $recipient_name !~ /^".*"$/) {
 
445
                my ($name, $addr) = ($recipient =~ /^(.*?)(\s+<.*)/);
 
446
                $recipient = "\"$name\"$addr";
 
447
        }
 
448
        return $recipient;
 
449
}
 
450
 
433
451
sub send_message
434
452
{
435
453
        my @recipients = unique_email_list(@to);
 
454
        @cc = (map { sanitize_address_rfc822($_) } @cc);
436
455
        my $to = join (",\n\t", @recipients);
437
456
        @recipients = unique_email_list(@recipients,@cc,@bcclist);
 
457
        @recipients = (map { extract_valid_address($_) } @recipients);
438
458
        my $date = format_2822_time($time++);
439
459
        my $gitversion = '@@GIT_VERSION@@';
440
460
        if ($gitversion =~ m/..GIT_VERSION../) {
441
461
            $gitversion = Git::version();
442
462
        }
443
463
 
444
 
        my ($author_name) = ($from =~ /^(.*?)\s+</);
445
 
        if ($author_name && $author_name =~ /\./ && $author_name !~ /^".*"$/) {
446
 
                my ($name, $addr) = ($from =~ /^(.*?)(\s+<.*)/);
447
 
                $from = "\"$name\"$addr";
448
 
        }
 
464
        my $cc = join(", ", unique_email_list(@cc));
 
465
        $from = sanitize_address_rfc822($from);
449
466
        my $header = "From: $from
450
467
To: $to
451
468
Cc: $cc
463
480
                $header .= join("\n", @xh) . "\n";
464
481
        }
465
482
 
 
483
        my @sendmail_parameters = ('-i', @recipients);
 
484
        my $raw_from = $from;
 
485
        $raw_from = $envelope_sender if (defined $envelope_sender);
 
486
        $raw_from = extract_valid_address($raw_from);
 
487
        unshift (@sendmail_parameters,
 
488
                        '-f', $raw_from) if(defined $envelope_sender);
 
489
 
466
490
        if ($dry_run) {
467
491
                # We don't want to send the email.
468
492
        } elsif ($smtp_server =~ m#^/#) {
469
493
                my $pid = open my $sm, '|-';
470
494
                defined $pid or die $!;
471
495
                if (!$pid) {
472
 
                        exec($smtp_server,'-i',
473
 
                             map { extract_valid_address($_) }
474
 
                             @recipients) or die $!;
 
496
                        exec($smtp_server, @sendmail_parameters) or die $!;
475
497
                }
476
498
                print $sm "$header\n$message";
477
499
                close $sm or die $?;
478
500
        } else {
479
501
                require Net::SMTP;
480
502
                $smtp ||= Net::SMTP->new( $smtp_server );
481
 
                $smtp->mail( $from ) or die $smtp->message;
 
503
                $smtp->mail( $raw_from ) or die $smtp->message;
482
504
                $smtp->to( @recipients ) or die $smtp->message;
483
505
                $smtp->data or die $smtp->message;
484
506
                $smtp->datasend("$header\n$message") or die $smtp->message;
486
508
                $smtp->ok or die "Failed to send $subject\n".$smtp->message;
487
509
        }
488
510
        if ($quiet) {
489
 
                printf "Sent %s\n", $subject;
 
511
                printf (($dry_run ? "Dry-" : "")."Sent %s\n", $subject);
490
512
        } else {
491
 
                print "OK. Log says:\nDate: $date\n";
492
 
                if ($smtp) {
 
513
                print (($dry_run ? "Dry-" : "")."OK. Log says:\nDate: $date\n");
 
514
                if ($smtp_server !~ m#^/#) {
493
515
                        print "Server: $smtp_server\n";
 
516
                        print "MAIL FROM:<$raw_from>\n";
 
517
                        print "RCPT TO:".join(',',(map { "<$_>" } @recipients))."\n";
494
518
                } else {
495
 
                        print "Sendmail: $smtp_server\n";
 
519
                        print "Sendmail: $smtp_server ".join(' ',@sendmail_parameters)."\n";
496
520
                }
497
521
                print "From: $from\nSubject: $subject\nCc: $cc\nTo: $to\n\n";
498
522
                if ($smtp) {
587
611
                $message = "From: $author_not_sender\n\n$message";
588
612
        }
589
613
 
590
 
        $cc = join(", ", unique_email_list(@cc));
591
614
 
592
615
        send_message();
593
616