* WL-ELS (SASL-MODULES): Remove sasl-scram, md4, ntlm,
[elisp/wanderlust.git] / elmo / elmo-imap4.el
index 84ed240..e3296bd 100644 (file)
@@ -530,7 +530,7 @@ BUFFER must be a single-byte buffer."
                     elmo-default-imap4-user)
       (setq append-serv (concat ":" (elmo-imap4-spec-username spec))))
     (unless (eq (elmo-imap4-spec-auth spec)
-                    elmo-default-imap4-authenticate-type)
+               elmo-default-imap4-authenticate-type)
       (setq append-serv 
            (concat append-serv "/" (symbol-name (elmo-imap4-spec-auth spec)))))
     (unless (string= (elmo-imap4-spec-hostname spec)
@@ -661,7 +661,7 @@ BUFFER must be a single-byte buffer."
   (if elmo-use-server-diff
       (elmo-imap4-server-diff spec)
     (elmo-generic-folder-diff spec folder number-list)))
-    
+
 (defun elmo-imap4-get-session (spec &optional if-exists)
   (elmo-network-get-session
    'elmo-imap4-session
@@ -1131,7 +1131,7 @@ If optional argument UNMARK is non-nil, unmark."
       (elmo-read
        (concat "(" (downcase (elmo-match-string 1 string)) ")"))))
 
-(defun elmo-imap4-login (session)
+(defun elmo-imap4-clear-login (session)
   (let ((elmo-imap4-debug-inhibit-logging t))
     (or
      (elmo-imap4-read-ok
@@ -1143,7 +1143,25 @@ If optional argument UNMARK is non-nil, unmark."
             " "
             (elmo-imap4-password
              (elmo-get-passwd (elmo-network-session-password-key session))))))
-     (signal 'elmo-authenticate-error '(login)))))
+     (signal 'elmo-authenticate-error '(elmo-imap4-clear-login)))))
+
+(defun elmo-imap4-auth-login (session)
+  (let ((tag (elmo-imap4-send-command session "authenticate login"))
+       (elmo-imap4-debug-inhibit-logging t))
+    (or (elmo-imap4-read-continue-req session)
+       (signal 'elmo-authenticate-error '(elmo-imap4-auth-login)))
+    (elmo-imap4-send-string session
+                           (elmo-base64-encode-string
+                            (elmo-network-session-user-internal session)))
+    (or (elmo-imap4-read-continue-req session)
+       (signal 'elmo-authenticate-error '(elmo-imap4-auth-login)))
+    (elmo-imap4-send-string session
+                           (elmo-base64-encode-string
+                            (elmo-get-passwd
+                             (elmo-network-session-password-key session))))
+    (or (elmo-imap4-read-ok session tag)
+       (signal 'elmo-authenticate-error '(elmo-imap4-auth-login)))
+    (setq elmo-imap4-status 'auth)))
   
 (luna-define-method
   elmo-network-initialize-session-buffer :after ((session
@@ -1196,8 +1214,12 @@ If optional argument UNMARK is non-nil, unmark."
           (auth (if (listp auth) auth (list auth))))
       (unless (or (eq elmo-imap4-status 'auth)
                  (null auth))
-       (if (eq 'plain (car auth))
-           (elmo-imap4-login session)
+       (cond
+        ((eq 'clear (car auth))
+         (elmo-imap4-clear-login session))
+        ((eq 'login (car auth))
+         (elmo-imap4-auth-login session))
+        (t
          (let* ((elmo-imap4-debug-inhibit-logging t)
                 (sasl-mechanisms
                  (delq nil
@@ -1250,31 +1272,31 @@ If optional argument UNMARK is non-nil, unmark."
                   session
                   (concat "AUTHENTICATE " name
                           (and (sasl-step-data step)
-                               (concat 
+                               (concat
                                 " "
                                 (elmo-base64-encode-string
                                  (sasl-step-data step)
-                                 'no-lin-break)))))) ;)
+                                 'no-lin-break))))))
            (catch 'done
              (while t
                (setq response
                      (elmo-imap4-read-untagged
                       (elmo-network-session-process-internal session)))
-               (if (elmo-imap4-response-continue-req-p response)
-                   (unless (sasl-next-step client step)
-                     ;; response is '+' but there's no next step.
-                     (signal 'elmo-authenticate-error
-                             (list (intern
-                                    (concat "elmo-imap4-auth-"
-                                            (downcase name))))))
-                 ;; response is OK.
-                 (if (elmo-imap4-response-ok-p response)
-                     (throw 'done nil) ; finished.
-                   ;; response is NO or BAD.
-                   (signal 'elmo-authenticate-error
-                           (list (intern
-                                  (concat "elmo-imap4-auth-"
-                                          (downcase name)))))))
+               (if (elmo-imap4-response-ok-p response)
+                   (if (sasl-next-step client step)
+                       ;; Bogus server?
+                       (signal 'elmo-authenticate-error
+                               (list (intern
+                                      (concat "elmo-imap4-auth-"
+                                              (downcase name)))))
+                     ;; The authentication process is finished.
+                     (throw 'done nil)))
+               (unless (elmo-imap4-response-continue-req-p response)
+                 ;; response is NO or BAD.
+                 (signal 'elmo-authenticate-error
+                         (list (intern
+                                (concat "elmo-imap4-auth-"
+                                        (downcase name))))))
                (sasl-step-set-data
                 step
                 (elmo-base64-decode-string
@@ -1286,8 +1308,8 @@ If optional argument UNMARK is non-nil, unmark."
                       (if (sasl-step-data step)
                           (elmo-base64-encode-string (sasl-step-data step)
                                                      'no-line-break)
-                        "")))))))))))
+                        ""))))))))))))
+
 (luna-define-method elmo-network-setup-session ((session
                                                 elmo-imap4-session))
   (with-current-buffer (elmo-network-session-buffer session)
@@ -1334,10 +1356,10 @@ If optional argument UNMARK is non-nil, unmark."
        'fetch)))))
 
 (defun elmo-imap4-prefetch-msg (spec msg outbuf)
-  (elmo-imap4-read-msg spec msg outbuf 'unseen))
+  (elmo-imap4-read-msg spec msg outbuf nil 'unseen))
 
 (defun elmo-imap4-read-msg (spec msg outbuf
-                                &optional leave-seen-flag-untouched)
+                                &optional msgdb leave-seen-flag-untouched)
   (let ((session (elmo-imap4-get-session spec))
        response)
     (elmo-imap4-session-select-mailbox session
@@ -1349,15 +1371,14 @@ If optional argument UNMARK is non-nil, unmark."
          (elmo-imap4-send-command-wait session
                                        (format
                                         (if elmo-imap4-use-uid
-                                            "uid fetch %s rfc822%s"
-                                          "fetch %s rfc822%s")
+                                            "uid fetch %s body%s[]"
+                                          "fetch %s body%s[]")
                                         msg
                                         (if leave-seen-flag-untouched
                                             ".peek" ""))))
-    (and (setq response (elmo-imap4-response-value
+    (and (setq response (elmo-imap4-response-bodydetail-text
                         (elmo-imap4-response-value-all
-                         response 'fetch )
-                        'rfc822))
+                         response 'fetch )))
         (with-current-buffer outbuf
           (erase-buffer)
           (insert response)
@@ -1561,6 +1582,7 @@ Return nil if no complete line has arrived."
 
 (defun elmo-imap4-arrival-filter (proc string)
   "IMAP process filter."
+  (when (buffer-live-p (process-buffer proc))
   (with-current-buffer (process-buffer proc)
     (elmo-imap4-debug "-> %s" string)
     (goto-char (point-max))
@@ -1588,7 +1610,7 @@ Return nil if no complete line has arrived."
                    (t
                     (message "Unknown state %s in arrival filter"
                              elmo-imap4-status))))
-         (delete-region (point-min) (point-max)))))))
+         (delete-region (point-min) (point-max))))))))
 
 ;; IMAP parser.