In case a message is edited before it is sent, its message number gets increased by 1, and so does its order in the message id. The cause of this bug was that when a person attempts to edit the message, the whole sub process_file gets terminated, and the user is asked to edit the message. After necessary edits are done, the whole sub process_file is executed again. The way sub process_file is designed, every time is runs, it increases the $message_num variable by 1. The reason for this was that the function ran again everytime a next message was sent in a thread, and thus we need to increase the message number for that message. In case a user edits the message, there is no check for the same and the new message gets treated as a subsequent message of a thread, therefore increasing its message number by one. This breaks the shallow thread logic which relies on $message_num being 1 for the first message, and it gets changed in case the user edits the first message. So, upon scanning the whole code, there are two significant variables at play here. First is $message_num, responsible for the message number and second is $message_id_serial, responsible for showing the message number in the Message-ID header. So, whenever we edit a message, lets just decrease them by 1, so that when the whole process to compose and send the message starts, these variables increase by 1 again, thus get set to the original values for that message. We also are doing the same thing in case the user chooses to not send a message out of many messages in a thread. By doing so, we will simply decrease these variables by 1 for further messages, thus ensuring the whole thread doesn't break. Signed-off-by: Aditya Garg <gargaditya08@xxxxxxxx> --- git-send-email.perl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/git-send-email.perl b/git-send-email.perl index 55b7e00d29..b09251c4fc 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1639,8 +1639,20 @@ sub send_message { default => $ask_default); die __("Send this email reply required") unless defined $_; if (/^n/i) { + # If we are skipping a message, we should make sure that + # the next message is treated as the successor to the + # previously sent message, and not the skipped message. + $message_num--; + $message_id_serial--; return 0; } elsif (/^e/i) { + # Since the same message will be sent again, we need to + # decrement the message number to the previous message. + # Otherwise, the edited message will be treated as a + # different message sent after the original non-edited + # message. + $message_num--; + $message_id_serial--; return -1; } elsif (/^q/i) { cleanup_compose_files(); -- 2.49.0.windows.1