@@ -73,9 +73,18 @@ sub usage {
73
73
--signed-off-cc Automatically add email addresses that appear in
74
74
Signed-off-by: or Cc: lines to the cc: list. Defaults to on.
75
75
76
+ --identity The configuration identity, a subsection to prioritise over
77
+ the default section.
78
+
76
79
--smtp-server If set, specifies the outgoing SMTP server to use.
77
80
Defaults to localhost.
78
81
82
+ --smtp-user The username for SMTP-AUTH.
83
+
84
+ --smtp-pass The password for SMTP-AUTH.
85
+
86
+ --smtp-ssl If set, connects to the SMTP server using SSL.
87
+
79
88
--suppress-from Suppress sending emails to yourself if your address
80
89
appears in a From: line. Defaults to off.
81
90
@@ -145,7 +154,6 @@ sub format_2822_time {
145
154
my (@to ,@cc ,@initial_cc ,@bcclist ,@xh ,
146
155
$initial_reply_to ,$initial_subject ,@files ,$author ,$sender ,$compose ,$time );
147
156
148
- my $smtp_server ;
149
157
my $envelope_sender ;
150
158
151
159
# Example reply to:
@@ -164,24 +172,26 @@ sub format_2822_time {
164
172
165
173
# Variables with corresponding config settings
166
174
my ($thread , $chain_reply_to , $suppress_from , $signed_off_cc , $cc_cmd );
175
+ my ($smtp_server , $smtp_authuser , $smtp_authpass , $smtp_ssl );
176
+ my ($identity , $aliasfiletype , @alias_files );
167
177
168
- my %config_settings = (
178
+ my %config_bool_settings = (
169
179
" thread" => [\$thread , 1],
170
180
" chainreplyto" => [\$chain_reply_to , 1],
171
181
" suppressfrom" => [\$suppress_from , 0],
172
182
" signedoffcc" => [\$signed_off_cc , 1],
173
- " cccmd " => [\$cc_cmd , " " ],
183
+ " smtpssl " => [\$smtp_ssl , 0 ],
174
184
);
175
185
176
- foreach my $setting ( keys %config_settings ) {
177
- my $config = $repo -> config_bool( " sendemail. $setting " );
178
- ${ $config_settings { $setting } -> [0]} = ( defined $config ) ? $config : $config_settings { $setting } -> [1];
179
- }
180
-
181
- @bcclist = $repo -> config( ' sendemail.bcc ' );
182
- if (! @bcclist or ! $bcclist [0]) {
183
- @bcclist = ();
184
- }
186
+ my %config_settings = (
187
+ " smtpserver " => \ $smtp_server ,
188
+ " smtpuser " => \ $smtp_authuser ,
189
+ " smtppass " => \ $smtp_authpass ,
190
+ " cccmd " => \ $cc_cmd ,
191
+ " aliasfiletype " => \ $aliasfiletype ,
192
+ " bcc " => \ @bcclist ,
193
+ " aliasesfile " => \ @alias_files ,
194
+ );
185
195
186
196
# Begin by accumulating all the variables (defined above), that we will end up
187
197
# needing, first, from the command line:
@@ -194,6 +204,10 @@ sub format_2822_time {
194
204
" bcc=s" => \@bcclist ,
195
205
" chain-reply-to!" => \$chain_reply_to ,
196
206
" smtp-server=s" => \$smtp_server ,
207
+ " smtp-user=s" => \$smtp_authuser ,
208
+ " smtp-pass=s" => \$smtp_authpass ,
209
+ " smtp-ssl!" => \$smtp_ssl ,
210
+ " identity=s" => \$identity ,
197
211
" compose" => \$compose ,
198
212
" quiet" => \$quiet ,
199
213
" cc-cmd=s" => \$cc_cmd ,
@@ -208,6 +222,43 @@ sub format_2822_time {
208
222
usage();
209
223
}
210
224
225
+ # Now, let's fill any that aren't set in with defaults:
226
+
227
+ sub read_config {
228
+ my ($prefix ) = @_ ;
229
+
230
+ foreach my $setting (keys %config_bool_settings ) {
231
+ my $target = $config_bool_settings {$setting }-> [0];
232
+ $$target = $repo -> config_bool(" $prefix .$setting " ) unless (defined $$target );
233
+ }
234
+
235
+ foreach my $setting (keys %config_settings ) {
236
+ my $target = $config_settings {$setting };
237
+ if (ref ($target ) eq " ARRAY" ) {
238
+ unless (@$target ) {
239
+ my @values = $repo -> config(" $prefix .$setting " );
240
+ @$target = @values if (@values && defined $values [0]);
241
+ }
242
+ }
243
+ else {
244
+ $$target = $repo -> config(" $prefix .$setting " ) unless (defined $$target );
245
+ }
246
+ }
247
+ }
248
+
249
+ # read configuration from [sendemail "$identity"], fall back on [sendemail]
250
+ $identity = $repo -> config(" sendemail.identity" ) unless (defined $identity );
251
+ read_config(" sendemail.$identity " ) if (defined $identity );
252
+ read_config(" sendemail" );
253
+
254
+ # fall back on builtin bool defaults
255
+ foreach my $setting (values %config_bool_settings ) {
256
+ ${$setting -> [0]} = $setting -> [1] unless (defined (${$setting -> [0]}));
257
+ }
258
+
259
+ my ($repoauthor ) = $repo -> ident_person(' author' );
260
+ my ($repocommitter ) = $repo -> ident_person(' committer' );
261
+
211
262
# Verify the user input
212
263
213
264
foreach my $entry (@to ) {
@@ -222,14 +273,7 @@ sub format_2822_time {
222
273
die " Comma in --bcclist entry: $entry '\n " unless $entry !~ m / ,/ ;
223
274
}
224
275
225
- # Now, let's fill any that aren't set in with defaults:
226
-
227
- my ($repoauthor ) = $repo -> ident_person(' author' );
228
- my ($repocommitter ) = $repo -> ident_person(' committer' );
229
-
230
276
my %aliases ;
231
- my @alias_files = $repo -> config(' sendemail.aliasesfile' );
232
- my $aliasfiletype = $repo -> config(' sendemail.aliasfiletype' );
233
277
my %parse_alias = (
234
278
# multiline formats can be supported in the future
235
279
mutt => sub { my $fh = shift ; while (<$fh >) {
@@ -320,10 +364,7 @@ sub expand_aliases {
320
364
$initial_reply_to =~ s / (^\s +|\s +$)// g ;
321
365
}
322
366
323
- if (!$smtp_server ) {
324
- $smtp_server = $repo -> config(' sendemail.smtpserver' );
325
- }
326
- if (!$smtp_server ) {
367
+ if (!defined $smtp_server ) {
327
368
foreach (qw( /usr/sbin/sendmail /usr/lib/sendmail ) ) {
328
369
if (-x $_ ) {
329
370
$smtp_server = $_ ;
@@ -553,8 +594,16 @@ sub send_message
553
594
print $sm " $header \n $message " ;
554
595
close $sm or die $? ;
555
596
} else {
556
- require Net::SMTP;
557
- $smtp ||= Net::SMTP-> new( $smtp_server );
597
+ if ($smtp_ssl ) {
598
+ require Net::SMTP::SSL;
599
+ $smtp ||= Net::SMTP::SSL-> new( $smtp_server , Port => 465 );
600
+ }
601
+ else {
602
+ require Net::SMTP;
603
+ $smtp ||= Net::SMTP-> new( $smtp_server );
604
+ }
605
+ $smtp -> auth( $smtp_authuser , $smtp_authpass )
606
+ or die $smtp -> message if (defined $smtp_authuser );
558
607
$smtp -> mail( $raw_from ) or die $smtp -> message;
559
608
$smtp -> to( @recipients ) or die $smtp -> message;
560
609
$smtp -> data or die $smtp -> message;
@@ -661,7 +710,7 @@ sub send_message
661
710
}
662
711
close F;
663
712
664
- if ($cc_cmd ne " " ) {
713
+ if (defined $cc_cmd ) {
665
714
open (F, " $cc_cmd $t |" )
666
715
or die " (cc-cmd) Could not execute '$cc_cmd '" ;
667
716
while (<F>) {
0 commit comments