@@ -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.
@@ -73,6 +73,10 @@ sub usage {
7373 --no-smtp-auth * Disable SMTP authentication. Shorthand for
7474 `--smtp-auth=none`
7575 --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.
7680
7781 --batch-size <int> * send max <int> message per connection.
7882 --relogin-delay <int> * delay <int> seconds between two successive login.
@@ -200,7 +204,7 @@ sub format_2822_time {
200204
201205# Variables we fill in automatically, or via prompting:
202206my (@to ,@cc ,@xh ,$envelope_sender ,
203- $initial_in_reply_to ,$reply_to ,$initial_subject ,@files ,
207+ $initial_in_reply_to ,$reply_to ,$initial_subject ,@files ,@imap_copy ,
204208 $author ,$sender ,$smtp_authpass ,$annotate ,$compose ,$time );
205209# Things we either get from config, *or* are overridden on the
206210# command-line.
@@ -277,6 +281,7 @@ sub do_edit {
277281my ($smtp_authuser , $smtp_encryption , $smtp_ssl_cert_path );
278282my ($batch_size , $relogin_delay );
279283my ($identity , $aliasfiletype , @alias_files , $smtp_domain , $smtp_auth );
284+ my ($imap_sent_folder );
280285my ($confirm );
281286my (@suppress_cc );
282287my ($auto_8bit_encoding );
@@ -293,6 +298,7 @@ sub do_edit {
293298my $target_xfer_encoding = ' auto' ;
294299my $forbid_sendmail_variables = 1;
295300my $outlook_id_fix = ' auto' ;
301+ my $use_imap_only = 0;
296302
297303my %config_bool_settings = (
298304 " thread" => \$thread ,
@@ -309,6 +315,7 @@ sub do_edit {
309315 " forbidsendmailvariables" => \$forbid_sendmail_variables ,
310316 " mailmap" => \$mailmap ,
311317 " outlookidfix" => \$outlook_id_fix ,
318+ " useimaponly" => \$use_imap_only ,
312319);
313320
314321my %config_settings = (
@@ -322,6 +329,7 @@ sub do_edit {
322329 " smtpauth" => \$smtp_auth ,
323330 " smtpbatchsize" => \$batch_size ,
324331 " smtprelogindelay" => \$relogin_delay ,
332+ " imapsentfolder" => \$imap_sent_folder ,
325333 " to" => \@config_to ,
326334 " tocmd" => \$to_cmd ,
327335 " cc" => \@config_cc ,
@@ -527,6 +535,8 @@ sub config_regexp {
527535 " smtp-domain:s" => \$smtp_domain ,
528536 " smtp-auth=s" => \$smtp_auth ,
529537 " no-smtp-auth" => sub {$smtp_auth = ' none' },
538+ " imap-sent-folder=s" => \$imap_sent_folder ,
539+ " use-imap-only!" => \$use_imap_only ,
530540 " annotate!" => \$annotate ,
531541 " compose" => \$compose ,
532542 " quiet" => \$quiet ,
@@ -1678,6 +1688,8 @@ sub send_message {
16781688
16791689 if ($dry_run ) {
16801690 # 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 ;
16811693 } elsif (defined $sendmail_cmd || file_name_is_absolute($smtp_server )) {
16821694 my $pid = open my $sm , ' |-' ;
16831695 defined $pid or die $! ;
@@ -1829,6 +1841,17 @@ sub send_message {
18291841 print " \n " ;
18301842 }
18311843
1844+ if ($imap_sent_folder && !$dry_run ) {
1845+ my $imap_header = $header ;
1846+ if (@initial_bcc ) {
1847+ # Bcc is not a part of $header, so we add it here.
1848+ # This is only for the IMAP copy, not for the actual email
1849+ # sent to the recipients.
1850+ $imap_header .= " Bcc: " . join (" , " , @initial_bcc ) . " \n " ;
1851+ }
1852+ push @imap_copy , " From git-send-email\n $imap_header \n $message " ;
1853+ }
1854+
18321855 return 1;
18331856}
18341857
@@ -2223,6 +2246,19 @@ sub cleanup_compose_files {
22232246
22242247$smtp -> quit if $smtp ;
22252248
2249+ if ($imap_sent_folder && @imap_copy && !$dry_run ) {
2250+ my $imap_input = join (" \n " , @imap_copy );
2251+ eval {
2252+ print " \n Starting git imap-send...\n " ;
2253+ my ($fh , $ctx ) = Git::command_input_pipe([' imap-send' , ' -f' , $imap_sent_folder ]);
2254+ print $fh $imap_input ;
2255+ Git::command_close_pipe($fh , $ctx );
2256+ 1;
2257+ } or do {
2258+ warn " Warning: failed to send messages to IMAP folder $imap_sent_folder : $@ " ;
2259+ };
2260+ }
2261+
22262262sub apply_transfer_encoding {
22272263 my $message = shift ;
22282264 my $from = shift ;
0 commit comments