* [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-20 9:25 [PATCH] send-email: add ability to send a copy of sent emails to an IMAP folder Aditya Garg
@ 2025-07-21 10:05 ` Aditya Garg
2025-07-21 16:34 ` Eric Sunshine
2025-07-21 19:13 ` Junio C Hamano
2025-07-22 11:14 ` [PATCH v3] " Aditya Garg
` (2 subsequent siblings)
3 siblings, 2 replies; 33+ messages in thread
From: Aditya Garg @ 2025-07-21 10:05 UTC (permalink / raw)
To: git@vger.kernel.org, Junio C Hamano
Cc: Eric Sunshine, Kristoffer Haugsbakk, Ben Knoble, brian m. carlson
Some email providers like Apple iCloud Mail do not support sending a copy
of sent emails to the "Sent" folder if SMTP server is used. As a
workaround, various email clients like Thunderbird which rely on SMTP,
use IMAP to send a copy of sent emails to the "Sent" folder. Something
similar can be done if sending emails via `git send-email`, by using
the `git imap-send` command to send a copy of the sent email to an IMAP
folder specified by the user.
Add this functionality to `git send-email` by introducing a new
configuration variable `sendemail.imapfolder` and command line option
`--imap-folder` which specifies the IMAP folder to send a copy of the
sent emails to. If specified, a copy of the sent emails will be sent
by piping the emails to `git imap-send` command, after the all emails are
sent via SMTP and the SMTP server has been closed.
Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
v2 - Fix indentation in patch for imap-send.c
- Minor edits to commit message
Documentation/config/sendemail.adoc | 1 +
Documentation/git-send-email.adoc | 12 +++++++++++
git-send-email.perl | 31 ++++++++++++++++++++++++++++-
imap-send.c | 26 ++++++++++++++++--------
4 files changed, 61 insertions(+), 9 deletions(-)
diff --git a/Documentation/config/sendemail.adoc b/Documentation/config/sendemail.adoc
index 4722334657..55b5943956 100644
--- a/Documentation/config/sendemail.adoc
+++ b/Documentation/config/sendemail.adoc
@@ -88,6 +88,7 @@ sendemail.smtpServer::
sendemail.smtpServerPort::
sendemail.smtpServerOption::
sendemail.smtpUser::
+sendemail.imapfolder::
sendemail.thread::
sendemail.transferEncoding::
sendemail.validate::
diff --git a/Documentation/git-send-email.adoc b/Documentation/git-send-email.adoc
index 5335502d68..74ec2944da 100644
--- a/Documentation/git-send-email.adoc
+++ b/Documentation/git-send-email.adoc
@@ -299,6 +299,18 @@ must be used for each option.
commands and replies will be printed. Useful to debug TLS
connection and authentication problems.
+--imap-folder=<folder>::
+ Some email providers (e.g. iCloud) do not send a copy of the emails sent
+ using SMTP to the `Sent` folder or similar in your mailbox. Use this option
+ to use `git imap-send` to send a copy of the emails to the folder specified
+ using this option. You can run `git imap-send --list` to get a list of
+ valid folder names, including the correct name of the `Sent` folder in
+ your mailbox. You can also use this option to send emails to a dedicated
+ IMAP folder of your choice.
++
+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
+to get instructions for the same.
+
--batch-size=<num>::
Some email servers (e.g. 'smtp.163.com') limit the number of emails to be
sent per session (connection) and this will lead to a failure when
diff --git a/git-send-email.perl b/git-send-email.perl
index 437f8ac46a..214a0023bf 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -73,6 +73,8 @@ sub usage {
--no-smtp-auth * Disable SMTP authentication. Shorthand for
`--smtp-auth=none`
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
+ --imap-folder <str> * IMAP folder where a copy of the emails should be sent.
+ Make sure `git imap-send` is setup to use this feature.
--batch-size <int> * send max <int> message per connection.
--relogin-delay <int> * delay <int> seconds between two successive login.
@@ -200,7 +202,7 @@ sub format_2822_time {
# Variables we fill in automatically, or via prompting:
my (@to,@cc,@xh,$envelope_sender,
- $initial_in_reply_to,$reply_to,$initial_subject,@files,
+ $initial_in_reply_to,$reply_to,$initial_subject,@files,@imap_copy,
$author,$sender,$smtp_authpass,$annotate,$compose,$time);
# Things we either get from config, *or* are overridden on the
# command-line.
@@ -277,6 +279,7 @@ sub do_edit {
my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);
my ($batch_size, $relogin_delay);
my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);
+my ($imap_folder);
my ($confirm);
my (@suppress_cc);
my ($auto_8bit_encoding);
@@ -322,6 +325,7 @@ sub do_edit {
"smtpauth" => \$smtp_auth,
"smtpbatchsize" => \$batch_size,
"smtprelogindelay" => \$relogin_delay,
+ "imapfolder" => \$imap_folder,
"to" => \@config_to,
"tocmd" => \$to_cmd,
"cc" => \@config_cc,
@@ -527,6 +531,7 @@ sub config_regexp {
"smtp-domain:s" => \$smtp_domain,
"smtp-auth=s" => \$smtp_auth,
"no-smtp-auth" => sub {$smtp_auth = 'none'},
+ "imap-folder=s" => \$imap_folder,
"annotate!" => \$annotate,
"compose" => \$compose,
"quiet" => \$quiet,
@@ -1829,6 +1834,17 @@ sub send_message {
print "\n";
}
+ if ($imap_folder) {
+ my $imap_header = $header;
+ if (@initial_bcc) {
+ # Bcc is not a part of $header, so we add it here.
+ # This is only for the IMAP copy, not for the actual email
+ # sent to the recipients.
+ $imap_header .= "Bcc: " . join(", ", @initial_bcc) . "\n";
+ }
+ push @imap_copy, "From git-send-email\n$imap_header\n$message";
+ }
+
return 1;
}
@@ -2223,6 +2239,19 @@ sub cleanup_compose_files {
$smtp->quit if $smtp;
+if ($imap_folder && @imap_copy) {
+ my $imap_input = join("\n", @imap_copy);
+ eval {
+ print "\nStarting git imap-send...\n";
+ my ($fh, $ctx) = Git::command_input_pipe(['imap-send', '-f', $imap_folder]);
+ print $fh $imap_input;
+ Git::command_close_pipe($fh, $ctx);
+ 1;
+ } or do {
+ warn "Warning: failed to send messages to IMAP folder $imap_folder via imap-send pipe: $@";
+ };
+}
+
sub apply_transfer_encoding {
my $message = shift;
my $from = shift;
diff --git a/imap-send.c b/imap-send.c
index f5a656ac71..44de0c5a77 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1441,14 +1441,24 @@ static int count_messages(struct strbuf *all_msgs)
while (1) {
if (starts_with(p, "From ")) {
- p = strstr(p+5, "\nFrom: ");
- if (!p) break;
- p = strstr(p+7, "\nDate: ");
- if (!p) break;
- p = strstr(p+7, "\nSubject: ");
- if (!p) break;
- p += 10;
- count++;
+ if (starts_with(p, "From git-send-email")) {
+ p = strstr(p+5, "\nFrom: ");
+ if (!p) break;
+ p += 7;
+ p = strstr(p, "\nTo: ");
+ if (!p) break;
+ p += 5;
+ count++;
+ } else {
+ p = strstr(p+5, "\nFrom: ");
+ if (!p) break;
+ p = strstr(p+7, "\nDate: ");
+ if (!p) break;
+ p = strstr(p+7, "\nSubject: ");
+ if (!p) break;
+ p += 10;
+ count++;
+ }
}
p = strstr(p+5, "\nFrom ");
if (!p)
Range-diff against v1:
1: c87d31a672 ! 1: 87a8901825 send-email: add ability to send a copy of sent emails to an IMAP folder
@@ Commit message
send-email: add ability to send a copy of sent emails to an IMAP folder
Some email providers like Apple iCloud Mail do not support sending a copy
- of sent emails to the "Sent" folder if emails are sent via SMTP. As a
+ of sent emails to the "Sent" folder if SMTP server is used. As a
workaround, various email clients like Thunderbird which rely on SMTP,
use IMAP to send a copy of sent emails to the "Sent" folder. Something
- similar can be done with if sending emails via `git send-email`, by using
+ similar can be done if sending emails via `git send-email`, by using
the `git imap-send` command to send a copy of the sent email to an IMAP
folder specified by the user.
@@ imap-send.c: static int count_messages(struct strbuf *all_msgs)
- p = strstr(p+7, "\nDate: ");
- if (!p) break;
- p = strstr(p+7, "\nSubject: ");
+- if (!p) break;
+- p += 10;
+- count++;
+ if (starts_with(p, "From git-send-email")) {
+ p = strstr(p+5, "\nFrom: ");
+ if (!p) break;
@@ imap-send.c: static int count_messages(struct strbuf *all_msgs)
+ p = strstr(p+7, "\nDate: ");
+ if (!p) break;
+ p = strstr(p+7, "\nSubject: ");
- if (!p) break;
- p += 10;
- count++;
++ if (!p) break;
++ p += 10;
++ count++;
+ }
}
p = strstr(p+5, "\nFrom ");
--
2.50.1.windows.1
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-21 10:05 ` [PATCH v2] " Aditya Garg
@ 2025-07-21 16:34 ` Eric Sunshine
2025-07-23 9:48 ` Aditya Garg
2025-07-21 19:13 ` Junio C Hamano
1 sibling, 1 reply; 33+ messages in thread
From: Eric Sunshine @ 2025-07-21 16:34 UTC (permalink / raw)
To: Aditya Garg
Cc: git@vger.kernel.org, Junio C Hamano, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
On Mon, Jul 21, 2025 at 6:05 AM Aditya Garg <gargaditya08@live.com> wrote:
> Some email providers like Apple iCloud Mail do not support sending a copy
> of sent emails to the "Sent" folder if SMTP server is used. As a
> workaround, various email clients like Thunderbird which rely on SMTP,
> use IMAP to send a copy of sent emails to the "Sent" folder. Something
> similar can be done if sending emails via `git send-email`, by using
> the `git imap-send` command to send a copy of the sent email to an IMAP
> folder specified by the user.
>
> Add this functionality to `git send-email` by introducing a new
> configuration variable `sendemail.imapfolder` and command line option
> `--imap-folder` which specifies the IMAP folder to send a copy of the
> sent emails to. If specified, a copy of the sent emails will be sent
> by piping the emails to `git imap-send` command, after the all emails are
> sent via SMTP and the SMTP server has been closed.
s/the all/all/
> Signed-off-by: Aditya Garg <gargaditya08@live.com>
> ---
> @@ -299,6 +299,18 @@ must be used for each option.
> +This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
> +to get instructions for the same.
Perhaps:
This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
for instructions.
> diff --git a/git-send-email.perl b/git-send-email.perl
> @@ -73,6 +73,8 @@ sub usage {
> + --imap-folder <str> * IMAP folder where a copy of the emails should be sent.
> + Make sure `git imap-send` is setup to use this feature.
s/setup/set up/
^ permalink raw reply [flat|nested] 33+ messages in thread* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-21 16:34 ` Eric Sunshine
@ 2025-07-23 9:48 ` Aditya Garg
0 siblings, 0 replies; 33+ messages in thread
From: Aditya Garg @ 2025-07-23 9:48 UTC (permalink / raw)
To: Eric Sunshine
Cc: git@vger.kernel.org, Junio C Hamano, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
On 21/07/25 10:04 pm, Eric Sunshine wrote:
> On Mon, Jul 21, 2025 at 6:05 AM Aditya Garg <gargaditya08@live.com> wrote:
>> Some email providers like Apple iCloud Mail do not support sending a copy
>> of sent emails to the "Sent" folder if SMTP server is used. As a
>> workaround, various email clients like Thunderbird which rely on SMTP,
>> use IMAP to send a copy of sent emails to the "Sent" folder. Something
>> similar can be done if sending emails via `git send-email`, by using
>> the `git imap-send` command to send a copy of the sent email to an IMAP
>> folder specified by the user.
>>
>> Add this functionality to `git send-email` by introducing a new
>> configuration variable `sendemail.imapfolder` and command line option
>> `--imap-folder` which specifies the IMAP folder to send a copy of the
>> sent emails to. If specified, a copy of the sent emails will be sent
>> by piping the emails to `git imap-send` command, after the all emails are
>> sent via SMTP and the SMTP server has been closed.
>
> s/the all/all/
>
>> Signed-off-by: Aditya Garg <gargaditya08@live.com>
>> ---
>> @@ -299,6 +299,18 @@ must be used for each option.
>> +This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
>> +to get instructions for the same.
>
> Perhaps:
>
> This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
> for instructions.
>
>> diff --git a/git-send-email.perl b/git-send-email.perl
>> @@ -73,6 +73,8 @@ sub usage {
>> + --imap-folder <str> * IMAP folder where a copy of the emails should be sent.
>> + Make sure `git imap-send` is setup to use this feature.
>
> s/setup/set up/
Will 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?
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-21 10:05 ` [PATCH v2] " Aditya Garg
2025-07-21 16:34 ` Eric Sunshine
@ 2025-07-21 19:13 ` Junio C Hamano
2025-07-22 0:19 ` brian m. carlson
2025-07-22 3:37 ` Aditya Garg
1 sibling, 2 replies; 33+ messages in thread
From: Junio C Hamano @ 2025-07-21 19:13 UTC (permalink / raw)
To: Aditya Garg
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
Aditya Garg <gargaditya08@live.com> writes:
> +sendemail.imapfolder::
Do we expect that the use of IMAP in git-send-email will be limited
forever to store outgoing e-mails to the Sent folder? I highly
doubt it. For example, would it be plausible that given send-email
has so much richer feature set compared to imap-send, it would not
be implausible for users of imap-send that want to stuff messages,
with Cc's, threading, etc., all prepared by send-email, to their
outgoing folder.
And when somebody wants to add such a feature to "git send-email",
how would they find this variable that uses imap-send for quite a
different purpose squatting on its name?
Same comment for the --imap-folder command line option and the
internal variable(s) used to implement this feature.
These things should be named with words like "sent", "fcc", etc., to
clarify the use case this new feature is trying to support.
As imap-send is not part of my daily workflow, I have no strong
opinions for or against the proposed feature, and I didn't find
anything glaringly wrong in the implementation, other than the poor
naming that would block possible future enhancements.
Thanks.
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-21 19:13 ` Junio C Hamano
@ 2025-07-22 0:19 ` brian m. carlson
2025-07-22 3:40 ` Aditya Garg
2025-07-22 3:37 ` Aditya Garg
1 sibling, 1 reply; 33+ messages in thread
From: brian m. carlson @ 2025-07-22 0:19 UTC (permalink / raw)
To: Junio C Hamano
Cc: Aditya Garg, git@vger.kernel.org, Eric Sunshine,
Kristoffer Haugsbakk, Ben Knoble
[-- Attachment #1: Type: text/plain, Size: 1827 bytes --]
On 2025-07-21 at 19:13:56, Junio C Hamano wrote:
> Aditya Garg <gargaditya08@live.com> writes:
>
> > +sendemail.imapfolder::
>
> Do we expect that the use of IMAP in git-send-email will be limited
> forever to store outgoing e-mails to the Sent folder? I highly
> doubt it. For example, would it be plausible that given send-email
> has so much richer feature set compared to imap-send, it would not
> be implausible for users of imap-send that want to stuff messages,
> with Cc's, threading, etc., all prepared by send-email, to their
> outgoing folder.
>
> And when somebody wants to add such a feature to "git send-email",
> how would they find this variable that uses imap-send for quite a
> different purpose squatting on its name?
>
> Same comment for the --imap-folder command line option and the
> internal variable(s) used to implement this feature.
>
> These things should be named with words like "sent", "fcc", etc., to
> clarify the use case this new feature is trying to support.
I think this is a good idea. We should be thoughtful about our option
names here.
> As imap-send is not part of my daily workflow, I have no strong
> opinions for or against the proposed feature, and I didn't find
> anything glaringly wrong in the implementation, other than the poor
> naming that would block possible future enhancements.
I would also like to advocate in favour of the feature in general. I
run my own mail server and there is no magical functionality to add my
outgoing emails to the Sent folder, so I can definitely see the utility
of this functionality. I'm sure there are also other, larger mail
providers for which this would be useful as well. (I suspect the patch
author is on one of them, in fact.)
--
brian m. carlson (they/them)
Toronto, Ontario, CA
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-22 0:19 ` brian m. carlson
@ 2025-07-22 3:40 ` Aditya Garg
0 siblings, 0 replies; 33+ messages in thread
From: Aditya Garg @ 2025-07-22 3:40 UTC (permalink / raw)
To: brian m. carlson, Junio C Hamano
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble
On 22 July 2025 5:49:42 am IST, "brian m. carlson" <sandals@crustytoothpaste.net> wrote:
>On 2025-07-21 at 19:13:56, Junio C Hamano wrote:
>> Aditya Garg <gargaditya08@live.com> writes:
>>
>> > +sendemail.imapfolder::
>>
>> Do we expect that the use of IMAP in git-send-email will be limited
>> forever to store outgoing e-mails to the Sent folder? I highly
>> doubt it. For example, would it be plausible that given send-email
>> has so much richer feature set compared to imap-send, it would not
>> be implausible for users of imap-send that want to stuff messages,
>> with Cc's, threading, etc., all prepared by send-email, to their
>> outgoing folder.
>>
>> And when somebody wants to add such a feature to "git send-email",
>> how would they find this variable that uses imap-send for quite a
>> different purpose squatting on its name?
>>
>> Same comment for the --imap-folder command line option and the
>> internal variable(s) used to implement this feature.
>>
>> These things should be named with words like "sent", "fcc", etc., to
>> clarify the use case this new feature is trying to support.
>
>I think this is a good idea. We should be thoughtful about our option
>names here.
>
As 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.
>> As imap-send is not part of my daily workflow, I have no strong
>> opinions for or against the proposed feature, and I didn't find
>> anything glaringly wrong in the implementation, other than the poor
>> naming that would block possible future enhancements.
>
>I would also like to advocate in favour of the feature in general. I
>run my own mail server and there is no magical functionality to add my
>outgoing emails to the Sent folder, so I can definitely see the utility
>of this functionality. I'm sure there are also other, larger mail
>providers for which this would be useful as well. (I suspect the patch
>author is on one of them, in fact.)
Fortunately 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.
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-21 19:13 ` Junio C Hamano
2025-07-22 0:19 ` brian m. carlson
@ 2025-07-22 3:37 ` Aditya Garg
2025-07-22 5:09 ` Junio C Hamano
1 sibling, 1 reply; 33+ messages in thread
From: Aditya Garg @ 2025-07-22 3:37 UTC (permalink / raw)
To: Junio C Hamano
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
On 22 July 2025 12:43:56 am IST, Junio C Hamano <gitster@pobox.com> wrote:
>Aditya Garg <gargaditya08@live.com> writes:
>
>> +sendemail.imapfolder::
>
>Do we expect that the use of IMAP in git-send-email will be limited
>forever to store outgoing e-mails to the Sent folder? I highly
>doubt it. For example, would it be plausible that given send-email
>has so much richer feature set compared to imap-send, it would not
>be implausible for users of imap-send that want to stuff messages,
>with Cc's, threading, etc., all prepared by send-email, to their
>outgoing folder.
I 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.
Or maybe you mean, ONLY send via imap and don't use SMTP? Like this users can use their email clients to send emails?
>
>And when somebody wants to add such a feature to "git send-email",
>how would they find this variable that uses imap-send for quite a
>different purpose squatting on its name?
>
>Same comment for the --imap-folder command line option and the
>internal variable(s) used to implement this feature.
>
>These things should be named with words like "sent", "fcc", etc., to
>clarify the use case this new feature is trying to support.
>
IMAP 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?
For cases which want to use ONLY IMAP send, a bool like use_imap_only etc can be used with imap_folder.
Although, I am open to better name suggestions.
>As imap-send is not part of my daily workflow, I have no strong
>opinions for or against the proposed feature, and I didn't find
>anything glaringly wrong in the implementation, other than the poor
>naming that would block possible future enhancements.
>
>Thanks.
>
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-22 3:37 ` Aditya Garg
@ 2025-07-22 5:09 ` Junio C Hamano
2025-07-22 6:14 ` Aditya Garg
0 siblings, 1 reply; 33+ messages in thread
From: Junio C Hamano @ 2025-07-22 5:09 UTC (permalink / raw)
To: Aditya Garg
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
Aditya Garg <gargaditya08@live.com> writes:
> Or maybe you mean, ONLY send via imap and don't use SMTP? Like
> this users can use their email clients to send emails?
Exactly. You sold this feature as "have send-email send the
message, and keep an extra copy you sent in your Sent imap folder".
I pointed out that "have send-email do everything it would normally
do before it talks to MSA or talk SMTP to send messages out, and
instead drive imap-send to store these messages in a folder like
imap-send users have used the program so far---as the user will send
the messages out of their draft folder as was traditionally done by
any imap-send users, send-email will *not* send anything out itself"
as a possible different way send-email may want to use imap-send.
These are two very different use cases. We could organize things
this way:
A1. When imap-folder is specified, that IMAP folder will get an extra
copy, in addition to what send-email sends out;
A2. When yet another new option, --send-email-no-send, is
specified, send-email would not send any messages out. Even
when this option is in effect, if --imap-folder is specified,
that IMAP folder will get an extra copy, in addition to what
send-email would send out (which is nothing).
Or alternatively, we can have two very different operation modes
that both involve imap-send:
B1. When --imap-sent-folder is specified, that IMAP folder will get
an extra copy, in addition to what send-email sent out via its
usual route (like by invoking MSA or talking SMTP)
B2. When --imap-outgo-folder is specified, that IMAP folder will
get the outgo copy, later to be sent by the user (just like a
user of imap-send would usually use), and send-email would not
send out anything by its usual route.
I thought the latter would be easier to explain to end-users, which
is why "sent" or "fcc" or something like that should be in the name
of the option when operating in the mode the patch implements.
This brings up a yet another possibility. Invoking imap-send can be
a new third way send-email uses to send out the messages, in addition
to existing (1) invoking a local "/usr/lib/sendmail" program, or (2)
talking SMTP to smarthost. That would be very easy to explain the
operating mode B2 to users of send-email or users of imap-send, but
it would be a bit awkward to find where B1 conceptually fits.
^ permalink raw reply [flat|nested] 33+ messages in thread* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-22 5:09 ` Junio C Hamano
@ 2025-07-22 6:14 ` Aditya Garg
2025-07-22 11:24 ` Aditya Garg
2025-07-22 13:24 ` Junio C Hamano
0 siblings, 2 replies; 33+ messages in thread
From: Aditya Garg @ 2025-07-22 6:14 UTC (permalink / raw)
To: Junio C Hamano
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
On 22 July 2025 10:39:01 am IST, Junio C Hamano <gitster@pobox.com> wrote:
>Aditya Garg <gargaditya08@live.com> writes:
>
>> Or maybe you mean, ONLY send via imap and don't use SMTP? Like
>> this users can use their email clients to send emails?
>
>Exactly. You sold this feature as "have send-email send the
>message, and keep an extra copy you sent in your Sent imap folder".
>
>I pointed out that "have send-email do everything it would normally
>do before it talks to MSA or talk SMTP to send messages out, and
>instead drive imap-send to store these messages in a folder like
>imap-send users have used the program so far---as the user will send
>the messages out of their draft folder as was traditionally done by
>any imap-send users, send-email will *not* send anything out itself"
>as a possible different way send-email may want to use imap-send.
>
>These are two very different use cases. We could organize things
>this way:
>
> A1. When imap-folder is specified, that IMAP folder will get an extra
> copy, in addition to what send-email sends out;
>
> A2. When yet another new option, --send-email-no-send, is
> specified, send-email would not send any messages out. Even
> when this option is in effect, if --imap-folder is specified,
> that IMAP folder will get an extra copy, in addition to what
> send-email would send out (which is nothing).
>
>Or alternatively, we can have two very different operation modes
>that both involve imap-send:
>
> B1. When --imap-sent-folder is specified, that IMAP folder will get
> an extra copy, in addition to what send-email sent out via its
> usual route (like by invoking MSA or talking SMTP)
>
> B2. When --imap-outgo-folder is specified, that IMAP folder will
> get the outgo copy, later to be sent by the user (just like a
> user of imap-send would usually use), and send-email would not
> send out anything by its usual route.
>
>I thought the latter would be easier to explain to end-users, which
>is why "sent" or "fcc" or something like that should be in the name
>of the option when operating in the mode the patch implements.
>
>This brings up a yet another possibility. Invoking imap-send can be
>a new third way send-email uses to send out the messages, in addition
>to existing (1) invoking a local "/usr/lib/sendmail" program, or (2)
>talking SMTP to smarthost. That would be very easy to explain the
>operating mode B2 to users of send-email or users of imap-send, but
>it would be a bit awkward to find where B1 conceptually fits.
>
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.
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?
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-22 6:14 ` Aditya Garg
@ 2025-07-22 11:24 ` Aditya Garg
2025-07-22 15:36 ` Junio C Hamano
2025-07-22 13:24 ` Junio C Hamano
1 sibling, 1 reply; 33+ messages in thread
From: Aditya Garg @ 2025-07-22 11:24 UTC (permalink / raw)
To: Junio C Hamano
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
On 22/07/25 11:44 am, Aditya Garg wrote:
>
>
>
>
> On 22 July 2025 10:39:01 am IST, Junio C Hamano <gitster@pobox.com> wrote:
>> Aditya Garg <gargaditya08@live.com> writes:
>>
>>> Or maybe you mean, ONLY send via imap and don't use SMTP? Like
>>> this users can use their email clients to send emails?
>>
>> Exactly. You sold this feature as "have send-email send the
>> message, and keep an extra copy you sent in your Sent imap folder".
>>
>> I pointed out that "have send-email do everything it would normally
>> do before it talks to MSA or talk SMTP to send messages out, and
>> instead drive imap-send to store these messages in a folder like
>> imap-send users have used the program so far---as the user will send
>> the messages out of their draft folder as was traditionally done by
>> any imap-send users, send-email will *not* send anything out itself"
>> as a possible different way send-email may want to use imap-send.
>>
>> These are two very different use cases. We could organize things
>> this way:
>>
>> A1. When imap-folder is specified, that IMAP folder will get an extra
>> copy, in addition to what send-email sends out;
>>
>> A2. When yet another new option, --send-email-no-send, is
>> specified, send-email would not send any messages out. Even
>> when this option is in effect, if --imap-folder is specified,
>> that IMAP folder will get an extra copy, in addition to what
>> send-email would send out (which is nothing).
>>
>> Or alternatively, we can have two very different operation modes
>> that both involve imap-send:
>>
>> B1. When --imap-sent-folder is specified, that IMAP folder will get
>> an extra copy, in addition to what send-email sent out via its
>> usual route (like by invoking MSA or talking SMTP)
>>
>> B2. When --imap-outgo-folder is specified, that IMAP folder will
>> get the outgo copy, later to be sent by the user (just like a
>> user of imap-send would usually use), and send-email would not
>> send out anything by its usual route.
>>
>> I thought the latter would be easier to explain to end-users, which
>> is why "sent" or "fcc" or something like that should be in the name
>> of the option when operating in the mode the patch implements.
>>
>> This brings up a yet another possibility. Invoking imap-send can be
>> a new third way send-email uses to send out the messages, in addition
>> to existing (1) invoking a local "/usr/lib/sendmail" program, or (2)
>> talking SMTP to smarthost. That would be very easy to explain the
>> operating mode B2 to users of send-email or users of imap-send, but
>> it would be a bit awkward to find where B1 conceptually fits.
>>
>
> 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.
>
> 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?
Also, as far as B2 is concerned, users can already do something like:
git format-patch -2 HEAD --to=someone@example.com --stdout | git imap-send
Which is more or less the same what git-send-email would do. The objective to add imap-send to send-email was not
to add another feature for sending emails, but rather keep to copy of the sent emails at the desired correct place
in their own mailbox.
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-22 11:24 ` Aditya Garg
@ 2025-07-22 15:36 ` Junio C Hamano
2025-07-22 16:31 ` Aditya Garg
0 siblings, 1 reply; 33+ messages in thread
From: Junio C Hamano @ 2025-07-22 15:36 UTC (permalink / raw)
To: Aditya Garg
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
Aditya Garg <gargaditya08@live.com> writes:
> Also, as far as B2 is concerned, users can already do something like:
>
> git format-patch -2 HEAD --to=someone@example.com --stdout | git imap-send
If the above command line is sufficient for users, "git send-email"
does not need its feature to drive format-patch and do
git format-patch -o outgo/. -2 HEAD &&
git send-email --to=someone@example.com ./outgo/*.patch
I used to think that way and I was naive ;-) But such an argument
completely misses the point of various send-email options that allow
the user to tweak CC: list programatically, compose the cover
letter, etc., doesn't it?
^ permalink raw reply [flat|nested] 33+ messages in thread* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-22 15:36 ` Junio C Hamano
@ 2025-07-22 16:31 ` Aditya Garg
2025-07-22 16:36 ` Aditya Garg
2025-07-22 17:23 ` Junio C Hamano
0 siblings, 2 replies; 33+ messages in thread
From: Aditya Garg @ 2025-07-22 16:31 UTC (permalink / raw)
To: Junio C Hamano
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
> On 22 Jul 2025, at 9:06 PM, Junio C Hamano <gitster@pobox.com> wrote:
>
> Aditya Garg <gargaditya08@live.com> writes:
>
>> Also, as far as B2 is concerned, users can already do something like:
>>
>> git format-patch -2 HEAD --to=someone@example.com --stdout | git imap-send
>
> If the above command line is sufficient for users, "git send-email"
> does not need its feature to drive format-patch and do
>
> git format-patch -o outgo/. -2 HEAD &&
> git send-email --to=someone@example.com ./outgo/*.patch
>
> I used to think that way and I was naive ;-) But such an argument
> completely misses the point of various send-email options that allow
> the user to tweak CC: list programatically, compose the cover
> letter, etc., doesn't it?
Hmm, yes it does, but is this functionality in the scope of this patch?
Honestly if you can use IMAP, you can also use SMTP, which makes me question if we really need this feature or not.
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-22 16:31 ` Aditya Garg
@ 2025-07-22 16:36 ` Aditya Garg
2025-07-22 17:23 ` Junio C Hamano
1 sibling, 0 replies; 33+ messages in thread
From: Aditya Garg @ 2025-07-22 16:36 UTC (permalink / raw)
To: Junio C Hamano
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
> On 22 Jul 2025, at 10:01 PM, Aditya Garg <gargaditya08@live.com> wrote:
>
>
>
>> On 22 Jul 2025, at 9:06 PM, Junio C Hamano <gitster@pobox.com> wrote:
>>
>> Aditya Garg <gargaditya08@live.com> writes:
>>
>>> Also, as far as B2 is concerned, users can already do something like:
>>>
>>> git format-patch -2 HEAD --to=someone@example.com --stdout | git imap-send
>>
>> If the above command line is sufficient for users, "git send-email"
>> does not need its feature to drive format-patch and do
>>
>> git format-patch -o outgo/. -2 HEAD &&
>> git send-email --to=someone@example.com ./outgo/*.patch
>>
>> I used to think that way and I was naive ;-) But such an argument
>> completely misses the point of various send-email options that allow
>> the user to tweak CC: list programatically, compose the cover
>> letter, etc., doesn't it?
>
> Hmm, yes it does, but is this functionality in the scope of this patch?
>
> Honestly if you can use IMAP, you can also use SMTP, which makes me question if we really need this feature or not.
By “this feature” I mean the one that sends emails to IMAP only btw.
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-22 16:31 ` Aditya Garg
2025-07-22 16:36 ` Aditya Garg
@ 2025-07-22 17:23 ` Junio C Hamano
2025-07-22 17:26 ` Aditya Garg
1 sibling, 1 reply; 33+ messages in thread
From: Junio C Hamano @ 2025-07-22 17:23 UTC (permalink / raw)
To: Aditya Garg
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
Aditya Garg <gargaditya08@live.com> writes:
> Hmm, yes it does, but is this functionality in the scope of this patch?
No, it is not.
But it is your responsibility to make sure that you leave the door
open for somebody who will want to do so later. And you do so by
not squatting on a way more generic option and configuration
variable name than what the feature you are adding, which is more
specific than its name.
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-22 17:23 ` Junio C Hamano
@ 2025-07-22 17:26 ` Aditya Garg
0 siblings, 0 replies; 33+ messages in thread
From: Aditya Garg @ 2025-07-22 17:26 UTC (permalink / raw)
To: Junio C Hamano
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
On 22 July 2025 10:53:04 pm IST, Junio C Hamano <gitster@pobox.com> wrote:
>Aditya Garg <gargaditya08@live.com> writes:
>
>> Hmm, yes it does, but is this functionality in the scope of this patch?
>
>No, it is not.
>
>But it is your responsibility to make sure that you leave the door
>open for somebody who will want to do so later. And you do so by
>not squatting on a way more generic option and configuration
>variable name than what the feature you are adding, which is more
>specific than its name.
I 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.
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-22 6:14 ` Aditya Garg
2025-07-22 11:24 ` Aditya Garg
@ 2025-07-22 13:24 ` Junio C Hamano
2025-07-22 13:26 ` Aditya Garg
1 sibling, 1 reply; 33+ messages in thread
From: Junio C Hamano @ 2025-07-22 13:24 UTC (permalink / raw)
To: Aditya Garg
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
Aditya Garg <gargaditya08@live.com> writes:
> 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?
Sorry, I am puzzled.
The reason why the option "--imap-sent-folder=<you-name-that-thing>"
takes a value, and not a "--[no-]imap-keep-copy-in-the-Sent-folder"
Boolean, is exactly because you want to give whatever name you want
it to use, so I am not sure why you are even asking that question.
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-22 13:24 ` Junio C Hamano
@ 2025-07-22 13:26 ` Aditya Garg
0 siblings, 0 replies; 33+ messages in thread
From: Aditya Garg @ 2025-07-22 13:26 UTC (permalink / raw)
To: Junio C Hamano
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
On 22 July 2025 6:54:05 pm IST, Junio C Hamano <gitster@pobox.com> wrote:
>Aditya Garg <gargaditya08@live.com> writes:
>
>> 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?
>
>Sorry, I am puzzled.
>
>The reason why the option "--imap-sent-folder=<you-name-that-thing>"
>takes a value, and not a "--[no-]imap-keep-copy-in-the-Sent-folder"
>Boolean, is exactly because you want to give whatever name you want
>it to use, so I am not sure why you are even asking that question.
I 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.
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH v3] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-20 9:25 [PATCH] send-email: add ability to send a copy of sent emails to an IMAP folder Aditya Garg
2025-07-21 10:05 ` [PATCH v2] " Aditya Garg
@ 2025-07-22 11:14 ` Aditya Garg
2025-07-23 9:05 ` Aditya Garg
2025-07-23 10:33 ` [PATCH v4 0/2] send-email: integrate with git imap-send Aditya Garg
2025-08-12 6:44 ` [PATCH v5 0/2] send-email: integrate with git imap-send Aditya Garg
3 siblings, 1 reply; 33+ messages in thread
From: Aditya Garg @ 2025-07-22 11:14 UTC (permalink / raw)
To: git@vger.kernel.org, Junio C Hamano
Cc: Eric Sunshine, Kristoffer Haugsbakk, Ben Knoble, brian m. carlson
Some email providers like Apple iCloud Mail do not support sending a copy
of sent emails to the "Sent" folder if SMTP server is used. As a
workaround, various email clients like Thunderbird which rely on SMTP,
use IMAP to send a copy of sent emails to the "Sent" folder. Something
similar can be done if sending emails via `git send-email`, by using
the `git imap-send` command to send a copy of the sent email to an IMAP
folder specified by the user.
Add this functionality to `git send-email` by introducing a new
configuration variable `sendemail.imapfolder` and command line option
`--imap-folder` which specifies the IMAP folder to send a copy of the
sent emails to. If specified, a copy of the sent emails will be sent
by piping the emails to `git imap-send` command, after the all emails are
sent via SMTP and the SMTP server has been closed.
Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
v2 - Fix indentation in patch for imap-send.c
- Minor edits to commit message
v3 - Rename imap folder to imap sent folder
- Make an error message shorter by removing unecessary details
Documentation/config/sendemail.adoc | 1 +
Documentation/git-send-email.adoc | 12 +++++++++++
git-send-email.perl | 31 ++++++++++++++++++++++++++++-
imap-send.c | 26 ++++++++++++++++--------
4 files changed, 61 insertions(+), 9 deletions(-)
diff --git a/Documentation/config/sendemail.adoc b/Documentation/config/sendemail.adoc
index 4722334657..dd2dbc87a0 100644
--- a/Documentation/config/sendemail.adoc
+++ b/Documentation/config/sendemail.adoc
@@ -88,6 +88,7 @@ sendemail.smtpServer::
sendemail.smtpServerPort::
sendemail.smtpServerOption::
sendemail.smtpUser::
+sendemail.imapSentFolder::
sendemail.thread::
sendemail.transferEncoding::
sendemail.validate::
diff --git a/Documentation/git-send-email.adoc b/Documentation/git-send-email.adoc
index 5335502d68..82a65fd47f 100644
--- a/Documentation/git-send-email.adoc
+++ b/Documentation/git-send-email.adoc
@@ -299,6 +299,18 @@ must be used for each option.
commands and replies will be printed. Useful to debug TLS
connection and authentication problems.
+--imap-sent-folder=<folder>::
+ Some email providers (e.g. iCloud) do not send a copy of the emails sent
+ using SMTP to the `Sent` folder or similar in your mailbox. Use this option
+ to use `git imap-send` to send a copy of the emails to the folder specified
+ using this option. You can run `git imap-send --list` to get a list of
+ valid folder names, including the correct name of the `Sent` folder in
+ your mailbox. You can also use this option to send emails to a dedicated
+ IMAP folder of your choice.
++
+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
+to get instructions for the same.
+
--batch-size=<num>::
Some email servers (e.g. 'smtp.163.com') limit the number of emails to be
sent per session (connection) and this will lead to a failure when
diff --git a/git-send-email.perl b/git-send-email.perl
index 437f8ac46a..5aafe8cdf3 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -73,6 +73,8 @@ sub usage {
--no-smtp-auth * Disable SMTP authentication. Shorthand for
`--smtp-auth=none`
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
+ --imap-sent-folder <str> * IMAP folder where a copy of the emails should be sent.
+ Make sure `git imap-send` is setup to use this feature.
--batch-size <int> * send max <int> message per connection.
--relogin-delay <int> * delay <int> seconds between two successive login.
@@ -200,7 +202,7 @@ sub format_2822_time {
# Variables we fill in automatically, or via prompting:
my (@to,@cc,@xh,$envelope_sender,
- $initial_in_reply_to,$reply_to,$initial_subject,@files,
+ $initial_in_reply_to,$reply_to,$initial_subject,@files,@imap_copy,
$author,$sender,$smtp_authpass,$annotate,$compose,$time);
# Things we either get from config, *or* are overridden on the
# command-line.
@@ -277,6 +279,7 @@ sub do_edit {
my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);
my ($batch_size, $relogin_delay);
my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);
+my ($imap_sent_folder);
my ($confirm);
my (@suppress_cc);
my ($auto_8bit_encoding);
@@ -322,6 +325,7 @@ sub do_edit {
"smtpauth" => \$smtp_auth,
"smtpbatchsize" => \$batch_size,
"smtprelogindelay" => \$relogin_delay,
+ "imapsentfolder" => \$imap_sent_folder,
"to" => \@config_to,
"tocmd" => \$to_cmd,
"cc" => \@config_cc,
@@ -527,6 +531,7 @@ sub config_regexp {
"smtp-domain:s" => \$smtp_domain,
"smtp-auth=s" => \$smtp_auth,
"no-smtp-auth" => sub {$smtp_auth = 'none'},
+ "imap-sent-folder=s" => \$imap_sent_folder,
"annotate!" => \$annotate,
"compose" => \$compose,
"quiet" => \$quiet,
@@ -1829,6 +1834,17 @@ sub send_message {
print "\n";
}
+ if ($imap_sent_folder) {
+ my $imap_header = $header;
+ if (@initial_bcc) {
+ # Bcc is not a part of $header, so we add it here.
+ # This is only for the IMAP copy, not for the actual email
+ # sent to the recipients.
+ $imap_header .= "Bcc: " . join(", ", @initial_bcc) . "\n";
+ }
+ push @imap_copy, "From git-send-email\n$imap_header\n$message";
+ }
+
return 1;
}
@@ -2223,6 +2239,19 @@ sub cleanup_compose_files {
$smtp->quit if $smtp;
+if ($imap_sent_folder && @imap_copy) {
+ my $imap_input = join("\n", @imap_copy);
+ eval {
+ print "\nStarting git imap-send...\n";
+ my ($fh, $ctx) = Git::command_input_pipe(['imap-send', '-f', $imap_sent_folder]);
+ print $fh $imap_input;
+ Git::command_close_pipe($fh, $ctx);
+ 1;
+ } or do {
+ warn "Warning: failed to send messages to IMAP folder $imap_sent_folder: $@";
+ };
+}
+
sub apply_transfer_encoding {
my $message = shift;
my $from = shift;
diff --git a/imap-send.c b/imap-send.c
index f5a656ac71..44de0c5a77 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1441,14 +1441,24 @@ static int count_messages(struct strbuf *all_msgs)
while (1) {
if (starts_with(p, "From ")) {
- p = strstr(p+5, "\nFrom: ");
- if (!p) break;
- p = strstr(p+7, "\nDate: ");
- if (!p) break;
- p = strstr(p+7, "\nSubject: ");
- if (!p) break;
- p += 10;
- count++;
+ if (starts_with(p, "From git-send-email")) {
+ p = strstr(p+5, "\nFrom: ");
+ if (!p) break;
+ p += 7;
+ p = strstr(p, "\nTo: ");
+ if (!p) break;
+ p += 5;
+ count++;
+ } else {
+ p = strstr(p+5, "\nFrom: ");
+ if (!p) break;
+ p = strstr(p+7, "\nDate: ");
+ if (!p) break;
+ p = strstr(p+7, "\nSubject: ");
+ if (!p) break;
+ p += 10;
+ count++;
+ }
}
p = strstr(p+5, "\nFrom ");
if (!p)
Range-diff against v2:
1: 01084f57f9 ! 1: da7cee769f send-email: add ability to send a copy of sent emails to an IMAP folder
@@ Documentation/config/sendemail.adoc: sendemail.smtpServer::
sendemail.smtpServerPort::
sendemail.smtpServerOption::
sendemail.smtpUser::
-+sendemail.imapfolder::
++sendemail.imapSentFolder::
sendemail.thread::
sendemail.transferEncoding::
sendemail.validate::
@@ Documentation/git-send-email.adoc: must be used for each option.
commands and replies will be printed. Useful to debug TLS
connection and authentication problems.
-+--imap-folder=<folder>::
++--imap-sent-folder=<folder>::
+ Some email providers (e.g. iCloud) do not send a copy of the emails sent
+ using SMTP to the `Sent` folder or similar in your mailbox. Use this option
+ to use `git imap-send` to send a copy of the emails to the folder specified
@@ git-send-email.perl: sub usage {
--no-smtp-auth * Disable SMTP authentication. Shorthand for
`--smtp-auth=none`
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
-+ --imap-folder <str> * IMAP folder where a copy of the emails should be sent.
++ --imap-sent-folder <str> * IMAP folder where a copy of the emails should be sent.
+ Make sure `git imap-send` is setup to use this feature.
--batch-size <int> * send max <int> message per connection.
@@ git-send-email.perl: sub do_edit {
my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);
my ($batch_size, $relogin_delay);
my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);
-+my ($imap_folder);
++my ($imap_sent_folder);
my ($confirm);
my (@suppress_cc);
my ($auto_8bit_encoding);
@@ git-send-email.perl: sub do_edit {
"smtpauth" => \$smtp_auth,
"smtpbatchsize" => \$batch_size,
"smtprelogindelay" => \$relogin_delay,
-+ "imapfolder" => \$imap_folder,
++ "imapsentfolder" => \$imap_sent_folder,
"to" => \@config_to,
"tocmd" => \$to_cmd,
"cc" => \@config_cc,
@@ git-send-email.perl: sub config_regexp {
"smtp-domain:s" => \$smtp_domain,
"smtp-auth=s" => \$smtp_auth,
"no-smtp-auth" => sub {$smtp_auth = 'none'},
-+ "imap-folder=s" => \$imap_folder,
++ "imap-sent-folder=s" => \$imap_sent_folder,
"annotate!" => \$annotate,
"compose" => \$compose,
"quiet" => \$quiet,
@@ git-send-email.perl: sub send_message {
print "\n";
}
-+ if ($imap_folder) {
++ if ($imap_sent_folder) {
+ my $imap_header = $header;
+ if (@initial_bcc) {
+ # Bcc is not a part of $header, so we add it here.
@@ git-send-email.perl: sub cleanup_compose_files {
$smtp->quit if $smtp;
-+if ($imap_folder && @imap_copy) {
++if ($imap_sent_folder && @imap_copy) {
+ my $imap_input = join("\n", @imap_copy);
+ eval {
+ print "\nStarting git imap-send...\n";
-+ my ($fh, $ctx) = Git::command_input_pipe(['imap-send', '-f', $imap_folder]);
++ my ($fh, $ctx) = Git::command_input_pipe(['imap-send', '-f', $imap_sent_folder]);
+ print $fh $imap_input;
+ Git::command_close_pipe($fh, $ctx);
+ 1;
+ } or do {
-+ warn "Warning: failed to send messages to IMAP folder $imap_folder via imap-send pipe: $@";
++ warn "Warning: failed to send messages to IMAP folder $imap_sent_folder: $@";
+ };
+}
+
--
2.50.1.319.gda7cee769f
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [PATCH v3] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-22 11:14 ` [PATCH v3] " Aditya Garg
@ 2025-07-23 9:05 ` Aditya Garg
0 siblings, 0 replies; 33+ messages in thread
From: Aditya Garg @ 2025-07-23 9:05 UTC (permalink / raw)
To: git, Junio C Hamano
Cc: Eric Sunshine, Kristoffer Haugsbakk, Ben Knoble, brian m. carlson
On 22/07/25 4:44 pm, Aditya Garg wrote:
> Some email providers like Apple iCloud Mail do not support sending a copy
> of sent emails to the "Sent" folder if SMTP server is used. As a
> workaround, various email clients like Thunderbird which rely on SMTP,
> use IMAP to send a copy of sent emails to the "Sent" folder. Something
> similar can be done if sending emails via `git send-email`, by using
> the `git imap-send` command to send a copy of the sent email to an IMAP
> folder specified by the user.
>
> Add this functionality to `git send-email` by introducing a new
> configuration variable `sendemail.imapfolder` and command line option
> `--imap-folder` which specifies the IMAP folder to send a copy of the
> sent emails to. If specified, a copy of the sent emails will be sent
> by piping the emails to `git imap-send` command, after the all emails are
> sent via SMTP and the SMTP server has been closed.
>
> Signed-off-by: Aditya Garg <gargaditya08@live.com>
> ---
>
> v2 - Fix indentation in patch for imap-send.c
> - Minor edits to commit message
>
> v3 - Rename imap folder to imap sent folder
> - Make an error message shorter by removing unecessary details
I just found a tiny bug here. It is sending emails to IMAP even if --dry-run is present. Will fix in v4.
Also, this little bug has also gave me an easier way to implement --use-imap-only, which is what Junio suggested before.
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH v4 0/2] send-email: integrate with git imap-send
2025-07-20 9:25 [PATCH] send-email: add ability to send a copy of sent emails to an IMAP folder Aditya Garg
2025-07-21 10:05 ` [PATCH v2] " Aditya Garg
2025-07-22 11:14 ` [PATCH v3] " Aditya Garg
@ 2025-07-23 10:33 ` Aditya Garg
2025-07-23 10:33 ` [PATCH v4 1/2] send-email: add ability to send a copy of sent emails to an IMAP folder Aditya Garg
2025-07-23 10:33 ` [PATCH v4 2/2] send-email: enable copying emails to IMAP folder without actually sending them Aditya Garg
2025-08-12 6:44 ` [PATCH v5 0/2] send-email: integrate with git imap-send Aditya Garg
3 siblings, 2 replies; 33+ messages in thread
From: Aditya Garg @ 2025-07-23 10:33 UTC (permalink / raw)
To: git, Junio C Hamano
Cc: Eric Sunshine, Kristoffer Haugsbakk, Ben Knoble, brian m. carlson
Hi all
This patch series introduces integration of `git send-email` with `git imap-send`.
The first patch adds the ability to send a copy of sent emails to an IMAP folder
specified by the user, which is useful for email providers that do not support
sending a copy of sent emails to the "Sent" folder via SMTP.
The second patch allows users to copy emails to an IMAP folder without actually
sending them.
v2 - Fix indentation in patch for imap-send.c
- Minor edits to commit message
v3 - Rename imap folder to imap sent folder
- Make an error message shorter by removing unecessary details
v4 - Fix a bug causing emails to be copied to an IMAP folder even if
--dry-run is specified.
- Minor edits to commit messages and docs.
- Add another patch that enables copying emails to an IMAP folder
without actually sending them.
Aditya Garg (2):
send-email: add ability to send a copy of sent emails to an IMAP
folder
send-email: enable copying emails to IMAP folder without actually
sending them
Documentation/config/sendemail.adoc | 2 ++
Documentation/git-send-email.adoc | 25 ++++++++++++++++++
git-send-email.perl | 40 +++++++++++++++++++++++++++--
imap-send.c | 26 +++++++++++++------
4 files changed, 83 insertions(+), 10 deletions(-)
Range-diff against v3:
1: da7cee769f ! 1: 27b5eb33bb send-email: add ability to send a copy of sent emails to an IMAP folder
@@ Commit message
configuration variable `sendemail.imapfolder` and command line option
`--imap-folder` which specifies the IMAP folder to send a copy of the
sent emails to. If specified, a copy of the sent emails will be sent
- by piping the emails to `git imap-send` command, after the all emails are
+ by piping the emails to `git imap-send` command, after all emails are
sent via SMTP and the SMTP server has been closed.
Signed-off-by: Aditya Garg <gargaditya08@live.com>
@@ Documentation/git-send-email.adoc: must be used for each option.
+ IMAP folder of your choice.
++
+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
-+to get instructions for the same.
++for instructions.
+
--batch-size=<num>::
Some email servers (e.g. 'smtp.163.com') limit the number of emails to be
@@ git-send-email.perl: sub usage {
`--smtp-auth=none`
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
+ --imap-sent-folder <str> * IMAP folder where a copy of the emails should be sent.
-+ Make sure `git imap-send` is setup to use this feature.
++ Make sure `git imap-send` is set up to use this feature.
--batch-size <int> * send max <int> message per connection.
--relogin-delay <int> * delay <int> seconds between two successive login.
@@ git-send-email.perl: sub send_message {
print "\n";
}
-+ if ($imap_sent_folder) {
++ if ($imap_sent_folder && !$dry_run) {
+ my $imap_header = $header;
+ if (@initial_bcc) {
+ # Bcc is not a part of $header, so we add it here.
@@ git-send-email.perl: sub cleanup_compose_files {
$smtp->quit if $smtp;
-+if ($imap_sent_folder && @imap_copy) {
++if ($imap_sent_folder && @imap_copy && !$dry_run) {
+ my $imap_input = join("\n", @imap_copy);
+ eval {
+ print "\nStarting git imap-send...\n";
-: ---------- > 2: 2ad311502d send-email: enable copying emails to IMAP folder without actually sending them
--
2.50.1.320.g2ad311502d
^ permalink raw reply [flat|nested] 33+ messages in thread* [PATCH v4 1/2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-07-23 10:33 ` [PATCH v4 0/2] send-email: integrate with git imap-send Aditya Garg
@ 2025-07-23 10:33 ` Aditya Garg
2025-07-23 10:33 ` [PATCH v4 2/2] send-email: enable copying emails to IMAP folder without actually sending them Aditya Garg
1 sibling, 0 replies; 33+ messages in thread
From: Aditya Garg @ 2025-07-23 10:33 UTC (permalink / raw)
To: git, Junio C Hamano
Cc: Eric Sunshine, Kristoffer Haugsbakk, Ben Knoble, brian m. carlson
Some email providers like Apple iCloud Mail do not support sending a copy
of sent emails to the "Sent" folder if SMTP server is used. As a
workaround, various email clients like Thunderbird which rely on SMTP,
use IMAP to send a copy of sent emails to the "Sent" folder. Something
similar can be done if sending emails via `git send-email`, by using
the `git imap-send` command to send a copy of the sent email to an IMAP
folder specified by the user.
Add this functionality to `git send-email` by introducing a new
configuration variable `sendemail.imapfolder` and command line option
`--imap-folder` which specifies the IMAP folder to send a copy of the
sent emails to. If specified, a copy of the sent emails will be sent
by piping the emails to `git imap-send` command, after all emails are
sent via SMTP and the SMTP server has been closed.
Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
Documentation/config/sendemail.adoc | 1 +
Documentation/git-send-email.adoc | 12 +++++++++++
git-send-email.perl | 31 ++++++++++++++++++++++++++++-
imap-send.c | 26 ++++++++++++++++--------
4 files changed, 61 insertions(+), 9 deletions(-)
diff --git a/Documentation/config/sendemail.adoc b/Documentation/config/sendemail.adoc
index 4722334657..dd2dbc87a0 100644
--- a/Documentation/config/sendemail.adoc
+++ b/Documentation/config/sendemail.adoc
@@ -88,6 +88,7 @@ sendemail.smtpServer::
sendemail.smtpServerPort::
sendemail.smtpServerOption::
sendemail.smtpUser::
+sendemail.imapSentFolder::
sendemail.thread::
sendemail.transferEncoding::
sendemail.validate::
diff --git a/Documentation/git-send-email.adoc b/Documentation/git-send-email.adoc
index 5335502d68..d1c41a0dbd 100644
--- a/Documentation/git-send-email.adoc
+++ b/Documentation/git-send-email.adoc
@@ -299,6 +299,18 @@ must be used for each option.
commands and replies will be printed. Useful to debug TLS
connection and authentication problems.
+--imap-sent-folder=<folder>::
+ Some email providers (e.g. iCloud) do not send a copy of the emails sent
+ using SMTP to the `Sent` folder or similar in your mailbox. Use this option
+ to use `git imap-send` to send a copy of the emails to the folder specified
+ using this option. You can run `git imap-send --list` to get a list of
+ valid folder names, including the correct name of the `Sent` folder in
+ your mailbox. You can also use this option to send emails to a dedicated
+ IMAP folder of your choice.
++
+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
+for instructions.
+
--batch-size=<num>::
Some email servers (e.g. 'smtp.163.com') limit the number of emails to be
sent per session (connection) and this will lead to a failure when
diff --git a/git-send-email.perl b/git-send-email.perl
index 437f8ac46a..b3cc237baa 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -73,6 +73,8 @@ sub usage {
--no-smtp-auth * Disable SMTP authentication. Shorthand for
`--smtp-auth=none`
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
+ --imap-sent-folder <str> * IMAP folder where a copy of the emails should be sent.
+ Make sure `git imap-send` is set up to use this feature.
--batch-size <int> * send max <int> message per connection.
--relogin-delay <int> * delay <int> seconds between two successive login.
@@ -200,7 +202,7 @@ sub format_2822_time {
# Variables we fill in automatically, or via prompting:
my (@to,@cc,@xh,$envelope_sender,
- $initial_in_reply_to,$reply_to,$initial_subject,@files,
+ $initial_in_reply_to,$reply_to,$initial_subject,@files,@imap_copy,
$author,$sender,$smtp_authpass,$annotate,$compose,$time);
# Things we either get from config, *or* are overridden on the
# command-line.
@@ -277,6 +279,7 @@ sub do_edit {
my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);
my ($batch_size, $relogin_delay);
my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);
+my ($imap_sent_folder);
my ($confirm);
my (@suppress_cc);
my ($auto_8bit_encoding);
@@ -322,6 +325,7 @@ sub do_edit {
"smtpauth" => \$smtp_auth,
"smtpbatchsize" => \$batch_size,
"smtprelogindelay" => \$relogin_delay,
+ "imapsentfolder" => \$imap_sent_folder,
"to" => \@config_to,
"tocmd" => \$to_cmd,
"cc" => \@config_cc,
@@ -527,6 +531,7 @@ sub config_regexp {
"smtp-domain:s" => \$smtp_domain,
"smtp-auth=s" => \$smtp_auth,
"no-smtp-auth" => sub {$smtp_auth = 'none'},
+ "imap-sent-folder=s" => \$imap_sent_folder,
"annotate!" => \$annotate,
"compose" => \$compose,
"quiet" => \$quiet,
@@ -1829,6 +1834,17 @@ sub send_message {
print "\n";
}
+ if ($imap_sent_folder && !$dry_run) {
+ my $imap_header = $header;
+ if (@initial_bcc) {
+ # Bcc is not a part of $header, so we add it here.
+ # This is only for the IMAP copy, not for the actual email
+ # sent to the recipients.
+ $imap_header .= "Bcc: " . join(", ", @initial_bcc) . "\n";
+ }
+ push @imap_copy, "From git-send-email\n$imap_header\n$message";
+ }
+
return 1;
}
@@ -2223,6 +2239,19 @@ sub cleanup_compose_files {
$smtp->quit if $smtp;
+if ($imap_sent_folder && @imap_copy && !$dry_run) {
+ my $imap_input = join("\n", @imap_copy);
+ eval {
+ print "\nStarting git imap-send...\n";
+ my ($fh, $ctx) = Git::command_input_pipe(['imap-send', '-f', $imap_sent_folder]);
+ print $fh $imap_input;
+ Git::command_close_pipe($fh, $ctx);
+ 1;
+ } or do {
+ warn "Warning: failed to send messages to IMAP folder $imap_sent_folder: $@";
+ };
+}
+
sub apply_transfer_encoding {
my $message = shift;
my $from = shift;
diff --git a/imap-send.c b/imap-send.c
index f5a656ac71..44de0c5a77 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1441,14 +1441,24 @@ static int count_messages(struct strbuf *all_msgs)
while (1) {
if (starts_with(p, "From ")) {
- p = strstr(p+5, "\nFrom: ");
- if (!p) break;
- p = strstr(p+7, "\nDate: ");
- if (!p) break;
- p = strstr(p+7, "\nSubject: ");
- if (!p) break;
- p += 10;
- count++;
+ if (starts_with(p, "From git-send-email")) {
+ p = strstr(p+5, "\nFrom: ");
+ if (!p) break;
+ p += 7;
+ p = strstr(p, "\nTo: ");
+ if (!p) break;
+ p += 5;
+ count++;
+ } else {
+ p = strstr(p+5, "\nFrom: ");
+ if (!p) break;
+ p = strstr(p+7, "\nDate: ");
+ if (!p) break;
+ p = strstr(p+7, "\nSubject: ");
+ if (!p) break;
+ p += 10;
+ count++;
+ }
}
p = strstr(p+5, "\nFrom ");
if (!p)
--
2.50.1.320.g2ad311502d
^ permalink raw reply related [flat|nested] 33+ messages in thread* [PATCH v4 2/2] send-email: enable copying emails to IMAP folder without actually sending them
2025-07-23 10:33 ` [PATCH v4 0/2] send-email: integrate with git imap-send Aditya Garg
2025-07-23 10:33 ` [PATCH v4 1/2] send-email: add ability to send a copy of sent emails to an IMAP folder Aditya Garg
@ 2025-07-23 10:33 ` Aditya Garg
2025-08-11 21:52 ` Junio C Hamano
1 sibling, 1 reply; 33+ messages in thread
From: Aditya Garg @ 2025-07-23 10:33 UTC (permalink / raw)
To: git, Junio C Hamano
Cc: Eric Sunshine, Kristoffer Haugsbakk, Ben Knoble, brian m. carlson
`git imap-send` was built on the idea of copying emails to an IMAP folder
like drafts, and sending them later using an email client. Currently
the only way to do it is by piping output of `git format-patch` to IMAP
send.
Add another way to do it by using `git send-email` with the
`--use-imap-only` or `sendmail.useImapOnly` option. This allows users to
use the advanced features of `git send-email` like tweaking Cc: list
programmatically, compose the cover letter, etc. and then send the well
formatted emails to an IMAP folder using `git imap-send`.
While at it, use `` instead of '' for --smtp-encryption ssl in help
section of `git send-email`.
Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
Documentation/config/sendemail.adoc | 1 +
Documentation/git-send-email.adoc | 13 +++++++++++++
git-send-email.perl | 9 ++++++++-
3 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/Documentation/config/sendemail.adoc b/Documentation/config/sendemail.adoc
index dd2dbc87a0..90164c734d 100644
--- a/Documentation/config/sendemail.adoc
+++ b/Documentation/config/sendemail.adoc
@@ -89,6 +89,7 @@ sendemail.smtpServerPort::
sendemail.smtpServerOption::
sendemail.smtpUser::
sendemail.imapSentFolder::
+sendemail.useImapOnly::
sendemail.thread::
sendemail.transferEncoding::
sendemail.validate::
diff --git a/Documentation/git-send-email.adoc b/Documentation/git-send-email.adoc
index d1c41a0dbd..88e183b489 100644
--- a/Documentation/git-send-email.adoc
+++ b/Documentation/git-send-email.adoc
@@ -311,6 +311,19 @@ must be used for each option.
This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
for instructions.
+--[no-]use-imap-only::
+ If this is set, all emails will only be copied to the IMAP folder specified
+ with `--imap-sent-folder` or `sendemail.imapSentFolder` and will not be sent
+ to the recipients. Useful if you just want to create a draft of the emails
+ and use another email client to send them.
+ If disabled with `--no-use-imap-only`, the emails will be sent like usual.
+ Disabled by default, but the `sendemail.useImapOnly` configuration
+ variable can be used to enable it.
+
++
+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
+for instructions.
+
--batch-size=<num>::
Some email servers (e.g. 'smtp.163.com') limit the number of emails to be
sent per session (connection) and this will lead to a failure when
diff --git a/git-send-email.perl b/git-send-email.perl
index b3cc237baa..96504e7be1 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -62,7 +62,7 @@ sub usage {
--smtp-user <str> * Username for SMTP-AUTH.
--smtp-pass <str> * Password for SMTP-AUTH; not necessary.
--smtp-encryption <str> * tls or ssl; anything else disables.
- --smtp-ssl * Deprecated. Use '--smtp-encryption ssl'.
+ --smtp-ssl * Deprecated. Use `--smtp-encryption ssl`.
--smtp-ssl-cert-path <str> * Path to ca-certificates (either directory or file).
Pass an empty string to disable certificate
verification.
@@ -75,6 +75,8 @@ sub usage {
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
--imap-sent-folder <str> * IMAP folder where a copy of the emails should be sent.
Make sure `git imap-send` is set up to use this feature.
+ --[no-]use-imap-only * Only copy emails to the IMAP folder specified by
+ `--imap-sent-folder` instead of actually sending them.
--batch-size <int> * send max <int> message per connection.
--relogin-delay <int> * delay <int> seconds between two successive login.
@@ -296,6 +298,7 @@ sub do_edit {
my $target_xfer_encoding = 'auto';
my $forbid_sendmail_variables = 1;
my $outlook_id_fix = 'auto';
+my $use_imap_only = 0;
my %config_bool_settings = (
"thread" => \$thread,
@@ -312,6 +315,7 @@ sub do_edit {
"forbidsendmailvariables" => \$forbid_sendmail_variables,
"mailmap" => \$mailmap,
"outlookidfix" => \$outlook_id_fix,
+ "useimaponly" => \$use_imap_only,
);
my %config_settings = (
@@ -532,6 +536,7 @@ sub config_regexp {
"smtp-auth=s" => \$smtp_auth,
"no-smtp-auth" => sub {$smtp_auth = 'none'},
"imap-sent-folder=s" => \$imap_sent_folder,
+ "use-imap-only!" => \$use_imap_only,
"annotate!" => \$annotate,
"compose" => \$compose,
"quiet" => \$quiet,
@@ -1683,6 +1688,8 @@ sub send_message {
if ($dry_run) {
# We don't want to send the email.
+ } elsif ($use_imap_only) {
+ die __("The destination IMAP folder is not properly defined.") if !defined $imap_sent_folder;
} elsif (defined $sendmail_cmd || file_name_is_absolute($smtp_server)) {
my $pid = open my $sm, '|-';
defined $pid or die $!;
--
2.50.1.320.g2ad311502d
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [PATCH v4 2/2] send-email: enable copying emails to IMAP folder without actually sending them
2025-07-23 10:33 ` [PATCH v4 2/2] send-email: enable copying emails to IMAP folder without actually sending them Aditya Garg
@ 2025-08-11 21:52 ` Junio C Hamano
2025-08-12 5:08 ` Aditya Garg
2025-08-12 6:51 ` Aditya Garg
0 siblings, 2 replies; 33+ messages in thread
From: Junio C Hamano @ 2025-08-11 21:52 UTC (permalink / raw)
To: Aditya Garg
Cc: git, Eric Sunshine, Kristoffer Haugsbakk, Ben Knoble,
brian m. carlson
Aditya Garg <gargaditya08@live.com> writes:
> +--[no-]use-imap-only::
This is better written on two separate lines, i.e.
--use-imap-only::
--no-use-imap-only::
if we want to pass "make check-docs" when the topic is merged to
'seen'.
Thanks.
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v4 2/2] send-email: enable copying emails to IMAP folder without actually sending them
2025-08-11 21:52 ` Junio C Hamano
@ 2025-08-12 5:08 ` Aditya Garg
2025-08-12 6:27 ` Aditya Garg
2025-08-12 6:51 ` Aditya Garg
1 sibling, 1 reply; 33+ messages in thread
From: Aditya Garg @ 2025-08-12 5:08 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Eric Sunshine, Kristoffer Haugsbakk, Ben Knoble,
brian m. carlson
On 12 August 2025 3:22:11 am IST, Junio C Hamano <gitster@pobox.com> wrote:
>Aditya Garg <gargaditya08@live.com> writes:
>
>> +--[no-]use-imap-only::
>
>This is better written on two separate lines, i.e.
>
> --use-imap-only::
> --no-use-imap-only::
>
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?
>if we want to pass "make check-docs" when the topic is merged to
>'seen'.
>
>Thanks.
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v4 2/2] send-email: enable copying emails to IMAP folder without actually sending them
2025-08-12 5:08 ` Aditya Garg
@ 2025-08-12 6:27 ` Aditya Garg
2025-08-12 14:15 ` Junio C Hamano
0 siblings, 1 reply; 33+ messages in thread
From: Aditya Garg @ 2025-08-12 6:27 UTC (permalink / raw)
To: Junio C Hamano
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
> On 12 Aug 2025, at 10:38 AM, Aditya Garg <gargaditya08@live.com> wrote:
>
>
>
>> On 12 August 2025 3:22:11 am IST, Junio C Hamano <gitster@pobox.com> wrote:
>> Aditya Garg <gargaditya08@live.com> writes:
>>
>>> +--[no-]use-imap-only::
>>
>> This is better written on two separate lines, i.e.
>>
>> --use-imap-only::
>> --no-use-imap-only::
>>
>
> 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?
Nvm, looks like they have been changed by a recent commit.
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v4 2/2] send-email: enable copying emails to IMAP folder without actually sending them
2025-08-12 6:27 ` Aditya Garg
@ 2025-08-12 14:15 ` Junio C Hamano
0 siblings, 0 replies; 33+ messages in thread
From: Junio C Hamano @ 2025-08-12 14:15 UTC (permalink / raw)
To: Aditya Garg
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
Aditya Garg <gargaditya08@live.com> writes:
>> On 12 Aug 2025, at 10:38 AM, Aditya Garg <gargaditya08@live.com> wrote:
>>
>>
>>
>>> On 12 August 2025 3:22:11 am IST, Junio C Hamano <gitster@pobox.com> wrote:
>>> Aditya Garg <gargaditya08@live.com> writes:
>>>
>>>> +--[no-]use-imap-only::
>>>
>>> This is better written on two separate lines, i.e.
>>>
>>> --use-imap-only::
>>> --no-use-imap-only::
>>>
>>
>> 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?
>
> Nvm, looks like they have been changed by a recent commit.
Yes.
Others around you are also working to make the system better in
other topics in flight concurrently with your topic. You do not
need to do everything yourself, but you'd need to be aware of their
effort and avoid adding more instances of what they are fixing.
And one of the jobs of the maintainer is to help contributors
coordinate among themselves, which is what I tried to do with my
message ;-)
Thanks.
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v4 2/2] send-email: enable copying emails to IMAP folder without actually sending them
2025-08-11 21:52 ` Junio C Hamano
2025-08-12 5:08 ` Aditya Garg
@ 2025-08-12 6:51 ` Aditya Garg
1 sibling, 0 replies; 33+ messages in thread
From: Aditya Garg @ 2025-08-12 6:51 UTC (permalink / raw)
To: Junio C Hamano
Cc: git@vger.kernel.org, Eric Sunshine, Kristoffer Haugsbakk,
Ben Knoble, brian m. carlson
> On 12 Aug 2025, at 3:22 AM, Junio C Hamano <gitster@pobox.com> wrote:
>
> Aditya Garg <gargaditya08@live.com> writes:
>
>> +--[no-]use-imap-only::
>
> This is better written on two separate lines, i.e.
>
> --use-imap-only::
> --no-use-imap-only::
Corrected in v5
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH v5 0/2] send-email: integrate with git imap-send
2025-07-20 9:25 [PATCH] send-email: add ability to send a copy of sent emails to an IMAP folder Aditya Garg
` (2 preceding siblings ...)
2025-07-23 10:33 ` [PATCH v4 0/2] send-email: integrate with git imap-send Aditya Garg
@ 2025-08-12 6:44 ` Aditya Garg
2025-08-12 6:44 ` [PATCH v5 1/2] send-email: add ability to send a copy of sent emails to an IMAP folder Aditya Garg
` (3 more replies)
3 siblings, 4 replies; 33+ messages in thread
From: Aditya Garg @ 2025-08-12 6:44 UTC (permalink / raw)
To: git, Junio C Hamano
Cc: Eric Sunshine, Kristoffer Haugsbakk, Ben Knoble, brian m. carlson
Hi all
This patch series introduces integration of `git send-email` with `git imap-send`.
The first patch adds the ability to send a copy of sent emails to an IMAP folder
specified by the user, which is useful for email providers that do not support
sending a copy of sent emails to the "Sent" folder via SMTP.
The second patch allows users to copy emails to an IMAP folder without actually
sending them.
v2 - Fix indentation in patch for imap-send.c
- Minor edits to commit message
v3 - Rename imap folder to imap sent folder
- Make an error message shorter by removing unecessary details
v4 - Fix a bug causing emails to be copied to an IMAP folder even if
--dry-run is specified.
- Minor edits to commit messages and docs.
- Add another patch that enables copying emails to an IMAP folder
without actually sending them.
v5 - Avoid using -[no-]parameter.
Aditya Garg (2):
send-email: add ability to send a copy of sent emails to an IMAP
folder
send-email: enable copying emails to an IMAP folder without actually
sending them
Documentation/config/sendemail.adoc | 2 ++
Documentation/git-send-email.adoc | 26 +++++++++++++++++++
git-send-email.perl | 40 +++++++++++++++++++++++++++--
imap-send.c | 26 +++++++++++++------
4 files changed, 84 insertions(+), 10 deletions(-)
Range-diff against v4:
1: 2ad311502d ! 1: 27b5eb33bb send-email: enable copying emails to IMAP folder without actually sending them
@@ Metadata
Author: Aditya Garg <gargaditya08@live.com>
## Commit message ##
- send-email: enable copying emails to IMAP folder without actually sending them
+ send-email: add ability to send a copy of sent emails to an IMAP folder
- `git imap-send` was built on the idea of copying emails to an IMAP folder
- like drafts, and sending them later using an email client. Currently
- the only way to do it is by piping output of `git format-patch` to IMAP
- send.
+ Some email providers like Apple iCloud Mail do not support sending a copy
+ of sent emails to the "Sent" folder if SMTP server is used. As a
+ workaround, various email clients like Thunderbird which rely on SMTP,
+ use IMAP to send a copy of sent emails to the "Sent" folder. Something
+ similar can be done if sending emails via `git send-email`, by using
+ the `git imap-send` command to send a copy of the sent email to an IMAP
+ folder specified by the user.
- Add another way to do it by using `git send-email` with the
- `--use-imap-only` or `sendmail.useImapOnly` option. This allows users to
- use the advanced features of `git send-email` like tweaking Cc: list
- programmatically, compose the cover letter, etc. and then send the well
- formatted emails to an IMAP folder using `git imap-send`.
-
- While at it, use `` instead of '' for --smtp-encryption ssl in help
- section of `git send-email`.
+ Add this functionality to `git send-email` by introducing a new
+ configuration variable `sendemail.imapfolder` and command line option
+ `--imap-folder` which specifies the IMAP folder to send a copy of the
+ sent emails to. If specified, a copy of the sent emails will be sent
+ by piping the emails to `git imap-send` command, after all emails are
+ sent via SMTP and the SMTP server has been closed.
Signed-off-by: Aditya Garg <gargaditya08@live.com>
## Documentation/config/sendemail.adoc ##
-@@ Documentation/config/sendemail.adoc: sendemail.smtpServerPort::
+@@ Documentation/config/sendemail.adoc: sendemail.smtpServer::
+ sendemail.smtpServerPort::
sendemail.smtpServerOption::
sendemail.smtpUser::
- sendemail.imapSentFolder::
-+sendemail.useImapOnly::
++sendemail.imapSentFolder::
sendemail.thread::
sendemail.transferEncoding::
sendemail.validate::
## Documentation/git-send-email.adoc ##
@@ Documentation/git-send-email.adoc: must be used for each option.
- This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
- for instructions.
+ commands and replies will be printed. Useful to debug TLS
+ connection and authentication problems.
-+--[no-]use-imap-only::
-+ If this is set, all emails will only be copied to the IMAP folder specified
-+ with `--imap-sent-folder` or `sendemail.imapSentFolder` and will not be sent
-+ to the recipients. Useful if you just want to create a draft of the emails
-+ and use another email client to send them.
-+ If disabled with `--no-use-imap-only`, the emails will be sent like usual.
-+ Disabled by default, but the `sendemail.useImapOnly` configuration
-+ variable can be used to enable it.
-+
++--imap-sent-folder=<folder>::
++ Some email providers (e.g. iCloud) do not send a copy of the emails sent
++ using SMTP to the `Sent` folder or similar in your mailbox. Use this option
++ to use `git imap-send` to send a copy of the emails to the folder specified
++ using this option. You can run `git imap-send --list` to get a list of
++ valid folder names, including the correct name of the `Sent` folder in
++ your mailbox. You can also use this option to send emails to a dedicated
++ IMAP folder of your choice.
++
+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
+for instructions.
@@ Documentation/git-send-email.adoc: must be used for each option.
## git-send-email.perl ##
@@ git-send-email.perl: sub usage {
- --smtp-user <str> * Username for SMTP-AUTH.
- --smtp-pass <str> * Password for SMTP-AUTH; not necessary.
- --smtp-encryption <str> * tls or ssl; anything else disables.
-- --smtp-ssl * Deprecated. Use '--smtp-encryption ssl'.
-+ --smtp-ssl * Deprecated. Use `--smtp-encryption ssl`.
- --smtp-ssl-cert-path <str> * Path to ca-certificates (either directory or file).
- Pass an empty string to disable certificate
- verification.
-@@ git-send-email.perl: sub usage {
+ --no-smtp-auth * Disable SMTP authentication. Shorthand for
+ `--smtp-auth=none`
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
- --imap-sent-folder <str> * IMAP folder where a copy of the emails should be sent.
- Make sure `git imap-send` is set up to use this feature.
-+ --[no-]use-imap-only * Only copy emails to the IMAP folder specified by
-+ `--imap-sent-folder` instead of actually sending them.
++ --imap-sent-folder <str> * IMAP folder where a copy of the emails should be sent.
++ Make sure `git imap-send` is set up to use this feature.
--batch-size <int> * send max <int> message per connection.
--relogin-delay <int> * delay <int> seconds between two successive login.
-@@ git-send-email.perl: sub do_edit {
- my $target_xfer_encoding = 'auto';
- my $forbid_sendmail_variables = 1;
- my $outlook_id_fix = 'auto';
-+my $use_imap_only = 0;
+@@ git-send-email.perl: sub format_2822_time {
- my %config_bool_settings = (
- "thread" => \$thread,
+ # Variables we fill in automatically, or via prompting:
+ my (@to,@cc,@xh,$envelope_sender,
+- $initial_in_reply_to,$reply_to,$initial_subject,@files,
++ $initial_in_reply_to,$reply_to,$initial_subject,@files,@imap_copy,
+ $author,$sender,$smtp_authpass,$annotate,$compose,$time);
+ # Things we either get from config, *or* are overridden on the
+ # command-line.
@@ git-send-email.perl: sub do_edit {
- "forbidsendmailvariables" => \$forbid_sendmail_variables,
- "mailmap" => \$mailmap,
- "outlookidfix" => \$outlook_id_fix,
-+ "useimaponly" => \$use_imap_only,
- );
-
- my %config_settings = (
+ my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);
+ my ($batch_size, $relogin_delay);
+ my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);
++my ($imap_sent_folder);
+ my ($confirm);
+ my (@suppress_cc);
+ my ($auto_8bit_encoding);
+@@ git-send-email.perl: sub do_edit {
+ "smtpauth" => \$smtp_auth,
+ "smtpbatchsize" => \$batch_size,
+ "smtprelogindelay" => \$relogin_delay,
++ "imapsentfolder" => \$imap_sent_folder,
+ "to" => \@config_to,
+ "tocmd" => \$to_cmd,
+ "cc" => \@config_cc,
@@ git-send-email.perl: sub config_regexp {
+ "smtp-domain:s" => \$smtp_domain,
"smtp-auth=s" => \$smtp_auth,
"no-smtp-auth" => sub {$smtp_auth = 'none'},
- "imap-sent-folder=s" => \$imap_sent_folder,
-+ "use-imap-only!" => \$use_imap_only,
++ "imap-sent-folder=s" => \$imap_sent_folder,
"annotate!" => \$annotate,
"compose" => \$compose,
"quiet" => \$quiet,
@@ git-send-email.perl: sub send_message {
+ print "\n";
+ }
+
++ if ($imap_sent_folder && !$dry_run) {
++ my $imap_header = $header;
++ if (@initial_bcc) {
++ # Bcc is not a part of $header, so we add it here.
++ # This is only for the IMAP copy, not for the actual email
++ # sent to the recipients.
++ $imap_header .= "Bcc: " . join(", ", @initial_bcc) . "\n";
++ }
++ push @imap_copy, "From git-send-email\n$imap_header\n$message";
++ }
++
+ return 1;
+ }
+
+@@ git-send-email.perl: sub cleanup_compose_files {
+
+ $smtp->quit if $smtp;
+
++if ($imap_sent_folder && @imap_copy && !$dry_run) {
++ my $imap_input = join("\n", @imap_copy);
++ eval {
++ print "\nStarting git imap-send...\n";
++ my ($fh, $ctx) = Git::command_input_pipe(['imap-send', '-f', $imap_sent_folder]);
++ print $fh $imap_input;
++ Git::command_close_pipe($fh, $ctx);
++ 1;
++ } or do {
++ warn "Warning: failed to send messages to IMAP folder $imap_sent_folder: $@";
++ };
++}
++
+ sub apply_transfer_encoding {
+ my $message = shift;
+ my $from = shift;
+
+ ## imap-send.c ##
+@@ imap-send.c: static int count_messages(struct strbuf *all_msgs)
- if ($dry_run) {
- # We don't want to send the email.
-+ } elsif ($use_imap_only) {
-+ die __("The destination IMAP folder is not properly defined.") if !defined $imap_sent_folder;
- } elsif (defined $sendmail_cmd || file_name_is_absolute($smtp_server)) {
- my $pid = open my $sm, '|-';
- defined $pid or die $!;
+ while (1) {
+ if (starts_with(p, "From ")) {
+- p = strstr(p+5, "\nFrom: ");
+- if (!p) break;
+- p = strstr(p+7, "\nDate: ");
+- if (!p) break;
+- p = strstr(p+7, "\nSubject: ");
+- if (!p) break;
+- p += 10;
+- count++;
++ if (starts_with(p, "From git-send-email")) {
++ p = strstr(p+5, "\nFrom: ");
++ if (!p) break;
++ p += 7;
++ p = strstr(p, "\nTo: ");
++ if (!p) break;
++ p += 5;
++ count++;
++ } else {
++ p = strstr(p+5, "\nFrom: ");
++ if (!p) break;
++ p = strstr(p+7, "\nDate: ");
++ if (!p) break;
++ p = strstr(p+7, "\nSubject: ");
++ if (!p) break;
++ p += 10;
++ count++;
++ }
+ }
+ p = strstr(p+5, "\nFrom ");
+ if (!p)
-: ---------- > 2: 1d74a857df send-email: enable copying emails to an IMAP folder without actually sending them
--
2.50.1
^ permalink raw reply [flat|nested] 33+ messages in thread* [PATCH v5 1/2] send-email: add ability to send a copy of sent emails to an IMAP folder
2025-08-12 6:44 ` [PATCH v5 0/2] send-email: integrate with git imap-send Aditya Garg
@ 2025-08-12 6:44 ` Aditya Garg
2025-08-12 6:44 ` [PATCH v5 2/2] send-email: enable copying emails to an IMAP folder without actually sending them Aditya Garg
` (2 subsequent siblings)
3 siblings, 0 replies; 33+ messages in thread
From: Aditya Garg @ 2025-08-12 6:44 UTC (permalink / raw)
To: git, Junio C Hamano
Cc: Eric Sunshine, Kristoffer Haugsbakk, Ben Knoble, brian m. carlson
Some email providers like Apple iCloud Mail do not support sending a copy
of sent emails to the "Sent" folder if SMTP server is used. As a
workaround, various email clients like Thunderbird which rely on SMTP,
use IMAP to send a copy of sent emails to the "Sent" folder. Something
similar can be done if sending emails via `git send-email`, by using
the `git imap-send` command to send a copy of the sent email to an IMAP
folder specified by the user.
Add this functionality to `git send-email` by introducing a new
configuration variable `sendemail.imapfolder` and command line option
`--imap-folder` which specifies the IMAP folder to send a copy of the
sent emails to. If specified, a copy of the sent emails will be sent
by piping the emails to `git imap-send` command, after all emails are
sent via SMTP and the SMTP server has been closed.
Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
Documentation/config/sendemail.adoc | 1 +
Documentation/git-send-email.adoc | 12 +++++++++++
git-send-email.perl | 31 ++++++++++++++++++++++++++++-
imap-send.c | 26 ++++++++++++++++--------
4 files changed, 61 insertions(+), 9 deletions(-)
diff --git a/Documentation/config/sendemail.adoc b/Documentation/config/sendemail.adoc
index 4722334657..dd2dbc87a0 100644
--- a/Documentation/config/sendemail.adoc
+++ b/Documentation/config/sendemail.adoc
@@ -88,6 +88,7 @@ sendemail.smtpServer::
sendemail.smtpServerPort::
sendemail.smtpServerOption::
sendemail.smtpUser::
+sendemail.imapSentFolder::
sendemail.thread::
sendemail.transferEncoding::
sendemail.validate::
diff --git a/Documentation/git-send-email.adoc b/Documentation/git-send-email.adoc
index 5335502d68..d1c41a0dbd 100644
--- a/Documentation/git-send-email.adoc
+++ b/Documentation/git-send-email.adoc
@@ -299,6 +299,18 @@ must be used for each option.
commands and replies will be printed. Useful to debug TLS
connection and authentication problems.
+--imap-sent-folder=<folder>::
+ Some email providers (e.g. iCloud) do not send a copy of the emails sent
+ using SMTP to the `Sent` folder or similar in your mailbox. Use this option
+ to use `git imap-send` to send a copy of the emails to the folder specified
+ using this option. You can run `git imap-send --list` to get a list of
+ valid folder names, including the correct name of the `Sent` folder in
+ your mailbox. You can also use this option to send emails to a dedicated
+ IMAP folder of your choice.
++
+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
+for instructions.
+
--batch-size=<num>::
Some email servers (e.g. 'smtp.163.com') limit the number of emails to be
sent per session (connection) and this will lead to a failure when
diff --git a/git-send-email.perl b/git-send-email.perl
index 437f8ac46a..b3cc237baa 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -73,6 +73,8 @@ sub usage {
--no-smtp-auth * Disable SMTP authentication. Shorthand for
`--smtp-auth=none`
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
+ --imap-sent-folder <str> * IMAP folder where a copy of the emails should be sent.
+ Make sure `git imap-send` is set up to use this feature.
--batch-size <int> * send max <int> message per connection.
--relogin-delay <int> * delay <int> seconds between two successive login.
@@ -200,7 +202,7 @@ sub format_2822_time {
# Variables we fill in automatically, or via prompting:
my (@to,@cc,@xh,$envelope_sender,
- $initial_in_reply_to,$reply_to,$initial_subject,@files,
+ $initial_in_reply_to,$reply_to,$initial_subject,@files,@imap_copy,
$author,$sender,$smtp_authpass,$annotate,$compose,$time);
# Things we either get from config, *or* are overridden on the
# command-line.
@@ -277,6 +279,7 @@ sub do_edit {
my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);
my ($batch_size, $relogin_delay);
my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);
+my ($imap_sent_folder);
my ($confirm);
my (@suppress_cc);
my ($auto_8bit_encoding);
@@ -322,6 +325,7 @@ sub do_edit {
"smtpauth" => \$smtp_auth,
"smtpbatchsize" => \$batch_size,
"smtprelogindelay" => \$relogin_delay,
+ "imapsentfolder" => \$imap_sent_folder,
"to" => \@config_to,
"tocmd" => \$to_cmd,
"cc" => \@config_cc,
@@ -527,6 +531,7 @@ sub config_regexp {
"smtp-domain:s" => \$smtp_domain,
"smtp-auth=s" => \$smtp_auth,
"no-smtp-auth" => sub {$smtp_auth = 'none'},
+ "imap-sent-folder=s" => \$imap_sent_folder,
"annotate!" => \$annotate,
"compose" => \$compose,
"quiet" => \$quiet,
@@ -1829,6 +1834,17 @@ sub send_message {
print "\n";
}
+ if ($imap_sent_folder && !$dry_run) {
+ my $imap_header = $header;
+ if (@initial_bcc) {
+ # Bcc is not a part of $header, so we add it here.
+ # This is only for the IMAP copy, not for the actual email
+ # sent to the recipients.
+ $imap_header .= "Bcc: " . join(", ", @initial_bcc) . "\n";
+ }
+ push @imap_copy, "From git-send-email\n$imap_header\n$message";
+ }
+
return 1;
}
@@ -2223,6 +2239,19 @@ sub cleanup_compose_files {
$smtp->quit if $smtp;
+if ($imap_sent_folder && @imap_copy && !$dry_run) {
+ my $imap_input = join("\n", @imap_copy);
+ eval {
+ print "\nStarting git imap-send...\n";
+ my ($fh, $ctx) = Git::command_input_pipe(['imap-send', '-f', $imap_sent_folder]);
+ print $fh $imap_input;
+ Git::command_close_pipe($fh, $ctx);
+ 1;
+ } or do {
+ warn "Warning: failed to send messages to IMAP folder $imap_sent_folder: $@";
+ };
+}
+
sub apply_transfer_encoding {
my $message = shift;
my $from = shift;
diff --git a/imap-send.c b/imap-send.c
index f5a656ac71..44de0c5a77 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1441,14 +1441,24 @@ static int count_messages(struct strbuf *all_msgs)
while (1) {
if (starts_with(p, "From ")) {
- p = strstr(p+5, "\nFrom: ");
- if (!p) break;
- p = strstr(p+7, "\nDate: ");
- if (!p) break;
- p = strstr(p+7, "\nSubject: ");
- if (!p) break;
- p += 10;
- count++;
+ if (starts_with(p, "From git-send-email")) {
+ p = strstr(p+5, "\nFrom: ");
+ if (!p) break;
+ p += 7;
+ p = strstr(p, "\nTo: ");
+ if (!p) break;
+ p += 5;
+ count++;
+ } else {
+ p = strstr(p+5, "\nFrom: ");
+ if (!p) break;
+ p = strstr(p+7, "\nDate: ");
+ if (!p) break;
+ p = strstr(p+7, "\nSubject: ");
+ if (!p) break;
+ p += 10;
+ count++;
+ }
}
p = strstr(p+5, "\nFrom ");
if (!p)
--
2.50.1
^ permalink raw reply related [flat|nested] 33+ messages in thread* [PATCH v5 2/2] send-email: enable copying emails to an IMAP folder without actually sending them
2025-08-12 6:44 ` [PATCH v5 0/2] send-email: integrate with git imap-send Aditya Garg
2025-08-12 6:44 ` [PATCH v5 1/2] send-email: add ability to send a copy of sent emails to an IMAP folder Aditya Garg
@ 2025-08-12 6:44 ` Aditya Garg
2025-08-12 16:00 ` [PATCH v5 0/2] send-email: integrate with git imap-send Junio C Hamano
2025-08-15 3:38 ` Junio C Hamano
3 siblings, 0 replies; 33+ messages in thread
From: Aditya Garg @ 2025-08-12 6:44 UTC (permalink / raw)
To: git, Junio C Hamano
Cc: Eric Sunshine, Kristoffer Haugsbakk, Ben Knoble, brian m. carlson
`git imap-send` was built on the idea of copying emails to an IMAP folder
like drafts, and sending them later using an email client. Currently
the only way to do it is by piping output of `git format-patch` to IMAP
send.
Add another way to do it by using `git send-email` with the
`--use-imap-only` or `sendmail.useImapOnly` option. This allows users to
use the advanced features of `git send-email` like tweaking Cc: list
programmatically, compose the cover letter, etc. and then send the well
formatted emails to an IMAP folder using `git imap-send`.
While at it, use `` instead of '' for --smtp-encryption ssl in help
section of `git send-email`.
Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
Documentation/config/sendemail.adoc | 1 +
Documentation/git-send-email.adoc | 14 ++++++++++++++
git-send-email.perl | 9 ++++++++-
3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/Documentation/config/sendemail.adoc b/Documentation/config/sendemail.adoc
index dd2dbc87a0..90164c734d 100644
--- a/Documentation/config/sendemail.adoc
+++ b/Documentation/config/sendemail.adoc
@@ -89,6 +89,7 @@ sendemail.smtpServerPort::
sendemail.smtpServerOption::
sendemail.smtpUser::
sendemail.imapSentFolder::
+sendemail.useImapOnly::
sendemail.thread::
sendemail.transferEncoding::
sendemail.validate::
diff --git a/Documentation/git-send-email.adoc b/Documentation/git-send-email.adoc
index d1c41a0dbd..a385f865fb 100644
--- a/Documentation/git-send-email.adoc
+++ b/Documentation/git-send-email.adoc
@@ -311,6 +311,20 @@ must be used for each option.
This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
for instructions.
+--use-imap-only::
+--no-use-imap-only::
+ If this is set, all emails will only be copied to the IMAP folder specified
+ with `--imap-sent-folder` or `sendemail.imapSentFolder` and will not be sent
+ to the recipients. Useful if you just want to create a draft of the emails
+ and use another email client to send them.
+ If disabled with `--no-use-imap-only`, the emails will be sent like usual.
+ Disabled by default, but the `sendemail.useImapOnly` configuration
+ variable can be used to enable it.
+
++
+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
+for instructions.
+
--batch-size=<num>::
Some email servers (e.g. 'smtp.163.com') limit the number of emails to be
sent per session (connection) and this will lead to a failure when
diff --git a/git-send-email.perl b/git-send-email.perl
index b3cc237baa..96504e7be1 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -62,7 +62,7 @@ sub usage {
--smtp-user <str> * Username for SMTP-AUTH.
--smtp-pass <str> * Password for SMTP-AUTH; not necessary.
--smtp-encryption <str> * tls or ssl; anything else disables.
- --smtp-ssl * Deprecated. Use '--smtp-encryption ssl'.
+ --smtp-ssl * Deprecated. Use `--smtp-encryption ssl`.
--smtp-ssl-cert-path <str> * Path to ca-certificates (either directory or file).
Pass an empty string to disable certificate
verification.
@@ -75,6 +75,8 @@ sub usage {
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
--imap-sent-folder <str> * IMAP folder where a copy of the emails should be sent.
Make sure `git imap-send` is set up to use this feature.
+ --[no-]use-imap-only * Only copy emails to the IMAP folder specified by
+ `--imap-sent-folder` instead of actually sending them.
--batch-size <int> * send max <int> message per connection.
--relogin-delay <int> * delay <int> seconds between two successive login.
@@ -296,6 +298,7 @@ sub do_edit {
my $target_xfer_encoding = 'auto';
my $forbid_sendmail_variables = 1;
my $outlook_id_fix = 'auto';
+my $use_imap_only = 0;
my %config_bool_settings = (
"thread" => \$thread,
@@ -312,6 +315,7 @@ sub do_edit {
"forbidsendmailvariables" => \$forbid_sendmail_variables,
"mailmap" => \$mailmap,
"outlookidfix" => \$outlook_id_fix,
+ "useimaponly" => \$use_imap_only,
);
my %config_settings = (
@@ -532,6 +536,7 @@ sub config_regexp {
"smtp-auth=s" => \$smtp_auth,
"no-smtp-auth" => sub {$smtp_auth = 'none'},
"imap-sent-folder=s" => \$imap_sent_folder,
+ "use-imap-only!" => \$use_imap_only,
"annotate!" => \$annotate,
"compose" => \$compose,
"quiet" => \$quiet,
@@ -1683,6 +1688,8 @@ sub send_message {
if ($dry_run) {
# We don't want to send the email.
+ } elsif ($use_imap_only) {
+ die __("The destination IMAP folder is not properly defined.") if !defined $imap_sent_folder;
} elsif (defined $sendmail_cmd || file_name_is_absolute($smtp_server)) {
my $pid = open my $sm, '|-';
defined $pid or die $!;
--
2.50.1
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [PATCH v5 0/2] send-email: integrate with git imap-send
2025-08-12 6:44 ` [PATCH v5 0/2] send-email: integrate with git imap-send Aditya Garg
2025-08-12 6:44 ` [PATCH v5 1/2] send-email: add ability to send a copy of sent emails to an IMAP folder Aditya Garg
2025-08-12 6:44 ` [PATCH v5 2/2] send-email: enable copying emails to an IMAP folder without actually sending them Aditya Garg
@ 2025-08-12 16:00 ` Junio C Hamano
2025-08-15 3:38 ` Junio C Hamano
3 siblings, 0 replies; 33+ messages in thread
From: Junio C Hamano @ 2025-08-12 16:00 UTC (permalink / raw)
To: Aditya Garg
Cc: git, Eric Sunshine, Kristoffer Haugsbakk, Ben Knoble,
brian m. carlson
Aditya Garg <gargaditya08@live.com> writes:
> ## Commit message ##
> - send-email: enable copying emails to IMAP folder without actually sending them
> + send-email: add ability to send a copy of sent emails to an IMAP folder
>
Thanks.
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v5 0/2] send-email: integrate with git imap-send
2025-08-12 6:44 ` [PATCH v5 0/2] send-email: integrate with git imap-send Aditya Garg
` (2 preceding siblings ...)
2025-08-12 16:00 ` [PATCH v5 0/2] send-email: integrate with git imap-send Junio C Hamano
@ 2025-08-15 3:38 ` Junio C Hamano
3 siblings, 0 replies; 33+ messages in thread
From: Junio C Hamano @ 2025-08-15 3:38 UTC (permalink / raw)
To: git
Cc: Aditya Garg, Eric Sunshine, Kristoffer Haugsbakk, Ben Knoble,
brian m. carlson
Aditya Garg <gargaditya08@live.com> writes:
> v2 - Fix indentation in patch for imap-send.c
> - Minor edits to commit message
>
> v3 - Rename imap folder to imap sent folder
> - Make an error message shorter by removing unecessary details
>
> v4 - Fix a bug causing emails to be copied to an IMAP folder even if
> --dry-run is specified.
> - Minor edits to commit messages and docs.
> - Add another patch that enables copying emails to an IMAP folder
> without actually sending them.
>
> v5 - Avoid using -[no-]parameter.
We haven't seen any further comments; shall we mark it for 'next'?
^ permalink raw reply [flat|nested] 33+ messages in thread