public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Aditya Garg <gargaditya08@live.com>
Cc: Julian Swagemakers <julian@swagemakers.org>,
	 git@vger.kernel.org,  M Hickford <mirth.hickford@gmail.com>,
	 sandals@crustytoothpaste.net, Shengyu Qu <wiagn233@outlook.com>
Subject: Re: [PATCH v3 2/3] send-email: retrieve Message-ID from outlook SMTP server
Date: Tue, 22 Apr 2025 15:05:51 -0700	[thread overview]
Message-ID: <xmqqmsc73l8g.fsf@gitster.g> (raw)
In-Reply-To: <PN3PR01MB9597D68A4E7A570949672832B8BB2@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM> (Aditya Garg's message of "Tue, 22 Apr 2025 15:23:20 +0000")

Aditya Garg <gargaditya08@live.com> writes:

> Outlook does not accept the Message-ID header in the email body. Instead
> it saves it in its own proprietary X-Microsoft-Original-Message-ID
> header and a random Message-ID is set my the server. As a result,
> replying to threads does not work.
>
> The $smtp->message variable in this script for outlook is something like
> this:
>
> 2.0.0 OK <Message-ID> [Hostname=Some-hostname]
>
> This contains the Message-ID set by Microsoft in the first <>.
>
> This patch retrieves the Message-ID from this server response
> and sets it in the email headers instead of using the self generated one.

Hmph.

send_message calls gen_header as the first thing.  This prepares the
usual From:/To:/Subject:/Date:/Message-ID: lines and returns the
header text as well as recipient addresses broken out into different
classes, among other things.

> Signed-off-by: Aditya Garg <gargaditya08@live.com>
> ---
>  git-send-email.perl | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/git-send-email.perl b/git-send-email.perl
> index a6cafda29c..216b23caa5 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -1799,6 +1799,17 @@ sub send_message {

And before these pre-context lines, the composed $header that
contains the message_id has already been sent by calling datasend()
method on the smtp object.  After that, we are ...

>  			$smtp->datasend("$line") or die $smtp->message;
>  		}

... sending the body of the e-mail here.

So it is not clear to me how ovewriting the $message_id variable
after the message with $header with "Message-ID:" line that
contained the ID we generated has already given to the SMTP server.
What the code is doing certainly contradicts with what the proposed
log message explains it does, i.e.

	... sets it in the email headers instead of using ...

It would affect the message-ID that is used by subsequent messages
when they are sent as replies to this message.  I do not think we
computed the header (the In-Reply-To: field) for the next message
at this point of the code, and I can well believe that mucking with
the $message variable at this point would make the next message
correctly a response to this one.

Perhaps you meant that Outlook DISCARDS the Message-ID: field in the
message it was instructed to send out, and INSERTS its own?  Then I
can see how this patch would improve the situation, but the last
paragraph in the proposed log message needs to be rewritten.


	After sending a message, retrieve the message-ID the Outlook
	server assigned to the message and store it in $message_id
	variable; this value will be used when next and subsequent
	message are sent as replies to the message, preserving the
	threading of the messages.

or something.

> +		# Retrieve the Message-ID from the server response in case of Outlook
> +		if ($smtp_server eq 'smtp.office365.com' || $smtp_server eq 'smtp-mail.outlook.com') {

Perhaps a small helper sub

	sub is_outlook {
		my ($host) = @_;
		return ($host eq '...' ||
			$host eq '...');
	}

would make it easier to maintain (and read).

> +			if ($smtp->message =~ /<([^>]+)>/) {
> +				$message_id = "<$1>";
> +				printf __("Outlook: Retrieved Message-ID: %s\n"), $message_id;

Is this worth reporting, or more or less a leftover debugging aid?

The fact that we retrieved (as opposed to "could not retrieve" case)
may have been significant during the development of this feature,
but to end-users who see this message, retrieved is not at all
interesting.  What is interesting to them is that the server gave
your message some random Message-ID you've never heard of, so while
it may make sense to report what that ID is, perhaps 

	Outlook reassigned Messsage-ID: %s

might be more meaningful to them.  rewritten, reassigned, used,
there may be even better verbs, but the point is that the subject of
that sentence is the outlook smtp serveron the other end of the
connection (as opposed to the actor of "retrived" is the program
running on our end).

> +			} else {
> +				warn __("Warning: Could not retrieve Message-ID from server response.\n");
> +			}
> +		}
> +
>  		$smtp->code =~ /250|200/ or die sprintf(__("Failed to send %s\n"), $subject).$smtp->message;
>  	}
>  	if ($quiet) {

  reply	other threads:[~2025-04-22 22:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-22 15:23 [PATCH v3 0/3] send-email: add oauth2 support and fix outlook breaking threads Aditya Garg
2025-04-22 15:23 ` [PATCH v3 1/3] send-email: implement SMTP bearer authentication Aditya Garg
2025-04-22 15:23 ` [PATCH v3 2/3] send-email: retrieve Message-ID from outlook SMTP server Aditya Garg
2025-04-22 22:05   ` Junio C Hamano [this message]
2025-04-23  3:22     ` Aditya Garg
2025-04-23 15:34       ` Junio C Hamano
2025-04-23 16:24         ` Aditya Garg
2025-04-22 15:23 ` [PATCH v3 3/3] send-email: add option to generate passswords like OAuth2 tokens Aditya Garg
2025-04-22 22:20   ` Junio C Hamano
2025-04-23  3:10     ` Aditya Garg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqmsc73l8g.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=gargaditya08@live.com \
    --cc=git@vger.kernel.org \
    --cc=julian@swagemakers.org \
    --cc=mirth.hickford@gmail.com \
    --cc=sandals@crustytoothpaste.net \
    --cc=wiagn233@outlook.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox