{"thread":{"id":"14152","subject":"[PATCH] git-send-email: add support for TLS via Net::SMTP::SSL","startedAt":"2008-06-25T19:42:43Z","lastAt":"2008-06-25T19:42:43Z","messageCount":1,"participants":["Thomas Rast"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"81169","messageId":"1214422963-30628-1-git-send-email-trast@student.ethz.ch","threadId":"14152","inReplyTo":null,"subject":"[PATCH] git-send-email: add support for TLS via Net::SMTP::SSL","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2008-06-25T19:42:43Z","receivedAt":"2008-06-25T19:42:43Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"We do this by handing over the Net::SMTP instance to Net::SMTP::SSL,\nwhich avoids Net::SMTP::TLS and its weird error checking.  This trick\nis due to Brian Evins.\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\n---\n\nThe SMTP at my university only works with TLS, so I needed this.  The\ntrick referred to above was posted here:\n  http://kerneltrap.org/mailarchive/git/2007/10/31/374810\n\n- Thomas\n\n\n Documentation/git-send-email.txt |   16 ++++++++++++----\n git-send-email.perl              |   33 ++++++++++++++++++++++++++++-----\n 2 files changed, 40 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt\nindex 251d661..dc7eb7b 100644\n--- a/Documentation/git-send-email.txt\n+++ b/Documentation/git-send-email.txt\n@@ -133,10 +133,13 @@ or on the command line. If a username has been specified (with\n specified (with --smtp-pass or a configuration variable), then the\n user is prompted for a password while the input is masked for privacy.\n \n+--smtp-encryption::\n+\tSpecify the encryption to use, either 'ssl' or 'tls'.  Any other\n+\tvalue reverts to plain SMTP.  Default is the value of\n+\t'sendemail.smtpencryption'.\n+\n --smtp-ssl::\n-\tIf set, connects to the SMTP server using SSL.\n-\tDefault is the value of the 'sendemail.smtpssl' configuration value;\n-\tif that is unspecified, does not use SSL.\n+\tLegacy alias for '--smtp-encryption=ssl'.\n \n --subject::\n \tSpecify the initial subject of the email thread.\n@@ -229,8 +232,13 @@ sendemail.smtpuser::\n sendemail.smtppass::\n \tDefault SMTP-AUTH password.\n \n+sendemail.smtpencryption::\n+\tDefault encryption method.  Use 'ssl' for SSL (and specify an\n+\tappropriate port), or 'tls' for TLS.  Takes precedence over\n+\t'smtpssl' if both are specified.\n+\n sendemail.smtpssl::\n-\tBoolean value specifying the default to the '--smtp-ssl' parameter.\n+\tLegacy boolean that sets 'smtpencryption=ssl' if enabled.\n \n Author\n ------\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 0b04ba3..7630720 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -84,7 +84,10 @@ Options:\n \n    --smtp-pass    The password for SMTP-AUTH.\n \n-   --smtp-ssl     If set, connects to the SMTP server using SSL.\n+   --smtp-encryption Specify 'tls' for STARTTLS encryption, or 'ssl' for SSL.\n+                  Any other value disables the feature.\n+\n+   --smtp-ssl     Synonym for '--smtp-encryption=ssl'.  Deprecated.\n \n    --suppress-cc  Suppress the specified category of auto-CC.  The category\n \t\t  can be one of 'author' for the patch author, 'self' to\n@@ -184,7 +187,7 @@ my ($quiet, $dry_run) = (0, 0);\n \n # Variables with corresponding config settings\n my ($thread, $chain_reply_to, $suppress_from, $signed_off_cc, $cc_cmd);\n-my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_ssl);\n+my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption);\n my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts);\n my ($no_validate);\n my (@suppress_cc);\n@@ -194,7 +197,6 @@ my %config_bool_settings = (\n     \"chainreplyto\" => [\\$chain_reply_to, 1],\n     \"suppressfrom\" => [\\$suppress_from, undef],\n     \"signedoffcc\" => [\\$signed_off_cc, undef],\n-    \"smtpssl\" => [\\$smtp_ssl, 0],\n );\n \n my %config_settings = (\n@@ -249,7 +251,8 @@ my $rc = GetOptions(\"sender|from=s\" => \\$sender,\n \t\t    \"smtp-server-port=s\" => \\$smtp_server_port,\n \t\t    \"smtp-user=s\" => \\$smtp_authuser,\n \t\t    \"smtp-pass:s\" => \\$smtp_authpass,\n-\t\t    \"smtp-ssl!\" => \\$smtp_ssl,\n+\t\t    \"smtp-ssl\" => sub { $smtp_encryption = 'ssl' },\n+\t\t    \"smtp-encryption=s\" => \\$smtp_encryption,\n \t\t    \"identity=s\" => \\$identity,\n \t\t    \"compose\" => \\$compose,\n \t\t    \"quiet\" => \\$quiet,\n@@ -289,6 +292,15 @@ sub read_config {\n \t\t\t$$target = Git::config(@repo, \"$prefix.$setting\") unless (defined $$target);\n \t\t}\n \t}\n+\n+\tif (!defined $smtp_encryption) {\n+\t\tmy $enc = Git::config(@repo, \"$prefix.smtpencryption\");\n+\t\tif (defined $enc) {\n+\t\t\t$smtp_encryption = $enc;\n+\t\t} elsif (Git::config_bool(@repo, \"$prefix.smtpssl\")) {\n+\t\t\t$smtp_encryption = 'ssl';\n+\t\t}\n+\t}\n }\n \n # read configuration from [sendemail \"$identity\"], fall back on [sendemail]\n@@ -738,7 +750,7 @@ X-Mailer: git-send-email $gitversion\n \t\t\tdie \"The required SMTP server is not properly defined.\"\n \t\t}\n \n-\t\tif ($smtp_ssl) {\n+\t\tif ($smtp_encryption eq 'ssl') {\n \t\t\t$smtp_server_port ||= 465; # ssmtp\n \t\t\trequire Net::SMTP::SSL;\n \t\t\t$smtp ||= Net::SMTP::SSL->new($smtp_server, Port => $smtp_server_port);\n@@ -748,6 +760,17 @@ X-Mailer: git-send-email $gitversion\n \t\t\t$smtp ||= Net::SMTP->new((defined $smtp_server_port)\n \t\t\t\t\t\t ? \"$smtp_server:$smtp_server_port\"\n \t\t\t\t\t\t : $smtp_server);\n+\t\t\tif ($smtp_encryption eq 'tls') {\n+\t\t\t\trequire Net::SMTP::SSL;\n+\t\t\t\t$smtp->command('STARTTLS');\n+\t\t\t\t$smtp->response();\n+\t\t\t\tif ($smtp->code == 220) {\n+\t\t\t\t\t$smtp = Net::SMTP::SSL->start_SSL($smtp)\n+\t\t\t\t\t\tor die \"STARTTLS failed! \".$smtp->message;\n+\t\t\t\t} else {\n+\t\t\t\t\tdie \"Server does not support STARTTLS! \".$smtp->message;\n+\t\t\t\t}\n+\t\t\t}\n \t\t}\n \n \t\tif (!$smtp) {\n-- \n1.5.6.84.ge5c1\n"}]}