@@ -75,6 +75,8 @@ sub usage {
7575 Pass an empty string to disable certificate
7676 verification.
7777 --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.
7880 --smtp-debug <0|1> * Disable, enable Net::SMTP debug.
7981
8082 Automating:
@@ -208,7 +210,7 @@ sub do_edit {
208210my ($to_cmd , $cc_cmd );
209211my ($smtp_server , $smtp_server_port , @smtp_server_options );
210212my ($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 );
212214my ($validate , $confirm );
213215my (@suppress_cc );
214216my ($auto_8bit_encoding );
@@ -239,6 +241,7 @@ sub do_edit {
239241 " smtppass" => \$smtp_authpass ,
240242 " smtpsslcertpath" => \$smtp_ssl_cert_path ,
241243 " smtpdomain" => \$smtp_domain ,
244+ " smtpauth" => \$smtp_auth ,
242245 " to" => \@initial_to ,
243246 " tocmd" => \$to_cmd ,
244247 " cc" => \@initial_cc ,
@@ -310,6 +313,7 @@ sub signal_handler {
310313 " smtp-ssl-cert-path=s" => \$smtp_ssl_cert_path ,
311314 " smtp-debug:i" => \$debug_net_smtp ,
312315 " smtp-domain:s" => \$smtp_domain ,
316+ " smtp-auth=s" => \$smtp_auth ,
313317 " identity=s" => \$identity ,
314318 " annotate!" => \$annotate ,
315319 " no-annotate" => sub {$annotate = 0},
@@ -1130,6 +1134,12 @@ sub smtp_auth_maybe {
11301134 Authen::SASL-> import (qw( Perl) );
11311135 };
11321136
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+
11331143 # TODO: Authentication may fail not because credentials were
11341144 # invalid but due to other reasons, in which we should not
11351145 # reject credentials.
@@ -1142,6 +1152,20 @@ sub smtp_auth_maybe {
11421152 ' password' => $smtp_authpass
11431153 }, sub {
11441154 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+
11451169 return !!$smtp -> auth($cred -> {' username' }, $cred -> {' password' });
11461170 });
11471171
0 commit comments