send-email: enable copying emails to an 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 <gargaditya08@live.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Aditya Garg committed Aug 12, 2025 at 06:44 UTC f33b2207da792b45354e9af8948745a169f75651
3 files changed +23 -1
Documentation/config/sendemail.adoc
+1
@@ -89,6 +89,7 @@ sendemail.smtpServerPort::
89 sendemail.smtpServerOption::
90 sendemail.smtpUser::
91 sendemail.imapSentFolder::
92 +sendemail.useImapOnly::
93 sendemail.thread::
94 sendemail.transferEncoding::
95 sendemail.validate::
Documentation/git-send-email.adoc
+14
@@ -311,6 +311,20 @@ must be used for each option.
311 This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
312 for instructions.
313
314 +--use-imap-only::
315 +--no-use-imap-only::
316 + If this is set, all emails will only be copied to the IMAP folder specified
317 + with `--imap-sent-folder` or `sendemail.imapSentFolder` and will not be sent
318 + to the recipients. Useful if you just want to create a draft of the emails
319 + and use another email client to send them.
320 + If disabled with `--no-use-imap-only`, the emails will be sent like usual.
321 + Disabled by default, but the `sendemail.useImapOnly` configuration
322 + variable can be used to enable it.
323 +
324 ++
325 +This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
326 +for instructions.
327 +
328 --batch-size=<num>::
329 Some email servers (e.g. 'smtp.163.com') limit the number of emails to be
330 sent per session (connection) and this will lead to a failure when
git-send-email.perl
+8 -1
@@ -62,7 +62,7 @@ git send-email --translate-aliases
62 --smtp-user <str> * Username for SMTP-AUTH.
63 --smtp-pass <str> * Password for SMTP-AUTH; not necessary.
64 --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`.
66 --smtp-ssl-cert-path <str> * Path to ca-certificates (either directory or file).
67 Pass an empty string to disable certificate
68 verification.
@@ -75,6 +75,8 @@ git send-email --translate-aliases
75 --smtp-debug <0|1> * Disable, enable Net::SMTP debug.
76 --imap-sent-folder <str> * IMAP folder where a copy of the emails should be sent.
77 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.
80
81 --batch-size <int> * send max <int> message per connection.
82 --relogin-delay <int> * delay <int> seconds between two successive login.
@@ -296,6 +298,7 @@ my $mailmap = 0;
298 my $target_xfer_encoding = 'auto';
299 my $forbid_sendmail_variables = 1;
300 my $outlook_id_fix = 'auto';
301 +my $use_imap_only = 0;
302
303 my %config_bool_settings = (
304 "thread" => \$thread,
@@ -312,6 +315,7 @@ my %config_bool_settings = (
315 "forbidsendmailvariables" => \$forbid_sendmail_variables,
316 "mailmap" => \$mailmap,
317 "outlookidfix" => \$outlook_id_fix,
318 + "useimaponly" => \$use_imap_only,
319 );
320
321 my %config_settings = (
@@ -532,6 +536,7 @@ my %options = (
536 "smtp-auth=s" => \$smtp_auth,
537 "no-smtp-auth" => sub {$smtp_auth = 'none'},
538 "imap-sent-folder=s" => \$imap_sent_folder,
539 + "use-imap-only!" => \$use_imap_only,
540 "annotate!" => \$annotate,
541 "compose" => \$compose,
542 "quiet" => \$quiet,
@@ -1683,6 +1688,8 @@ EOF
1688
1689 if ($dry_run) {
1690 # 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;
1693 } elsif (defined $sendmail_cmd || file_name_is_absolute($smtp_server)) {
1694 my $pid = open my $sm, '|-';
1695 defined $pid or die $!;