{"thread":{"id":"63810","subject":"[PATCH] send-email: add ability to send a copy of sent emails to an IMAP folder","startedAt":"2025-07-20T09:25:31Z","lastAt":"2025-08-15T03:38:48Z","messageCount":33,"participants":["Aditya Garg","Eric Sunshine","Junio C Hamano","brian m. carlson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"522337","messageId":"08528f201acc1038ebc5861321395d17516094fd.1753003385.git.gargaditya08@live.com","threadId":"63810","inReplyTo":null,"subject":"[PATCH] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-20T09:25:27Z","receivedAt":"2025-07-20T09:25:31Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Some email providers like Apple iCloud Mail do not support sending a copy\nof sent emails to the \"Sent\" folder if emails are sent via SMTP. As a\nworkaround, various email clients like Thunderbird which rely on SMTP,\nuse IMAP to send a copy of sent emails to the \"Sent\" folder. Something\nsimilar can be done with if sending emails via `git send-email`, by using\nthe `git imap-send` command to send a copy of the sent email to an IMAP\nfolder specified by the user.\n\nAdd this functionality to `git send-email` by introducing a new\nconfiguration variable `sendemail.imapfolder` and command line option\n`--imap-folder` which specifies the IMAP folder to send a copy of the\nsent emails to. If specified, a copy of the sent emails will be sent\nby piping the emails to `git imap-send` command, after the all emails are\nsent via SMTP and the SMTP server has been closed.\n\nSigned-off-by: Aditya Garg <gargaditya08@live.com>\n---\n Documentation/config/sendemail.adoc |  1 +\n Documentation/git-send-email.adoc   | 12 +++++++++++\n git-send-email.perl                 | 31 ++++++++++++++++++++++++++++-\n imap-send.c                         | 20 ++++++++++++++-----\n 4 files changed, 58 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/config/sendemail.adoc b/Documentation/config/sendemail.adoc\nindex 4722334657..55b5943956 100644\n--- a/Documentation/config/sendemail.adoc\n+++ b/Documentation/config/sendemail.adoc\n@@ -88,6 +88,7 @@ sendemail.smtpServer::\n sendemail.smtpServerPort::\n sendemail.smtpServerOption::\n sendemail.smtpUser::\n+sendemail.imapfolder::\n sendemail.thread::\n sendemail.transferEncoding::\n sendemail.validate::\ndiff --git a/Documentation/git-send-email.adoc b/Documentation/git-send-email.adoc\nindex 5335502d68..74ec2944da 100644\n--- a/Documentation/git-send-email.adoc\n+++ b/Documentation/git-send-email.adoc\n@@ -299,6 +299,18 @@ must be used for each option.\n \tcommands and replies will be printed. Useful to debug TLS\n \tconnection and authentication problems.\n \n+--imap-folder=<folder>::\n+\tSome email providers (e.g. iCloud) do not send a copy of the emails sent\n+\tusing SMTP to the `Sent` folder or similar in your mailbox. Use this option\n+\tto use `git imap-send` to send a copy of the emails to the folder specified\n+\tusing this option. You can run `git imap-send --list` to get a list of\n+\tvalid folder names, including the correct name of the `Sent` folder in\n+\tyour mailbox. You can also use this option to send emails to a dedicated\n+\tIMAP folder of your choice.\n++\n+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n+to get instructions for the same.\n+\n --batch-size=<num>::\n \tSome email servers (e.g. 'smtp.163.com') limit the number of emails to be\n \tsent per session (connection) and this will lead to a failure when\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex cb6dca2500..571e4b78c9 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -73,6 +73,8 @@ sub usage {\n     --no-smtp-auth                 * Disable SMTP authentication. Shorthand for\n                                      `--smtp-auth=none`\n     --smtp-debug            <0|1>  * Disable, enable Net::SMTP debug.\n+    --imap-folder           <str>  * IMAP folder where a copy of the emails should be sent.\n+                                     Make sure `git imap-send` is setup to use this feature.\n \n     --batch-size            <int>  * send max <int> message per connection.\n     --relogin-delay         <int>  * delay <int> seconds between two successive login.\n@@ -200,7 +202,7 @@ sub format_2822_time {\n \n # Variables we fill in automatically, or via prompting:\n my (@to,@cc,@xh,$envelope_sender,\n-\t$initial_in_reply_to,$reply_to,$initial_subject,@files,\n+\t$initial_in_reply_to,$reply_to,$initial_subject,@files,@imap_copy,\n \t$author,$sender,$smtp_authpass,$annotate,$compose,$time);\n # Things we either get from config, *or* are overridden on the\n # command-line.\n@@ -277,6 +279,7 @@ sub do_edit {\n my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);\n my ($batch_size, $relogin_delay);\n my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);\n+my ($imap_folder);\n my ($confirm);\n my (@suppress_cc);\n my ($auto_8bit_encoding);\n@@ -322,6 +325,7 @@ sub do_edit {\n     \"smtpauth\" => \\$smtp_auth,\n     \"smtpbatchsize\" => \\$batch_size,\n     \"smtprelogindelay\" => \\$relogin_delay,\n+    \"imapfolder\" => \\$imap_folder,\n     \"to\" => \\@config_to,\n     \"tocmd\" => \\$to_cmd,\n     \"cc\" => \\@config_cc,\n@@ -527,6 +531,7 @@ sub config_regexp {\n \t\t    \"smtp-domain:s\" => \\$smtp_domain,\n \t\t    \"smtp-auth=s\" => \\$smtp_auth,\n \t\t    \"no-smtp-auth\" => sub {$smtp_auth = 'none'},\n+\t\t    \"imap-folder=s\" => \\$imap_folder,\n \t\t    \"annotate!\" => \\$annotate,\n \t\t    \"compose\" => \\$compose,\n \t\t    \"quiet\" => \\$quiet,\n@@ -1829,6 +1834,17 @@ sub send_message {\n \t\tprint \"\\n\";\n \t}\n \n+\tif ($imap_folder) {\n+\t\tmy $imap_header = $header;\n+\t\tif (@initial_bcc) {\n+\t\t\t# Bcc is not a part of $header, so we add it here.\n+\t\t\t# This is only for the IMAP copy, not for the actual email\n+\t\t\t# sent to the recipients.\n+\t\t\t$imap_header .= \"Bcc: \" . join(\", \", @initial_bcc) . \"\\n\";\n+\t\t}\n+\t\tpush @imap_copy, \"From git-send-email\\n$imap_header\\n$message\";\n+\t}\n+\n \treturn 1;\n }\n \n@@ -2212,6 +2228,19 @@ sub cleanup_compose_files {\n \n $smtp->quit if $smtp;\n \n+if ($imap_folder && @imap_copy) {\n+\tmy $imap_input = join(\"\\n\", @imap_copy);\n+\teval {\n+\t\tprint \"\\nStarting git imap-send...\\n\";\n+\t\tmy ($fh, $ctx) = Git::command_input_pipe(['imap-send', '-f', $imap_folder]);\n+\t\tprint $fh $imap_input;\n+\t\tGit::command_close_pipe($fh, $ctx);\n+\t\t1;\n+\t} or do {\n+\t\twarn \"Warning: failed to send messages to IMAP folder $imap_folder via imap-send pipe: $@\";\n+\t};\n+}\n+\n sub apply_transfer_encoding {\n \tmy $message = shift;\n \tmy $from = shift;\ndiff --git a/imap-send.c b/imap-send.c\nindex f5a656ac71..e82dbb2170 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -1441,14 +1441,24 @@ static int count_messages(struct strbuf *all_msgs)\n \n \twhile (1) {\n \t\tif (starts_with(p, \"From \")) {\n-\t\t\tp = strstr(p+5, \"\\nFrom: \");\n-\t\t\tif (!p) break;\n-\t\t\tp = strstr(p+7, \"\\nDate: \");\n-\t\t\tif (!p) break;\n-\t\t\tp = strstr(p+7, \"\\nSubject: \");\n+\t\t\tif (starts_with(p, \"From git-send-email\")) {\n+\t\t\t\tp = strstr(p+5, \"\\nFrom: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp += 7;\n+\t\t\t\tp = strstr(p, \"\\nTo: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp += 5;\n+\t\t\t\tcount++;\n+\t\t\t} else {\n+\t\t\t\tp = strstr(p+5, \"\\nFrom: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp = strstr(p+7, \"\\nDate: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp = strstr(p+7, \"\\nSubject: \");\n \t\t\tif (!p) break;\n \t\t\tp += 10;\n \t\t\tcount++;\n+\t\t\t}\n \t\t}\n \t\tp = strstr(p+5, \"\\nFrom \");\n \t\tif (!p)\n-- \n2.43.0\n\n"},{"id":"522343","messageId":"87a890182591c9c21061e85834fc99a766252611.1753092192.git.gargaditya08@live.com","threadId":"63810","inReplyTo":"08528f201acc1038ebc5861321395d17516094fd.1753003385.git.gargaditya08@live.com","subject":"[PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-21T10:05:39Z","receivedAt":"2025-07-21T10:05:43Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Some email providers like Apple iCloud Mail do not support sending a copy\nof sent emails to the \"Sent\" folder if SMTP server is used. As a\nworkaround, various email clients like Thunderbird which rely on SMTP,\nuse IMAP to send a copy of sent emails to the \"Sent\" folder. Something\nsimilar can be done if sending emails via `git send-email`, by using\nthe `git imap-send` command to send a copy of the sent email to an IMAP\nfolder specified by the user.\n\nAdd this functionality to `git send-email` by introducing a new\nconfiguration variable `sendemail.imapfolder` and command line option\n`--imap-folder` which specifies the IMAP folder to send a copy of the\nsent emails to. If specified, a copy of the sent emails will be sent\nby piping the emails to `git imap-send` command, after the all emails are\nsent via SMTP and the SMTP server has been closed.\n\nSigned-off-by: Aditya Garg <gargaditya08@live.com>\n---\n\nv2 - Fix indentation in patch for imap-send.c\n   - Minor edits to commit message\n\n Documentation/config/sendemail.adoc |  1 +\n Documentation/git-send-email.adoc   | 12 +++++++++++\n git-send-email.perl                 | 31 ++++++++++++++++++++++++++++-\n imap-send.c                         | 26 ++++++++++++++++--------\n 4 files changed, 61 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/config/sendemail.adoc b/Documentation/config/sendemail.adoc\nindex 4722334657..55b5943956 100644\n--- a/Documentation/config/sendemail.adoc\n+++ b/Documentation/config/sendemail.adoc\n@@ -88,6 +88,7 @@ sendemail.smtpServer::\n sendemail.smtpServerPort::\n sendemail.smtpServerOption::\n sendemail.smtpUser::\n+sendemail.imapfolder::\n sendemail.thread::\n sendemail.transferEncoding::\n sendemail.validate::\ndiff --git a/Documentation/git-send-email.adoc b/Documentation/git-send-email.adoc\nindex 5335502d68..74ec2944da 100644\n--- a/Documentation/git-send-email.adoc\n+++ b/Documentation/git-send-email.adoc\n@@ -299,6 +299,18 @@ must be used for each option.\n \tcommands and replies will be printed. Useful to debug TLS\n \tconnection and authentication problems.\n \n+--imap-folder=<folder>::\n+\tSome email providers (e.g. iCloud) do not send a copy of the emails sent\n+\tusing SMTP to the `Sent` folder or similar in your mailbox. Use this option\n+\tto use `git imap-send` to send a copy of the emails to the folder specified\n+\tusing this option. You can run `git imap-send --list` to get a list of\n+\tvalid folder names, including the correct name of the `Sent` folder in\n+\tyour mailbox. You can also use this option to send emails to a dedicated\n+\tIMAP folder of your choice.\n++\n+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n+to get instructions for the same.\n+\n --batch-size=<num>::\n \tSome email servers (e.g. 'smtp.163.com') limit the number of emails to be\n \tsent per session (connection) and this will lead to a failure when\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 437f8ac46a..214a0023bf 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -73,6 +73,8 @@ sub usage {\n     --no-smtp-auth                 * Disable SMTP authentication. Shorthand for\n                                      `--smtp-auth=none`\n     --smtp-debug            <0|1>  * Disable, enable Net::SMTP debug.\n+    --imap-folder           <str>  * IMAP folder where a copy of the emails should be sent.\n+                                     Make sure `git imap-send` is setup to use this feature.\n \n     --batch-size            <int>  * send max <int> message per connection.\n     --relogin-delay         <int>  * delay <int> seconds between two successive login.\n@@ -200,7 +202,7 @@ sub format_2822_time {\n \n # Variables we fill in automatically, or via prompting:\n my (@to,@cc,@xh,$envelope_sender,\n-\t$initial_in_reply_to,$reply_to,$initial_subject,@files,\n+\t$initial_in_reply_to,$reply_to,$initial_subject,@files,@imap_copy,\n \t$author,$sender,$smtp_authpass,$annotate,$compose,$time);\n # Things we either get from config, *or* are overridden on the\n # command-line.\n@@ -277,6 +279,7 @@ sub do_edit {\n my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);\n my ($batch_size, $relogin_delay);\n my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);\n+my ($imap_folder);\n my ($confirm);\n my (@suppress_cc);\n my ($auto_8bit_encoding);\n@@ -322,6 +325,7 @@ sub do_edit {\n     \"smtpauth\" => \\$smtp_auth,\n     \"smtpbatchsize\" => \\$batch_size,\n     \"smtprelogindelay\" => \\$relogin_delay,\n+    \"imapfolder\" => \\$imap_folder,\n     \"to\" => \\@config_to,\n     \"tocmd\" => \\$to_cmd,\n     \"cc\" => \\@config_cc,\n@@ -527,6 +531,7 @@ sub config_regexp {\n \t\t    \"smtp-domain:s\" => \\$smtp_domain,\n \t\t    \"smtp-auth=s\" => \\$smtp_auth,\n \t\t    \"no-smtp-auth\" => sub {$smtp_auth = 'none'},\n+\t\t    \"imap-folder=s\" => \\$imap_folder,\n \t\t    \"annotate!\" => \\$annotate,\n \t\t    \"compose\" => \\$compose,\n \t\t    \"quiet\" => \\$quiet,\n@@ -1829,6 +1834,17 @@ sub send_message {\n \t\tprint \"\\n\";\n \t}\n \n+\tif ($imap_folder) {\n+\t\tmy $imap_header = $header;\n+\t\tif (@initial_bcc) {\n+\t\t\t# Bcc is not a part of $header, so we add it here.\n+\t\t\t# This is only for the IMAP copy, not for the actual email\n+\t\t\t# sent to the recipients.\n+\t\t\t$imap_header .= \"Bcc: \" . join(\", \", @initial_bcc) . \"\\n\";\n+\t\t}\n+\t\tpush @imap_copy, \"From git-send-email\\n$imap_header\\n$message\";\n+\t}\n+\n \treturn 1;\n }\n \n@@ -2223,6 +2239,19 @@ sub cleanup_compose_files {\n \n $smtp->quit if $smtp;\n \n+if ($imap_folder && @imap_copy) {\n+\tmy $imap_input = join(\"\\n\", @imap_copy);\n+\teval {\n+\t\tprint \"\\nStarting git imap-send...\\n\";\n+\t\tmy ($fh, $ctx) = Git::command_input_pipe(['imap-send', '-f', $imap_folder]);\n+\t\tprint $fh $imap_input;\n+\t\tGit::command_close_pipe($fh, $ctx);\n+\t\t1;\n+\t} or do {\n+\t\twarn \"Warning: failed to send messages to IMAP folder $imap_folder via imap-send pipe: $@\";\n+\t};\n+}\n+\n sub apply_transfer_encoding {\n \tmy $message = shift;\n \tmy $from = shift;\ndiff --git a/imap-send.c b/imap-send.c\nindex f5a656ac71..44de0c5a77 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -1441,14 +1441,24 @@ static int count_messages(struct strbuf *all_msgs)\n \n \twhile (1) {\n \t\tif (starts_with(p, \"From \")) {\n-\t\t\tp = strstr(p+5, \"\\nFrom: \");\n-\t\t\tif (!p) break;\n-\t\t\tp = strstr(p+7, \"\\nDate: \");\n-\t\t\tif (!p) break;\n-\t\t\tp = strstr(p+7, \"\\nSubject: \");\n-\t\t\tif (!p) break;\n-\t\t\tp += 10;\n-\t\t\tcount++;\n+\t\t\tif (starts_with(p, \"From git-send-email\")) {\n+\t\t\t\tp = strstr(p+5, \"\\nFrom: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp += 7;\n+\t\t\t\tp = strstr(p, \"\\nTo: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp += 5;\n+\t\t\t\tcount++;\n+\t\t\t} else {\n+\t\t\t\tp = strstr(p+5, \"\\nFrom: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp = strstr(p+7, \"\\nDate: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp = strstr(p+7, \"\\nSubject: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp += 10;\n+\t\t\t\tcount++;\n+\t\t\t}\n \t\t}\n \t\tp = strstr(p+5, \"\\nFrom \");\n \t\tif (!p)\n\nRange-diff against v1:\n1:  c87d31a672 ! 1:  87a8901825 send-email: add ability to send a copy of sent emails to an IMAP folder\n    @@ Commit message\n         send-email: add ability to send a copy of sent emails to an IMAP folder\n     \n         Some email providers like Apple iCloud Mail do not support sending a copy\n    -    of sent emails to the \"Sent\" folder if emails are sent via SMTP. As a\n    +    of sent emails to the \"Sent\" folder if SMTP server is used. As a\n         workaround, various email clients like Thunderbird which rely on SMTP,\n         use IMAP to send a copy of sent emails to the \"Sent\" folder. Something\n    -    similar can be done with if sending emails via `git send-email`, by using\n    +    similar can be done if sending emails via `git send-email`, by using\n         the `git imap-send` command to send a copy of the sent email to an IMAP\n         folder specified by the user.\n     \n    @@ imap-send.c: static int count_messages(struct strbuf *all_msgs)\n     -\t\t\tp = strstr(p+7, \"\\nDate: \");\n     -\t\t\tif (!p) break;\n     -\t\t\tp = strstr(p+7, \"\\nSubject: \");\n    +-\t\t\tif (!p) break;\n    +-\t\t\tp += 10;\n    +-\t\t\tcount++;\n     +\t\t\tif (starts_with(p, \"From git-send-email\")) {\n     +\t\t\t\tp = strstr(p+5, \"\\nFrom: \");\n     +\t\t\t\tif (!p) break;\n    @@ imap-send.c: static int count_messages(struct strbuf *all_msgs)\n     +\t\t\t\tp = strstr(p+7, \"\\nDate: \");\n     +\t\t\t\tif (!p) break;\n     +\t\t\t\tp = strstr(p+7, \"\\nSubject: \");\n    - \t\t\tif (!p) break;\n    - \t\t\tp += 10;\n    - \t\t\tcount++;\n    ++\t\t\t\tif (!p) break;\n    ++\t\t\t\tp += 10;\n    ++\t\t\t\tcount++;\n     +\t\t\t}\n      \t\t}\n      \t\tp = strstr(p+5, \"\\nFrom \");\n-- \n2.50.1.windows.1\n\n"},{"id":"522362","messageId":"CAPig+cQGhy57YWLpyxZyMEUb5jc=9wHWYOOhjzEaj1yHf6MC6Q@mail.gmail.com","threadId":"63810","inReplyTo":"87a890182591c9c21061e85834fc99a766252611.1753092192.git.gargaditya08@live.com","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2025-07-21T16:34:28Z","receivedAt":"2025-07-21T16:34:40Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Jul 21, 2025 at 6:05 AM Aditya Garg <gargaditya08@live.com> wrote:\n> Some email providers like Apple iCloud Mail do not support sending a copy\n> of sent emails to the \"Sent\" folder if SMTP server is used. As a\n> workaround, various email clients like Thunderbird which rely on SMTP,\n> use IMAP to send a copy of sent emails to the \"Sent\" folder. Something\n> similar can be done if sending emails via `git send-email`, by using\n> the `git imap-send` command to send a copy of the sent email to an IMAP\n> folder specified by the user.\n>\n> Add this functionality to `git send-email` by introducing a new\n> configuration variable `sendemail.imapfolder` and command line option\n> `--imap-folder` which specifies the IMAP folder to send a copy of the\n> sent emails to. If specified, a copy of the sent emails will be sent\n> by piping the emails to `git imap-send` command, after the all emails are\n> sent via SMTP and the SMTP server has been closed.\n\ns/the all/all/\n\n> Signed-off-by: Aditya Garg <gargaditya08@live.com>\n> ---\n> @@ -299,6 +299,18 @@ must be used for each option.\n> +This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n> +to get instructions for the same.\n\nPerhaps:\n\n  This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n  for instructions.\n\n> diff --git a/git-send-email.perl b/git-send-email.perl\n> @@ -73,6 +73,8 @@ sub usage {\n> +    --imap-folder           <str>  * IMAP folder where a copy of the emails should be sent.\n> +                                     Make sure `git imap-send` is setup to use this feature.\n\ns/setup/set up/\n"},{"id":"522367","messageId":"xmqqpldtxsp7.fsf@gitster.g","threadId":"63810","inReplyTo":"87a890182591c9c21061e85834fc99a766252611.1753092192.git.gargaditya08@live.com","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-07-21T19:13:56Z","receivedAt":"2025-07-21T19:13:59Z","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> +sendemail.imapfolder::\n\nDo we expect that the use of IMAP in git-send-email will be limited\nforever to store outgoing e-mails to the Sent folder?  I highly\ndoubt it.  For example, would it be plausible that given send-email\nhas so much richer feature set compared to imap-send, it would not\nbe implausible for users of imap-send that want to stuff messages,\nwith Cc's, threading, etc., all prepared by send-email, to their\noutgoing folder.\n\nAnd when somebody wants to add such a feature to \"git send-email\",\nhow would they find this variable that uses imap-send for quite a\ndifferent purpose squatting on its name?\n\nSame comment for the --imap-folder command line option and the\ninternal variable(s) used to implement this feature.\n\nThese things should be named with words like \"sent\", \"fcc\", etc., to\nclarify the use case this new feature is trying to support.\n\nAs imap-send is not part of my daily workflow, I have no strong\nopinions for or against the proposed feature, and I didn't find\nanything glaringly wrong in the implementation, other than the poor\nnaming that would block possible future enhancements.\n\nThanks.\n\n"},{"id":"522380","messageId":"aH7ZHlA4CtIBHSgX@fruit.crustytoothpaste.net","threadId":"63810","inReplyTo":"xmqqpldtxsp7.fsf@gitster.g","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2025-07-22T00:19:42Z","receivedAt":"2025-07-22T00:19:44Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2025-07-21 at 19:13:56, Junio C Hamano wrote:\n> Aditya Garg <gargaditya08@live.com> writes:\n> \n> > +sendemail.imapfolder::\n> \n> Do we expect that the use of IMAP in git-send-email will be limited\n> forever to store outgoing e-mails to the Sent folder?  I highly\n> doubt it.  For example, would it be plausible that given send-email\n> has so much richer feature set compared to imap-send, it would not\n> be implausible for users of imap-send that want to stuff messages,\n> with Cc's, threading, etc., all prepared by send-email, to their\n> outgoing folder.\n> \n> And when somebody wants to add such a feature to \"git send-email\",\n> how would they find this variable that uses imap-send for quite a\n> different purpose squatting on its name?\n> \n> Same comment for the --imap-folder command line option and the\n> internal variable(s) used to implement this feature.\n> \n> These things should be named with words like \"sent\", \"fcc\", etc., to\n> clarify the use case this new feature is trying to support.\n\nI think this is a good idea.  We should be thoughtful about our option\nnames here.\n\n> As imap-send is not part of my daily workflow, I have no strong\n> opinions for or against the proposed feature, and I didn't find\n> anything glaringly wrong in the implementation, other than the poor\n> naming that would block possible future enhancements.\n\nI would also like to advocate in favour of the feature in general.  I\nrun my own mail server and there is no magical functionality to add my\noutgoing emails to the Sent folder, so I can definitely see the utility\nof this functionality.  I'm sure there are also other, larger mail\nproviders for which this would be useful as well.  (I suspect the patch\nauthor is on one of them, in fact.)\n-- \nbrian m. carlson (they/them)\nToronto, Ontario, CA\n"},{"id":"522388","messageId":"PN3PR01MB95976A7BE0F9A54E836FA2F5B85CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"xmqqpldtxsp7.fsf@gitster.g","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-22T03:37:26Z","receivedAt":"2025-07-22T03:37:33Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\nOn 22 July 2025 12:43:56 am IST, Junio C Hamano <gitster@pobox.com> wrote:\n>Aditya Garg <gargaditya08@live.com> writes:\n>\n>> +sendemail.imapfolder::\n>\n>Do we expect that the use of IMAP in git-send-email will be limited\n>forever to store outgoing e-mails to the Sent folder?  I highly\n>doubt it.  For example, would it be plausible that given send-email\n>has so much richer feature set compared to imap-send, it would not\n>be implausible for users of imap-send that want to stuff messages,\n>with Cc's, threading, etc., all prepared by send-email, to their\n>outgoing folder.\n\nI have left that feature opened, thus I have not hardcoded and folder name here. You can simply set imapfolder as Outgoing, Drafts etc as well.\n\nOr maybe you mean, ONLY send via imap and don't use SMTP? Like this users can use their email clients to send emails?\n\n>\n>And when somebody wants to add such a feature to \"git send-email\",\n>how would they find this variable that uses imap-send for quite a\n>different purpose squatting on its name?\n>\n>Same comment for the --imap-folder command line option and the\n>internal variable(s) used to implement this feature.\n>\n>These things should be named with words like \"sent\", \"fcc\", etc., to\n>clarify the use case this new feature is trying to support.\n>\n\nIMAP folder is a simple variable that decides to which folder the mails need to be sent. It can be sent, outbox, Drafts etc. I don't think any future enhancement would have any confusion with this?\n\nFor cases which want to use ONLY IMAP send, a bool like use_imap_only etc can be used with imap_folder.\n\nAlthough, I am open to better name suggestions.\n\n>As imap-send is not part of my daily workflow, I have no strong\n>opinions for or against the proposed feature, and I didn't find\n>anything glaringly wrong in the implementation, other than the poor\n>naming that would block possible future enhancements.\n>\n>Thanks.\n>\n"},{"id":"522389","messageId":"PN3PR01MB959761400F09B60093A5ABD7B85CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"aH7ZHlA4CtIBHSgX@fruit.crustytoothpaste.net","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-22T03:40:40Z","receivedAt":"2025-07-22T03:40:47Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\nOn 22 July 2025 5:49:42 am IST, \"brian m. carlson\" <sandals@crustytoothpaste.net> wrote:\n>On 2025-07-21 at 19:13:56, Junio C Hamano wrote:\n>> Aditya Garg <gargaditya08@live.com> writes:\n>> \n>> > +sendemail.imapfolder::\n>> \n>> Do we expect that the use of IMAP in git-send-email will be limited\n>> forever to store outgoing e-mails to the Sent folder?  I highly\n>> doubt it.  For example, would it be plausible that given send-email\n>> has so much richer feature set compared to imap-send, it would not\n>> be implausible for users of imap-send that want to stuff messages,\n>> with Cc's, threading, etc., all prepared by send-email, to their\n>> outgoing folder.\n>> \n>> And when somebody wants to add such a feature to \"git send-email\",\n>> how would they find this variable that uses imap-send for quite a\n>> different purpose squatting on its name?\n>> \n>> Same comment for the --imap-folder command line option and the\n>> internal variable(s) used to implement this feature.\n>> \n>> These things should be named with words like \"sent\", \"fcc\", etc., to\n>> clarify the use case this new feature is trying to support.\n>\n>I think this is a good idea.  We should be thoughtful about our option\n>names here.\n>\n\nAs I said to Junio, I am happy to have ideas on better names, since I would like to clarify that sent folder is a typical use case, but the variable can be used for any IMAP folder.\n\n>> As imap-send is not part of my daily workflow, I have no strong\n>> opinions for or against the proposed feature, and I didn't find\n>> anything glaringly wrong in the implementation, other than the poor\n>> naming that would block possible future enhancements.\n>\n>I would also like to advocate in favour of the feature in general.  I\n>run my own mail server and there is no magical functionality to add my\n>outgoing emails to the Sent folder, so I can definitely see the utility\n>of this functionality.  I'm sure there are also other, larger mail\n>providers for which this would be useful as well.  (I suspect the patch\n>author is on one of them, in fact.)\n\nFortunately my Outlook email which I am using for this chat has the magic functionality of saving a copy to sent folder, but my personal iCloud email does not, which after this patch works as intended.\n"},{"id":"522391","messageId":"xmqq4iv4x15e.fsf@gitster.g","threadId":"63810","inReplyTo":"PN3PR01MB95976A7BE0F9A54E836FA2F5B85CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-07-22T05:09:01Z","receivedAt":"2025-07-22T05:09:05Z","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> Or maybe you mean, ONLY send via imap and don't use SMTP? Like\n> this users can use their email clients to send emails?\n\nExactly.  You sold this feature as \"have send-email send the\nmessage, and keep an extra copy you sent in your Sent imap folder\".\n\nI pointed out that \"have send-email do everything it would normally\ndo before it talks to MSA or talk SMTP to send messages out, and\ninstead drive imap-send to store these messages in a folder like\nimap-send users have used the program so far---as the user will send\nthe messages out of their draft folder as was traditionally done by\nany imap-send users, send-email will *not* send anything out itself\"\nas a possible different way send-email may want to use imap-send.\n\nThese are two very different use cases.  We could organize things\nthis way:\n\n A1. When imap-folder is specified, that IMAP folder will get an extra\n     copy, in addition to what send-email sends out;\n\n A2. When yet another new option, --send-email-no-send, is\n     specified, send-email would not send any messages out.  Even\n     when this option is in effect, if --imap-folder is specified,\n     that IMAP folder will get an extra copy, in addition to what\n     send-email would send out (which is nothing).\n\nOr alternatively, we can have two very different operation modes\nthat both involve imap-send:\n\n B1. When --imap-sent-folder is specified, that IMAP folder will get\n     an extra copy, in addition to what send-email sent out via its\n     usual route (like by invoking MSA or talking SMTP)\n\n B2. When --imap-outgo-folder is specified, that IMAP folder will\n     get the outgo copy, later to be sent by the user (just like a\n     user of imap-send would usually use), and send-email would not\n     send out anything by its usual route.\n\nI thought the latter would be easier to explain to end-users, which\nis why \"sent\" or \"fcc\" or something like that should be in the name\nof the option when operating in the mode the patch implements.\n\nThis brings up a yet another possibility.  Invoking imap-send can be\na new third way send-email uses to send out the messages, in addition\nto existing (1) invoking a local \"/usr/lib/sendmail\" program, or (2)\ntalking SMTP to smarthost.  That would be very easy to explain the\noperating mode B2 to users of send-email or users of imap-send, but\nit would be a bit awkward to find where B1 conceptually fits.\n\n"},{"id":"522392","messageId":"PN3PR01MB9597B8D3D84D9F7660F15E94B85CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"xmqq4iv4x15e.fsf@gitster.g","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-22T06:14:28Z","receivedAt":"2025-07-22T06:14:44Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\n\n\nOn 22 July 2025 10:39:01 am IST, Junio C Hamano <gitster@pobox.com> wrote:\n>Aditya Garg <gargaditya08@live.com> writes:\n>\n>> Or maybe you mean, ONLY send via imap and don't use SMTP? Like\n>> this users can use their email clients to send emails?\n>\n>Exactly.  You sold this feature as \"have send-email send the\n>message, and keep an extra copy you sent in your Sent imap folder\".\n>\n>I pointed out that \"have send-email do everything it would normally\n>do before it talks to MSA or talk SMTP to send messages out, and\n>instead drive imap-send to store these messages in a folder like\n>imap-send users have used the program so far---as the user will send\n>the messages out of their draft folder as was traditionally done by\n>any imap-send users, send-email will *not* send anything out itself\"\n>as a possible different way send-email may want to use imap-send.\n>\n>These are two very different use cases.  We could organize things\n>this way:\n>\n> A1. When imap-folder is specified, that IMAP folder will get an extra\n>     copy, in addition to what send-email sends out;\n>\n> A2. When yet another new option, --send-email-no-send, is\n>     specified, send-email would not send any messages out.  Even\n>     when this option is in effect, if --imap-folder is specified,\n>     that IMAP folder will get an extra copy, in addition to what\n>     send-email would send out (which is nothing).\n>\n>Or alternatively, we can have two very different operation modes\n>that both involve imap-send:\n>\n> B1. When --imap-sent-folder is specified, that IMAP folder will get\n>     an extra copy, in addition to what send-email sent out via its\n>     usual route (like by invoking MSA or talking SMTP)\n>\n> B2. When --imap-outgo-folder is specified, that IMAP folder will\n>     get the outgo copy, later to be sent by the user (just like a\n>     user of imap-send would usually use), and send-email would not\n>     send out anything by its usual route.\n>\n>I thought the latter would be easier to explain to end-users, which\n>is why \"sent\" or \"fcc\" or something like that should be in the name\n>of the option when operating in the mode the patch implements.\n>\n>This brings up a yet another possibility.  Invoking imap-send can be\n>a new third way send-email uses to send out the messages, in addition\n>to existing (1) invoking a local \"/usr/lib/sendmail\" program, or (2)\n>talking SMTP to smarthost.  That would be very easy to explain the\n>operating mode B2 to users of send-email or users of imap-send, but\n>it would be a bit awkward to find where B1 conceptually fits.\n>\n\nHonestly, B2 looks like a doable thing, but I don't think people would really want to use this mode. Considering the fact that using an MSA or SMTP is much better, and commonly used. Also, imap-send was definitely not in use, especially looking that the fact that it was broken for a very long time.\n\nI'll rename it to imap-sent-folder, but the name looks more like it is only for \"Sent\" folder, and no other folder can be used. For example I like to keep a copy of the emails I send to git mailing list in a seperate 'git' folder in my mailbox. I can set the folder name as git, and thus have a copy saved there. What do you think about that?\n"},{"id":"522422","messageId":"da7cee769f25871ed3f934e3ec7f2cccf0a0420c.1753182534.git.gargaditya08@live.com","threadId":"63810","inReplyTo":"08528f201acc1038ebc5861321395d17516094fd.1753003385.git.gargaditya08@live.com","subject":"[PATCH v3] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-22T11:14:16Z","receivedAt":"2025-07-22T11:14:21Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Some email providers like Apple iCloud Mail do not support sending a copy\nof sent emails to the \"Sent\" folder if SMTP server is used. As a\nworkaround, various email clients like Thunderbird which rely on SMTP,\nuse IMAP to send a copy of sent emails to the \"Sent\" folder. Something\nsimilar can be done if sending emails via `git send-email`, by using\nthe `git imap-send` command to send a copy of the sent email to an IMAP\nfolder specified by the user.\n\nAdd this functionality to `git send-email` by introducing a new\nconfiguration variable `sendemail.imapfolder` and command line option\n`--imap-folder` which specifies the IMAP folder to send a copy of the\nsent emails to. If specified, a copy of the sent emails will be sent\nby piping the emails to `git imap-send` command, after the all emails are\nsent via SMTP and the SMTP server has been closed.\n\nSigned-off-by: Aditya Garg <gargaditya08@live.com>\n---\n\nv2 - Fix indentation in patch for imap-send.c\n   - Minor edits to commit message\n\nv3 - Rename imap folder to imap sent folder\n   - Make an error message shorter by removing unecessary details\n\n Documentation/config/sendemail.adoc |  1 +\n Documentation/git-send-email.adoc   | 12 +++++++++++\n git-send-email.perl                 | 31 ++++++++++++++++++++++++++++-\n imap-send.c                         | 26 ++++++++++++++++--------\n 4 files changed, 61 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/config/sendemail.adoc b/Documentation/config/sendemail.adoc\nindex 4722334657..dd2dbc87a0 100644\n--- a/Documentation/config/sendemail.adoc\n+++ b/Documentation/config/sendemail.adoc\n@@ -88,6 +88,7 @@ sendemail.smtpServer::\n sendemail.smtpServerPort::\n sendemail.smtpServerOption::\n sendemail.smtpUser::\n+sendemail.imapSentFolder::\n sendemail.thread::\n sendemail.transferEncoding::\n sendemail.validate::\ndiff --git a/Documentation/git-send-email.adoc b/Documentation/git-send-email.adoc\nindex 5335502d68..82a65fd47f 100644\n--- a/Documentation/git-send-email.adoc\n+++ b/Documentation/git-send-email.adoc\n@@ -299,6 +299,18 @@ must be used for each option.\n \tcommands and replies will be printed. Useful to debug TLS\n \tconnection and authentication problems.\n \n+--imap-sent-folder=<folder>::\n+\tSome email providers (e.g. iCloud) do not send a copy of the emails sent\n+\tusing SMTP to the `Sent` folder or similar in your mailbox. Use this option\n+\tto use `git imap-send` to send a copy of the emails to the folder specified\n+\tusing this option. You can run `git imap-send --list` to get a list of\n+\tvalid folder names, including the correct name of the `Sent` folder in\n+\tyour mailbox. You can also use this option to send emails to a dedicated\n+\tIMAP folder of your choice.\n++\n+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n+to get instructions for the same.\n+\n --batch-size=<num>::\n \tSome email servers (e.g. 'smtp.163.com') limit the number of emails to be\n \tsent per session (connection) and this will lead to a failure when\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 437f8ac46a..5aafe8cdf3 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -73,6 +73,8 @@ sub usage {\n     --no-smtp-auth                 * Disable SMTP authentication. Shorthand for\n                                      `--smtp-auth=none`\n     --smtp-debug            <0|1>  * Disable, enable Net::SMTP debug.\n+    --imap-sent-folder      <str>  * IMAP folder where a copy of the emails should be sent.\n+                                     Make sure `git imap-send` is setup to use this feature.\n \n     --batch-size            <int>  * send max <int> message per connection.\n     --relogin-delay         <int>  * delay <int> seconds between two successive login.\n@@ -200,7 +202,7 @@ sub format_2822_time {\n \n # Variables we fill in automatically, or via prompting:\n my (@to,@cc,@xh,$envelope_sender,\n-\t$initial_in_reply_to,$reply_to,$initial_subject,@files,\n+\t$initial_in_reply_to,$reply_to,$initial_subject,@files,@imap_copy,\n \t$author,$sender,$smtp_authpass,$annotate,$compose,$time);\n # Things we either get from config, *or* are overridden on the\n # command-line.\n@@ -277,6 +279,7 @@ sub do_edit {\n my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);\n my ($batch_size, $relogin_delay);\n my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);\n+my ($imap_sent_folder);\n my ($confirm);\n my (@suppress_cc);\n my ($auto_8bit_encoding);\n@@ -322,6 +325,7 @@ sub do_edit {\n     \"smtpauth\" => \\$smtp_auth,\n     \"smtpbatchsize\" => \\$batch_size,\n     \"smtprelogindelay\" => \\$relogin_delay,\n+    \"imapsentfolder\" => \\$imap_sent_folder,\n     \"to\" => \\@config_to,\n     \"tocmd\" => \\$to_cmd,\n     \"cc\" => \\@config_cc,\n@@ -527,6 +531,7 @@ sub config_regexp {\n \t\t    \"smtp-domain:s\" => \\$smtp_domain,\n \t\t    \"smtp-auth=s\" => \\$smtp_auth,\n \t\t    \"no-smtp-auth\" => sub {$smtp_auth = 'none'},\n+\t\t    \"imap-sent-folder=s\" => \\$imap_sent_folder,\n \t\t    \"annotate!\" => \\$annotate,\n \t\t    \"compose\" => \\$compose,\n \t\t    \"quiet\" => \\$quiet,\n@@ -1829,6 +1834,17 @@ sub send_message {\n \t\tprint \"\\n\";\n \t}\n \n+\tif ($imap_sent_folder) {\n+\t\tmy $imap_header = $header;\n+\t\tif (@initial_bcc) {\n+\t\t\t# Bcc is not a part of $header, so we add it here.\n+\t\t\t# This is only for the IMAP copy, not for the actual email\n+\t\t\t# sent to the recipients.\n+\t\t\t$imap_header .= \"Bcc: \" . join(\", \", @initial_bcc) . \"\\n\";\n+\t\t}\n+\t\tpush @imap_copy, \"From git-send-email\\n$imap_header\\n$message\";\n+\t}\n+\n \treturn 1;\n }\n \n@@ -2223,6 +2239,19 @@ sub cleanup_compose_files {\n \n $smtp->quit if $smtp;\n \n+if ($imap_sent_folder && @imap_copy) {\n+\tmy $imap_input = join(\"\\n\", @imap_copy);\n+\teval {\n+\t\tprint \"\\nStarting git imap-send...\\n\";\n+\t\tmy ($fh, $ctx) = Git::command_input_pipe(['imap-send', '-f', $imap_sent_folder]);\n+\t\tprint $fh $imap_input;\n+\t\tGit::command_close_pipe($fh, $ctx);\n+\t\t1;\n+\t} or do {\n+\t\twarn \"Warning: failed to send messages to IMAP folder $imap_sent_folder: $@\";\n+\t};\n+}\n+\n sub apply_transfer_encoding {\n \tmy $message = shift;\n \tmy $from = shift;\ndiff --git a/imap-send.c b/imap-send.c\nindex f5a656ac71..44de0c5a77 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -1441,14 +1441,24 @@ static int count_messages(struct strbuf *all_msgs)\n \n \twhile (1) {\n \t\tif (starts_with(p, \"From \")) {\n-\t\t\tp = strstr(p+5, \"\\nFrom: \");\n-\t\t\tif (!p) break;\n-\t\t\tp = strstr(p+7, \"\\nDate: \");\n-\t\t\tif (!p) break;\n-\t\t\tp = strstr(p+7, \"\\nSubject: \");\n-\t\t\tif (!p) break;\n-\t\t\tp += 10;\n-\t\t\tcount++;\n+\t\t\tif (starts_with(p, \"From git-send-email\")) {\n+\t\t\t\tp = strstr(p+5, \"\\nFrom: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp += 7;\n+\t\t\t\tp = strstr(p, \"\\nTo: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp += 5;\n+\t\t\t\tcount++;\n+\t\t\t} else {\n+\t\t\t\tp = strstr(p+5, \"\\nFrom: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp = strstr(p+7, \"\\nDate: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp = strstr(p+7, \"\\nSubject: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp += 10;\n+\t\t\t\tcount++;\n+\t\t\t}\n \t\t}\n \t\tp = strstr(p+5, \"\\nFrom \");\n \t\tif (!p)\n\nRange-diff against v2:\n1:  01084f57f9 ! 1:  da7cee769f send-email: add ability to send a copy of sent emails to an IMAP folder\n    @@ Documentation/config/sendemail.adoc: sendemail.smtpServer::\n      sendemail.smtpServerPort::\n      sendemail.smtpServerOption::\n      sendemail.smtpUser::\n    -+sendemail.imapfolder::\n    ++sendemail.imapSentFolder::\n      sendemail.thread::\n      sendemail.transferEncoding::\n      sendemail.validate::\n    @@ Documentation/git-send-email.adoc: must be used for each option.\n      \tcommands and replies will be printed. Useful to debug TLS\n      \tconnection and authentication problems.\n      \n    -+--imap-folder=<folder>::\n    ++--imap-sent-folder=<folder>::\n     +\tSome email providers (e.g. iCloud) do not send a copy of the emails sent\n     +\tusing SMTP to the `Sent` folder or similar in your mailbox. Use this option\n     +\tto use `git imap-send` to send a copy of the emails to the folder specified\n    @@ git-send-email.perl: sub usage {\n          --no-smtp-auth                 * Disable SMTP authentication. Shorthand for\n                                           `--smtp-auth=none`\n          --smtp-debug            <0|1>  * Disable, enable Net::SMTP debug.\n    -+    --imap-folder           <str>  * IMAP folder where a copy of the emails should be sent.\n    ++    --imap-sent-folder      <str>  * IMAP folder where a copy of the emails should be sent.\n     +                                     Make sure `git imap-send` is setup to use this feature.\n      \n          --batch-size            <int>  * send max <int> message per connection.\n    @@ git-send-email.perl: sub do_edit {\n      my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);\n      my ($batch_size, $relogin_delay);\n      my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);\n    -+my ($imap_folder);\n    ++my ($imap_sent_folder);\n      my ($confirm);\n      my (@suppress_cc);\n      my ($auto_8bit_encoding);\n    @@ git-send-email.perl: sub do_edit {\n          \"smtpauth\" => \\$smtp_auth,\n          \"smtpbatchsize\" => \\$batch_size,\n          \"smtprelogindelay\" => \\$relogin_delay,\n    -+    \"imapfolder\" => \\$imap_folder,\n    ++    \"imapsentfolder\" => \\$imap_sent_folder,\n          \"to\" => \\@config_to,\n          \"tocmd\" => \\$to_cmd,\n          \"cc\" => \\@config_cc,\n    @@ git-send-email.perl: sub config_regexp {\n      \t\t    \"smtp-domain:s\" => \\$smtp_domain,\n      \t\t    \"smtp-auth=s\" => \\$smtp_auth,\n      \t\t    \"no-smtp-auth\" => sub {$smtp_auth = 'none'},\n    -+\t\t    \"imap-folder=s\" => \\$imap_folder,\n    ++\t\t    \"imap-sent-folder=s\" => \\$imap_sent_folder,\n      \t\t    \"annotate!\" => \\$annotate,\n      \t\t    \"compose\" => \\$compose,\n      \t\t    \"quiet\" => \\$quiet,\n    @@ git-send-email.perl: sub send_message {\n      \t\tprint \"\\n\";\n      \t}\n      \n    -+\tif ($imap_folder) {\n    ++\tif ($imap_sent_folder) {\n     +\t\tmy $imap_header = $header;\n     +\t\tif (@initial_bcc) {\n     +\t\t\t# Bcc is not a part of $header, so we add it here.\n    @@ git-send-email.perl: sub cleanup_compose_files {\n      \n      $smtp->quit if $smtp;\n      \n    -+if ($imap_folder && @imap_copy) {\n    ++if ($imap_sent_folder && @imap_copy) {\n     +\tmy $imap_input = join(\"\\n\", @imap_copy);\n     +\teval {\n     +\t\tprint \"\\nStarting git imap-send...\\n\";\n    -+\t\tmy ($fh, $ctx) = Git::command_input_pipe(['imap-send', '-f', $imap_folder]);\n    ++\t\tmy ($fh, $ctx) = Git::command_input_pipe(['imap-send', '-f', $imap_sent_folder]);\n     +\t\tprint $fh $imap_input;\n     +\t\tGit::command_close_pipe($fh, $ctx);\n     +\t\t1;\n     +\t} or do {\n    -+\t\twarn \"Warning: failed to send messages to IMAP folder $imap_folder via imap-send pipe: $@\";\n    ++\t\twarn \"Warning: failed to send messages to IMAP folder $imap_sent_folder: $@\";\n     +\t};\n     +}\n     +\n-- \n2.50.1.319.gda7cee769f\n\n"},{"id":"522432","messageId":"PN3PR01MB95973B291F0A52A19DA8BD49B85CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"PN3PR01MB9597B8D3D84D9F7660F15E94B85CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-22T11:24:51Z","receivedAt":"2025-07-22T11:24:58Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\nOn 22/07/25 11:44 am, Aditya Garg wrote:\n> \n> \n> \n> \n> On 22 July 2025 10:39:01 am IST, Junio C Hamano <gitster@pobox.com> wrote:\n>> Aditya Garg <gargaditya08@live.com> writes:\n>>\n>>> Or maybe you mean, ONLY send via imap and don't use SMTP? Like\n>>> this users can use their email clients to send emails?\n>>\n>> Exactly.  You sold this feature as \"have send-email send the\n>> message, and keep an extra copy you sent in your Sent imap folder\".\n>>\n>> I pointed out that \"have send-email do everything it would normally\n>> do before it talks to MSA or talk SMTP to send messages out, and\n>> instead drive imap-send to store these messages in a folder like\n>> imap-send users have used the program so far---as the user will send\n>> the messages out of their draft folder as was traditionally done by\n>> any imap-send users, send-email will *not* send anything out itself\"\n>> as a possible different way send-email may want to use imap-send.\n>>\n>> These are two very different use cases.  We could organize things\n>> this way:\n>>\n>> A1. When imap-folder is specified, that IMAP folder will get an extra\n>>     copy, in addition to what send-email sends out;\n>>\n>> A2. When yet another new option, --send-email-no-send, is\n>>     specified, send-email would not send any messages out.  Even\n>>     when this option is in effect, if --imap-folder is specified,\n>>     that IMAP folder will get an extra copy, in addition to what\n>>     send-email would send out (which is nothing).\n>>\n>> Or alternatively, we can have two very different operation modes\n>> that both involve imap-send:\n>>\n>> B1. When --imap-sent-folder is specified, that IMAP folder will get\n>>     an extra copy, in addition to what send-email sent out via its\n>>     usual route (like by invoking MSA or talking SMTP)\n>>\n>> B2. When --imap-outgo-folder is specified, that IMAP folder will\n>>     get the outgo copy, later to be sent by the user (just like a\n>>     user of imap-send would usually use), and send-email would not\n>>     send out anything by its usual route.\n>>\n>> I thought the latter would be easier to explain to end-users, which\n>> is why \"sent\" or \"fcc\" or something like that should be in the name\n>> of the option when operating in the mode the patch implements.\n>>\n>> This brings up a yet another possibility.  Invoking imap-send can be\n>> a new third way send-email uses to send out the messages, in addition\n>> to existing (1) invoking a local \"/usr/lib/sendmail\" program, or (2)\n>> talking SMTP to smarthost.  That would be very easy to explain the\n>> operating mode B2 to users of send-email or users of imap-send, but\n>> it would be a bit awkward to find where B1 conceptually fits.\n>>\n> \n> Honestly, B2 looks like a doable thing, but I don't think people would really want to use this mode. Considering the fact that using an MSA or SMTP is much better, and commonly used. Also, imap-send was definitely not in use, especially looking that the fact that it was broken for a very long time.\n> \n> I'll rename it to imap-sent-folder, but the name looks more like it is only for \"Sent\" folder, and no other folder can be used. For example I like to keep a copy of the emails I send to git mailing list in a seperate 'git' folder in my mailbox. I can set the folder name as git, and thus have a copy saved there. What do you think about that?\n\nAlso, as far as B2 is concerned, users can already do something like:\n\ngit format-patch -2 HEAD --to=someone@example.com --stdout | git imap-send\n\nWhich is more or less the same what git-send-email would do. The objective to add imap-send to send-email was not\nto add another feature for sending emails, but rather keep to copy of the sent emails at the desired correct place\nin their own mailbox.\n\n"},{"id":"522439","messageId":"xmqqtt34uznu.fsf@gitster.g","threadId":"63810","inReplyTo":"PN3PR01MB9597B8D3D84D9F7660F15E94B85CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-07-22T13:24:05Z","receivedAt":"2025-07-22T13:24:08Z","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> I'll rename it to imap-sent-folder, but the name looks more like\n> it is only for \"Sent\" folder, and no other folder can be used. For\n> example I like to keep a copy of the emails I send to git mailing\n> list in a seperate 'git' folder in my mailbox. I can set the\n> folder name as git, and thus have a copy saved there. What do you\n> think about that?\n\nSorry, I am puzzled.\n\nThe reason why the option \"--imap-sent-folder=<you-name-that-thing>\"\ntakes a value, and not a \"--[no-]imap-keep-copy-in-the-Sent-folder\"\nBoolean, is exactly because you want to give whatever name you want\nit to use, so I am not sure why you are even asking that question.\n"},{"id":"522440","messageId":"PN3PR01MB9597E6071DC91F5256930AF1B85CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"xmqqtt34uznu.fsf@gitster.g","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-22T13:26:21Z","receivedAt":"2025-07-22T13:26:32Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\nOn 22 July 2025 6:54:05 pm IST, Junio C Hamano <gitster@pobox.com> wrote:\n>Aditya Garg <gargaditya08@live.com> writes:\n>\n>> I'll rename it to imap-sent-folder, but the name looks more like\n>> it is only for \"Sent\" folder, and no other folder can be used. For\n>> example I like to keep a copy of the emails I send to git mailing\n>> list in a seperate 'git' folder in my mailbox. I can set the\n>> folder name as git, and thus have a copy saved there. What do you\n>> think about that?\n>\n>Sorry, I am puzzled.\n>\n>The reason why the option \"--imap-sent-folder=<you-name-that-thing>\"\n>takes a value, and not a \"--[no-]imap-keep-copy-in-the-Sent-folder\"\n>Boolean, is exactly because you want to give whatever name you want\n>it to use, so I am not sure why you are even asking that question.\n\nI asked that question because --imap-sent-folder gives user an intuition to type in the name of the Sent folder rather than any folder. Anyways, I am fine with any name.\n"},{"id":"522457","messageId":"xmqqo6tctez2.fsf@gitster.g","threadId":"63810","inReplyTo":"PN3PR01MB95973B291F0A52A19DA8BD49B85CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-07-22T15:36:17Z","receivedAt":"2025-07-22T15:36:20Z","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> Also, as far as B2 is concerned, users can already do something like:\n>\n> git format-patch -2 HEAD --to=someone@example.com --stdout | git imap-send\n\nIf the above command line is sufficient for users, \"git send-email\"\ndoes not need its feature to drive format-patch and do\n\n    git format-patch -o outgo/. -2 HEAD &&\n    git send-email --to=someone@example.com ./outgo/*.patch\n\nI used to think that way and I was naive ;-) But such an argument\ncompletely misses the point of various send-email options that allow\nthe user to tweak CC: list programatically, compose the cover\nletter, etc., doesn't it?\n\n\n"},{"id":"522468","messageId":"8596251B-7A3F-4220-8759-B75FF63964C0@live.com","threadId":"63810","inReplyTo":"xmqqo6tctez2.fsf@gitster.g","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-22T16:31:59Z","receivedAt":"2025-07-22T16:32:03Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\n> On 22 Jul 2025, at 9:06 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> \n> Aditya Garg <gargaditya08@live.com> writes:\n> \n>> Also, as far as B2 is concerned, users can already do something like:\n>> \n>> git format-patch -2 HEAD --to=someone@example.com --stdout | git imap-send\n> \n> If the above command line is sufficient for users, \"git send-email\"\n> does not need its feature to drive format-patch and do\n> \n>    git format-patch -o outgo/. -2 HEAD &&\n>    git send-email --to=someone@example.com ./outgo/*.patch\n> \n> I used to think that way and I was naive ;-) But such an argument\n> completely misses the point of various send-email options that allow\n> the user to tweak CC: list programatically, compose the cover\n> letter, etc., doesn't it?\n\nHmm, yes it does, but is this functionality in the scope of this patch?\n\nHonestly if you can use IMAP, you can also use SMTP, which makes me question if we really need this feature or not.\n\n"},{"id":"522470","messageId":"12F1986A-F7CE-47A4-8F30-2664799BE2FA@live.com","threadId":"63810","inReplyTo":"8596251B-7A3F-4220-8759-B75FF63964C0@live.com","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-22T16:36:46Z","receivedAt":"2025-07-22T16:36:50Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\n> On 22 Jul 2025, at 10:01 PM, Aditya Garg <gargaditya08@live.com> wrote:\n> \n> \n> \n>> On 22 Jul 2025, at 9:06 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> \n>> Aditya Garg <gargaditya08@live.com> writes:\n>> \n>>> Also, as far as B2 is concerned, users can already do something like:\n>>> \n>>> git format-patch -2 HEAD --to=someone@example.com --stdout | git imap-send\n>> \n>> If the above command line is sufficient for users, \"git send-email\"\n>> does not need its feature to drive format-patch and do\n>> \n>>   git format-patch -o outgo/. -2 HEAD &&\n>>   git send-email --to=someone@example.com ./outgo/*.patch\n>> \n>> I used to think that way and I was naive ;-) But such an argument\n>> completely misses the point of various send-email options that allow\n>> the user to tweak CC: list programatically, compose the cover\n>> letter, etc., doesn't it?\n> \n> Hmm, yes it does, but is this functionality in the scope of this patch?\n> \n> Honestly if you can use IMAP, you can also use SMTP, which makes me question if we really need this feature or not.\n\nBy “this feature” I mean the one that sends emails to IMAP only btw.\n\n"},{"id":"522475","messageId":"xmqqqzy8rvgn.fsf@gitster.g","threadId":"63810","inReplyTo":"8596251B-7A3F-4220-8759-B75FF63964C0@live.com","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-07-22T17:23:04Z","receivedAt":"2025-07-22T17:23:06Z","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> Hmm, yes it does, but is this functionality in the scope of this patch?\n\nNo, it is not.\n\nBut it is your responsibility to make sure that you leave the door\nopen for somebody who will want to do so later.  And you do so by\nnot squatting on a way more generic option and configuration\nvariable name than what the feature you are adding, which is more\nspecific than its name.\n\n"},{"id":"522476","messageId":"PN3PR01MB9597B5A115C48F6E1BD44026B85CA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"xmqqqzy8rvgn.fsf@gitster.g","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-22T17:26:21Z","receivedAt":"2025-07-22T17:26:30Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\nOn 22 July 2025 10:53:04 pm IST, Junio C Hamano <gitster@pobox.com> wrote:\n>Aditya Garg <gargaditya08@live.com> writes:\n>\n>> Hmm, yes it does, but is this functionality in the scope of this patch?\n>\n>No, it is not.\n>\n>But it is your responsibility to make sure that you leave the door\n>open for somebody who will want to do so later.  And you do so by\n>not squatting on a way more generic option and configuration\n>variable name than what the feature you are adding, which is more\n>specific than its name.\n\nI got that. I was not against renaming, I was just hoping for a better name. Anyways, I hope v3 sent already has addressed this concern.\n"},{"id":"522537","messageId":"PN3PR01MB9597EAA61E0E40B027B81DF6B85FA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"da7cee769f25871ed3f934e3ec7f2cccf0a0420c.1753182534.git.gargaditya08@live.com","subject":"Re: [PATCH v3] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-23T09:05:35Z","receivedAt":"2025-07-23T09:05:44Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\nOn 22/07/25 4:44 pm, Aditya Garg wrote:\n> Some email providers like Apple iCloud Mail do not support sending a copy\n> of sent emails to the \"Sent\" folder if SMTP server is used. As a\n> workaround, various email clients like Thunderbird which rely on SMTP,\n> use IMAP to send a copy of sent emails to the \"Sent\" folder. Something\n> similar can be done if sending emails via `git send-email`, by using\n> the `git imap-send` command to send a copy of the sent email to an IMAP\n> folder specified by the user.\n> \n> Add this functionality to `git send-email` by introducing a new\n> configuration variable `sendemail.imapfolder` and command line option\n> `--imap-folder` which specifies the IMAP folder to send a copy of the\n> sent emails to. If specified, a copy of the sent emails will be sent\n> by piping the emails to `git imap-send` command, after the all emails are\n> sent via SMTP and the SMTP server has been closed.\n> \n> Signed-off-by: Aditya Garg <gargaditya08@live.com>\n> ---\n> \n> v2 - Fix indentation in patch for imap-send.c\n>    - Minor edits to commit message\n> \n> v3 - Rename imap folder to imap sent folder\n>    - Make an error message shorter by removing unecessary details\n\nI just found a tiny bug here. It is sending emails to IMAP even if --dry-run is present. Will fix in v4.\nAlso, this little bug has also gave me an easier way to implement --use-imap-only, which is what Junio suggested before.\n\n\n\n"},{"id":"522541","messageId":"PN3PR01MB95971D1F070EDFA2562AB2D1B85FA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"CAPig+cQGhy57YWLpyxZyMEUb5jc=9wHWYOOhjzEaj1yHf6MC6Q@mail.gmail.com","subject":"Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-23T09:48:44Z","receivedAt":"2025-07-23T09:48:51Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\nOn 21/07/25 10:04 pm, Eric Sunshine wrote:\n> On Mon, Jul 21, 2025 at 6:05 AM Aditya Garg <gargaditya08@live.com> wrote:\n>> Some email providers like Apple iCloud Mail do not support sending a copy\n>> of sent emails to the \"Sent\" folder if SMTP server is used. As a\n>> workaround, various email clients like Thunderbird which rely on SMTP,\n>> use IMAP to send a copy of sent emails to the \"Sent\" folder. Something\n>> similar can be done if sending emails via `git send-email`, by using\n>> the `git imap-send` command to send a copy of the sent email to an IMAP\n>> folder specified by the user.\n>>\n>> Add this functionality to `git send-email` by introducing a new\n>> configuration variable `sendemail.imapfolder` and command line option\n>> `--imap-folder` which specifies the IMAP folder to send a copy of the\n>> sent emails to. If specified, a copy of the sent emails will be sent\n>> by piping the emails to `git imap-send` command, after the all emails are\n>> sent via SMTP and the SMTP server has been closed.\n> \n> s/the all/all/\n> \n>> Signed-off-by: Aditya Garg <gargaditya08@live.com>\n>> ---\n>> @@ -299,6 +299,18 @@ must be used for each option.\n>> +This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n>> +to get instructions for the same.\n> \n> Perhaps:\n> \n>   This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n>   for instructions.\n> \n>> diff --git a/git-send-email.perl b/git-send-email.perl\n>> @@ -73,6 +73,8 @@ sub usage {\n>> +    --imap-folder           <str>  * IMAP folder where a copy of the emails should be sent.\n>> +                                     Make sure `git imap-send` is setup to use this feature.\n> \n> s/setup/set up/\n\nWill apply these suggestions in v4. BTW Eric, is it the issue with Outlook marking your emails as spam everytime inspite of adding you to safe senders list, or something is wrong with your domain config?\n"},{"id":"522542","messageId":"PN3PR01MB9597EC4C5DF97943587AEEB4B85FA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"08528f201acc1038ebc5861321395d17516094fd.1753003385.git.gargaditya08@live.com","subject":"[PATCH v4 0/2] send-email: integrate with git imap-send","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-23T10:33:49Z","receivedAt":"2025-07-23T10:34:34Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Hi all\n\nThis patch series introduces integration of `git send-email` with `git imap-send`.\n\nThe first patch adds the ability to send a copy of sent emails to an IMAP folder\nspecified by the user, which is useful for email providers that do not support\nsending a copy of sent emails to the \"Sent\" folder via SMTP.\n\nThe second patch allows users to copy emails to an IMAP folder without actually\nsending them.\n\nv2 - Fix indentation in patch for imap-send.c\n   - Minor edits to commit message\n\nv3 - Rename imap folder to imap sent folder\n   - Make an error message shorter by removing unecessary details\n\nv4 - Fix a bug causing emails to be copied to an IMAP folder even if\n     --dry-run is specified.\n   - Minor edits to commit messages and docs.\n   - Add another patch that enables copying emails to an IMAP folder\n     without actually sending them.\n\nAditya Garg (2):\n  send-email: add ability to send a copy of sent emails to an IMAP\n    folder\n  send-email: enable copying emails to IMAP folder without actually\n    sending them\n\n Documentation/config/sendemail.adoc |  2 ++\n Documentation/git-send-email.adoc   | 25 ++++++++++++++++++\n git-send-email.perl                 | 40 +++++++++++++++++++++++++++--\n imap-send.c                         | 26 +++++++++++++------\n 4 files changed, 83 insertions(+), 10 deletions(-)\n\nRange-diff against v3:\n1:  da7cee769f ! 1:  27b5eb33bb send-email: add ability to send a copy of sent emails to an IMAP folder\n    @@ Commit message\n         configuration variable `sendemail.imapfolder` and command line option\n         `--imap-folder` which specifies the IMAP folder to send a copy of the\n         sent emails to. If specified, a copy of the sent emails will be sent\n    -    by piping the emails to `git imap-send` command, after the all emails are\n    +    by piping the emails to `git imap-send` command, after all emails are\n         sent via SMTP and the SMTP server has been closed.\n     \n         Signed-off-by: Aditya Garg <gargaditya08@live.com>\n    @@ Documentation/git-send-email.adoc: must be used for each option.\n     +\tIMAP folder of your choice.\n     ++\n     +This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n    -+to get instructions for the same.\n    ++for instructions.\n     +\n      --batch-size=<num>::\n      \tSome email servers (e.g. 'smtp.163.com') limit the number of emails to be\n    @@ git-send-email.perl: sub usage {\n                                           `--smtp-auth=none`\n          --smtp-debug            <0|1>  * Disable, enable Net::SMTP debug.\n     +    --imap-sent-folder      <str>  * IMAP folder where a copy of the emails should be sent.\n    -+                                     Make sure `git imap-send` is setup to use this feature.\n    ++                                     Make sure `git imap-send` is set up to use this feature.\n      \n          --batch-size            <int>  * send max <int> message per connection.\n          --relogin-delay         <int>  * delay <int> seconds between two successive login.\n    @@ git-send-email.perl: sub send_message {\n      \t\tprint \"\\n\";\n      \t}\n      \n    -+\tif ($imap_sent_folder) {\n    ++\tif ($imap_sent_folder && !$dry_run) {\n     +\t\tmy $imap_header = $header;\n     +\t\tif (@initial_bcc) {\n     +\t\t\t# Bcc is not a part of $header, so we add it here.\n    @@ git-send-email.perl: sub cleanup_compose_files {\n      \n      $smtp->quit if $smtp;\n      \n    -+if ($imap_sent_folder && @imap_copy) {\n    ++if ($imap_sent_folder && @imap_copy && !$dry_run) {\n     +\tmy $imap_input = join(\"\\n\", @imap_copy);\n     +\teval {\n     +\t\tprint \"\\nStarting git imap-send...\\n\";\n-:  ---------- > 2:  2ad311502d send-email: enable copying emails to IMAP folder without actually sending them\n-- \n2.50.1.320.g2ad311502d\n\n"},{"id":"522543","messageId":"PN3PR01MB9597A17413F208C032E086E8B85FA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"PN3PR01MB9597EC4C5DF97943587AEEB4B85FA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"[PATCH v4 1/2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-23T10:33:50Z","receivedAt":"2025-07-23T10:34:37Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Some email providers like Apple iCloud Mail do not support sending a copy\nof sent emails to the \"Sent\" folder if SMTP server is used. As a\nworkaround, various email clients like Thunderbird which rely on SMTP,\nuse IMAP to send a copy of sent emails to the \"Sent\" folder. Something\nsimilar can be done if sending emails via `git send-email`, by using\nthe `git imap-send` command to send a copy of the sent email to an IMAP\nfolder specified by the user.\n\nAdd this functionality to `git send-email` by introducing a new\nconfiguration variable `sendemail.imapfolder` and command line option\n`--imap-folder` which specifies the IMAP folder to send a copy of the\nsent emails to. If specified, a copy of the sent emails will be sent\nby piping the emails to `git imap-send` command, after all emails are\nsent via SMTP and the SMTP server has been closed.\n\nSigned-off-by: Aditya Garg <gargaditya08@live.com>\n---\n Documentation/config/sendemail.adoc |  1 +\n Documentation/git-send-email.adoc   | 12 +++++++++++\n git-send-email.perl                 | 31 ++++++++++++++++++++++++++++-\n imap-send.c                         | 26 ++++++++++++++++--------\n 4 files changed, 61 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/config/sendemail.adoc b/Documentation/config/sendemail.adoc\nindex 4722334657..dd2dbc87a0 100644\n--- a/Documentation/config/sendemail.adoc\n+++ b/Documentation/config/sendemail.adoc\n@@ -88,6 +88,7 @@ sendemail.smtpServer::\n sendemail.smtpServerPort::\n sendemail.smtpServerOption::\n sendemail.smtpUser::\n+sendemail.imapSentFolder::\n sendemail.thread::\n sendemail.transferEncoding::\n sendemail.validate::\ndiff --git a/Documentation/git-send-email.adoc b/Documentation/git-send-email.adoc\nindex 5335502d68..d1c41a0dbd 100644\n--- a/Documentation/git-send-email.adoc\n+++ b/Documentation/git-send-email.adoc\n@@ -299,6 +299,18 @@ must be used for each option.\n \tcommands and replies will be printed. Useful to debug TLS\n \tconnection and authentication problems.\n \n+--imap-sent-folder=<folder>::\n+\tSome email providers (e.g. iCloud) do not send a copy of the emails sent\n+\tusing SMTP to the `Sent` folder or similar in your mailbox. Use this option\n+\tto use `git imap-send` to send a copy of the emails to the folder specified\n+\tusing this option. You can run `git imap-send --list` to get a list of\n+\tvalid folder names, including the correct name of the `Sent` folder in\n+\tyour mailbox. You can also use this option to send emails to a dedicated\n+\tIMAP folder of your choice.\n++\n+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n+for instructions.\n+\n --batch-size=<num>::\n \tSome email servers (e.g. 'smtp.163.com') limit the number of emails to be\n \tsent per session (connection) and this will lead to a failure when\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 437f8ac46a..b3cc237baa 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -73,6 +73,8 @@ sub usage {\n     --no-smtp-auth                 * Disable SMTP authentication. Shorthand for\n                                      `--smtp-auth=none`\n     --smtp-debug            <0|1>  * Disable, enable Net::SMTP debug.\n+    --imap-sent-folder      <str>  * IMAP folder where a copy of the emails should be sent.\n+                                     Make sure `git imap-send` is set up to use this feature.\n \n     --batch-size            <int>  * send max <int> message per connection.\n     --relogin-delay         <int>  * delay <int> seconds between two successive login.\n@@ -200,7 +202,7 @@ sub format_2822_time {\n \n # Variables we fill in automatically, or via prompting:\n my (@to,@cc,@xh,$envelope_sender,\n-\t$initial_in_reply_to,$reply_to,$initial_subject,@files,\n+\t$initial_in_reply_to,$reply_to,$initial_subject,@files,@imap_copy,\n \t$author,$sender,$smtp_authpass,$annotate,$compose,$time);\n # Things we either get from config, *or* are overridden on the\n # command-line.\n@@ -277,6 +279,7 @@ sub do_edit {\n my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);\n my ($batch_size, $relogin_delay);\n my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);\n+my ($imap_sent_folder);\n my ($confirm);\n my (@suppress_cc);\n my ($auto_8bit_encoding);\n@@ -322,6 +325,7 @@ sub do_edit {\n     \"smtpauth\" => \\$smtp_auth,\n     \"smtpbatchsize\" => \\$batch_size,\n     \"smtprelogindelay\" => \\$relogin_delay,\n+    \"imapsentfolder\" => \\$imap_sent_folder,\n     \"to\" => \\@config_to,\n     \"tocmd\" => \\$to_cmd,\n     \"cc\" => \\@config_cc,\n@@ -527,6 +531,7 @@ sub config_regexp {\n \t\t    \"smtp-domain:s\" => \\$smtp_domain,\n \t\t    \"smtp-auth=s\" => \\$smtp_auth,\n \t\t    \"no-smtp-auth\" => sub {$smtp_auth = 'none'},\n+\t\t    \"imap-sent-folder=s\" => \\$imap_sent_folder,\n \t\t    \"annotate!\" => \\$annotate,\n \t\t    \"compose\" => \\$compose,\n \t\t    \"quiet\" => \\$quiet,\n@@ -1829,6 +1834,17 @@ sub send_message {\n \t\tprint \"\\n\";\n \t}\n \n+\tif ($imap_sent_folder && !$dry_run) {\n+\t\tmy $imap_header = $header;\n+\t\tif (@initial_bcc) {\n+\t\t\t# Bcc is not a part of $header, so we add it here.\n+\t\t\t# This is only for the IMAP copy, not for the actual email\n+\t\t\t# sent to the recipients.\n+\t\t\t$imap_header .= \"Bcc: \" . join(\", \", @initial_bcc) . \"\\n\";\n+\t\t}\n+\t\tpush @imap_copy, \"From git-send-email\\n$imap_header\\n$message\";\n+\t}\n+\n \treturn 1;\n }\n \n@@ -2223,6 +2239,19 @@ sub cleanup_compose_files {\n \n $smtp->quit if $smtp;\n \n+if ($imap_sent_folder && @imap_copy && !$dry_run) {\n+\tmy $imap_input = join(\"\\n\", @imap_copy);\n+\teval {\n+\t\tprint \"\\nStarting git imap-send...\\n\";\n+\t\tmy ($fh, $ctx) = Git::command_input_pipe(['imap-send', '-f', $imap_sent_folder]);\n+\t\tprint $fh $imap_input;\n+\t\tGit::command_close_pipe($fh, $ctx);\n+\t\t1;\n+\t} or do {\n+\t\twarn \"Warning: failed to send messages to IMAP folder $imap_sent_folder: $@\";\n+\t};\n+}\n+\n sub apply_transfer_encoding {\n \tmy $message = shift;\n \tmy $from = shift;\ndiff --git a/imap-send.c b/imap-send.c\nindex f5a656ac71..44de0c5a77 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -1441,14 +1441,24 @@ static int count_messages(struct strbuf *all_msgs)\n \n \twhile (1) {\n \t\tif (starts_with(p, \"From \")) {\n-\t\t\tp = strstr(p+5, \"\\nFrom: \");\n-\t\t\tif (!p) break;\n-\t\t\tp = strstr(p+7, \"\\nDate: \");\n-\t\t\tif (!p) break;\n-\t\t\tp = strstr(p+7, \"\\nSubject: \");\n-\t\t\tif (!p) break;\n-\t\t\tp += 10;\n-\t\t\tcount++;\n+\t\t\tif (starts_with(p, \"From git-send-email\")) {\n+\t\t\t\tp = strstr(p+5, \"\\nFrom: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp += 7;\n+\t\t\t\tp = strstr(p, \"\\nTo: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp += 5;\n+\t\t\t\tcount++;\n+\t\t\t} else {\n+\t\t\t\tp = strstr(p+5, \"\\nFrom: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp = strstr(p+7, \"\\nDate: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp = strstr(p+7, \"\\nSubject: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp += 10;\n+\t\t\t\tcount++;\n+\t\t\t}\n \t\t}\n \t\tp = strstr(p+5, \"\\nFrom \");\n \t\tif (!p)\n-- \n2.50.1.320.g2ad311502d\n\n"},{"id":"522544","messageId":"PN3PR01MB95972CAE853F4079F0F62F0AB85FA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"PN3PR01MB9597EC4C5DF97943587AEEB4B85FA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"[PATCH v4 2/2] send-email: enable copying emails to IMAP folder without actually sending them","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-07-23T10:33:51Z","receivedAt":"2025-07-23T10:34:39Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"`git imap-send` was built on the idea of copying emails to an IMAP folder\nlike drafts, and sending them later using an email client. Currently\nthe only way to do it is by piping output of `git format-patch` to IMAP\nsend.\n\nAdd another way to do it by using `git send-email` with the\n`--use-imap-only` or `sendmail.useImapOnly` option. This allows users to\nuse the advanced features of `git send-email` like tweaking Cc: list\nprogrammatically, compose the cover letter, etc. and then send the well\nformatted emails to an IMAP folder using `git imap-send`.\n\nWhile at it, use `` instead of '' for --smtp-encryption ssl in help\nsection of `git send-email`.\n\nSigned-off-by: Aditya Garg <gargaditya08@live.com>\n---\n Documentation/config/sendemail.adoc |  1 +\n Documentation/git-send-email.adoc   | 13 +++++++++++++\n git-send-email.perl                 |  9 ++++++++-\n 3 files changed, 22 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/config/sendemail.adoc b/Documentation/config/sendemail.adoc\nindex dd2dbc87a0..90164c734d 100644\n--- a/Documentation/config/sendemail.adoc\n+++ b/Documentation/config/sendemail.adoc\n@@ -89,6 +89,7 @@ sendemail.smtpServerPort::\n sendemail.smtpServerOption::\n sendemail.smtpUser::\n sendemail.imapSentFolder::\n+sendemail.useImapOnly::\n sendemail.thread::\n sendemail.transferEncoding::\n sendemail.validate::\ndiff --git a/Documentation/git-send-email.adoc b/Documentation/git-send-email.adoc\nindex d1c41a0dbd..88e183b489 100644\n--- a/Documentation/git-send-email.adoc\n+++ b/Documentation/git-send-email.adoc\n@@ -311,6 +311,19 @@ must be used for each option.\n This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n for instructions.\n \n+--[no-]use-imap-only::\n+\tIf this is set, all emails will only be copied to the IMAP folder specified\n+\twith `--imap-sent-folder` or `sendemail.imapSentFolder` and will not be sent\n+\tto the recipients. Useful if you just want to create a draft of the emails\n+\tand use another email client to send them.\n+\tIf disabled with `--no-use-imap-only`, the emails will be sent like usual.\n+\tDisabled by default, but the `sendemail.useImapOnly` configuration\n+\tvariable can be used to enable it.\n+\n++\n+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n+for instructions.\n+\n --batch-size=<num>::\n \tSome email servers (e.g. 'smtp.163.com') limit the number of emails to be\n \tsent per session (connection) and this will lead to a failure when\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex b3cc237baa..96504e7be1 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -62,7 +62,7 @@ sub usage {\n     --smtp-user             <str>  * Username for SMTP-AUTH.\n     --smtp-pass             <str>  * Password for SMTP-AUTH; not necessary.\n     --smtp-encryption       <str>  * tls or ssl; anything else disables.\n-    --smtp-ssl                     * Deprecated. Use '--smtp-encryption ssl'.\n+    --smtp-ssl                     * Deprecated. Use `--smtp-encryption ssl`.\n     --smtp-ssl-cert-path    <str>  * Path to ca-certificates (either directory or file).\n                                      Pass an empty string to disable certificate\n                                      verification.\n@@ -75,6 +75,8 @@ sub usage {\n     --smtp-debug            <0|1>  * Disable, enable Net::SMTP debug.\n     --imap-sent-folder      <str>  * IMAP folder where a copy of the emails should be sent.\n                                      Make sure `git imap-send` is set up to use this feature.\n+    --[no-]use-imap-only           * Only copy emails to the IMAP folder specified by\n+                                     `--imap-sent-folder` instead of actually sending them.\n \n     --batch-size            <int>  * send max <int> message per connection.\n     --relogin-delay         <int>  * delay <int> seconds between two successive login.\n@@ -296,6 +298,7 @@ sub do_edit {\n my $target_xfer_encoding = 'auto';\n my $forbid_sendmail_variables = 1;\n my $outlook_id_fix = 'auto';\n+my $use_imap_only = 0;\n \n my %config_bool_settings = (\n     \"thread\" => \\$thread,\n@@ -312,6 +315,7 @@ sub do_edit {\n     \"forbidsendmailvariables\" => \\$forbid_sendmail_variables,\n     \"mailmap\" => \\$mailmap,\n     \"outlookidfix\" => \\$outlook_id_fix,\n+    \"useimaponly\" => \\$use_imap_only,\n );\n \n my %config_settings = (\n@@ -532,6 +536,7 @@ sub config_regexp {\n \t\t    \"smtp-auth=s\" => \\$smtp_auth,\n \t\t    \"no-smtp-auth\" => sub {$smtp_auth = 'none'},\n \t\t    \"imap-sent-folder=s\" => \\$imap_sent_folder,\n+\t\t    \"use-imap-only!\" => \\$use_imap_only,\n \t\t    \"annotate!\" => \\$annotate,\n \t\t    \"compose\" => \\$compose,\n \t\t    \"quiet\" => \\$quiet,\n@@ -1683,6 +1688,8 @@ sub send_message {\n \n \tif ($dry_run) {\n \t\t# We don't want to send the email.\n+\t} elsif ($use_imap_only) {\n+\t\tdie __(\"The destination IMAP folder is not properly defined.\") if !defined $imap_sent_folder;\n \t} elsif (defined $sendmail_cmd || file_name_is_absolute($smtp_server)) {\n \t\tmy $pid = open my $sm, '|-';\n \t\tdefined $pid or die $!;\n-- \n2.50.1.320.g2ad311502d\n\n"},{"id":"523994","messageId":"xmqqv7mtzfuc.fsf@gitster.g","threadId":"63810","inReplyTo":"PN3PR01MB95972CAE853F4079F0F62F0AB85FA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"Re: [PATCH v4 2/2] send-email: enable copying emails to IMAP folder without actually sending them","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-08-11T21:52:11Z","receivedAt":"2025-08-11T21:52:14Z","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> +--[no-]use-imap-only::\n\nThis is better written on two separate lines, i.e.\n\n\t--use-imap-only::\n\t--no-use-imap-only::\n\nif we want to pass \"make check-docs\" when the topic is merged to\n'seen'.\n\nThanks.\n"},{"id":"524011","messageId":"PN3PR01MB95977F0C73C909929400B3EEB82BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"xmqqv7mtzfuc.fsf@gitster.g","subject":"Re: [PATCH v4 2/2] send-email: enable copying emails to IMAP folder without actually sending them","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-08-12T05:08:01Z","receivedAt":"2025-08-12T05:08:09Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\nOn 12 August 2025 3:22:11 am IST, Junio C Hamano <gitster@pobox.com> wrote:\n>Aditya Garg <gargaditya08@live.com> writes:\n>\n>> +--[no-]use-imap-only::\n>\n>This is better written on two separate lines, i.e.\n>\n>\t--use-imap-only::\n>\t--no-use-imap-only::\n>\n\nThere are many instances in the docs where the command line option has been written as --[no-]something. Do they also have to be changed?\n\n>if we want to pass \"make check-docs\" when the topic is merged to\n>'seen'.\n>\n>Thanks.\n"},{"id":"524012","messageId":"PN3PR01MB95970565CA1F554E4B440C63B82BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"PN3PR01MB95977F0C73C909929400B3EEB82BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"Re: [PATCH v4 2/2] send-email: enable copying emails to IMAP folder without actually sending them","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-08-12T06:27:43Z","receivedAt":"2025-08-12T06:27:48Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\n> On 12 Aug 2025, at 10:38 AM, Aditya Garg <gargaditya08@live.com> wrote:\n> \n> ﻿\n> \n>> On 12 August 2025 3:22:11 am IST, Junio C Hamano <gitster@pobox.com> wrote:\n>> Aditya Garg <gargaditya08@live.com> writes:\n>> \n>>> +--[no-]use-imap-only::\n>> \n>> This is better written on two separate lines, i.e.\n>> \n>>    --use-imap-only::\n>>    --no-use-imap-only::\n>> \n> \n> There are many instances in the docs where the command line option has been written as --[no-]something. Do they also have to be changed?\n\nNvm, looks like they have been changed by a recent commit.\n"},{"id":"524013","messageId":"PN3PR01MB9597E8E33868386C997D2563B82BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"08528f201acc1038ebc5861321395d17516094fd.1753003385.git.gargaditya08@live.com","subject":"[PATCH v5 0/2] send-email: integrate with git imap-send","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-08-12T06:44:34Z","receivedAt":"2025-08-12T06:45:08Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Hi all\n\nThis patch series introduces integration of `git send-email` with `git imap-send`.\n\nThe first patch adds the ability to send a copy of sent emails to an IMAP folder\nspecified by the user, which is useful for email providers that do not support\nsending a copy of sent emails to the \"Sent\" folder via SMTP.\n\nThe second patch allows users to copy emails to an IMAP folder without actually\nsending them.\n\nv2 - Fix indentation in patch for imap-send.c\n   - Minor edits to commit message\n\nv3 - Rename imap folder to imap sent folder\n   - Make an error message shorter by removing unecessary details\n\nv4 - Fix a bug causing emails to be copied to an IMAP folder even if\n     --dry-run is specified.\n   - Minor edits to commit messages and docs.\n   - Add another patch that enables copying emails to an IMAP folder\n     without actually sending them.\n\nv5 - Avoid using -[no-]parameter.\n\nAditya Garg (2):\n  send-email: add ability to send a copy of sent emails to an IMAP\n    folder\n  send-email: enable copying emails to an IMAP folder without actually\n    sending them\n\n Documentation/config/sendemail.adoc |  2 ++\n Documentation/git-send-email.adoc   | 26 +++++++++++++++++++\n git-send-email.perl                 | 40 +++++++++++++++++++++++++++--\n imap-send.c                         | 26 +++++++++++++------\n 4 files changed, 84 insertions(+), 10 deletions(-)\n\nRange-diff against v4:\n1:  2ad311502d ! 1:  27b5eb33bb send-email: enable copying emails to IMAP folder without actually sending them\n    @@ Metadata\n     Author: Aditya Garg <gargaditya08@live.com>\n     \n      ## Commit message ##\n    -    send-email: enable copying emails to IMAP folder without actually sending them\n    +    send-email: add ability to send a copy of sent emails to an IMAP folder\n     \n    -    `git imap-send` was built on the idea of copying emails to an IMAP folder\n    -    like drafts, and sending them later using an email client. Currently\n    -    the only way to do it is by piping output of `git format-patch` to IMAP\n    -    send.\n    +    Some email providers like Apple iCloud Mail do not support sending a copy\n    +    of sent emails to the \"Sent\" folder if SMTP server is used. As a\n    +    workaround, various email clients like Thunderbird which rely on SMTP,\n    +    use IMAP to send a copy of sent emails to the \"Sent\" folder. Something\n    +    similar can be done if sending emails via `git send-email`, by using\n    +    the `git imap-send` command to send a copy of the sent email to an IMAP\n    +    folder specified by the user.\n     \n    -    Add another way to do it by using `git send-email` with the\n    -    `--use-imap-only` or `sendmail.useImapOnly` option. This allows users to\n    -    use the advanced features of `git send-email` like tweaking Cc: list\n    -    programmatically, compose the cover letter, etc. and then send the well\n    -    formatted emails to an IMAP folder using `git imap-send`.\n    -\n    -    While at it, use `` instead of '' for --smtp-encryption ssl in help\n    -    section of `git send-email`.\n    +    Add this functionality to `git send-email` by introducing a new\n    +    configuration variable `sendemail.imapfolder` and command line option\n    +    `--imap-folder` which specifies the IMAP folder to send a copy of the\n    +    sent emails to. If specified, a copy of the sent emails will be sent\n    +    by piping the emails to `git imap-send` command, after all emails are\n    +    sent via SMTP and the SMTP server has been closed.\n     \n         Signed-off-by: Aditya Garg <gargaditya08@live.com>\n     \n      ## Documentation/config/sendemail.adoc ##\n    -@@ Documentation/config/sendemail.adoc: sendemail.smtpServerPort::\n    +@@ Documentation/config/sendemail.adoc: sendemail.smtpServer::\n    + sendemail.smtpServerPort::\n      sendemail.smtpServerOption::\n      sendemail.smtpUser::\n    - sendemail.imapSentFolder::\n    -+sendemail.useImapOnly::\n    ++sendemail.imapSentFolder::\n      sendemail.thread::\n      sendemail.transferEncoding::\n      sendemail.validate::\n     \n      ## Documentation/git-send-email.adoc ##\n     @@ Documentation/git-send-email.adoc: must be used for each option.\n    - This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n    - for instructions.\n    + \tcommands and replies will be printed. Useful to debug TLS\n    + \tconnection and authentication problems.\n      \n    -+--[no-]use-imap-only::\n    -+\tIf this is set, all emails will only be copied to the IMAP folder specified\n    -+\twith `--imap-sent-folder` or `sendemail.imapSentFolder` and will not be sent\n    -+\tto the recipients. Useful if you just want to create a draft of the emails\n    -+\tand use another email client to send them.\n    -+\tIf disabled with `--no-use-imap-only`, the emails will be sent like usual.\n    -+\tDisabled by default, but the `sendemail.useImapOnly` configuration\n    -+\tvariable can be used to enable it.\n    -+\n    ++--imap-sent-folder=<folder>::\n    ++\tSome email providers (e.g. iCloud) do not send a copy of the emails sent\n    ++\tusing SMTP to the `Sent` folder or similar in your mailbox. Use this option\n    ++\tto use `git imap-send` to send a copy of the emails to the folder specified\n    ++\tusing this option. You can run `git imap-send --list` to get a list of\n    ++\tvalid folder names, including the correct name of the `Sent` folder in\n    ++\tyour mailbox. You can also use this option to send emails to a dedicated\n    ++\tIMAP folder of your choice.\n     ++\n     +This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n     +for instructions.\n    @@ Documentation/git-send-email.adoc: must be used for each option.\n     \n      ## git-send-email.perl ##\n     @@ git-send-email.perl: sub usage {\n    -     --smtp-user             <str>  * Username for SMTP-AUTH.\n    -     --smtp-pass             <str>  * Password for SMTP-AUTH; not necessary.\n    -     --smtp-encryption       <str>  * tls or ssl; anything else disables.\n    --    --smtp-ssl                     * Deprecated. Use '--smtp-encryption ssl'.\n    -+    --smtp-ssl                     * Deprecated. Use `--smtp-encryption ssl`.\n    -     --smtp-ssl-cert-path    <str>  * Path to ca-certificates (either directory or file).\n    -                                      Pass an empty string to disable certificate\n    -                                      verification.\n    -@@ git-send-email.perl: sub usage {\n    +     --no-smtp-auth                 * Disable SMTP authentication. Shorthand for\n    +                                      `--smtp-auth=none`\n          --smtp-debug            <0|1>  * Disable, enable Net::SMTP debug.\n    -     --imap-sent-folder      <str>  * IMAP folder where a copy of the emails should be sent.\n    -                                      Make sure `git imap-send` is set up to use this feature.\n    -+    --[no-]use-imap-only           * Only copy emails to the IMAP folder specified by\n    -+                                     `--imap-sent-folder` instead of actually sending them.\n    ++    --imap-sent-folder      <str>  * IMAP folder where a copy of the emails should be sent.\n    ++                                     Make sure `git imap-send` is set up to use this feature.\n      \n          --batch-size            <int>  * send max <int> message per connection.\n          --relogin-delay         <int>  * delay <int> seconds between two successive login.\n    -@@ git-send-email.perl: sub do_edit {\n    - my $target_xfer_encoding = 'auto';\n    - my $forbid_sendmail_variables = 1;\n    - my $outlook_id_fix = 'auto';\n    -+my $use_imap_only = 0;\n    +@@ git-send-email.perl: sub format_2822_time {\n      \n    - my %config_bool_settings = (\n    -     \"thread\" => \\$thread,\n    + # Variables we fill in automatically, or via prompting:\n    + my (@to,@cc,@xh,$envelope_sender,\n    +-\t$initial_in_reply_to,$reply_to,$initial_subject,@files,\n    ++\t$initial_in_reply_to,$reply_to,$initial_subject,@files,@imap_copy,\n    + \t$author,$sender,$smtp_authpass,$annotate,$compose,$time);\n    + # Things we either get from config, *or* are overridden on the\n    + # command-line.\n     @@ git-send-email.perl: sub do_edit {\n    -     \"forbidsendmailvariables\" => \\$forbid_sendmail_variables,\n    -     \"mailmap\" => \\$mailmap,\n    -     \"outlookidfix\" => \\$outlook_id_fix,\n    -+    \"useimaponly\" => \\$use_imap_only,\n    - );\n    - \n    - my %config_settings = (\n    + my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);\n    + my ($batch_size, $relogin_delay);\n    + my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);\n    ++my ($imap_sent_folder);\n    + my ($confirm);\n    + my (@suppress_cc);\n    + my ($auto_8bit_encoding);\n    +@@ git-send-email.perl: sub do_edit {\n    +     \"smtpauth\" => \\$smtp_auth,\n    +     \"smtpbatchsize\" => \\$batch_size,\n    +     \"smtprelogindelay\" => \\$relogin_delay,\n    ++    \"imapsentfolder\" => \\$imap_sent_folder,\n    +     \"to\" => \\@config_to,\n    +     \"tocmd\" => \\$to_cmd,\n    +     \"cc\" => \\@config_cc,\n     @@ git-send-email.perl: sub config_regexp {\n    + \t\t    \"smtp-domain:s\" => \\$smtp_domain,\n      \t\t    \"smtp-auth=s\" => \\$smtp_auth,\n      \t\t    \"no-smtp-auth\" => sub {$smtp_auth = 'none'},\n    - \t\t    \"imap-sent-folder=s\" => \\$imap_sent_folder,\n    -+\t\t    \"use-imap-only!\" => \\$use_imap_only,\n    ++\t\t    \"imap-sent-folder=s\" => \\$imap_sent_folder,\n      \t\t    \"annotate!\" => \\$annotate,\n      \t\t    \"compose\" => \\$compose,\n      \t\t    \"quiet\" => \\$quiet,\n     @@ git-send-email.perl: sub send_message {\n    + \t\tprint \"\\n\";\n    + \t}\n    + \n    ++\tif ($imap_sent_folder && !$dry_run) {\n    ++\t\tmy $imap_header = $header;\n    ++\t\tif (@initial_bcc) {\n    ++\t\t\t# Bcc is not a part of $header, so we add it here.\n    ++\t\t\t# This is only for the IMAP copy, not for the actual email\n    ++\t\t\t# sent to the recipients.\n    ++\t\t\t$imap_header .= \"Bcc: \" . join(\", \", @initial_bcc) . \"\\n\";\n    ++\t\t}\n    ++\t\tpush @imap_copy, \"From git-send-email\\n$imap_header\\n$message\";\n    ++\t}\n    ++\n    + \treturn 1;\n    + }\n    + \n    +@@ git-send-email.perl: sub cleanup_compose_files {\n    + \n    + $smtp->quit if $smtp;\n    + \n    ++if ($imap_sent_folder && @imap_copy && !$dry_run) {\n    ++\tmy $imap_input = join(\"\\n\", @imap_copy);\n    ++\teval {\n    ++\t\tprint \"\\nStarting git imap-send...\\n\";\n    ++\t\tmy ($fh, $ctx) = Git::command_input_pipe(['imap-send', '-f', $imap_sent_folder]);\n    ++\t\tprint $fh $imap_input;\n    ++\t\tGit::command_close_pipe($fh, $ctx);\n    ++\t\t1;\n    ++\t} or do {\n    ++\t\twarn \"Warning: failed to send messages to IMAP folder $imap_sent_folder: $@\";\n    ++\t};\n    ++}\n    ++\n    + sub apply_transfer_encoding {\n    + \tmy $message = shift;\n    + \tmy $from = shift;\n    +\n    + ## imap-send.c ##\n    +@@ imap-send.c: static int count_messages(struct strbuf *all_msgs)\n      \n    - \tif ($dry_run) {\n    - \t\t# We don't want to send the email.\n    -+\t} elsif ($use_imap_only) {\n    -+\t\tdie __(\"The destination IMAP folder is not properly defined.\") if !defined $imap_sent_folder;\n    - \t} elsif (defined $sendmail_cmd || file_name_is_absolute($smtp_server)) {\n    - \t\tmy $pid = open my $sm, '|-';\n    - \t\tdefined $pid or die $!;\n    + \twhile (1) {\n    + \t\tif (starts_with(p, \"From \")) {\n    +-\t\t\tp = strstr(p+5, \"\\nFrom: \");\n    +-\t\t\tif (!p) break;\n    +-\t\t\tp = strstr(p+7, \"\\nDate: \");\n    +-\t\t\tif (!p) break;\n    +-\t\t\tp = strstr(p+7, \"\\nSubject: \");\n    +-\t\t\tif (!p) break;\n    +-\t\t\tp += 10;\n    +-\t\t\tcount++;\n    ++\t\t\tif (starts_with(p, \"From git-send-email\")) {\n    ++\t\t\t\tp = strstr(p+5, \"\\nFrom: \");\n    ++\t\t\t\tif (!p) break;\n    ++\t\t\t\tp += 7;\n    ++\t\t\t\tp = strstr(p, \"\\nTo: \");\n    ++\t\t\t\tif (!p) break;\n    ++\t\t\t\tp += 5;\n    ++\t\t\t\tcount++;\n    ++\t\t\t} else {\n    ++\t\t\t\tp = strstr(p+5, \"\\nFrom: \");\n    ++\t\t\t\tif (!p) break;\n    ++\t\t\t\tp = strstr(p+7, \"\\nDate: \");\n    ++\t\t\t\tif (!p) break;\n    ++\t\t\t\tp = strstr(p+7, \"\\nSubject: \");\n    ++\t\t\t\tif (!p) break;\n    ++\t\t\t\tp += 10;\n    ++\t\t\t\tcount++;\n    ++\t\t\t}\n    + \t\t}\n    + \t\tp = strstr(p+5, \"\\nFrom \");\n    + \t\tif (!p)\n-:  ---------- > 2:  1d74a857df send-email: enable copying emails to an IMAP folder without actually sending them\n-- \n2.50.1\n\n"},{"id":"524014","messageId":"PN3PR01MB95976402ED4371D443518650B82BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"PN3PR01MB9597E8E33868386C997D2563B82BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"[PATCH v5 1/2] send-email: add ability to send a copy of sent emails to an IMAP folder","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-08-12T06:44:35Z","receivedAt":"2025-08-12T06:45:11Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"Some email providers like Apple iCloud Mail do not support sending a copy\nof sent emails to the \"Sent\" folder if SMTP server is used. As a\nworkaround, various email clients like Thunderbird which rely on SMTP,\nuse IMAP to send a copy of sent emails to the \"Sent\" folder. Something\nsimilar can be done if sending emails via `git send-email`, by using\nthe `git imap-send` command to send a copy of the sent email to an IMAP\nfolder specified by the user.\n\nAdd this functionality to `git send-email` by introducing a new\nconfiguration variable `sendemail.imapfolder` and command line option\n`--imap-folder` which specifies the IMAP folder to send a copy of the\nsent emails to. If specified, a copy of the sent emails will be sent\nby piping the emails to `git imap-send` command, after all emails are\nsent via SMTP and the SMTP server has been closed.\n\nSigned-off-by: Aditya Garg <gargaditya08@live.com>\n---\n Documentation/config/sendemail.adoc |  1 +\n Documentation/git-send-email.adoc   | 12 +++++++++++\n git-send-email.perl                 | 31 ++++++++++++++++++++++++++++-\n imap-send.c                         | 26 ++++++++++++++++--------\n 4 files changed, 61 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/config/sendemail.adoc b/Documentation/config/sendemail.adoc\nindex 4722334657..dd2dbc87a0 100644\n--- a/Documentation/config/sendemail.adoc\n+++ b/Documentation/config/sendemail.adoc\n@@ -88,6 +88,7 @@ sendemail.smtpServer::\n sendemail.smtpServerPort::\n sendemail.smtpServerOption::\n sendemail.smtpUser::\n+sendemail.imapSentFolder::\n sendemail.thread::\n sendemail.transferEncoding::\n sendemail.validate::\ndiff --git a/Documentation/git-send-email.adoc b/Documentation/git-send-email.adoc\nindex 5335502d68..d1c41a0dbd 100644\n--- a/Documentation/git-send-email.adoc\n+++ b/Documentation/git-send-email.adoc\n@@ -299,6 +299,18 @@ must be used for each option.\n \tcommands and replies will be printed. Useful to debug TLS\n \tconnection and authentication problems.\n \n+--imap-sent-folder=<folder>::\n+\tSome email providers (e.g. iCloud) do not send a copy of the emails sent\n+\tusing SMTP to the `Sent` folder or similar in your mailbox. Use this option\n+\tto use `git imap-send` to send a copy of the emails to the folder specified\n+\tusing this option. You can run `git imap-send --list` to get a list of\n+\tvalid folder names, including the correct name of the `Sent` folder in\n+\tyour mailbox. You can also use this option to send emails to a dedicated\n+\tIMAP folder of your choice.\n++\n+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n+for instructions.\n+\n --batch-size=<num>::\n \tSome email servers (e.g. 'smtp.163.com') limit the number of emails to be\n \tsent per session (connection) and this will lead to a failure when\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 437f8ac46a..b3cc237baa 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -73,6 +73,8 @@ sub usage {\n     --no-smtp-auth                 * Disable SMTP authentication. Shorthand for\n                                      `--smtp-auth=none`\n     --smtp-debug            <0|1>  * Disable, enable Net::SMTP debug.\n+    --imap-sent-folder      <str>  * IMAP folder where a copy of the emails should be sent.\n+                                     Make sure `git imap-send` is set up to use this feature.\n \n     --batch-size            <int>  * send max <int> message per connection.\n     --relogin-delay         <int>  * delay <int> seconds between two successive login.\n@@ -200,7 +202,7 @@ sub format_2822_time {\n \n # Variables we fill in automatically, or via prompting:\n my (@to,@cc,@xh,$envelope_sender,\n-\t$initial_in_reply_to,$reply_to,$initial_subject,@files,\n+\t$initial_in_reply_to,$reply_to,$initial_subject,@files,@imap_copy,\n \t$author,$sender,$smtp_authpass,$annotate,$compose,$time);\n # Things we either get from config, *or* are overridden on the\n # command-line.\n@@ -277,6 +279,7 @@ sub do_edit {\n my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);\n my ($batch_size, $relogin_delay);\n my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);\n+my ($imap_sent_folder);\n my ($confirm);\n my (@suppress_cc);\n my ($auto_8bit_encoding);\n@@ -322,6 +325,7 @@ sub do_edit {\n     \"smtpauth\" => \\$smtp_auth,\n     \"smtpbatchsize\" => \\$batch_size,\n     \"smtprelogindelay\" => \\$relogin_delay,\n+    \"imapsentfolder\" => \\$imap_sent_folder,\n     \"to\" => \\@config_to,\n     \"tocmd\" => \\$to_cmd,\n     \"cc\" => \\@config_cc,\n@@ -527,6 +531,7 @@ sub config_regexp {\n \t\t    \"smtp-domain:s\" => \\$smtp_domain,\n \t\t    \"smtp-auth=s\" => \\$smtp_auth,\n \t\t    \"no-smtp-auth\" => sub {$smtp_auth = 'none'},\n+\t\t    \"imap-sent-folder=s\" => \\$imap_sent_folder,\n \t\t    \"annotate!\" => \\$annotate,\n \t\t    \"compose\" => \\$compose,\n \t\t    \"quiet\" => \\$quiet,\n@@ -1829,6 +1834,17 @@ sub send_message {\n \t\tprint \"\\n\";\n \t}\n \n+\tif ($imap_sent_folder && !$dry_run) {\n+\t\tmy $imap_header = $header;\n+\t\tif (@initial_bcc) {\n+\t\t\t# Bcc is not a part of $header, so we add it here.\n+\t\t\t# This is only for the IMAP copy, not for the actual email\n+\t\t\t# sent to the recipients.\n+\t\t\t$imap_header .= \"Bcc: \" . join(\", \", @initial_bcc) . \"\\n\";\n+\t\t}\n+\t\tpush @imap_copy, \"From git-send-email\\n$imap_header\\n$message\";\n+\t}\n+\n \treturn 1;\n }\n \n@@ -2223,6 +2239,19 @@ sub cleanup_compose_files {\n \n $smtp->quit if $smtp;\n \n+if ($imap_sent_folder && @imap_copy && !$dry_run) {\n+\tmy $imap_input = join(\"\\n\", @imap_copy);\n+\teval {\n+\t\tprint \"\\nStarting git imap-send...\\n\";\n+\t\tmy ($fh, $ctx) = Git::command_input_pipe(['imap-send', '-f', $imap_sent_folder]);\n+\t\tprint $fh $imap_input;\n+\t\tGit::command_close_pipe($fh, $ctx);\n+\t\t1;\n+\t} or do {\n+\t\twarn \"Warning: failed to send messages to IMAP folder $imap_sent_folder: $@\";\n+\t};\n+}\n+\n sub apply_transfer_encoding {\n \tmy $message = shift;\n \tmy $from = shift;\ndiff --git a/imap-send.c b/imap-send.c\nindex f5a656ac71..44de0c5a77 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -1441,14 +1441,24 @@ static int count_messages(struct strbuf *all_msgs)\n \n \twhile (1) {\n \t\tif (starts_with(p, \"From \")) {\n-\t\t\tp = strstr(p+5, \"\\nFrom: \");\n-\t\t\tif (!p) break;\n-\t\t\tp = strstr(p+7, \"\\nDate: \");\n-\t\t\tif (!p) break;\n-\t\t\tp = strstr(p+7, \"\\nSubject: \");\n-\t\t\tif (!p) break;\n-\t\t\tp += 10;\n-\t\t\tcount++;\n+\t\t\tif (starts_with(p, \"From git-send-email\")) {\n+\t\t\t\tp = strstr(p+5, \"\\nFrom: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp += 7;\n+\t\t\t\tp = strstr(p, \"\\nTo: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp += 5;\n+\t\t\t\tcount++;\n+\t\t\t} else {\n+\t\t\t\tp = strstr(p+5, \"\\nFrom: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp = strstr(p+7, \"\\nDate: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp = strstr(p+7, \"\\nSubject: \");\n+\t\t\t\tif (!p) break;\n+\t\t\t\tp += 10;\n+\t\t\t\tcount++;\n+\t\t\t}\n \t\t}\n \t\tp = strstr(p+5, \"\\nFrom \");\n \t\tif (!p)\n-- \n2.50.1\n\n"},{"id":"524015","messageId":"PN3PR01MB95976EFF4DA2B0BB479E2113B82BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"PN3PR01MB9597E8E33868386C997D2563B82BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"[PATCH v5 2/2] send-email: enable copying emails to an IMAP folder without actually sending them","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-08-12T06:44:36Z","receivedAt":"2025-08-12T06:45:13Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"`git imap-send` was built on the idea of copying emails to an IMAP folder\nlike drafts, and sending them later using an email client. Currently\nthe only way to do it is by piping output of `git format-patch` to IMAP\nsend.\n\nAdd another way to do it by using `git send-email` with the\n`--use-imap-only` or `sendmail.useImapOnly` option. This allows users to\nuse the advanced features of `git send-email` like tweaking Cc: list\nprogrammatically, compose the cover letter, etc. and then send the well\nformatted emails to an IMAP folder using `git imap-send`.\n\nWhile at it, use `` instead of '' for --smtp-encryption ssl in help\nsection of `git send-email`.\n\nSigned-off-by: Aditya Garg <gargaditya08@live.com>\n---\n Documentation/config/sendemail.adoc |  1 +\n Documentation/git-send-email.adoc   | 14 ++++++++++++++\n git-send-email.perl                 |  9 ++++++++-\n 3 files changed, 23 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/config/sendemail.adoc b/Documentation/config/sendemail.adoc\nindex dd2dbc87a0..90164c734d 100644\n--- a/Documentation/config/sendemail.adoc\n+++ b/Documentation/config/sendemail.adoc\n@@ -89,6 +89,7 @@ sendemail.smtpServerPort::\n sendemail.smtpServerOption::\n sendemail.smtpUser::\n sendemail.imapSentFolder::\n+sendemail.useImapOnly::\n sendemail.thread::\n sendemail.transferEncoding::\n sendemail.validate::\ndiff --git a/Documentation/git-send-email.adoc b/Documentation/git-send-email.adoc\nindex d1c41a0dbd..a385f865fb 100644\n--- a/Documentation/git-send-email.adoc\n+++ b/Documentation/git-send-email.adoc\n@@ -311,6 +311,20 @@ must be used for each option.\n This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n for instructions.\n \n+--use-imap-only::\n+--no-use-imap-only::\n+\tIf this is set, all emails will only be copied to the IMAP folder specified\n+\twith `--imap-sent-folder` or `sendemail.imapSentFolder` and will not be sent\n+\tto the recipients. Useful if you just want to create a draft of the emails\n+\tand use another email client to send them.\n+\tIf disabled with `--no-use-imap-only`, the emails will be sent like usual.\n+\tDisabled by default, but the `sendemail.useImapOnly` configuration\n+\tvariable can be used to enable it.\n+\n++\n+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]\n+for instructions.\n+\n --batch-size=<num>::\n \tSome email servers (e.g. 'smtp.163.com') limit the number of emails to be\n \tsent per session (connection) and this will lead to a failure when\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex b3cc237baa..96504e7be1 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -62,7 +62,7 @@ sub usage {\n     --smtp-user             <str>  * Username for SMTP-AUTH.\n     --smtp-pass             <str>  * Password for SMTP-AUTH; not necessary.\n     --smtp-encryption       <str>  * tls or ssl; anything else disables.\n-    --smtp-ssl                     * Deprecated. Use '--smtp-encryption ssl'.\n+    --smtp-ssl                     * Deprecated. Use `--smtp-encryption ssl`.\n     --smtp-ssl-cert-path    <str>  * Path to ca-certificates (either directory or file).\n                                      Pass an empty string to disable certificate\n                                      verification.\n@@ -75,6 +75,8 @@ sub usage {\n     --smtp-debug            <0|1>  * Disable, enable Net::SMTP debug.\n     --imap-sent-folder      <str>  * IMAP folder where a copy of the emails should be sent.\n                                      Make sure `git imap-send` is set up to use this feature.\n+    --[no-]use-imap-only           * Only copy emails to the IMAP folder specified by\n+                                     `--imap-sent-folder` instead of actually sending them.\n \n     --batch-size            <int>  * send max <int> message per connection.\n     --relogin-delay         <int>  * delay <int> seconds between two successive login.\n@@ -296,6 +298,7 @@ sub do_edit {\n my $target_xfer_encoding = 'auto';\n my $forbid_sendmail_variables = 1;\n my $outlook_id_fix = 'auto';\n+my $use_imap_only = 0;\n \n my %config_bool_settings = (\n     \"thread\" => \\$thread,\n@@ -312,6 +315,7 @@ sub do_edit {\n     \"forbidsendmailvariables\" => \\$forbid_sendmail_variables,\n     \"mailmap\" => \\$mailmap,\n     \"outlookidfix\" => \\$outlook_id_fix,\n+    \"useimaponly\" => \\$use_imap_only,\n );\n \n my %config_settings = (\n@@ -532,6 +536,7 @@ sub config_regexp {\n \t\t    \"smtp-auth=s\" => \\$smtp_auth,\n \t\t    \"no-smtp-auth\" => sub {$smtp_auth = 'none'},\n \t\t    \"imap-sent-folder=s\" => \\$imap_sent_folder,\n+\t\t    \"use-imap-only!\" => \\$use_imap_only,\n \t\t    \"annotate!\" => \\$annotate,\n \t\t    \"compose\" => \\$compose,\n \t\t    \"quiet\" => \\$quiet,\n@@ -1683,6 +1688,8 @@ sub send_message {\n \n \tif ($dry_run) {\n \t\t# We don't want to send the email.\n+\t} elsif ($use_imap_only) {\n+\t\tdie __(\"The destination IMAP folder is not properly defined.\") if !defined $imap_sent_folder;\n \t} elsif (defined $sendmail_cmd || file_name_is_absolute($smtp_server)) {\n \t\tmy $pid = open my $sm, '|-';\n \t\tdefined $pid or die $!;\n-- \n2.50.1\n\n"},{"id":"524016","messageId":"PN3PR01MB959751BD9AAB42393EF01D11B82BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63810","inReplyTo":"xmqqv7mtzfuc.fsf@gitster.g","subject":"Re: [PATCH v4 2/2] send-email: enable copying emails to IMAP folder without actually sending them","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-08-12T06:51:22Z","receivedAt":"2025-08-12T06:51:27Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\n> On 12 Aug 2025, at 3:22 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> \n> ﻿Aditya Garg <gargaditya08@live.com> writes:\n> \n>> +--[no-]use-imap-only::\n> \n> This is better written on two separate lines, i.e.\n> \n>    --use-imap-only::\n>    --no-use-imap-only::\n\nCorrected in v5"},{"id":"524044","messageId":"xmqqpld0y6be.fsf@gitster.g","threadId":"63810","inReplyTo":"PN3PR01MB95970565CA1F554E4B440C63B82BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"Re: [PATCH v4 2/2] send-email: enable copying emails to IMAP folder without actually sending them","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-08-12T14:15:33Z","receivedAt":"2025-08-12T14:15:35Z","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>> On 12 Aug 2025, at 10:38 AM, Aditya Garg <gargaditya08@live.com> wrote:\n>> \n>> ﻿\n>> \n>>> On 12 August 2025 3:22:11 am IST, Junio C Hamano <gitster@pobox.com> wrote:\n>>> Aditya Garg <gargaditya08@live.com> writes:\n>>> \n>>>> +--[no-]use-imap-only::\n>>> \n>>> This is better written on two separate lines, i.e.\n>>> \n>>>    --use-imap-only::\n>>>    --no-use-imap-only::\n>>> \n>> \n>> There are many instances in the docs where the command line option has been written as --[no-]something. Do they also have to be changed?\n>\n> Nvm, looks like they have been changed by a recent commit.\n\nYes.\n\nOthers around you are also working to make the system better in\nother topics in flight concurrently with your topic.  You do not\nneed to do everything yourself, but you'd need to be aware of their\neffort and avoid adding more instances of what they are fixing.\n\nAnd one of the jobs of the maintainer is to help contributors\ncoordinate among themselves, which is what I tried to do with my\nmessage ;-)\n\nThanks.\n\n\n"},{"id":"524061","messageId":"xmqqikisv8bq.fsf@gitster.g","threadId":"63810","inReplyTo":"PN3PR01MB9597E8E33868386C997D2563B82BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"Re: [PATCH v5 0/2] send-email: integrate with git imap-send","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-08-12T16:00:25Z","receivedAt":"2025-08-12T16:00:27Z","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>       ## Commit message ##\n>     -    send-email: enable copying emails to IMAP folder without actually sending them\n>     +    send-email: add ability to send a copy of sent emails to an IMAP folder\n>      \n\nThanks.\n"},{"id":"524224","messageId":"xmqq349tuud6.fsf@gitster.g","threadId":"63810","inReplyTo":"PN3PR01MB9597E8E33868386C997D2563B82BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","subject":"Re: [PATCH v5 0/2] send-email: integrate with git imap-send","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-08-15T03:38:45Z","receivedAt":"2025-08-15T03:38:48Z","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> v2 - Fix indentation in patch for imap-send.c\n>    - Minor edits to commit message\n>\n> v3 - Rename imap folder to imap sent folder\n>    - Make an error message shorter by removing unecessary details\n>\n> v4 - Fix a bug causing emails to be copied to an IMAP folder even if\n>      --dry-run is specified.\n>    - Minor edits to commit messages and docs.\n>    - Add another patch that enables copying emails to an IMAP folder\n>      without actually sending them.\n>\n> v5 - Avoid using -[no-]parameter.\n\nWe haven't seen any further comments; shall we mark it for 'next'?\n"}]}