If the user doesn't have a /etc/services, supply some sensible port defaults.
[gnus] / lisp / nnimap.el
index 53f247f..c53b9db 100644 (file)
 (eval-and-compile
   (require 'nnheader))
 
 (eval-and-compile
   (require 'nnheader))
 
+(eval-when-compile
+  (require 'cl))
+
+(require 'netrc)
+
 (nnoo-declare nnimap)
 
 (defvoo nnimap-address nil
 (nnoo-declare nnimap)
 
 (defvoo nnimap-address nil
@@ -103,7 +108,7 @@ not done by default on servers that doesn't support that command.")
          (nnimap-article-ranges (gnus-compress-sequence articles))
          (format "(UID RFC822.SIZE BODYSTRUCTURE %s)"
                  (format
          (nnimap-article-ranges (gnus-compress-sequence articles))
          (format "(UID RFC822.SIZE BODYSTRUCTURE %s)"
                  (format
-                  (if (member "IMAP4rev1"
+                  (if (member "IMAP4REV1"
                               (nnimap-capabilities nnimap-object))
                       "BODY.PEEK[HEADER.FIELDS %s]"
                     "RFC822.HEADER.LINES %s")
                               (nnimap-capabilities nnimap-object))
                       "BODY.PEEK[HEADER.FIELDS %s]"
                     "RFC822.HEADER.LINES %s")
@@ -206,7 +211,10 @@ not done by default on servers that doesn't support that command.")
            (cond
             ((eq nnimap-stream 'network)
              (open-network-stream "*nnimap*" (current-buffer) nnimap-address
            (cond
             ((eq nnimap-stream 'network)
              (open-network-stream "*nnimap*" (current-buffer) nnimap-address
-                                  (or nnimap-server-port "imap"))
+                                  (or nnimap-server-port
+                                      (if (netrc-find-service-number "imap")
+                                          "imap"
+                                        "143")))
              (netrc-credentials nnimap-address "imap"))
             ((eq nnimap-stream 'stream)
              (nnimap-open-shell-stream
              (netrc-credentials nnimap-address "imap"))
             ((eq nnimap-stream 'stream)
              (nnimap-open-shell-stream
@@ -215,7 +223,10 @@ not done by default on servers that doesn't support that command.")
              (netrc-credentials nnimap-address "imap"))
             ((eq nnimap-stream 'ssl)
              (open-tls-stream "*nnimap*" (current-buffer) nnimap-address
              (netrc-credentials nnimap-address "imap"))
             ((eq nnimap-stream 'ssl)
              (open-tls-stream "*nnimap*" (current-buffer) nnimap-address
-                              (or nnimap-server-port "imaps"))
+                              (or nnimap-server-port
+                                  (if (netrc-find-service-number "imaps")
+                                      "imaps"
+                                    "993")))
              (netrc-credentials nnimap-address "imaps" "imap")))))
       (setf (nnimap-process nnimap-object)
            (get-buffer-process (current-buffer)))
              (netrc-credentials nnimap-address "imaps" "imap")))))
       (setf (nnimap-process nnimap-object)
            (get-buffer-process (current-buffer)))
@@ -233,9 +244,11 @@ not done by default on servers that doesn't support that command.")
            (error "Unable to login to the server: %s"
                   (mapconcat #'identity (cadr result) " ")))
          (setf (nnimap-capabilities nnimap-object)
            (error "Unable to login to the server: %s"
                   (mapconcat #'identity (cadr result) " ")))
          (setf (nnimap-capabilities nnimap-object)
-               (or (nnimap-find-parameter "CAPABILITY" (cdr result))
-                   (nnimap-find-parameter
-                    "CAPABILITY" (cdr (nnimap-command "CAPABILITY")))))
+               (mapcar
+                #'upcase
+                (or (nnimap-find-parameter "CAPABILITY" (cdr result))
+                    (nnimap-find-parameter
+                     "CAPABILITY" (cdr (nnimap-command "CAPABILITY"))))))
          (when (member "QRESYNC" (nnimap-capabilities nnimap-object))
            (nnimap-command "ENABLE QRESYNC"))
          t)))))
          (when (member "QRESYNC" (nnimap-capabilities nnimap-object))
            (nnimap-command "ENABLE QRESYNC"))
          t)))))
@@ -279,7 +292,7 @@ not done by default on servers that doesn't support that command.")
         (erase-buffer)
         (setq result
               (nnimap-command
         (erase-buffer)
         (setq result
               (nnimap-command
-               (if (member "IMAP4rev1" (nnimap-capabilities nnimap-object))
+               (if (member "IMAP4REV1" (nnimap-capabilities nnimap-object))
                    "UID FETCH %d BODY.PEEK[]"
                  "UID FETCH %d RFC822.PEEK")
                article)))
                    "UID FETCH %d BODY.PEEK[]"
                  "UID FETCH %d RFC822.PEEK")
                article)))
@@ -449,7 +462,8 @@ not done by default on servers that doesn't support that command.")
     (when (car result)
       (dolist (line (cdr result))
        (when (and (equal (car line) "LIST")
     (when (car result)
       (dolist (line (cdr result))
        (when (and (equal (car line) "LIST")
-                  (not (string-match "noselect" (caadr line))))
+                  (not (and (caadr line)
+                            (string-match "noselect" (caadr line)))))
          (push (car (last line)) groups)))
       (nreverse groups))))
 
          (push (car (last line)) groups)))
       (nreverse groups))))
 
@@ -805,7 +819,7 @@ not done by default on servers that doesn't support that command.")
     (nnimap-article-ranges articles)
     (format "(UID %s%s)"
            (format
     (nnimap-article-ranges articles)
     (format "(UID %s%s)"
            (format
-            (if (member "IMAP4rev1"
+            (if (member "IMAP4REV1"
                         (nnimap-capabilities nnimap-object))
                 "BODY.PEEK[HEADER] BODY.PEEK"
               "RFC822.PEEK"))
                         (nnimap-capabilities nnimap-object))
                 "BODY.PEEK[HEADER] BODY.PEEK"
               "RFC822.PEEK"))