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 <dennis@kaarsemaker.net> Reviewed-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Dennis Kaarsemaker committed Mar 24, 2017 at 22:37 UTC 0ead000c3aca13a10ae51a3c74c866981e0d33b8
1 file changed +35 -19
git-send-email.perl
+35 -19
@@ -1353,10 +1353,12 @@ EOF
1353 die __("The required SMTP server is not properly defined.")
1354 }
1355
1356 + require Net::SMTP;
1357 + my $use_net_smtp_ssl = version->parse($Net::SMTP::VERSION) < version->parse("1.28");
1358 + $smtp_domain ||= maildomain();
1359 +
1360 if ($smtp_encryption eq 'ssl') {
1361 $smtp_server_port ||= 465; # ssmtp
1358 - require Net::SMTP::SSL;
1359 - $smtp_domain ||= maildomain();
1362 require IO::Socket::SSL;
1363
1364 # Suppress "variable accessed once" warning.
@@ -1368,34 +1370,48 @@ EOF
1370 # Net::SMTP::SSL->new() does not forward any SSL options
1371 IO::Socket::SSL::set_client_defaults(
1372 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 + }
1388 }
1389 else {
1377 - require Net::SMTP;
1378 - $smtp_domain ||= maildomain();
1390 $smtp_server_port ||= 25;
1391 $smtp ||= Net::SMTP->new($smtp_server,
1392 Hello => $smtp_domain,
1393 Debug => $debug_net_smtp,
1394 Port => $smtp_server_port);
1395 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;
1403 $smtp = Net::SMTP::SSL->start_SSL($smtp,
1404 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());
1410 }
1411 + $smtp_encryption = '';
1412 + # Send EHLO again to receive fresh
1413 + # supported commands
1414 + $smtp->hello($smtp_domain);
1415 }
1416 }
1417