{"thread":{"id":"63526","subject":"[PATCH v4 0/2] send-email: fix threads breaking in case user edits emails and improvements to outlook ID fix.","startedAt":"2025-05-26T15:51:47Z","lastAt":"2025-06-04T16:31:15Z","messageCount":14,"participants":["Aditya Garg","Junio C Hamano"],"isPatch":true,"patchVersion":4,"patchTotal":2},"messages":[{"id":"518944","messageId":"cover.1748274404.git.gargaditya08@live.com","threadId":"63526","inReplyTo":null,"subject":"[PATCH v4 0/2] send-email: fix threads breaking in case user edits emails and improvements to outlook ID fix.","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-05-26T15:51:41Z","receivedAt":"2025-05-26T15:51:47Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Hi all,\n\nThis patch series fixes two minor issues with git-send-email.\n\nThe first patch fixes a bug that caused the message number to increase\nwhen a user edits an email. As a result of this bug, threads would\nbreak when a user edits an email.\n\nThe second patch improves the logging of the new message ID assigned by\nOutlook when a user edits an email.\n\nv2 - Change the bugfix logic used to fix the threading bug.\nv3 - Add additional patch to improve the logging of the new\n     message ID assigned by Outlook.\nv4 - Completely rewrite the commit message of the first patch to\n     explain the bug in detail and how it is fixed. Also, add\n     example logs to explain the second patch.\n\nAditya Garg (2):\n  send-email: fix bug resulting in increased message number if a message\n    is edited\n  send-email: show the new message id assigned by outlook in the logs\n\n git-send-email.perl | 16 +++++++++++++++-\n 1 file changed, 15 insertions(+), 1 deletion(-)\n\nRange-diff:\n1:  259e20261e ! 1:  63addf9d9b send-email: fix bug resulting in increased message number if a message is edited\n    @@ Metadata\n      ## Commit message ##\n         send-email: fix bug resulting in increased message number if a message is edited\n     \n    -    In case a message is edited before it is sent, its message number gets\n    -    increased by 1, and so does its order in the message id. The cause of\n    -    this bug was that when a person attempts to edit the message, the whole\n    -    sub process_file gets terminated, and the user is asked to edit the message.\n    -    After necessary edits are done, the whole sub process_file is executed again.\n    -    The way sub process_file is designed, every time is runs, it increases the\n    -    $message_num variable by 1. The reason for this was that the function ran\n    -    again everytime a next message was sent in a thread, and thus we need to\n    -    increase the message number for that message. In case a user edits the message,\n    -    there is no check for the same and the new message gets treated as a subsequent\n    -    message of a thread, therefore increasing its message number by one. This\n    -    breaks the shallow thread logic which relies on $message_num being 1 for the\n    -    first message, and it gets changed in case the user edits the first message.\n    -\n    -    So, upon scanning the whole code, there are two significant variables at play\n    -    here. First is $message_num, responsible for the message number and second\n    -    is $message_id_serial, responsible for showing the message number in the\n    -    Message-ID header. So, whenever we edit a message, lets just decrease them\n    -    by 1, so that when the whole process to compose and send the message starts,\n    -    these variables increase by 1 again, thus get set to the original values for\n    -    that message.\n    -\n    -    We also are doing the same thing in case the user chooses to not send a message\n    -    out of many messages in a thread. By doing so, we will simply decrease these\n    -    variables by 1 for further messages, thus ensuring the whole thread doesn't\n    -    break.\n    +    Whenever we send a thread of emails using send-email, a message number\n    +    is internally assigned to each email. This number is used to track the\n    +    order of the emails in the thread. Whenever a new message is processed\n    +    in a thread, the current script logic increases the message number by\n    +    one, which is intended.\n    +\n    +    But, if a message is edited and then resent, its message number again\n    +    gets increased. This is because the script uses the same logic to\n    +    process the edited message, which is uses the send the next message.\n    +\n    +    This minor bug is usually harmless unless some special situations arise.\n    +    One such situation is when the first message in a thread is edited\n    +    and resent, and an `--in-reply-to` argument is also passed to send-email.\n    +    In this case if the user has chosen shallow threading, the threading\n    +    does not work as expected, and all messaged become as replies to the\n    +    Message-ID specified in the `--in-reply-to` argument.\n    +\n    +    The reason for this bug is hidden in the code for threading itself.\n    +\n    +    if ($thread) {\n    +            if ($message_was_sent &&\n    +              ($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 ||\n    +              $message_num == 1)) {\n    +                    $in_reply_to = $message_id;\n    +                    if (length $references > 0) {\n    +                            $references .= \"\\n $message_id\";\n    +                    } else {\n    +                            $references = \"$message_id\";\n    +                    }\n    +            }\n    +    }\n    +\n    +    Here $message_num is the current message number, and $in_reply_to is\n    +    the Message-ID of the message to which the current message is a reply.\n    +    In case `--in-reply-to` is specified, the `$in_reply_to` variable\n    +    is set to the value of the `--in-reply-to` argument.\n    +\n    +    Whenever this whole set of conditions is true, the script sets the\n    +    `$in_reply_to` variable to the current message's ID. This is done to\n    +    ensure that the next message in the thread is a reply to this message.\n    +\n    +    In case we specify an `--in-reply-to` argument, and have shallow\n    +    threading, the only condition that can make this true is\n    +    `$message_num == 1`, which is true for the first message in a thread.\n    +    Thus the $in_reply_to variable gets set to the first message's ID.\n    +    For subsequent messages, the `$message_num` variable is always\n    +    greater than 1, and the whole set of conditions is false, and thus the\n    +    $in_reply_to variable remains as the first message's ID. This is what\n    +    we expect in shallow threading. But, in case the user edits the first\n    +    message and resends it, the `$message_num` variable gets increased by 1,\n    +    and thus the condition `$message_num == 1` becomes false. This means\n    +    that the `$in_reply_to` variable is not set to the first message's ID,\n    +    and thus the next message in the thread is not a reply to the first\n    +    message, but to the `--in-reply-to` argument, effectively breaking\n    +    the threading.\n    +\n    +    In case the user does not specify an `--in-reply-to` argument, the\n    +    !defined $in_reply_to condition is true, and thus the `$in_reply_to`\n    +    variable is set to the first message's ID, and the threading works\n    +    as expected, irrespective of what the message number is.\n    +\n    +    Just like $message_num, $message_id_serial variable also increases by 1\n    +    whenever a new message is sent. This variable displays the message\n    +    number is the Message-ID of the email.\n    +\n    +    So, in order to fix this bug, we need to ensure that the $message_num\n    +    variable is not increased by 1 when a message is edited and resent.\n    +    We do this by decreasing the $message_num and $message_id_serial\n    +    variable by 1 whenever the request to edit a message is received. This\n    +    way, the next message in the thread will have the same message number as\n    +    the edited message, and thus the threading will work as expected.\n    +\n    +    The same logic has also been applied in case the user drops a single\n    +    message from the thread by choosing the \"[n]o\" option during\n    +    confirmation. By doing this, the next message in the thread is assigned\n    +    the message number of the dropped message, and thus the threading\n    +    works as expected.\n     \n         Signed-off-by: Aditya Garg <gargaditya08@live.com>\n     \n2:  65619ac4d7 ! 2:  72b3cd1bfb send-email: show the new message id assigned by outlook in the logs\n    @@ Commit message\n         send-email: show the new message id assigned by outlook in the logs\n     \n         Whenever an email is sent, send-email shows a log at last, which\n    -    contains all the headers of the email that was send successfully.\n    -    In case outlook changes the Message-ID, a log for the same is\n    -    shown to the user, but that change is not reflected when the log\n    -    containing all the headers is displayed.\n    +    contains all the headers of the email that were received by the\n    +    receipients.\n    +\n    +    In case outlook changes the Message-ID, a log for the same is shown to\n    +    the user, but that change is not reflected when the log containing all\n    +    the headers is displayed. Here is an example of the log that is shown\n    +    when outlook changes the Message-ID:\n    +\n    +    Outlook reassigned Message-ID to: <PN3PR01MB95973E5ACD7CCFADCB4E298CB865A@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>\n    +    OK. Log says:\n    +    Server: smtp.office365.com\n    +    MAIL FROM:<gargaditya08@live.com>\n    +    RCPT TO:<negahe7142@nomrista.com>\n    +    From: Aditya Garg <gargaditya08@live.com>\n    +    To: negahe7142@nomrista.com\n    +    Subject: [PATCH] send-email: show the new message id assigned by outlook in the logs\n    +    Date: Mon, 26 May 2025 20:28:36 +0530\n    +    Message-ID: <20250526145836.4825-1-gargaditya08@live.com>\n    +    X-Mailer: git-send-email @GIT_VERSION@\n    +    MIME-Version: 1.0\n    +    Content-Transfer-Encoding: 8bit\n    +\n    +    Result: 250\n     \n         This patch fixes this by modifying the $header variable, which is\n    -    responsible for showing the logs at the end. Also, the log which\n    -    states that the Message-ID has been changed will now be shown only\n    -    when smtp-debug is enabled, since the main log having all of the\n    -    headers is anyways displaying the new Message-ID.\n    +    responsible for showing the logs at the end. Also, the log which states\n    +    that the Message-ID has been changed will now be shown only when\n    +    smtp-debug is enabled, since the main log having all of the headers is\n    +    anyways displaying the new Message-ID. It should look like this after\n    +    this patch:\n    +\n    +    OK. Log says:\n    +    Server: smtp.office365.com\n    +    MAIL FROM:<gargaditya08@live.com>\n    +    RCPT TO:<negahe7142@nomrista.com>\n    +    From: Aditya Garg <gargaditya08@live.com>\n    +    To: negahe7142@nomrista.com\n    +    Subject: [PATCH] send-email: show the new message id assigned by outlook in the logs\n    +    Date: Mon, 26 May 2025 20:29:22 +0530\n    +    Message-ID: <PN3PR01MB95977486061BD2542BD09B67B865A@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>\n    +    X-Mailer: git-send-email @GIT_VERSION@\n    +    MIME-Version: 1.0\n    +    Content-Transfer-Encoding: 8bit\n    +\n    +    Result: 250\n     \n         Signed-off-by: Aditya Garg <gargaditya08@live.com>\n     \n-- \n2.43.0\n\n"},{"id":"518945","messageId":"63addf9d9b6491cba2148ba838f99119d50c0e68.1748274404.git.gargaditya08@live.com","threadId":"63526","inReplyTo":"cover.1748274404.git.gargaditya08@live.com","subject":"[PATCH v4 1/2] send-email: fix bug resulting in increased message number if a message is edited","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-05-26T15:51:43Z","receivedAt":"2025-05-26T15:51:50Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Whenever we send a thread of emails using send-email, a message number\nis internally assigned to each email. This number is used to track the\norder of the emails in the thread. Whenever a new message is processed\nin a thread, the current script logic increases the message number by\none, which is intended.\n\nBut, if a message is edited and then resent, its message number again\ngets increased. This is because the script uses the same logic to\nprocess the edited message, which is uses the send the next message.\n\nThis minor bug is usually harmless unless some special situations arise.\nOne such situation is when the first message in a thread is edited\nand resent, and an `--in-reply-to` argument is also passed to send-email.\nIn this case if the user has chosen shallow threading, the threading\ndoes not work as expected, and all messaged become as replies to the\nMessage-ID specified in the `--in-reply-to` argument.\n\nThe reason for this bug is hidden in the code for threading itself.\n\nif ($thread) {\n\tif ($message_was_sent &&\n\t  ($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 ||\n\t  $message_num == 1)) {\n\t\t$in_reply_to = $message_id;\n\t\tif (length $references > 0) {\n\t\t\t$references .= \"\\n $message_id\";\n\t\t} else {\n\t\t\t$references = \"$message_id\";\n\t\t}\n\t}\n}\n\nHere $message_num is the current message number, and $in_reply_to is\nthe Message-ID of the message to which the current message is a reply.\nIn case `--in-reply-to` is specified, the `$in_reply_to` variable\nis set to the value of the `--in-reply-to` argument.\n\nWhenever this whole set of conditions is true, the script sets the\n`$in_reply_to` variable to the current message's ID. This is done to\nensure that the next message in the thread is a reply to this message.\n\nIn case we specify an `--in-reply-to` argument, and have shallow\nthreading, the only condition that can make this true is\n`$message_num == 1`, which is true for the first message in a thread.\nThus the $in_reply_to variable gets set to the first message's ID.\nFor subsequent messages, the `$message_num` variable is always\ngreater than 1, and the whole set of conditions is false, and thus the\n$in_reply_to variable remains as the first message's ID. This is what\nwe expect in shallow threading. But, in case the user edits the first\nmessage and resends it, the `$message_num` variable gets increased by 1,\nand thus the condition `$message_num == 1` becomes false. This means\nthat the `$in_reply_to` variable is not set to the first message's ID,\nand thus the next message in the thread is not a reply to the first\nmessage, but to the `--in-reply-to` argument, effectively breaking\nthe threading.\n\nIn case the user does not specify an `--in-reply-to` argument, the\n!defined $in_reply_to condition is true, and thus the `$in_reply_to`\nvariable is set to the first message's ID, and the threading works\nas expected, irrespective of what the message number is.\n\nJust like $message_num, $message_id_serial variable also increases by 1\nwhenever a new message is sent. This variable displays the message\nnumber is the Message-ID of the email.\n\nSo, in order to fix this bug, we need to ensure that the $message_num\nvariable is not increased by 1 when a message is edited and resent.\nWe do this by decreasing the $message_num and $message_id_serial\nvariable by 1 whenever the request to edit a message is received. This\nway, the next message in the thread will have the same message number as\nthe edited message, and thus the threading will work as expected.\n\nThe same logic has also been applied in case the user drops a single\nmessage from the thread by choosing the \"[n]o\" option during\nconfirmation. By doing this, the next message in the thread is assigned\nthe message number of the dropped message, and thus the threading\nworks as expected.\n\nSigned-off-by: Aditya Garg <gargaditya08@live.com>\n---\n git-send-email.perl | 12 ++++++++++++\n 1 file changed, 12 insertions(+)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 55b7e00d29..b09251c4fc 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -1639,8 +1639,20 @@ sub send_message {\n \t\t         default => $ask_default);\n \t\tdie __(\"Send this email reply required\") unless defined $_;\n \t\tif (/^n/i) {\n+\t\t\t# If we are skipping a message, we should make sure that\n+\t\t\t# the next message is treated as the successor to the\n+\t\t\t# previously sent message, and not the skipped message.\n+\t\t\t$message_num--;\n+\t\t\t$message_id_serial--;\n \t\t\treturn 0;\n \t\t} elsif (/^e/i) {\n+\t\t\t# Since the same message will be sent again, we need to\n+\t\t\t# decrement the message number to the previous message.\n+\t\t\t# Otherwise, the edited message will be treated as a\n+\t\t\t# different message sent after the original non-edited\n+\t\t\t# message.\n+\t\t\t$message_num--;\n+\t\t\t$message_id_serial--;\n \t\t\treturn -1;\n \t\t} elsif (/^q/i) {\n \t\t\tcleanup_compose_files();\n-- \n2.43.0\n\n"},{"id":"518946","messageId":"72b3cd1bfbce5ce6d82ea549445732b0caa02bbf.1748274404.git.gargaditya08@live.com","threadId":"63526","inReplyTo":"cover.1748274404.git.gargaditya08@live.com","subject":"[PATCH v4 2/2] send-email: show the new message id assigned by outlook in the logs","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-05-26T15:51:45Z","receivedAt":"2025-05-26T15:51:52Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Whenever an email is sent, send-email shows a log at last, which\ncontains all the headers of the email that were received by the\nreceipients.\n\nIn case outlook changes the Message-ID, a log for the same is shown to\nthe user, but that change is not reflected when the log containing all\nthe headers is displayed. Here is an example of the log that is shown\nwhen outlook changes the Message-ID:\n\nOutlook reassigned Message-ID to: <PN3PR01MB95973E5ACD7CCFADCB4E298CB865A@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>\nOK. Log says:\nServer: smtp.office365.com\nMAIL FROM:<gargaditya08@live.com>\nRCPT TO:<negahe7142@nomrista.com>\nFrom: Aditya Garg <gargaditya08@live.com>\nTo: negahe7142@nomrista.com\nSubject: [PATCH] send-email: show the new message id assigned by outlook in the logs\nDate: Mon, 26 May 2025 20:28:36 +0530\nMessage-ID: <20250526145836.4825-1-gargaditya08@live.com>\nX-Mailer: git-send-email @GIT_VERSION@\nMIME-Version: 1.0\nContent-Transfer-Encoding: 8bit\n\nResult: 250\n\nThis patch fixes this by modifying the $header variable, which is\nresponsible for showing the logs at the end. Also, the log which states\nthat the Message-ID has been changed will now be shown only when\nsmtp-debug is enabled, since the main log having all of the headers is\nanyways displaying the new Message-ID. It should look like this after\nthis patch:\n\nOK. Log says:\nServer: smtp.office365.com\nMAIL FROM:<gargaditya08@live.com>\nRCPT TO:<negahe7142@nomrista.com>\nFrom: Aditya Garg <gargaditya08@live.com>\nTo: negahe7142@nomrista.com\nSubject: [PATCH] send-email: show the new message id assigned by outlook in the logs\nDate: Mon, 26 May 2025 20:29:22 +0530\nMessage-ID: <PN3PR01MB95977486061BD2542BD09B67B865A@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>\nX-Mailer: git-send-email @GIT_VERSION@\nMIME-Version: 1.0\nContent-Transfer-Encoding: 8bit\n\nResult: 250\n\nSigned-off-by: Aditya Garg <gargaditya08@live.com>\n---\n git-send-email.perl | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex b09251c4fc..e8019c40ba 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -1776,7 +1776,9 @@ sub send_message {\n \t\tif (is_outlook($smtp_server)) {\n \t\t\tif ($smtp->message =~ /<([^>]+)>/) {\n \t\t\t\t$message_id = \"<$1>\";\n-\t\t\t\tprintf __(\"Outlook reassigned Message-ID to: %s\\n\"), $message_id;\n+\t\t\t\t# Replace the original Message-ID in $header with the new one\n+\t\t\t\t$header =~ s/^(Message-ID:\\s*).*\\n/${1}$message_id\\n/m;\n+\t\t\t\tprintf __(\"Outlook reassigned Message-ID to: %s\\n\"), $message_id if $smtp->debug;\n \t\t\t} else {\n \t\t\t\twarn __(\"Warning: Could not retrieve Message-ID from server response.\\n\");\n \t\t\t}\n-- \n2.43.0\n\n"},{"id":"519141","messageId":"cover.1748529954.git.gargaditya08@live.com","threadId":"63526","inReplyTo":"cover.1748274404.git.gargaditya08@live.com","subject":"[PATCH v6 0/2] send-email: fix threads breaking in case user edits emails and improvements to outlook ID fix.","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-05-29T14:57:00Z","receivedAt":"2025-05-29T14:57:06Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Hi all,\n\nThis patch series fixes two minor issues with git-send-email.\n\nThe first patch fixes a bug that caused the message number to increase\nwhen a user edits an email. As a result of this bug, threads would\nbreak when a user edits an email.\n\nThe second patch improves the logging of the new message ID assigned by\nOutlook when a user edits an email.\n\nv2 - Change the bugfix logic used to fix the threading bug.\nv3 - Add additional patch to improve the logging of the new\n     message ID assigned by Outlook.\nv4 - Completely rewrite the commit message of the first patch to\n     explain the bug in detail and how it is fixed. Also, add\n     example logs to explain the second patch.\nv5 - Fix numerous spelling and grammatical errors in the commit\n     message of the first patch.\nv6 - Change the subject of the first patch.\n   - Prefer using \"increment\" instead of \"increase\" in the commit\n     message of the first patch.\n   - Avoid decreasing the `$message_id_serial` variable in the first patch.\n\nAditya Garg (2):\n  send-email: fix bug resulting in broken threads if a message is edited\n  send-email: show the new message id assigned by outlook in the logs\n\n git-send-email.perl | 14 +++++++++++++-\n 1 file changed, 13 insertions(+), 1 deletion(-)\n\nRange-diff against v5:\n1:  5103ea4034 ! 1:  d965439f76 send-email: fix bug resulting in increased message number if a message is edited\n    @@ Metadata\n     Author: Aditya Garg <gargaditya08@live.com>\n     \n      ## Commit message ##\n    -    send-email: fix bug resulting in increased message number if a message is edited\n    +    send-email: fix bug resulting in broken threads if a message is edited\n     \n         Whenever we send a thread of emails using send-email, a message number\n         is internally assigned to each email. This number is used to track the\n         order of the emails in the thread. Whenever a new message is processed\n    -    in a thread, the current script logic increases the message number by\n    +    in a thread, the current script logic increments the message number by\n         one, which is intended.\n     \n         But, if a message is edited and then resent, its message number again\n    -    gets increased. This is because the script uses the same logic to\n    +    gets incrmented. This is because the script uses the same logic to\n         process the edited message, which it uses to send the next message.\n     \n    -    This minor bug is usually harmless, unless some special situations arise.\n    -    One such situation is when the first message in a thread is edited\n    -    and resent, and an `--in-reply-to` argument is also passed to send-email.\n    +    This minor bug is usually harmless, unless a special situations arises.\n    +    That situation is when the first message in a thread is edited and\n    +    resent, and an `--in-reply-to` argument is also passed to send-email.\n         In this case, if the user has chosen shallow threading, the threading\n         does not work as expected, and all messages become replies to the\n         Message-ID specified in the `--in-reply-to` argument.\n    @@ Commit message\n         greater than 1, and the whole set of conditions is false. Therefore, the\n         `$in_reply_to` variable remains as the first message's ID. This is what\n         we expect in shallow threading. But if the user edits the first message\n    -    and resends it, the `$message_num` variable gets increased by 1, and\n    +    and resends it, the `$message_num` variable gets incremented by 1, and\n         thus the condition `$message_num == 1` becomes false. This means that\n         the `$in_reply_to` variable is not set to the first message's ID. As a\n         result the next message in the thread is not a reply to the first\n    @@ Commit message\n         variable is set to the first message's ID, and the threading works\n         as expected, regardless of the message number.\n     \n    -    Just like the `$message_num` variable, the `$message_id_serial` variable\n    -    also increases by 1 whenever a new message is sent. This variable\n    -    displays the message number in the Message-ID of the email.\n    -\n         To fix this bug, we need to ensure that the `$message_num` variable is\n    -    not increased by 1 when a message is edited and resent. We do this by\n    -    decreasing both the `$message_num` and `$message_id_serial` variables\n    -    by 1 whenever the request to edit a message is received. This way, the\n    -    next message in the thread will have the same message number as the\n    -    edited message. Therefore the threading will work as expected.\n    +    not incremented by 1 when a message is edited and resent. We do this by\n    +    decreasing the `$message_num` variable by 1 whenever the request to edit\n    +    a message is received. This way, the next message in the thread will\n    +    have the same message number as the edited message. Therefore the\n    +    threading will work as expected.\n     \n         The same logic has also been applied in case the user drops a single\n         message from the thread by choosing the \"[n]o\" option during\n    @@ git-send-email.perl: sub send_message {\n     +\t\t\t# the next message is treated as the successor to the\n     +\t\t\t# previously sent message, and not the skipped message.\n     +\t\t\t$message_num--;\n    -+\t\t\t$message_id_serial--;\n      \t\t\treturn 0;\n      \t\t} elsif (/^e/i) {\n     +\t\t\t# Since the same message will be sent again, we need to\n    @@ git-send-email.perl: sub send_message {\n     +\t\t\t# different message sent after the original non-edited\n     +\t\t\t# message.\n     +\t\t\t$message_num--;\n    -+\t\t\t$message_id_serial--;\n      \t\t\treturn -1;\n      \t\t} elsif (/^q/i) {\n      \t\t\tcleanup_compose_files();\n2:  6f2668de07 = 2:  caf46596a7 send-email: show the new message id assigned by outlook in the logs\n-- \n2.49.0.635.g48fa2f4343\n\n"},{"id":"519142","messageId":"d965439f76e341b97c8356e6d3c021532d4bcbeb.1748529954.git.gargaditya08@live.com","threadId":"63526","inReplyTo":"cover.1748529954.git.gargaditya08@live.com","subject":"[PATCH v6 1/2] send-email: fix bug resulting in broken threads if a message is edited","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-05-29T14:57:02Z","receivedAt":"2025-05-29T14:57:08Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Whenever we send a thread of emails using send-email, a message number\nis internally assigned to each email. This number is used to track the\norder of the emails in the thread. Whenever a new message is processed\nin a thread, the current script logic increments the message number by\none, which is intended.\n\nBut, if a message is edited and then resent, its message number again\ngets incrmented. This is because the script uses the same logic to\nprocess the edited message, which it uses to send the next message.\n\nThis minor bug is usually harmless, unless a special situations arises.\nThat situation is when the first message in a thread is edited and\nresent, and an `--in-reply-to` argument is also passed to send-email.\nIn this case, if the user has chosen shallow threading, the threading\ndoes not work as expected, and all messages become replies to the\nMessage-ID specified in the `--in-reply-to` argument.\n\nThe reason for this bug is hidden in the code for threading itself.\n\nif ($thread) {\n\tif ($message_was_sent &&\n\t  ($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 ||\n\t  $message_num == 1)) {\n\t\t$in_reply_to = $message_id;\n\t\tif (length $references > 0) {\n\t\t\t$references .= \"\\n $message_id\";\n\t\t} else {\n\t\t\t$references = \"$message_id\";\n\t\t}\n\t}\n}\n\nHere `$message_num` is the current message number, and `$in_reply_to` is\nthe Message-ID of the message to which the current message is a reply.\nIn case `--in-reply-to` is specified, the `$in_reply_to` variable\nis set to the value of the `--in-reply-to` argument.\n\nWhenever this whole set of conditions is true, the script sets the\n`$in_reply_to` variable to the current message's ID. This is done to\nensure that the next message in the thread is a reply to this message.\n\nIn case we specify an `--in-reply-to` argument, and have shallow\nthreading, the only condition that can make this true is\n`$message_num == 1`, which is true for the first message in a thread.\nThus, the `$in_reply_to` variable gets set to the first message's ID.\nFor subsequent messages, the `$message_num` variable is always\ngreater than 1, and the whole set of conditions is false. Therefore, the\n`$in_reply_to` variable remains as the first message's ID. This is what\nwe expect in shallow threading. But if the user edits the first message\nand resends it, the `$message_num` variable gets incremented by 1, and\nthus the condition `$message_num == 1` becomes false. This means that\nthe `$in_reply_to` variable is not set to the first message's ID. As a\nresult the next message in the thread is not a reply to the first\nmessage, but to the `--in-reply-to` argument, effectively breaking the\nthreading.\n\nIn case the user does not specify an `--in-reply-to` argument, the\n`!defined $in_reply_to` condition is true, and thus the `$in_reply_to`\nvariable is set to the first message's ID, and the threading works\nas expected, regardless of the message number.\n\nTo fix this bug, we need to ensure that the `$message_num` variable is\nnot incremented by 1 when a message is edited and resent. We do this by\ndecreasing the `$message_num` variable by 1 whenever the request to edit\na message is received. This way, the next message in the thread will\nhave the same message number as the edited message. Therefore the\nthreading will work as expected.\n\nThe same logic has also been applied in case the user drops a single\nmessage from the thread by choosing the \"[n]o\" option during\nconfirmation. By doing this, the next message in the thread is assigned\nthe message number of the dropped message, and thus the threading\nworks as expected.\n\nSigned-off-by: Aditya Garg <gargaditya08@live.com>\n---\n git-send-email.perl | 10 ++++++++++\n 1 file changed, 10 insertions(+)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 55b7e00d29..ac1d5b7070 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -1639,8 +1639,18 @@ sub send_message {\n \t\t         default => $ask_default);\n \t\tdie __(\"Send this email reply required\") unless defined $_;\n \t\tif (/^n/i) {\n+\t\t\t# If we are skipping a message, we should make sure that\n+\t\t\t# the next message is treated as the successor to the\n+\t\t\t# previously sent message, and not the skipped message.\n+\t\t\t$message_num--;\n \t\t\treturn 0;\n \t\t} elsif (/^e/i) {\n+\t\t\t# Since the same message will be sent again, we need to\n+\t\t\t# decrement the message number to the previous message.\n+\t\t\t# Otherwise, the edited message will be treated as a\n+\t\t\t# different message sent after the original non-edited\n+\t\t\t# message.\n+\t\t\t$message_num--;\n \t\t\treturn -1;\n \t\t} elsif (/^q/i) {\n \t\t\tcleanup_compose_files();\n-- \n2.49.0.635.g48fa2f4343\n\n"},{"id":"519143","messageId":"caf46596a709df7205495b75da569baef2c7c9a2.1748529954.git.gargaditya08@live.com","threadId":"63526","inReplyTo":"cover.1748529954.git.gargaditya08@live.com","subject":"[PATCH v6 2/2] send-email: show the new message id assigned by outlook in the logs","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-05-29T14:57:04Z","receivedAt":"2025-05-29T14:57:11Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Whenever an email is sent, send-email shows a log at last, which\ncontains all the headers of the email that were received by the\nreceipients.\n\nIn case outlook changes the Message-ID, a log for the same is shown to\nthe user, but that change is not reflected when the log containing all\nthe headers is displayed. Here is an example of the log that is shown\nwhen outlook changes the Message-ID:\n\nOutlook reassigned Message-ID to: <PN3PR01MB95973E5ACD7CCFADCB4E298CB865A@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>\nOK. Log says:\nServer: smtp.office365.com\nMAIL FROM:<gargaditya08@live.com>\nRCPT TO:<negahe7142@nomrista.com>\nFrom: Aditya Garg <gargaditya08@live.com>\nTo: negahe7142@nomrista.com\nSubject: [PATCH] send-email: show the new message id assigned by outlook in the logs\nDate: Mon, 26 May 2025 20:28:36 +0530\nMessage-ID: <20250526145836.4825-1-gargaditya08@live.com>\nX-Mailer: git-send-email @GIT_VERSION@\nMIME-Version: 1.0\nContent-Transfer-Encoding: 8bit\n\nResult: 250\n\nThis patch fixes this by modifying the $header variable, which is\nresponsible for showing the logs at the end. Also, the log which states\nthat the Message-ID has been changed will now be shown only when\nsmtp-debug is enabled, since the main log having all of the headers is\nanyways displaying the new Message-ID. It should look like this after\nthis patch:\n\nOK. Log says:\nServer: smtp.office365.com\nMAIL FROM:<gargaditya08@live.com>\nRCPT TO:<negahe7142@nomrista.com>\nFrom: Aditya Garg <gargaditya08@live.com>\nTo: negahe7142@nomrista.com\nSubject: [PATCH] send-email: show the new message id assigned by outlook in the logs\nDate: Mon, 26 May 2025 20:29:22 +0530\nMessage-ID: <PN3PR01MB95977486061BD2542BD09B67B865A@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>\nX-Mailer: git-send-email @GIT_VERSION@\nMIME-Version: 1.0\nContent-Transfer-Encoding: 8bit\n\nResult: 250\n\nSigned-off-by: Aditya Garg <gargaditya08@live.com>\n---\n git-send-email.perl | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex ac1d5b7070..79d230448f 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -1774,7 +1774,9 @@ sub send_message {\n \t\tif (is_outlook($smtp_server)) {\n \t\t\tif ($smtp->message =~ /<([^>]+)>/) {\n \t\t\t\t$message_id = \"<$1>\";\n-\t\t\t\tprintf __(\"Outlook reassigned Message-ID to: %s\\n\"), $message_id;\n+\t\t\t\t# Replace the original Message-ID in $header with the new one\n+\t\t\t\t$header =~ s/^(Message-ID:\\s*).*\\n/${1}$message_id\\n/m;\n+\t\t\t\tprintf __(\"Outlook reassigned Message-ID to: %s\\n\"), $message_id if $smtp->debug;\n \t\t\t} else {\n \t\t\t\twarn __(\"Warning: Could not retrieve Message-ID from server response.\\n\");\n \t\t\t}\n-- \n2.49.0.635.g48fa2f4343\n\n"},{"id":"519148","messageId":"xmqq5xhjmmno.fsf@gitster.g","threadId":"63526","inReplyTo":"caf46596a709df7205495b75da569baef2c7c9a2.1748529954.git.gargaditya08@live.com","subject":"Re: [PATCH v6 2/2] send-email: show the new message id assigned by outlook in the logs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-05-29T16:01:15Z","receivedAt":"2025-05-29T16:01:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Aditya Garg <gargaditya08@live.com> writes:\n\n> This patch fixes this by modifying the $header variable, which is\n> responsible for showing the logs at the end. Also, the log which states\n> that the Message-ID has been changed will now be shown only when\n> smtp-debug is enabled, since the main log having all of the headers is\n> anyways displaying the new Message-ID. It should look like this after\n> this patch:\n\nWe do not say \"This patch does X\" or \"I do Y\" when describing a\nchange.  Rather, you give an order to somebody who is modifying the\ncodebase to \"make it so\".  Something like ...\n\n    Fix this by updating the $header variable, which has the message\n    ID we internally assigned on the \"Message-ID:\" header, with the\n    message ID the Outlook server assigned.\n\nThe change itself looks good, but ...\n\n> +\t\t\t\t# Replace the original Message-ID in $header with the new one\n> +\t\t\t\t$header =~ s/^(Message-ID:\\s*).*\\n/${1}$message_id\\n/m;\n\n... is the comment adding any useful information over what the code\nalready says?\n\nWill queue, with a typofix to \"incrmented\" in [1/2].\n\nThanks.\n"},{"id":"519152","messageId":"PN0PR01MB9588AF2A370D8A1F50745C97B866A@PN0PR01MB9588.INDPRD01.PROD.OUTLOOK.COM","threadId":"63526","inReplyTo":"xmqq5xhjmmno.fsf@gitster.g","subject":"Re: [PATCH v6 2/2] send-email: show the new message id assigned by outlook in the logs","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-05-29T16:18:46Z","receivedAt":"2025-05-29T16:18:54Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\nOn 29/05/25 9:31 pm, Junio C Hamano wrote:\n> Aditya Garg <gargaditya08@live.com> writes:\n> \n>> This patch fixes this by modifying the $header variable, which is\n>> responsible for showing the logs at the end. Also, the log which states\n>> that the Message-ID has been changed will now be shown only when\n>> smtp-debug is enabled, since the main log having all of the headers is\n>> anyways displaying the new Message-ID. It should look like this after\n>> this patch:\n> \n> We do not say \"This patch does X\" or \"I do Y\" when describing a\n> change.  Rather, you give an order to somebody who is modifying the\n> codebase to \"make it so\".  Something like ...\n> \n>     Fix this by updating the $header variable, which has the message\n>     ID we internally assigned on the \"Message-ID:\" header, with the\n>     message ID the Outlook server assigned.\n\nOk. Want me to send another revision, or we good for now?\n\n> \n> The change itself looks good, but ...\n> \n>> +\t\t\t\t# Replace the original Message-ID in $header with the new one\n>> +\t\t\t\t$header =~ s/^(Message-ID:\\s*).*\\n/${1}$message_id\\n/m;\n> \n> ... is the comment adding any useful information over what the code\n> already says?\n\nConsidering the fact that making this regex what itself a pain, a small\ncomment for readers doesn't hurt right?\n\n> \n> Will queue, with a typofix to \"incrmented\" in [1/2].\n> \n> Thanks.\n\n"},{"id":"519657","messageId":"xmqq8qm7g00q.fsf@gitster.g","threadId":"63526","inReplyTo":"PN0PR01MB9588AF2A370D8A1F50745C97B866A@PN0PR01MB9588.INDPRD01.PROD.OUTLOOK.COM","subject":"Re: [PATCH v6 2/2] send-email: show the new message id assigned by outlook in the logs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-06-04T12:32:37Z","receivedAt":"2025-06-04T12:32:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Aditya Garg <gargaditya08@live.com> writes:\n\n>> We do not say \"This patch does X\" or \"I do Y\" when describing a\n>> change.  Rather, you give an order to somebody who is modifying the\n>> codebase to \"make it so\".  Something like ...\n>> ...\n> Ok. Want me to send another revision, or we good for now?\n\nAs the codebase will be frozen during the rc period, I am not in a\nhurry.  But submitting hopefully a small and final reroll would be a\ngood way to conclude the cycle.\n\nThanks.\n"},{"id":"519659","messageId":"PN3PR01MB95979AA8114CA26405BE02CFB86CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63526","inReplyTo":"cover.1748274404.git.gargaditya08@live.com","subject":"[PATCH v7 0/2] send-email: fix threads breaking in case user edits emails and improvements to outlook ID fix.","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-06-04T12:55:12Z","receivedAt":"2025-06-04T12:55:51Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Hi all,\n\nThis patch series fixes two minor issues with git-send-email.\n\nThe first patch fixes a bug that caused the message number to increase\nwhen a user edits an email. As a result of this bug, threads would\nbreak when a user edits an email.\n\nThe second patch improves the logging of the new message ID assigned by\nOutlook when a user edits an email.\n\nv2 - Change the bugfix logic used to fix the threading bug.\nv3 - Add additional patch to improve the logging of the new\n     message ID assigned by Outlook.\nv4 - Completely rewrite the commit message of the first patch to\n     explain the bug in detail and how it is fixed. Also, add\n     example logs to explain the second patch.\nv5 - Fix numerous spelling and grammatical errors in the commit\n     message of the first patch.\nv6 - Change the subject of the first patch.\n   - Prefer using \"increment\" instead of \"increase\" in the commit\n     message of the first patch.\n   - Avoid decreasing the `$message_id_serial` variable in the first patch.\nv7 - Remove unecessary comment in the second patch.\n   - Mild rewording of the commit message of the second patch.\n   - Fix incrmented -> incremented\n\nAditya Garg (2):\n  send-email: fix bug resulting in broken threads if a message is edited\n  send-email: show the new message id assigned by outlook in the logs\n\n git-send-email.perl | 13 ++++++++++++-\n 1 file changed, 12 insertions(+), 1 deletion(-)\n\nRange-diff against v6:\n1:  a5dcec5428 ! 1:  05724ae6d3 send-email: fix bug resulting in broken threads if a message is edited\n    @@ Commit message\n         one, which is intended.\n     \n         But, if a message is edited and then resent, its message number again\n    -    gets incrmented. This is because the script uses the same logic to\n    +    gets incremented. This is because the script uses the same logic to\n         process the edited message, which it uses to send the next message.\n     \n         This minor bug is usually harmless, unless a special situations arises.\n2:  43227e8a5e ! 2:  360391c8e2 send-email: show the new message id assigned by outlook in the logs\n    @@ Commit message\n     \n         Result: 250\n     \n    -    This patch fixes this by modifying the $header variable, which is\n    -    responsible for showing the logs at the end. Also, the log which states\n    -    that the Message-ID has been changed will now be shown only when\n    -    smtp-debug is enabled, since the main log having all of the headers is\n    -    anyways displaying the new Message-ID. It should look like this after\n    -    this patch:\n    +    Fix this by updating the $header variable, which has the message ID we\n    +    internally assigned on the \"Message-ID:\" header, with the message ID the\n    +    Outlook server assigned. It should look like this after this patch:\n     \n         OK. Log says:\n         Server: smtp.office365.com\n    @@ git-send-email.perl: sub send_message {\n      \t\t\tif ($smtp->message =~ /<([^>]+)>/) {\n      \t\t\t\t$message_id = \"<$1>\";\n     -\t\t\t\tprintf __(\"Outlook reassigned Message-ID to: %s\\n\"), $message_id;\n    -+\t\t\t\t# Replace the original Message-ID in $header with the new one\n     +\t\t\t\t$header =~ s/^(Message-ID:\\s*).*\\n/${1}$message_id\\n/m;\n     +\t\t\t\tprintf __(\"Outlook reassigned Message-ID to: %s\\n\"), $message_id if $smtp->debug;\n      \t\t\t} else {\n-- \n2.49.0.windows.1\n\n"},{"id":"519660","messageId":"PN3PR01MB95979A02866CF1AD640E48ADB86CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63526","inReplyTo":"PN3PR01MB95979AA8114CA26405BE02CFB86CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"[PATCH v7 2/2] send-email: show the new message id assigned by outlook in the logs","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-06-04T12:55:14Z","receivedAt":"2025-06-04T12:55:55Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Whenever an email is sent, send-email shows a log at last, which\ncontains all the headers of the email that were received by the\nreceipients.\n\nIn case outlook changes the Message-ID, a log for the same is shown to\nthe user, but that change is not reflected when the log containing all\nthe headers is displayed. Here is an example of the log that is shown\nwhen outlook changes the Message-ID:\n\nOutlook reassigned Message-ID to: <PN3PR01MB95973E5ACD7CCFADCB4E298CB865A@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>\nOK. Log says:\nServer: smtp.office365.com\nMAIL FROM:<gargaditya08@live.com>\nRCPT TO:<negahe7142@nomrista.com>\nFrom: Aditya Garg <gargaditya08@live.com>\nTo: negahe7142@nomrista.com\nSubject: [PATCH] send-email: show the new message id assigned by outlook in the logs\nDate: Mon, 26 May 2025 20:28:36 +0530\nMessage-ID: <20250526145836.4825-1-gargaditya08@live.com>\nX-Mailer: git-send-email @GIT_VERSION@\nMIME-Version: 1.0\nContent-Transfer-Encoding: 8bit\n\nResult: 250\n\nFix this by updating the $header variable, which has the message ID we\ninternally assigned on the \"Message-ID:\" header, with the message ID the\nOutlook server assigned. It should look like this after this patch:\n\nOK. Log says:\nServer: smtp.office365.com\nMAIL FROM:<gargaditya08@live.com>\nRCPT TO:<negahe7142@nomrista.com>\nFrom: Aditya Garg <gargaditya08@live.com>\nTo: negahe7142@nomrista.com\nSubject: [PATCH] send-email: show the new message id assigned by outlook in the logs\nDate: Mon, 26 May 2025 20:29:22 +0530\nMessage-ID: <PN3PR01MB95977486061BD2542BD09B67B865A@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>\nX-Mailer: git-send-email @GIT_VERSION@\nMIME-Version: 1.0\nContent-Transfer-Encoding: 8bit\n\nResult: 250\n\nSigned-off-by: Aditya Garg <gargaditya08@live.com>\n---\n git-send-email.perl | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex ac1d5b7070..175b0c184b 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -1774,7 +1774,8 @@ sub send_message {\n \t\tif (is_outlook($smtp_server)) {\n \t\t\tif ($smtp->message =~ /<([^>]+)>/) {\n \t\t\t\t$message_id = \"<$1>\";\n-\t\t\t\tprintf __(\"Outlook reassigned Message-ID to: %s\\n\"), $message_id;\n+\t\t\t\t$header =~ s/^(Message-ID:\\s*).*\\n/${1}$message_id\\n/m;\n+\t\t\t\tprintf __(\"Outlook reassigned Message-ID to: %s\\n\"), $message_id if $smtp->debug;\n \t\t\t} else {\n \t\t\t\twarn __(\"Warning: Could not retrieve Message-ID from server response.\\n\");\n \t\t\t}\n-- \n2.49.0.windows.1\n\n"},{"id":"519661","messageId":"PN3PR01MB95977671AA4500599872A1A3B86CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63526","inReplyTo":"PN3PR01MB95979AA8114CA26405BE02CFB86CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"[PATCH v7 1/2] send-email: fix bug resulting in broken threads if a message is edited","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-06-04T12:55:13Z","receivedAt":"2025-06-04T12:55:58Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Whenever we send a thread of emails using send-email, a message number\nis internally assigned to each email. This number is used to track the\norder of the emails in the thread. Whenever a new message is processed\nin a thread, the current script logic increments the message number by\none, which is intended.\n\nBut, if a message is edited and then resent, its message number again\ngets incremented. This is because the script uses the same logic to\nprocess the edited message, which it uses to send the next message.\n\nThis minor bug is usually harmless, unless a special situations arises.\nThat situation is when the first message in a thread is edited and\nresent, and an `--in-reply-to` argument is also passed to send-email.\nIn this case, if the user has chosen shallow threading, the threading\ndoes not work as expected, and all messages become replies to the\nMessage-ID specified in the `--in-reply-to` argument.\n\nThe reason for this bug is hidden in the code for threading itself.\n\nif ($thread) {\n\tif ($message_was_sent &&\n\t  ($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 ||\n\t  $message_num == 1)) {\n\t\t$in_reply_to = $message_id;\n\t\tif (length $references > 0) {\n\t\t\t$references .= \"\\n $message_id\";\n\t\t} else {\n\t\t\t$references = \"$message_id\";\n\t\t}\n\t}\n}\n\nHere `$message_num` is the current message number, and `$in_reply_to` is\nthe Message-ID of the message to which the current message is a reply.\nIn case `--in-reply-to` is specified, the `$in_reply_to` variable\nis set to the value of the `--in-reply-to` argument.\n\nWhenever this whole set of conditions is true, the script sets the\n`$in_reply_to` variable to the current message's ID. This is done to\nensure that the next message in the thread is a reply to this message.\n\nIn case we specify an `--in-reply-to` argument, and have shallow\nthreading, the only condition that can make this true is\n`$message_num == 1`, which is true for the first message in a thread.\nThus, the `$in_reply_to` variable gets set to the first message's ID.\nFor subsequent messages, the `$message_num` variable is always\ngreater than 1, and the whole set of conditions is false. Therefore, the\n`$in_reply_to` variable remains as the first message's ID. This is what\nwe expect in shallow threading. But if the user edits the first message\nand resends it, the `$message_num` variable gets incremented by 1, and\nthus the condition `$message_num == 1` becomes false. This means that\nthe `$in_reply_to` variable is not set to the first message's ID. As a\nresult the next message in the thread is not a reply to the first\nmessage, but to the `--in-reply-to` argument, effectively breaking the\nthreading.\n\nIn case the user does not specify an `--in-reply-to` argument, the\n`!defined $in_reply_to` condition is true, and thus the `$in_reply_to`\nvariable is set to the first message's ID, and the threading works\nas expected, regardless of the message number.\n\nTo fix this bug, we need to ensure that the `$message_num` variable is\nnot incremented by 1 when a message is edited and resent. We do this by\ndecreasing the `$message_num` variable by 1 whenever the request to edit\na message is received. This way, the next message in the thread will\nhave the same message number as the edited message. Therefore the\nthreading will work as expected.\n\nThe same logic has also been applied in case the user drops a single\nmessage from the thread by choosing the \"[n]o\" option during\nconfirmation. By doing this, the next message in the thread is assigned\nthe message number of the dropped message, and thus the threading\nworks as expected.\n\nSigned-off-by: Aditya Garg <gargaditya08@live.com>\n---\n git-send-email.perl | 10 ++++++++++\n 1 file changed, 10 insertions(+)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 55b7e00d29..ac1d5b7070 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -1639,8 +1639,18 @@ sub send_message {\n \t\t         default => $ask_default);\n \t\tdie __(\"Send this email reply required\") unless defined $_;\n \t\tif (/^n/i) {\n+\t\t\t# If we are skipping a message, we should make sure that\n+\t\t\t# the next message is treated as the successor to the\n+\t\t\t# previously sent message, and not the skipped message.\n+\t\t\t$message_num--;\n \t\t\treturn 0;\n \t\t} elsif (/^e/i) {\n+\t\t\t# Since the same message will be sent again, we need to\n+\t\t\t# decrement the message number to the previous message.\n+\t\t\t# Otherwise, the edited message will be treated as a\n+\t\t\t# different message sent after the original non-edited\n+\t\t\t# message.\n+\t\t\t$message_num--;\n \t\t\treturn -1;\n \t\t} elsif (/^q/i) {\n \t\t\tcleanup_compose_files();\n-- \n2.49.0.windows.1\n\n"},{"id":"519662","messageId":"PN3PR01MB95978CC57C19CD03B67EB782B86CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63526","inReplyTo":"xmqq8qm7g00q.fsf@gitster.g","subject":"Re: [PATCH v6 2/2] send-email: show the new message id assigned by outlook in the logs","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-06-04T12:55:59Z","receivedAt":"2025-06-04T12:56:07Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\nOn 04-06-2025 06:02 pm, Junio C Hamano wrote:\n> Aditya Garg <gargaditya08@live.com> writes:\n> \n>>> We do not say \"This patch does X\" or \"I do Y\" when describing a\n>>> change.  Rather, you give an order to somebody who is modifying the\n>>> codebase to \"make it so\".  Something like ...\n>>> ...\n>> Ok. Want me to send another revision, or we good for now?\n> \n> As the codebase will be frozen during the rc period, I am not in a\n> hurry.  But submitting hopefully a small and final reroll would be a\n> good way to conclude the cycle.\n\nSent\n\n"},{"id":"519681","messageId":"xmqqplfjbh9s.fsf@gitster.g","threadId":"63526","inReplyTo":"PN3PR01MB95979AA8114CA26405BE02CFB86CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"Re: [PATCH v7 0/2] send-email: fix threads breaking in case user edits emails and improvements to outlook ID fix.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-06-04T16:31:11Z","receivedAt":"2025-06-04T16:31:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Aditya Garg <gargaditya08@live.com> writes:\n\n> v7 - Remove unecessary comment in the second patch.\n>    - Mild rewording of the commit message of the second patch.\n>    - Fix incrmented -> incremented\n\nLooking good.  Will queue.  Thanks.\n"}]}