unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Robert Pluim <rpluim@gmail.com>
To: Ryan Tate <ryantate@ryantate.com>
Cc: 38066@debbugs.gnu.org
Subject: bug#38066: 26.1; X-Message-SMTP-Method header does not affect smtpmail-stream-type
Date: Tue, 05 Nov 2019 18:24:16 +0100	[thread overview]
Message-ID: <m2zhhadynz.fsf@gmail.com> (raw)
In-Reply-To: <87o8xqcn8v.fsf@disp2634> (Ryan Tate's message of "Tue, 05 Nov 2019 11:16:16 -0500")


(please keep 38066@debbugs.gnu.org in the CC)

>>>>> On Tue, 05 Nov 2019 11:16:16 -0500, Ryan Tate <ryantate@ryantate.com> said:

    >> Alternatively we could put this kind of code in open-network-stream,
    >> to allow other protocols to benefit from the same kind of detection.

    Ryan> I don't know enough about the open-network-stream corner of emacs so won't argue either
    Ryan> way. At the very least, I think it certainly makes sense with regard to the X-Message-SMTP-Method
    Ryan> header because this is a convenience feature (so some small amount "magic"
    Ryan> seems permissable) and there is no existing way to set the stream type
    Ryan> here. I imagine it could be useful elsewhere in emacs though.

If we do it in the lower layers, then everyone gets to use it, not
just people using X-Message-SMTP-Method or smtpmail-stream-type.

    Ryan> Your patches look good, thank you for writing them! (Do I need to submit
    Ryan> them formally as a patch on this list?)

No, if they gain traction I can commit them. I took a look at
open-network-stream, and itʼs not too hard to do the equivalent there,
although it probably needs to be conditioned on the specified :type
being nil rather than unconditionally overriding it.

diff --git i/lisp/net/gnutls.el w/lisp/net/gnutls.el
index 9b13adaefe..a083e9df6c 100644
--- i/lisp/net/gnutls.el
+++ w/lisp/net/gnutls.el
@@ -202,6 +202,7 @@ open-gnutls-stream
          (process (open-network-stream
                    name buffer host service
                    :nowait nowait
+                   :auto-tls (plist-get parameters :auto-tls)
                    :tls-parameters
                    (and nowait
                         (cons 'gnutls-x509pki
diff --git i/lisp/net/network-stream.el w/lisp/net/network-stream.el
index 4050c83eb0..8b4bd66ef4 100644
--- i/lisp/net/network-stream.el
+++ w/lisp/net/network-stream.el
@@ -73,6 +73,35 @@ network-stream-use-client-certificates
   :type 'boolean
   :version "27.1")
 
+(defcustom network-stream-auto-tls nil
+  "Whether to automatically try with TLS for certain port
+numbers.  See `network-stream-auto-tls-alist' for the default
+settings."
+  :group 'network
+  :type 'boolean
+  :version "27.1")
+
+(defcustom network-stream-auto-tls-alist
+  '((465 . tls)
+    (587 . starttls)
+    (993 . tls))
+  "Alist used for mapping ports to TLS usage.
+Specifies which port number to map to which TLS behaviour.  See
+`open-network-stream' for a full explanation of the possible
+behaviours."
+  :group 'network
+  :type '(alist :key-type integer
+                :value-type (choice
+                             (const :tag "Possibly upgrade to STARTTLS" nil)
+                             (const :tag "Always use STARTTLS" starttls)
+                             (const :tag "Never use STARTTLS" plain)
+                             (const :tag "Use TLS/SSL" tls)))
+  :version "27.1")
+
 ;;;###autoload
 (defun open-network-stream (name buffer host service &rest parameters)
   "Open a TCP connection to HOST, optionally with encryption.
@@ -175,7 +204,19 @@ open-network-stream
   (unless (featurep 'make-network-process)
     (error "Emacs was compiled without networking support"))
   (let ((type (plist-get parameters :type))
-	(return-list (plist-get parameters :return-list)))
+	(return-list (plist-get parameters :return-list))
+        mapped-type)
+    (when (and network-stream-auto-tls (not (plist-get parameters :auto-tls)))
+      (setq mapped-type (assoc (if (integerp service)
+                                   service
+                                 (string-to-number service))
+                               network-stream-auto-tls-alist))
+      (when mapped-type
+        (setq type (cdr mapped-type)
+              parameters (plist-put
+                          (plist-put parameters :auto-tls t)
+                          :type (cdr mapped-type)))))
+    (message "Auto-TLS %s %s" type mapped-type)
     (if (and (not return-list)
 	     (or (eq type 'plain)
 		 (and (memq type '(nil network))





  parent reply	other threads:[~2019-11-05 17:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-05  4:45 bug#38066: 26.1; X-Message-SMTP-Method header does not affect smtpmail-stream-type Ryan Tate via Bug reports for GNU Emacs, the Swiss army knife of text editors
2019-11-05 10:18 ` Robert Pluim
     [not found]   ` <87o8xqcn8v.fsf@disp2634>
2019-11-05 17:24     ` Robert Pluim [this message]
2019-11-05 17:42       ` Lars Ingebrigtsen
2019-11-05 17:53         ` Robert Pluim
2019-11-05 18:23           ` Lars Ingebrigtsen
2019-11-05 20:09             ` Robert Pluim
2019-11-08 20:56               ` Lars Ingebrigtsen
2020-08-20 15:05                 ` Lars Ingebrigtsen
2019-11-05 17:57       ` Andreas Schwab

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=m2zhhadynz.fsf@gmail.com \
    --to=rpluim@gmail.com \
    --cc=38066@debbugs.gnu.org \
    --cc=ryantate@ryantate.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).