Skip to content

Commit 0ead000

Browse files
seveasgitster
authored andcommitted
send-email: Net::SMTP::SSL is obsolete, use only when necessary
Net::SMTP itself can do the necessary SSL and STARTTLS bits just fine since version 1.28, and Net::SMTP::SSL is now deprecated. Since 1.28 isn't that old yet, keep the old code in place and use it when necessary. While we're in the area, mark some messages for translation that were not yet marked as such. Signed-off-by: Dennis Kaarsemaker <[email protected]> Reviewed-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 95d6787 commit 0ead000

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

git-send-email.perl

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,10 +1353,12 @@ sub send_message {
13531353
die __("The required SMTP server is not properly defined.")
13541354
}
13551355

1356+
require Net::SMTP;
1357+
my $use_net_smtp_ssl = version->parse($Net::SMTP::VERSION) < version->parse("1.28");
1358+
$smtp_domain ||= maildomain();
1359+
13561360
if ($smtp_encryption eq 'ssl') {
13571361
$smtp_server_port ||= 465; # ssmtp
1358-
require Net::SMTP::SSL;
1359-
$smtp_domain ||= maildomain();
13601362
require IO::Socket::SSL;
13611363

13621364
# Suppress "variable accessed once" warning.
@@ -1368,34 +1370,48 @@ sub send_message {
13681370
# Net::SMTP::SSL->new() does not forward any SSL options
13691371
IO::Socket::SSL::set_client_defaults(
13701372
ssl_verify_params());
1371-
$smtp ||= Net::SMTP::SSL->new($smtp_server,
1372-
Hello => $smtp_domain,
1373-
Port => $smtp_server_port,
1374-
Debug => $debug_net_smtp);
1373+
1374+
if ($use_net_smtp_ssl) {
1375+
require Net::SMTP::SSL;
1376+
$smtp ||= Net::SMTP::SSL->new($smtp_server,
1377+
Hello => $smtp_domain,
1378+
Port => $smtp_server_port,
1379+
Debug => $debug_net_smtp);
1380+
}
1381+
else {
1382+
$smtp ||= Net::SMTP->new($smtp_server,
1383+
Hello => $smtp_domain,
1384+
Port => $smtp_server_port,
1385+
Debug => $debug_net_smtp,
1386+
SSL => 1);
1387+
}
13751388
}
13761389
else {
1377-
require Net::SMTP;
1378-
$smtp_domain ||= maildomain();
13791390
$smtp_server_port ||= 25;
13801391
$smtp ||= Net::SMTP->new($smtp_server,
13811392
Hello => $smtp_domain,
13821393
Debug => $debug_net_smtp,
13831394
Port => $smtp_server_port);
13841395
if ($smtp_encryption eq 'tls' && $smtp) {
1385-
require Net::SMTP::SSL;
1386-
$smtp->command('STARTTLS');
1387-
$smtp->response();
1388-
if ($smtp->code == 220) {
1396+
if ($use_net_smtp_ssl) {
1397+
$smtp->command('STARTTLS');
1398+
$smtp->response();
1399+
if ($smtp->code != 220) {
1400+
die sprintf(__("Server does not support STARTTLS! %s"), $smtp->message);
1401+
}
1402+
require Net::SMTP::SSL;
13891403
$smtp = Net::SMTP::SSL->start_SSL($smtp,
13901404
ssl_verify_params())
1391-
or die "STARTTLS failed! ".IO::Socket::SSL::errstr();
1392-
$smtp_encryption = '';
1393-
# Send EHLO again to receive fresh
1394-
# supported commands
1395-
$smtp->hello($smtp_domain);
1396-
} else {
1397-
die sprintf(__("Server does not support STARTTLS! %s"), $smtp->message);
1405+
or die sprintf(__("STARTTLS failed! %s"), IO::Socket::SSL::errstr());
1406+
}
1407+
else {
1408+
$smtp->starttls(ssl_verify_params())
1409+
or die sprintf(__("STARTTLS failed! %s"), IO::Socket::SSL::errstr());
13981410
}
1411+
$smtp_encryption = '';
1412+
# Send EHLO again to receive fresh
1413+
# supported commands
1414+
$smtp->hello($smtp_domain);
13991415
}
14001416
}
14011417

0 commit comments

Comments
 (0)