All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dennis Kaarsemaker <dennis@kaarsemaker.net>
To: git@vger.kernel.org
Cc: Dennis Kaarsemaker <dennis@kaarsemaker.net>
Subject: [PATCH] send-email: Net::SMTP::SSL is obsolete, use only when necessary
Date: Sat, 18 Mar 2017 23:23:11 +0100	[thread overview]
Message-ID: <20170318222311.9993-1-dennis@kaarsemaker.net> (raw)
In-Reply-To: <451E4A46-BA43-41A5-9E68-DE0D89BE676A@csh.rit.edu>

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.

Signed-off-by: Dennis Kaarsemaker <dennis@kaarsemaker.net>
---
 Note: I've only been able to test the starttls bits. None of the smtp servers
 I use actually use ssl, only starttls.

 git-send-email.perl | 52 ++++++++++++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 18 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index eea0a517f7..e247ea39dd 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1353,10 +1353,12 @@ EOF
 			die __("The required SMTP server is not properly defined.")
 		}
 
+		require Net::SMTP;
+		my $use_net_smtp_ssl = $Net::SMTP::VERSION lt "1.28";
+		$smtp_domain ||= maildomain();
+
 		if ($smtp_encryption eq 'ssl') {
 			$smtp_server_port ||= 465; # ssmtp
-			require Net::SMTP::SSL;
-			$smtp_domain ||= maildomain();
 			require IO::Socket::SSL;
 
 			# Suppress "variable accessed once" warning.
@@ -1368,34 +1370,48 @@ EOF
 			# Net::SMTP::SSL->new() does not forward any SSL options
 			IO::Socket::SSL::set_client_defaults(
 				ssl_verify_params());
-			$smtp ||= Net::SMTP::SSL->new($smtp_server,
-						      Hello => $smtp_domain,
-						      Port => $smtp_server_port,
-						      Debug => $debug_net_smtp);
+
+			if ($use_net_smtp_ssl) {
+				require Net::SMTP::SSL;
+				$smtp ||= Net::SMTP::SSL->new($smtp_server,
+							      Hello => $smtp_domain,
+							      Port => $smtp_server_port,
+							      Debug => $debug_net_smtp);
+			}
+			else {
+				$smtp ||= Net::SMTP->new($smtp_server,
+							 Hello => $smtp_domain,
+							 Port => $smtp_server_port,
+							 Debug => $debug_net_smtp,
+							 SSL => 1);
+			}
 		}
 		else {
-			require Net::SMTP;
-			$smtp_domain ||= maildomain();
 			$smtp_server_port ||= 25;
 			$smtp ||= Net::SMTP->new($smtp_server,
 						 Hello => $smtp_domain,
 						 Debug => $debug_net_smtp,
 						 Port => $smtp_server_port);
 			if ($smtp_encryption eq 'tls' && $smtp) {
-				require Net::SMTP::SSL;
-				$smtp->command('STARTTLS');
-				$smtp->response();
-				if ($smtp->code == 220) {
+				if ($use_net_smtp_ssl) {
+					$smtp->command('STARTTLS');
+					$smtp->response();
+					if ($smtp->code != 220) {
+						die sprintf(__("Server does not support STARTTLS! %s"), $smtp->message);
+					}
+					require Net::SMTP::SSL;
 					$smtp = Net::SMTP::SSL->start_SSL($smtp,
 									  ssl_verify_params())
 						or die "STARTTLS failed! ".IO::Socket::SSL::errstr();
-					$smtp_encryption = '';
-					# Send EHLO again to receive fresh
-					# supported commands
-					$smtp->hello($smtp_domain);
-				} else {
-					die sprintf(__("Server does not support STARTTLS! %s"), $smtp->message);
 				}
+				else {
+					$smtp->starttls(ssl_verify_params())
+						or die "STARTTLS failed! ".IO::Socket::SSL::errstr();
+				}
+				$smtp_encryption = '';
+				# Send EHLO again to receive fresh
+				# supported commands
+				$smtp->hello($smtp_domain);
 			}
 		}
 
-- 
2.12.0-437-g0cc2799


  parent reply	other threads:[~2017-03-18 22:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-20 21:18 [PATCH] Remove dependency on deprecated Net::SMTP::SSL Mike Fisher
2016-11-20 21:53 ` brian m. carlson
2017-01-13 14:59   ` Renato Botelho
2016-11-21  5:37 ` Torsten Bögershausen
2017-03-18 22:23 ` Dennis Kaarsemaker [this message]
2017-03-18 22:47   ` [PATCH] send-email: Net::SMTP::SSL is obsolete, use only when necessary Ævar Arnfjörð Bjarmason
2017-03-18 23:14     ` Dennis Kaarsemaker
2017-03-24 21:37     ` [PATCH v2] " Dennis Kaarsemaker
2017-05-04  7:01       ` Dennis Kaarsemaker
2017-05-19 20:54         ` Dennis Kaarsemaker
2017-05-20  7:56           ` Ævar Arnfjörð Bjarmason
2017-05-31 22:50           ` Junio C Hamano
2017-06-01 19:42             ` Dennis Kaarsemaker
2017-05-31 21:46       ` Jonathan Nieder
2017-05-31 22:39         ` Junio C Hamano
2017-05-31 22:53           ` Jonathan Nieder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170318222311.9993-1-dennis@kaarsemaker.net \
    --to=dennis@kaarsemaker.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.