@@ -46,6 +46,8 @@ sub usage {
--compose-encoding <str> * Encoding to assume for introduction.
--8bit-encoding <str> * Encoding to assume 8bit mails if undeclared
--transfer-encoding <str> * Transfer encoding to use (quoted-printable, 8bit, base64)
+ --[no-]mailmap * Use mailmap file to map all email addresses to canonical
+ real names and email addresses.
Sending:
--envelope-sender <str> * Email envelope sender.
@@ -272,12 +274,14 @@ sub do_edit {
my ($auto_8bit_encoding);
my ($compose_encoding);
my ($sendmail_cmd);
+my ($mailmap_file, $mailmap_blob);
# Variables with corresponding config settings & hardcoded defaults
my ($debug_net_smtp) = 0; # Net::SMTP, see send_message()
my $thread = 1;
my $chain_reply_to = 0;
my $use_xmailer = 1;
my $validate = 1;
+my $mailmap = 0;
my $target_xfer_encoding = 'auto';
my $forbid_sendmail_variables = 1;
@@ -294,6 +298,7 @@ sub do_edit {
"annotate" => \$annotate,
"xmailer" => \$use_xmailer,
"forbidsendmailvariables" => \$forbid_sendmail_variables,
+ "mailmap" => \$mailmap,
);
my %config_settings = (
@@ -327,6 +332,8 @@ sub do_edit {
my %config_path_settings = (
"aliasesfile" => \@alias_files,
"smtpsslcertpath" => \$smtp_ssl_cert_path,
+ "mailmap.file" => \$mailmap_file,
+ "mailmap.blob" => \$mailmap_blob,
);
# Handle Uncouth Termination
@@ -524,6 +531,8 @@ sub config_regexp {
"thread!" => \$thread,
"validate!" => \$validate,
"transfer-encoding=s" => \$target_xfer_encoding,
+ "mailmap!" => \$mailmap,
+ "use-mailmap!" => \$mailmap,
"format-patch!" => \$format_patch,
"8bit-encoding=s" => \$auto_8bit_encoding,
"compose-encoding=s" => \$compose_encoding,
@@ -1085,6 +1094,16 @@ sub expand_one_alias {
our ($message_id, %mail, $subject, $in_reply_to, $references, $message,
$needs_confirm, $message_num, $ask_default);
+sub mailmap_address_list {
+ return @_ unless @_ and $mailmap;
+ my @options = ();
+ push(@options, "--mailmap-file=$mailmap_file") if $mailmap_file;
+ push(@options, "--mailmap-blob=$mailmap_blob") if $mailmap_blob;
+ my @addr_list = Git::command('check-mailmap', @options, @_);
+ s/^<(.*)>$/$1/ for @addr_list;
+ return @addr_list;
+}
+
sub extract_valid_address {
my $address = shift;
my $local_part_regexp = qr/[^<>"\s@]+/;
@@ -1294,6 +1313,7 @@ sub process_address_list {
@addr_list = expand_aliases(@addr_list);
@addr_list = sanitize_address_list(@addr_list);
@addr_list = validate_address_list(@addr_list);
+ @addr_list = mailmap_address_list(@addr_list);
return @addr_list;
}
@@ -2379,6 +2379,128 @@ test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
test_cmp expected-list actual-list
'
+test_expect_success $PREREQ 'mailmap support with --to' '
+ clean_fake_sendmail &&
+ test_config mailmap.file "mailmap.test" &&
+ cat >mailmap.test <<-EOF &&
+ Some Body <someone@example.com> <someone@example.org>
+ EOF
+ git format-patch --stdout -1 >a.patch &&
+ git send-email \
+ --from="Example <nobody@example.com>" \
+ --smtp-server="$(pwd)/fake.sendmail" \
+ --to=someone@example.org \
+ --mailmap \
+ a.patch \
+ 2>errors >out &&
+ grep "^!someone@example\.com!$" commandline1
+'
+
+test_expect_success $PREREQ 'sendemail.mailmap configuration' '
+ clean_fake_sendmail &&
+ test_config mailmap.file "mailmap.test" &&
+ test_config sendemail.mailmap "true" &&
+ cat >mailmap.test <<-EOF &&
+ Some Body <someone@example.com> <someone@example.org>
+ EOF
+ git format-patch --stdout -1 >a.patch &&
+ git send-email \
+ --from="Example <nobody@example.com>" \
+ --smtp-server="$(pwd)/fake.sendmail" \
+ --to=someone@example.org \
+ a.patch \
+ 2>errors >out &&
+ grep "^!someone@example\.com!$" commandline1
+'
+
+test_expect_success $PREREQ 'sendemail.mailmap.file configuration' '
+ clean_fake_sendmail &&
+ test_config sendemail.mailmap.file "mailmap.test" &&
+ test_config sendemail.mailmap "true" &&
+ cat >mailmap.test <<-EOF &&
+ Some Body <someone@example.com> <someone@example.org>
+ EOF
+ git format-patch --stdout -1 >a.patch &&
+ git send-email \
+ --from="Example <nobody@example.com>" \
+ --smtp-server="$(pwd)/fake.sendmail" \
+ --to=someone@example.org \
+ a.patch \
+ 2>errors >out &&
+ grep "^!someone@example\.com!$" commandline1
+'
+
+test_expect_success $PREREQ 'sendemail.mailmap identity overrides configuration' '
+ clean_fake_sendmail &&
+ test_config sendemail.cloud.mailmap.file "mailmap.test" &&
+ test_config sendemail.mailmap "false" &&
+ test_config sendemail.cloud.mailmap "true" &&
+ cat >mailmap.test <<-EOF &&
+ Some Body <someone@example.com> <someone@example.org>
+ EOF
+ git format-patch --stdout -1 >a.patch &&
+ git send-email \
+ --from="Example <nobody@example.com>" \
+ --smtp-server="$(pwd)/fake.sendmail" \
+ --identity=cloud \
+ --to=someone@example.org \
+ a.patch \
+ 2>errors >out &&
+ grep "^!someone@example\.com!$" commandline1
+'
+
+test_expect_success $PREREQ '--no-mailmap overrides configuration' '
+ clean_fake_sendmail &&
+ test_config sendemail.cloud.mailmap.file "mailmap.test" &&
+ test_config sendemail.mailmap "false" &&
+ test_config sendemail.cloud.mailmap "true" &&
+ cat >mailmap.test <<-EOF &&
+ Some Body <someone@example.com> <someone@example.org>
+ EOF
+ git format-patch --stdout -1 >a.patch &&
+ git send-email \
+ --from="Example <nobody@example.com>" \
+ --smtp-server="$(pwd)/fake.sendmail" \
+ --identity=cloud \
+ --to=someone@example.org \
+ --no-mailmap \
+ a.patch \
+ 2>errors >out &&
+ grep "^!someone@example\.org!$" commandline1
+'
+
+test_expect_success $PREREQ 'mailmap support in To header' '
+ clean_fake_sendmail &&
+ test_config mailmap.file "mailmap.test" &&
+ cat >mailmap.test <<-EOF &&
+ <someone@example.com> <someone@example.org>
+ EOF
+ git format-patch --stdout -1 --to=someone@example.org >a.patch &&
+ git send-email \
+ --from="Example <nobody@example.com>" \
+ --smtp-server="$(pwd)/fake.sendmail" \
+ --mailmap \
+ a.patch \
+ 2>errors >out &&
+ grep "^!someone@example\.com!$" commandline1
+'
+
+test_expect_success $PREREQ 'mailmap support in Cc header' '
+ clean_fake_sendmail &&
+ test_config mailmap.file "mailmap.test" &&
+ cat >mailmap.test <<-EOF &&
+ <someone@example.com> <someone@example.org>
+ EOF
+ git format-patch --stdout -1 --cc=someone@example.org >a.patch &&
+ git send-email \
+ --from="Example <nobody@example.com>" \
+ --smtp-server="$(pwd)/fake.sendmail" \
+ --mailmap \
+ a.patch \
+ 2>errors >out &&
+ grep "^!someone@example\.com!$" commandline1
+'
+
test_expect_success $PREREQ 'test using command name with --sendmail-cmd' '
clean_fake_sendmail &&
PATH="$PWD:$PATH" \