From 9f34e03f677f070476756e24d07c4ecc803d4aee Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Thu, 30 Sep 2010 23:24:40 +0200 Subject: [PATCH] Reinstate the auto-upgrade from unencrypted to STARTTLS, if possible. --- lisp/ChangeLog | 5 +++++ lisp/nnimap.el | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ece613240..007a26641 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2010-09-30 Lars Magne Ingebrigtsen + + * nnimap.el (nnimap-open-connection): Reinstate the auto-upgrade from + unencrypted to STARTTLS, if possible. + 2010-09-30 Teemu Likonen (tiny change) * message.el (message-ignored-supersedes-headers): Strip Injection-* diff --git a/lisp/nnimap.el b/lisp/nnimap.el index ff589e62b..4d26cdb63 100644 --- a/lisp/nnimap.el +++ b/lisp/nnimap.el @@ -350,6 +350,21 @@ textual parts.") "CAPABILITY" (cdr (nnimap-command "CAPABILITY"))))) (when nnimap-server-port (push (format "%s" nnimap-server-port) ports)) + ;; If this is a STARTTLS-capable server, then sever the + ;; connection and start a STARTTLS connection instead. + (when (and (eq nnimap-stream 'network) + (member "STARTTLS" (nnimap-capabilities nnimap-object))) + (let ((nnimap-stream 'starttls)) + (let ((tls-process + (nnimap-open-connection buffer))) + ;; If the STARTTLS connection was successful, we + ;; kill our first non-encrypted connection. If it + ;; wasn't successful, we just use our unencrypted + ;; connection. + (when (memq (process-status tls-process) '(open run)) + (delete-process (nnimap-process nnimap-object)) + (kill-buffer (current-buffer)) + (return tls-process))))) (unless (equal connection-result "PREAUTH") (if (not (setq credentials (if (eq nnimap-authenticator 'anonymous) @@ -381,7 +396,7 @@ textual parts.") (when nnimap-object (when (member "QRESYNC" (nnimap-capabilities nnimap-object)) (nnimap-command "ENABLE QRESYNC")) - t))))))) + (nnimap-process nnimap-object)))))))) (defun nnimap-extend-tls-programs () (let ((programs tls-program) -- 2.25.1