summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-07-13 14:34:30 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-07-13 14:35:00 +0200
commit3d7a8320928a186bd567ff880ccf0fa872b969d1 (patch)
tree5028ebced4fe02e3ea2f8aaf0a25e5eb0ed9a6a0
parent9f6d8486b46ce4d2dfaba9a59ccc349359688878 (diff)
downloademacs-3d7a8320928a186bd567ff880ccf0fa872b969d1.tar.gz
Make smtpmail try all auth methods
* lisp/mail/smtpmail.el (smtpmail-try-auth-methods): Try all valid methods, even if one fails (bug#48562).
-rw-r--r--lisp/mail/smtpmail.el33
1 files changed, 20 insertions, 13 deletions
diff --git a/lisp/mail/smtpmail.el b/lisp/mail/smtpmail.el
index 8cba2b14e14..fcb072d5d09 100644
--- a/lisp/mail/smtpmail.el
+++ b/lisp/mail/smtpmail.el
@@ -550,7 +550,6 @@ for `smtpmail-try-auth-method'.")
:require (and ask-for-password
'(:user :secret))
:create ask-for-password)))
- (mech (or (plist-get auth-info :smtp-auth) (car mechs)))
(user (plist-get auth-info :user))
(password (auth-info-password auth-info))
(save-function (and ask-for-password
@@ -570,18 +569,26 @@ for `smtpmail-try-auth-method'.")
:require '(:user :secret)
:create t))
password (auth-info-password auth-info)))
- (let ((result (catch 'done
- (if (and mech user password)
- (smtpmail-try-auth-method process mech user password)
- ;; No mechanism, or no credentials.
- mech))))
- (if (stringp result)
- (progn
- (auth-source-forget+ :host host :port port)
- (throw 'done result))
- (when save-function
- (funcall save-function))
- result))))
+ (let ((mechs (or (ensure-list (plist-get auth-info :smtp-auth))
+ mechs))
+ (result ""))
+ (when (and mechs user password)
+ (while (and mechs
+ (stringp result))
+ (setq result (catch 'done
+ (smtpmail-try-auth-method
+ process (pop mechs) user password))))
+ ;; A string result is an error.
+ (if (stringp result)
+ (progn
+ ;; All methods failed.
+ ;; Forget the credentials.
+ (auth-source-forget+ :host host :port port)
+ (throw 'done result))
+ ;; Success.
+ (when save-function
+ (funcall save-function))
+ result)))))
(cl-defgeneric smtpmail-try-auth-method (_process mech _user _password)
"Perform authentication of type MECH for USER with PASSWORD.