@@ -41,6 +41,8 @@ sub usage {
41
41
--subject <str> * Email "Subject:"
42
42
--reply-to <str> * Email "Reply-To:"
43
43
--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.
44
46
--[no-]xmailer * Add "X-Mailer:" header (default).
45
47
--[no-]annotate * Review each patch that will be sent in an editor.
46
48
--compose * Open an editor for introduction.
@@ -68,7 +70,7 @@ sub usage {
68
70
--smtp-auth <str> * Space-separated list of allowed AUTH mechanisms, or
69
71
"none" to disable authentication.
70
72
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
72
74
`--smtp-auth=none`
73
75
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
74
76
@@ -290,6 +292,7 @@ sub do_edit {
290
292
my $mailmap = 0;
291
293
my $target_xfer_encoding = ' auto' ;
292
294
my $forbid_sendmail_variables = 1;
295
+ my $outlook_id_fix = ' auto' ;
293
296
294
297
my %config_bool_settings = (
295
298
" thread" => \$thread ,
@@ -305,6 +308,7 @@ sub do_edit {
305
308
" xmailer" => \$use_xmailer ,
306
309
" forbidsendmailvariables" => \$forbid_sendmail_variables ,
307
310
" mailmap" => \$mailmap ,
311
+ " outlookidfix" => \$outlook_id_fix ,
308
312
);
309
313
310
314
my %config_settings = (
@@ -551,6 +555,7 @@ sub config_regexp {
551
555
" relogin-delay=i" => \$relogin_delay ,
552
556
" git-completion-helper" => \$git_completion_helper ,
553
557
" v=s" => \$reroll_count ,
558
+ " outlook-id-fix!" => \$outlook_id_fix ,
554
559
);
555
560
$rc = GetOptions(%options );
556
561
@@ -1574,6 +1579,16 @@ sub gen_header {
1574
1579
return ($recipients_ref , $to , $date , $gitversion , $cc , $ccline , $header );
1575
1580
}
1576
1581
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
+
1577
1592
# Prepares the email, then asks the user what to do.
1578
1593
#
1579
1594
# If the user chooses to send the email, it's sent and 1 is returned.
@@ -1737,6 +1752,22 @@ sub send_message {
1737
1752
$smtp -> datasend(" $line " ) or die $smtp -> message;
1738
1753
}
1739
1754
$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
+
1740
1771
$smtp -> code =~ / 250|200/ or die sprintf (__(" Failed to send %s \n " ), $subject ).$smtp -> message;
1741
1772
}
1742
1773
if ($quiet ) {
0 commit comments