Function: nnimap-login

nnimap-login is a byte-compiled function defined in nnimap.el.gz.

Signature

(nnimap-login USER PASSWORD)

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/nnimap.el.gz
(defun nnimap-login (user password)
  (cond
   ;; Prefer plain LOGIN if it's enabled (since it requires fewer
   ;; round trips than CRAM-MD5, and it's less likely to be buggy),
   ;; and we're using an encrypted connection.
   ((and (not (nnimap-capability "LOGINDISABLED"))
	 (eq (nnimap-stream-type nnimap-object) 'tls)
	 (or (null nnimap-authenticator)
             (eq nnimap-authenticator 'anonymous)
	     (eq nnimap-authenticator 'login)))
    (nnimap-command "LOGIN %S %S" user password))
   ((and (nnimap-capability "AUTH=XOAUTH2")
         (eq nnimap-authenticator 'xoauth2))
    (nnimap-command  "AUTHENTICATE XOAUTH2 %s"
                     (base64-encode-string
                      (format "user=%s\001auth=Bearer %s\001\001"
                              (nnimap-quote-specials user)
                              (nnimap-quote-specials password)))))
   ((and (nnimap-capability "AUTH=CRAM-MD5")
	 (or (null nnimap-authenticator)
	     (eq nnimap-authenticator 'cram-md5)))
    (erase-buffer)
    (let ((sequence (nnimap-send-command "AUTHENTICATE CRAM-MD5"))
	  (challenge (nnimap-wait-for-line "^\\+\\(.*\\)\n")))
      (process-send-string
       (get-buffer-process (current-buffer))
       (concat
	(base64-encode-string
	 (concat user " "
		 (rfc2104-hash 'md5 64 16 password
			       (base64-decode-string challenge)))
	 t)
	"\r\n"))
      (nnimap-wait-for-response sequence)))
   ((and (not (nnimap-capability "LOGINDISABLED"))
	 (or (null nnimap-authenticator)
             (eq nnimap-authenticator 'anonymous)
	     (eq nnimap-authenticator 'login)))
    (nnimap-command "LOGIN %S %S" user password))
   ((and (nnimap-capability "AUTH=PLAIN")
	 (or (null nnimap-authenticator)
	     (eq nnimap-authenticator 'plain)))
    (nnimap-command
     "AUTHENTICATE PLAIN %s"
     (base64-encode-string
      (format "\000%s\000%s"
	      (nnimap-quote-specials user)
	      (nnimap-quote-specials password))
      t)))))