Skip to content

Commit 38758be

Browse files
committed
Merge branch 'ag/send-email-outlook'
Update send-email to work better with Outlook's smtp server. * ag/send-email-outlook: send-email: add --[no-]outlook-id-fix option send-email: retrieve Message-ID from outlook SMTP server
2 parents 7a1d2bd + daec3c0 commit 38758be

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

Documentation/git-send-email.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ illustration below where `[PATCH v2 0/3]` is in reply to `[PATCH 0/2]`:
115115
Only necessary if --compose is also set. If --compose
116116
is not set, this will be prompted for.
117117

118+
--[no-]outlook-id-fix::
119+
Microsoft Outlook SMTP servers discard the Message-ID sent via email and
120+
assign a new random Message-ID, thus breaking threads.
121+
+
122+
With `--outlook-id-fix`, 'git send-email' uses a mechanism specific to
123+
Outlook servers to learn the Message-ID the server assigned to fix the
124+
threading. Use it only when you know that the server reports the
125+
rewritten Message-ID the same way as Outlook servers do.
126+
+
127+
Without this option specified, the fix is done by default when talking
128+
to 'smtp.office365.com' or 'smtp-mail.outlook.com'. Use
129+
`--no-outlook-id-fix` to disable even when talking to these two servers.
130+
118131
--subject=<string>::
119132
Specify the initial subject of the email thread.
120133
Only necessary if --compose is also set. If --compose

git-send-email.perl

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ sub usage {
4141
--subject <str> * Email "Subject:"
4242
--reply-to <str> * Email "Reply-To:"
4343
--in-reply-to <str> * Email "In-Reply-To:"
44+
--[no-]outlook-id-fix * The SMTP host is an Outlook server that munges the
45+
Message-ID. Retrieve it from the server.
4446
--[no-]xmailer * Add "X-Mailer:" header (default).
4547
--[no-]annotate * Review each patch that will be sent in an editor.
4648
--compose * Open an editor for introduction.
@@ -68,7 +70,7 @@ sub usage {
6870
--smtp-auth <str> * Space-separated list of allowed AUTH mechanisms, or
6971
"none" to disable authentication.
7072
This setting forces to use one of the listed mechanisms.
71-
--no-smtp-auth Disable SMTP authentication. Shorthand for
73+
--no-smtp-auth * Disable SMTP authentication. Shorthand for
7274
`--smtp-auth=none`
7375
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
7476
@@ -290,6 +292,7 @@ sub do_edit {
290292
my $mailmap = 0;
291293
my $target_xfer_encoding = 'auto';
292294
my $forbid_sendmail_variables = 1;
295+
my $outlook_id_fix = 'auto';
293296

294297
my %config_bool_settings = (
295298
"thread" => \$thread,
@@ -305,6 +308,7 @@ sub do_edit {
305308
"xmailer" => \$use_xmailer,
306309
"forbidsendmailvariables" => \$forbid_sendmail_variables,
307310
"mailmap" => \$mailmap,
311+
"outlookidfix" => \$outlook_id_fix,
308312
);
309313

310314
my %config_settings = (
@@ -551,6 +555,7 @@ sub config_regexp {
551555
"relogin-delay=i" => \$relogin_delay,
552556
"git-completion-helper" => \$git_completion_helper,
553557
"v=s" => \$reroll_count,
558+
"outlook-id-fix!" => \$outlook_id_fix,
554559
);
555560
$rc = GetOptions(%options);
556561

@@ -1574,6 +1579,16 @@ sub gen_header {
15741579
return ($recipients_ref, $to, $date, $gitversion, $cc, $ccline, $header);
15751580
}
15761581

1582+
sub is_outlook {
1583+
my ($host) = @_;
1584+
if ($outlook_id_fix eq 'auto') {
1585+
$outlook_id_fix =
1586+
($host eq 'smtp.office365.com' ||
1587+
$host eq 'smtp-mail.outlook.com') ? 1 : 0;
1588+
}
1589+
return $outlook_id_fix;
1590+
}
1591+
15771592
# Prepares the email, then asks the user what to do.
15781593
#
15791594
# If the user chooses to send the email, it's sent and 1 is returned.
@@ -1737,6 +1752,22 @@ sub send_message {
17371752
$smtp->datasend("$line") or die $smtp->message;
17381753
}
17391754
$smtp->dataend() or die $smtp->message;
1755+
1756+
# Outlook discards the Message-ID header we set while sending the email
1757+
# and generates a new random Message-ID. So in order to avoid breaking
1758+
# threads, we simply retrieve the Message-ID from the server response
1759+
# and assign it to the $message_id variable, which will then be
1760+
# assigned to $in_reply_to by the caller when the next message is sent
1761+
# as a response to this message.
1762+
if (is_outlook($smtp_server)) {
1763+
if ($smtp->message =~ /<([^>]+)>/) {
1764+
$message_id = "<$1>";
1765+
printf __("Outlook reassigned Message-ID to: %s\n"), $message_id;
1766+
} else {
1767+
warn __("Warning: Could not retrieve Message-ID from server response.\n");
1768+
}
1769+
}
1770+
17401771
$smtp->code =~ /250|200/ or die sprintf(__("Failed to send %s\n"), $subject).$smtp->message;
17411772
}
17421773
if ($quiet) {

0 commit comments

Comments
 (0)