X-Git-Url: http://cgit.sxemacs.org/?a=blobdiff_plain;f=lisp%2Fnnimap.el;h=a53f9ac468d43b7d50b6aedede8cb1528f4818d9;hb=b337710ff9bcdbc013e6a12ce3cb4f8c934f6b2b;hp=c7fe512881bcdc77e80f782cd30183d14b5abc75;hpb=f42874c5647ac6d10ce3cf8776c004f8f174fcf3;p=gnus diff --git a/lisp/nnimap.el b/lisp/nnimap.el index c7fe51288..a53f9ac46 100644 --- a/lisp/nnimap.el +++ b/lisp/nnimap.el @@ -45,7 +45,7 @@ (require 'tls) (require 'parse-time) (require 'nnmail) -(require 'meta-stream) +(require 'proto-stream) (eval-when-compile (require 'gnus-sum)) @@ -63,9 +63,10 @@ If nnimap-stream is `ssl', this will default to `imaps'. If not, it will default to `imap'.") -(defvoo nnimap-stream 'ssl +(defvoo nnimap-stream 'undecided "How nnimap will talk to the IMAP server. -Values are `ssl', `network', `starttls' or `shell'.") +Values are `ssl', `network', `starttls' or `shell'. +The default is to try `ssl' first, and then `network'.") (defvoo nnimap-shell-program (if (boundp 'imap-shell-program) (if (listp imap-shell-program) @@ -302,6 +303,24 @@ textual parts.") (nnimap-send-command "NOOP"))))))) (defun nnimap-open-connection (buffer) + ;; Be backwards-compatible -- the earlier value of nnimap-stream was + ;; `ssl' when nnimap-server-port was nil. Sort of. + (when (and nnimap-server-port + (eq nnimap-stream 'undecided)) + (setq nnimap-stream 'ssl)) + (let ((stream + (if (eq nnimap-stream 'undecided) + (loop for type in '(ssl network) + for stream = (let ((nnimap-stream type)) + (nnimap-open-connection-1 buffer)) + while (eq stream 'no-connect) + finally (return stream)) + (nnimap-open-connection-1 buffer)))) + (if (eq stream 'no-connect) + nil + stream))) + +(defun nnimap-open-connection-1 (buffer) (unless nnimap-keepalive-timer (setq nnimap-keepalive-timer (run-at-time (* 60 15) (* 60 15) 'nnimap-keepalive))) @@ -326,34 +345,36 @@ textual parts.") '("143" "993" "imap" "imaps")) (t (error "Unknown stream type: %s" nnimap-stream)))) - connection-result login-result credentials) + (proto-stream-always-use-starttls t) + login-result credentials) + (when nnimap-server-port + (setq ports (append ports (list nnimap-server-port)))) (destructuring-bind (stream greeting capabilities) - (open-proto-stream + (open-protocol-stream "*nnimap*" (current-buffer) nnimap-address (car (last ports)) :type nnimap-stream :shell-command nnimap-shell-program :capability-command "1 CAPABILITY\r\n" + :success " OK " :starttls-function - (lambda (stream capabilities) - (if (not (string-match "STARTTLS" capabilities)) - ;; Not a STARTTLS-capable server. - nil - "1 STARTTLS"))) + (lambda (capabilities) + (when (gnus-string-match-p "STARTTLS" capabilities) + "1 STARTTLS\r\n"))) (setf (nnimap-process nnimap-object) stream) (if (not stream) - (nnheader-report 'nnimap "Unable to contact %s:%s via %s" - nnimap-address port nnimap-stream) + (progn + (nnheader-report 'nnimap "Unable to contact %s:%s via %s" + nnimap-address port nnimap-stream) + 'no-connect) (gnus-set-process-query-on-exit-flag stream nil) - (if (not (string-match "[*.] \\([A-Z0-9]+\\)" greeting)) + (if (not (gnus-string-match-p "[*.] \\(OK\\|PREAUTH\\)" greeting)) (nnheader-report 'nnimap "%s" greeting) ;; Store the greeting (for debugging purposes). (setf (nnimap-greeting nnimap-object) greeting) (setf (nnimap-capabilities nnimap-object) (mapcar #'upcase (split-string capabilities))) - (when nnimap-server-port - (push (format "%s" nnimap-server-port) ports)) - (unless (equal connection-result "PREAUTH") + (unless (gnus-string-match-p "[*.] PREAUTH" greeting) (if (not (setq credentials (if (eq nnimap-authenticator 'anonymous) (list "anonymous" @@ -1042,7 +1063,7 @@ textual parts.") uidvalidity modseq) (push - (list (nnimap-send-command "EXAMINE %S (QRESYNC (%s %s))" + (list (nnimap-send-command "EXAMINE %S (QRESYNC (%s %s))" (utf7-encode group t) uidvalidity modseq) 'qresync