@@ -75,6 +75,8 @@ sub usage {
75
75
Pass an empty string to disable certificate
76
76
verification.
77
77
--smtp-domain <str> * The domain name sent to HELO/EHLO handshake
78
+ --smtp-auth <str> * Space-separated list of allowed AUTH mechanisms.
79
+ This setting forces to use one of the listed mechanisms.
78
80
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
79
81
80
82
Automating:
@@ -208,7 +210,7 @@ sub do_edit {
208
210
my ($to_cmd , $cc_cmd );
209
211
my ($smtp_server , $smtp_server_port , @smtp_server_options );
210
212
my ($smtp_authuser , $smtp_encryption , $smtp_ssl_cert_path );
211
- my ($identity , $aliasfiletype , @alias_files , $smtp_domain );
213
+ my ($identity , $aliasfiletype , @alias_files , $smtp_domain , $smtp_auth );
212
214
my ($validate , $confirm );
213
215
my (@suppress_cc );
214
216
my ($auto_8bit_encoding );
@@ -239,6 +241,7 @@ sub do_edit {
239
241
" smtppass" => \$smtp_authpass ,
240
242
" smtpsslcertpath" => \$smtp_ssl_cert_path ,
241
243
" smtpdomain" => \$smtp_domain ,
244
+ " smtpauth" => \$smtp_auth ,
242
245
" to" => \@initial_to ,
243
246
" tocmd" => \$to_cmd ,
244
247
" cc" => \@initial_cc ,
@@ -310,6 +313,7 @@ sub signal_handler {
310
313
" smtp-ssl-cert-path=s" => \$smtp_ssl_cert_path ,
311
314
" smtp-debug:i" => \$debug_net_smtp ,
312
315
" smtp-domain:s" => \$smtp_domain ,
316
+ " smtp-auth=s" => \$smtp_auth ,
313
317
" identity=s" => \$identity ,
314
318
" annotate!" => \$annotate ,
315
319
" no-annotate" => sub {$annotate = 0},
@@ -1130,6 +1134,12 @@ sub smtp_auth_maybe {
1130
1134
Authen::SASL-> import (qw( Perl) );
1131
1135
};
1132
1136
1137
+ # Check mechanism naming as defined in:
1138
+ # https://tools.ietf.org/html/rfc4422#page-8
1139
+ if ($smtp_auth !~ / ^(\b [A-Z0-9-_]{1,20}\s *)*$ / ) {
1140
+ die " invalid smtp auth: '${smtp_auth} '" ;
1141
+ }
1142
+
1133
1143
# TODO: Authentication may fail not because credentials were
1134
1144
# invalid but due to other reasons, in which we should not
1135
1145
# reject credentials.
@@ -1142,6 +1152,20 @@ sub smtp_auth_maybe {
1142
1152
' password' => $smtp_authpass
1143
1153
}, sub {
1144
1154
my $cred = shift ;
1155
+
1156
+ if ($smtp_auth ) {
1157
+ my $sasl = Authen::SASL-> new(
1158
+ mechanism => $smtp_auth ,
1159
+ callback => {
1160
+ user => $cred -> {' username' },
1161
+ pass => $cred -> {' password' },
1162
+ authname => $cred -> {' username' },
1163
+ }
1164
+ );
1165
+
1166
+ return !!$smtp -> auth($sasl );
1167
+ }
1168
+
1145
1169
return !!$smtp -> auth($cred -> {' username' }, $cred -> {' password' });
1146
1170
});
1147
1171
0 commit comments