Store the IMAP greeting, so that we can tell what kind of server we're talking to.
[gnus] / lisp / nnimap.el
index f3cb77f..6c112fa 100644 (file)
@@ -96,7 +96,7 @@ some servers.")
 
 (defstruct nnimap
   group process commands capabilities select-result newlinep server
-  last-command-time)
+  last-command-time greeting)
 
 (defvar nnimap-object nil)
 
@@ -119,7 +119,6 @@ some servers.")
     (erase-buffer)
     (when (nnimap-possibly-change-group group server)
       (with-current-buffer (nnimap-buffer)
-       (nnimap-send-command "SELECT %S" (utf7-encode group t))
        (erase-buffer)
        (nnimap-wait-for-response
         (nnimap-send-command
@@ -238,7 +237,7 @@ some servers.")
                     ?s host
                     ?p port)))))
 
-(defun nnimap-credentials (address ports)
+(defun nnimap-credentials (address ports &optional inhibit-create)
   (let (port credentials)
     ;; Request the credentials from all ports, but only query on the
     ;; last port if all the previous ones have failed.
@@ -246,7 +245,10 @@ some servers.")
                (setq port (pop ports)))
       (setq credentials
            (auth-source-user-or-password
-            '("login" "password") address port nil (null ports))))
+            '("login" "password") address port nil
+            (if inhibit-create
+                nil
+              (null ports)))))
     credentials))
 
 (defun nnimap-keepalive ()
@@ -315,19 +317,27 @@ some servers.")
            (nnheader-report 'nnimap
                             "%s" (buffer-substring
                                   (point) (line-end-position)))
+         (setf (nnimap-greeting nnimap-object)
+               (buffer-substring (line-beginning-position)
+                                 (line-end-position)))
          (when (eq nnimap-stream 'starttls)
            (nnimap-command "STARTTLS")
            (starttls-negotiate (nnimap-process nnimap-object)))
+         (when nnimap-server-port
+           (push (format "%s" nnimap-server-port) ports))
          (unless (equal connection-result "PREAUTH")
            (if (not (setq credentials
                           (if (eq nnimap-authenticator 'anonymous)
                               (list "anonymous"
                                     (message-make-address))
-                            (nnimap-credentials
-                             nnimap-address
-                             (if nnimap-server-port
-                                 (cons (format "%s" nnimap-server-port) ports)
-                               ports)))))
+                            (or
+                             ;; First look for the credentials based
+                             ;; on the virtual server name.
+                             (nnimap-credentials
+                              (nnoo-current-server 'nnimap) ports t)
+                             ;; Then look them up based on the
+                             ;; physical address.
+                             (nnimap-credentials nnimap-address ports)))))
                (setq nnimap-object nil)
              (setq login-result (nnimap-command "LOGIN %S %S"
                                                 (car credentials)
@@ -618,7 +628,7 @@ some servers.")
     articles)
    ((and force
         (eq nnmail-expiry-target 'delete))
-    (unless (nnimap-delete-article articles)
+    (unless (nnimap-delete-article (gnus-compress-sequence articles))
       (message "Article marked for deletion, but not expunged."))
     nil)
    (t
@@ -632,7 +642,7 @@ some servers.")
       (if (null deletable-articles)
          articles
        (if (eq nnmail-expiry-target 'delete)
-           (nnimap-delete-article deletable-articles)
+           (nnimap-delete-article (gnus-compress-sequence deletable-articles))
          (setq deletable-articles
                (nnimap-process-expiry-targets
                 deletable-articles group server)))
@@ -659,7 +669,7 @@ some servers.")
     ;; Change back to the current group again.
     (nnimap-possibly-change-group group server)
     (setq deleted-articles (nreverse deleted-articles))
-    (nnimap-delete-article deleted-articles)
+    (nnimap-delete-article (gnus-compress-sequence deleted-articles))
     deleted-articles))
 
 (defun nnimap-find-expired-articles (group)