Skip to content

Commit 480f67f

Browse files
AdityaGarg8gitster
authored andcommitted
send-email: enable copying emails to IMAP folder without actually sending them
`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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 560be06 commit 480f67f

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Documentation/config/sendemail.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ sendemail.smtpServerPort::
8989
sendemail.smtpServerOption::
9090
sendemail.smtpUser::
9191
sendemail.imapSentFolder::
92+
sendemail.useImapOnly::
9293
sendemail.thread::
9394
sendemail.transferEncoding::
9495
sendemail.validate::

Documentation/git-send-email.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,19 @@ must be used for each option.
311311
This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
312312
for instructions.
313313

314+
--[no-]use-imap-only::
315+
If this is set, all emails will only be copied to the IMAP folder specified
316+
with `--imap-sent-folder` or `sendemail.imapSentFolder` and will not be sent
317+
to the recipients. Useful if you just want to create a draft of the emails
318+
and use another email client to send them.
319+
If disabled with `--no-use-imap-only`, the emails will be sent like usual.
320+
Disabled by default, but the `sendemail.useImapOnly` configuration
321+
variable can be used to enable it.
322+
323+
+
324+
This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
325+
for instructions.
326+
314327
--batch-size=<num>::
315328
Some email servers (e.g. 'smtp.163.com') limit the number of emails to be
316329
sent per session (connection) and this will lead to a failure when

git-send-email.perl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ sub usage {
6262
--smtp-user <str> * Username for SMTP-AUTH.
6363
--smtp-pass <str> * Password for SMTP-AUTH; not necessary.
6464
--smtp-encryption <str> * tls or ssl; anything else disables.
65-
--smtp-ssl * Deprecated. Use '--smtp-encryption ssl'.
65+
--smtp-ssl * Deprecated. Use `--smtp-encryption ssl`.
6666
--smtp-ssl-cert-path <str> * Path to ca-certificates (either directory or file).
6767
Pass an empty string to disable certificate
6868
verification.
@@ -75,6 +75,8 @@ sub usage {
7575
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
7676
--imap-sent-folder <str> * IMAP folder where a copy of the emails should be sent.
7777
Make sure `git imap-send` is set up to use this feature.
78+
--[no-]use-imap-only * Only copy emails to the IMAP folder specified by
79+
`--imap-sent-folder` instead of actually sending them.
7880
7981
--batch-size <int> * send max <int> message per connection.
8082
--relogin-delay <int> * delay <int> seconds between two successive login.
@@ -296,6 +298,7 @@ sub do_edit {
296298
my $target_xfer_encoding = 'auto';
297299
my $forbid_sendmail_variables = 1;
298300
my $outlook_id_fix = 'auto';
301+
my $use_imap_only = 0;
299302

300303
my %config_bool_settings = (
301304
"thread" => \$thread,
@@ -312,6 +315,7 @@ sub do_edit {
312315
"forbidsendmailvariables" => \$forbid_sendmail_variables,
313316
"mailmap" => \$mailmap,
314317
"outlookidfix" => \$outlook_id_fix,
318+
"useimaponly" => \$use_imap_only,
315319
);
316320

317321
my %config_settings = (
@@ -532,6 +536,7 @@ sub config_regexp {
532536
"smtp-auth=s" => \$smtp_auth,
533537
"no-smtp-auth" => sub {$smtp_auth = 'none'},
534538
"imap-sent-folder=s" => \$imap_sent_folder,
539+
"use-imap-only!" => \$use_imap_only,
535540
"annotate!" => \$annotate,
536541
"compose" => \$compose,
537542
"quiet" => \$quiet,
@@ -1683,6 +1688,8 @@ sub send_message {
16831688

16841689
if ($dry_run) {
16851690
# We don't want to send the email.
1691+
} elsif ($use_imap_only) {
1692+
die __("The destination IMAP folder is not properly defined.") if !defined $imap_sent_folder;
16861693
} elsif (defined $sendmail_cmd || file_name_is_absolute($smtp_server)) {
16871694
my $pid = open my $sm, '|-';
16881695
defined $pid or die $!;

0 commit comments

Comments
 (0)