Use AUTHENTICATE PLAIN on servers that say they support that.
[gnus] / lisp / nnimap.el
index 8ea5063..43dbbb8 100644 (file)
@@ -412,9 +412,18 @@ textual parts.")
                                ;; physical address.
                                (nnimap-credentials nnimap-address ports)))))
                  (setq nnimap-object nil)
-               (setq login-result (nnimap-command "LOGIN %S %S"
-                                                  (car credentials)
-                                                  (cadr credentials)))
+               (setq login-result
+                     (if (member "AUTH=PLAIN"
+                                 (nnimap-capabilities nnimap-object))
+                         (nnimap-command
+                          "AUTHENTICATE PLAIN %s"
+                          (base64-encode-string
+                           (format "\000%s\000%s"
+                                   (nnimap-quote-specials (car credentials))
+                                   (nnimap-quote-specials (cadr credentials)))))
+                       (nnimap-command "LOGIN %S %S"
+                                       (car credentials)
+                                       (cadr credentials))))
                (unless (car login-result)
                  ;; If the login failed, then forget the credentials
                  ;; that are now possibly cached.
@@ -431,6 +440,16 @@ textual parts.")
                (nnimap-command "ENABLE QRESYNC"))
              (nnimap-process nnimap-object))))))))
 
+(defun nnimap-quote-specials (string)
+  (with-temp-buffer
+    (insert string)
+    (goto-char (point-min))
+    (while (re-search-forward "[\\\"]" nil t)
+      (forward-char -1)
+      (insert "\\")
+      (forward-char 1))
+    (buffer-string)))
+
 (defun nnimap-find-parameter (parameter elems)
   (let (result)
     (dolist (elem elems)