@@ -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 {
290292my $mailmap = 0;
291293my $target_xfer_encoding = ' auto' ;
292294my $forbid_sendmail_variables = 1;
295+ my $outlook_id_fix = ' auto' ;
293296
294297my %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
310314my %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