@matheusbsbs / matheus-bagliano / commits / f6bebd121a
Fork 0

git-send-email: add support for TLS via Net::SMTP::SSL

We do this by handing over the Net::SMTP instance to Net::SMTP::SSL, which avoids Net::SMTP::TLS and its weird error checking. This trick is due to Brian Evins. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Jun 25, 2008 at 21:42 UTC f6bebd121ac531871c4cee576b0baf6814099425
2 files changed +40 -9
Documentation/git-send-email.txt
+12 -4
@@ -133,10 +133,13 @@ or on the command line. If a username has been specified (with
133 specified (with --smtp-pass or a configuration variable), then the
134 user is prompted for a password while the input is masked for privacy.
135
136 +--smtp-encryption::
137 + Specify the encryption to use, either 'ssl' or 'tls'. Any other
138 + value reverts to plain SMTP. Default is the value of
139 + 'sendemail.smtpencryption'.
140 +
141 --smtp-ssl::
137 - If set, connects to the SMTP server using SSL.
138 - Default is the value of the 'sendemail.smtpssl' configuration value;
139 - if that is unspecified, does not use SSL.
142 + Legacy alias for '--smtp-encryption=ssl'.
143
144 --subject::
145 Specify the initial subject of the email thread.
@@ -229,8 +232,13 @@ sendemail.smtpuser::
232 sendemail.smtppass::
233 Default SMTP-AUTH password.
234
235 +sendemail.smtpencryption::
236 + Default encryption method. Use 'ssl' for SSL (and specify an
237 + appropriate port), or 'tls' for TLS. Takes precedence over
238 + 'smtpssl' if both are specified.
239 +
240 sendemail.smtpssl::
233 - Boolean value specifying the default to the '--smtp-ssl' parameter.
241 + Legacy boolean that sets 'smtpencryption=ssl' if enabled.
242
243 Author
244 ------
git-send-email.perl
+28 -5
@@ -84,7 +84,10 @@ Options:
84
85 --smtp-pass The password for SMTP-AUTH.
86
87 - --smtp-ssl If set, connects to the SMTP server using SSL.
87 + --smtp-encryption Specify 'tls' for STARTTLS encryption, or 'ssl' for SSL.
88 + Any other value disables the feature.
89 +
90 + --smtp-ssl Synonym for '--smtp-encryption=ssl'. Deprecated.
91
92 --suppress-cc Suppress the specified category of auto-CC. The category
93 can be one of 'author' for the patch author, 'self' to
@@ -184,7 +187,7 @@ my ($quiet, $dry_run) = (0, 0);
187
188 # Variables with corresponding config settings
189 my ($thread, $chain_reply_to, $suppress_from, $signed_off_cc, $cc_cmd);
187 -my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_ssl);
190 +my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption);
191 my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts);
192 my ($no_validate);
193 my (@suppress_cc);
@@ -194,7 +197,6 @@ my %config_bool_settings = (
197 "chainreplyto" => [\$chain_reply_to, 1],
198 "suppressfrom" => [\$suppress_from, undef],
199 "signedoffcc" => [\$signed_off_cc, undef],
197 - "smtpssl" => [\$smtp_ssl, 0],
200 );
201
202 my %config_settings = (
@@ -249,7 +251,8 @@ my $rc = GetOptions("sender|from=s" => \$sender,
251 "smtp-server-port=s" => \$smtp_server_port,
252 "smtp-user=s" => \$smtp_authuser,
253 "smtp-pass:s" => \$smtp_authpass,
252 - "smtp-ssl!" => \$smtp_ssl,
254 + "smtp-ssl" => sub { $smtp_encryption = 'ssl' },
255 + "smtp-encryption=s" => \$smtp_encryption,
256 "identity=s" => \$identity,
257 "compose" => \$compose,
258 "quiet" => \$quiet,
@@ -289,6 +292,15 @@ sub read_config {
292 $$target = Git::config(@repo, "$prefix.$setting") unless (defined $$target);
293 }
294 }
295 +
296 + if (!defined $smtp_encryption) {
297 + my $enc = Git::config(@repo, "$prefix.smtpencryption");
298 + if (defined $enc) {
299 + $smtp_encryption = $enc;
300 + } elsif (Git::config_bool(@repo, "$prefix.smtpssl")) {
301 + $smtp_encryption = 'ssl';
302 + }
303 + }
304 }
305
306 # read configuration from [sendemail "$identity"], fall back on [sendemail]
@@ -738,7 +750,7 @@ X-Mailer: git-send-email $gitversion
750 die "The required SMTP server is not properly defined."
751 }
752
741 - if ($smtp_ssl) {
753 + if ($smtp_encryption eq 'ssl') {
754 $smtp_server_port ||= 465; # ssmtp
755 require Net::SMTP::SSL;
756 $smtp ||= Net::SMTP::SSL->new($smtp_server, Port => $smtp_server_port);
@@ -748,6 +760,17 @@ X-Mailer: git-send-email $gitversion
760 $smtp ||= Net::SMTP->new((defined $smtp_server_port)
761 ? "$smtp_server:$smtp_server_port"
762 : $smtp_server);
763 + if ($smtp_encryption eq 'tls') {
764 + require Net::SMTP::SSL;
765 + $smtp->command('STARTTLS');
766 + $smtp->response();
767 + if ($smtp->code == 220) {
768 + $smtp = Net::SMTP::SSL->start_SSL($smtp)
769 + or die "STARTTLS failed! ".$smtp->message;
770 + } else {
771 + die "Server does not support STARTTLS! ".$smtp->message;
772 + }
773 + }
774 }
775
776 if (!$smtp) {