@@ -62,7 +62,7 @@ sub usage {
62
62
--smtp-user <str> * Username for SMTP-AUTH.
63
63
--smtp-pass <str> * Password for SMTP-AUTH; not necessary.
64
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
66
--smtp-ssl-cert-path <str> * Path to ca-certificates (either directory or file).
67
67
Pass an empty string to disable certificate
68
68
verification.
@@ -73,6 +73,10 @@ sub usage {
73
73
--no-smtp-auth * Disable SMTP authentication. Shorthand for
74
74
`--smtp-auth=none`
75
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.
76
80
77
81
--batch-size <int> * send max <int> message per connection.
78
82
--relogin-delay <int> * delay <int> seconds between two successive login.
@@ -200,7 +204,7 @@ sub format_2822_time {
200
204
201
205
# Variables we fill in automatically, or via prompting:
202
206
my (@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 ,
204
208
$author ,$sender ,$smtp_authpass ,$annotate ,$compose ,$time );
205
209
# Things we either get from config, *or* are overridden on the
206
210
# command-line.
@@ -277,6 +281,7 @@ sub do_edit {
277
281
my ($smtp_authuser , $smtp_encryption , $smtp_ssl_cert_path );
278
282
my ($batch_size , $relogin_delay );
279
283
my ($identity , $aliasfiletype , @alias_files , $smtp_domain , $smtp_auth );
284
+ my ($imap_sent_folder );
280
285
my ($confirm );
281
286
my (@suppress_cc );
282
287
my ($auto_8bit_encoding );
@@ -293,6 +298,7 @@ sub do_edit {
293
298
my $target_xfer_encoding = ' auto' ;
294
299
my $forbid_sendmail_variables = 1;
295
300
my $outlook_id_fix = ' auto' ;
301
+ my $use_imap_only = 0;
296
302
297
303
my %config_bool_settings = (
298
304
" thread" => \$thread ,
@@ -309,6 +315,7 @@ sub do_edit {
309
315
" forbidsendmailvariables" => \$forbid_sendmail_variables ,
310
316
" mailmap" => \$mailmap ,
311
317
" outlookidfix" => \$outlook_id_fix ,
318
+ " useimaponly" => \$use_imap_only ,
312
319
);
313
320
314
321
my %config_settings = (
@@ -322,6 +329,7 @@ sub do_edit {
322
329
" smtpauth" => \$smtp_auth ,
323
330
" smtpbatchsize" => \$batch_size ,
324
331
" smtprelogindelay" => \$relogin_delay ,
332
+ " imapsentfolder" => \$imap_sent_folder ,
325
333
" to" => \@config_to ,
326
334
" tocmd" => \$to_cmd ,
327
335
" cc" => \@config_cc ,
@@ -527,6 +535,8 @@ sub config_regexp {
527
535
" smtp-domain:s" => \$smtp_domain ,
528
536
" smtp-auth=s" => \$smtp_auth ,
529
537
" no-smtp-auth" => sub {$smtp_auth = ' none' },
538
+ " imap-sent-folder=s" => \$imap_sent_folder ,
539
+ " use-imap-only!" => \$use_imap_only ,
530
540
" annotate!" => \$annotate ,
531
541
" compose" => \$compose ,
532
542
" quiet" => \$quiet ,
@@ -1678,6 +1688,8 @@ sub send_message {
1678
1688
1679
1689
if ($dry_run ) {
1680
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 ;
1681
1693
} elsif (defined $sendmail_cmd || file_name_is_absolute($smtp_server )) {
1682
1694
my $pid = open my $sm , ' |-' ;
1683
1695
defined $pid or die $! ;
@@ -1829,6 +1841,17 @@ sub send_message {
1829
1841
print " \n " ;
1830
1842
}
1831
1843
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
+
1832
1855
return 1;
1833
1856
}
1834
1857
@@ -2223,6 +2246,19 @@ sub cleanup_compose_files {
2223
2246
2224
2247
$smtp -> quit if $smtp ;
2225
2248
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
+
2226
2262
sub apply_transfer_encoding {
2227
2263
my $message = shift ;
2228
2264
my $from = shift ;
0 commit comments