Patchwork smtp: use 465 as default port for SMTPS

login
register
mail settings
Submitter Katsunori FUJIWARA
Date April 18, 2013, 5:08 p.m.
Message ID <fa1246e1b7453276ca71.1366304927@feefifofum>
Download mbox | patch
Permalink /patch/1428/
State Accepted
Commit 601c1e226889d41bd166ad0829f103577362b2b6
Headers show

Comments

Katsunori FUJIWARA - April 18, 2013, 5:08 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1366302383 -32400
#      Fri Apr 19 01:26:23 2013 +0900
# Node ID fa1246e1b7453276ca71fb4349e4fac5a2473dff
# Parent  7d31f2e42a8afb54c8fae87e8e3e29a63578aea4
smtp: use 465 as default port for SMTPS

Before this patch, port 25 (wellknown port of SMTP) is used as default
port, even if "[smtp] tls" is configured as "smtps".

This patch uses port 465 (wellknown port of SMTPS) as default port, if
"[smtp] tls" is configured as "smtps".
Bryan O'Sullivan - April 18, 2013, 5:37 p.m.
On Thu, Apr 18, 2013 at 10:08 AM, FUJIWARA Katsunori
<foozy@lares.dti.ne.jp>wrote:

> smtp: use 465 as default port for SMTPS
>

Pushed to crew, thanks.
Bryan O'Sullivan - April 18, 2013, 5:41 p.m.
On Thu, Apr 18, 2013 at 10:39 AM, Kevin Bullock <
kbullock+mercurial@ringworld.org> wrote:

> This is arguably a bug, but would also break backward compatibility in a
> 3-year-old feature.


"It's been broken for years" is not a very persuasive argument :-)
Matt Mackall - April 18, 2013, 6:17 p.m.
On Thu, 2013-04-18 at 12:39 -0500, Kevin Bullock wrote:
> On 18 Apr 2013, at 12:08 PM, FUJIWARA Katsunori wrote:
> 
> > # HG changeset patch
> > # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> > # Date 1366302383 -32400
> > #      Fri Apr 19 01:26:23 2013 +0900
> > # Node ID fa1246e1b7453276ca71fb4349e4fac5a2473dff
> > # Parent  7d31f2e42a8afb54c8fae87e8e3e29a63578aea4
> > smtp: use 465 as default port for SMTPS
> > 
> > Before this patch, port 25 (wellknown port of SMTP) is used as default
> > port, even if "[smtp] tls" is configured as "smtps".
> > 
> > This patch uses port 465 (wellknown port of SMTPS) as default port, if
> > "[smtp] tls" is configured as "smtps".
> 
> This is arguably a bug, but would also break backward compatibility in
> a 3-year-old feature. Our documented default port setting is 25,
> independent of the 'tls' setting.

SSMTP is much like HTTPS: it starts an SSL connection immediately with
no negotiation. Thus, if you try to speak SSMTP on the SMTP port, you
will fail (and vice versa). 

So the only people for whom this would be a regression are people who've
configured their SMTP servers to be incompatible with the rest of the
internet.

Patch

diff -r 7d31f2e42a8afb54c8fae87e8e3e29a63578aea4 -r fa1246e1b7453276ca71fb4349e4fac5a2473dff mercurial/help/config.txt
--- a/mercurial/help/config.txt	Mon Apr 15 18:57:04 2013 -0300
+++ b/mercurial/help/config.txt	Fri Apr 19 01:26:23 2013 +0900
@@ -1046,7 +1046,8 @@ 
     Host name of mail server, e.g. "mail.example.com".
 
 ``port``
-    Optional. Port to connect to on mail server. Default: 25.
+    Optional. Port to connect to on mail server. Default: 465 (if
+    ``tls`` is smtps) or 25 (otherwise).
 
 ``tls``
     Optional. Method to enable TLS when connecting to mail server: starttls,
diff -r 7d31f2e42a8afb54c8fae87e8e3e29a63578aea4 -r fa1246e1b7453276ca71fb4349e4fac5a2473dff mercurial/mail.py
--- a/mercurial/mail.py	Mon Apr 15 18:57:04 2013 -0300
+++ b/mercurial/mail.py	Fri Apr 19 01:26:23 2013 +0900
@@ -111,7 +111,11 @@ 
         s = STARTTLS(sslkwargs, local_hostname=local_hostname)
     else:
         s = smtplib.SMTP(local_hostname=local_hostname)
-    mailport = util.getport(ui.config('smtp', 'port', 25))
+    if smtps:
+        defaultport = 465
+    else:
+        defaultport = 25
+    mailport = util.getport(ui.config('smtp', 'port', defaultport))
     ui.note(_('sending mail: smtp host %s, port %s\n') %
             (mailhost, mailport))
     s.connect(host=mailhost, port=mailport)