Function: imap-authenticate

imap-authenticate is a byte-compiled function defined in imap.el.gz.

Signature

(imap-authenticate &optional USER PASSWD BUFFER)

Documentation

Authenticate to server in BUFFER, using current buffer if nil.

It uses the authenticator specified when opening the server.

Optional arguments USER and PASSWD specify the username and password to use if the authenticator requires a username and/or password. If omitted or nil, the authenticator may query the user for a username and/or password.

Probably introduced at or before Emacs version 31.1.

Source Code

;; Defined in /usr/src/emacs/lisp/net/imap.el.gz
(defun imap-authenticate (&optional user passwd buffer)
  "Authenticate to server in BUFFER, using current buffer if nil.
It uses the authenticator specified when opening the server.

Optional arguments USER and PASSWD specify the username and
password to use if the authenticator requires a username and/or
password.  If omitted or nil, the authenticator may query the
user for a username and/or password."
  (with-current-buffer (or buffer (current-buffer))
    (if (not (eq imap-state 'nonauth))
	(or (eq imap-state 'auth)
	    (eq imap-state 'selected)
	    (eq imap-state 'examine))
      (make-local-variable 'imap-username)
      (make-local-variable 'imap-password)
      (make-local-variable 'imap-last-authenticator)
      (when user (setq imap-username user))
      (when passwd (setq imap-password passwd))
      (if imap-auth
	  (and (setq imap-last-authenticator
		     (assq imap-auth imap-authenticator-alist))
	       (funcall (nth 2 imap-last-authenticator) (current-buffer))
	       (setq imap-state 'auth))
	;; Choose authenticator.
	(let ((auths imap-authenticators)
	      auth)
	  (while (setq auth (pop auths))
	    ;; OK to use authenticator?
	    (setq imap-last-authenticator
		  (assq auth imap-authenticator-alist))
	    (when (funcall (nth 1 imap-last-authenticator) (current-buffer))
	      (message "imap: Authenticating to `%s' using `%s'..."
		       imap-server auth)
	      (setq imap-auth auth)
	      (if (funcall (nth 2 imap-last-authenticator) (current-buffer))
		  (progn
		    (message "imap: Authenticating to `%s' using `%s'...done"
			     imap-server auth)
		    ;; set imap-state correctly on successful auth attempt
		    (setq imap-state 'auth)
		    ;; stop iterating through the authenticator list
		    (setq auths nil))
		(message "imap: Authenticating to `%s' using `%s'...failed"
			 imap-server auth)))))
	imap-state))))