Mercurial > emacs
comparison lisp/mail/smtpmail.el @ 94880:e1d2da11b5ac
Add autoload for
`auth-source-user-or-password'.
(smtpmail-try-auth-methods): Use it.
author | Teodor Zlatanov <tzz@lifelogs.com> |
---|---|
date | Mon, 12 May 2008 12:40:12 +0000 |
parents | ef65fa4dca3b |
children | a9fc7556436a |
comparison
equal
deleted
inserted
replaced
94879:fc66ed3d9938 | 94880:e1d2da11b5ac |
---|---|
75 (autoload 'rfc2104-hash "rfc2104") | 75 (autoload 'rfc2104-hash "rfc2104") |
76 (autoload 'netrc-parse "netrc") | 76 (autoload 'netrc-parse "netrc") |
77 (autoload 'netrc-machine "netrc") | 77 (autoload 'netrc-machine "netrc") |
78 (autoload 'netrc-get "netrc") | 78 (autoload 'netrc-get "netrc") |
79 (autoload 'password-read "password-cache") | 79 (autoload 'password-read "password-cache") |
80 | |
81 (eval-and-compile | |
82 (autoload 'auth-source-user-or-password "auth-source")) | |
80 | 83 |
81 ;;; | 84 ;;; |
82 (defgroup smtpmail nil | 85 (defgroup smtpmail nil |
83 "SMTP protocol for sending mail." | 86 "SMTP protocol for sending mail." |
84 :group 'mail) | 87 :group 'mail) |
537 (declare-function password-cache-add "password-cache" (key password)) | 540 (declare-function password-cache-add "password-cache" (key password)) |
538 | 541 |
539 (defun smtpmail-try-auth-methods (process supported-extensions host port) | 542 (defun smtpmail-try-auth-methods (process supported-extensions host port) |
540 (let* ((mechs (cdr-safe (assoc 'auth supported-extensions))) | 543 (let* ((mechs (cdr-safe (assoc 'auth supported-extensions))) |
541 (mech (car (smtpmail-intersection smtpmail-auth-supported mechs))) | 544 (mech (car (smtpmail-intersection smtpmail-auth-supported mechs))) |
542 (cred (if (stringp smtpmail-auth-credentials) | 545 (auth-user (auth-source-user-or-password |
543 (let* ((netrc (netrc-parse smtpmail-auth-credentials)) | 546 "login" host (or port "smtp"))) |
544 (port-name (format "%s" (or port "smtp"))) | 547 (auth-pass (auth-source-user-or-password |
545 (hostentry (netrc-machine netrc host port-name | 548 "password" host (or port "smtp"))) |
546 port-name))) | 549 (cred (if (and auth-user auth-pass) ; try user-auth-* before netrc-* |
547 (when hostentry | 550 (list host port auth-user auth-pass) |
548 (list host port | 551 ;; else, if auth-source didn't return them... |
549 (netrc-get hostentry "login") | 552 (if (stringp smtpmail-auth-credentials) |
550 (netrc-get hostentry "password")))) | 553 (let* ((netrc (netrc-parse smtpmail-auth-credentials)) |
551 (smtpmail-find-credentials | 554 (port-name (format "%s" (or port "smtp"))) |
552 smtpmail-auth-credentials host port))) | 555 (hostentry (netrc-machine netrc host port-name |
556 port-name))) | |
557 (when hostentry | |
558 (list host port | |
559 (netrc-get hostentry "login") | |
560 (netrc-get hostentry "password")))) | |
561 ;; else, try smtpmail-find-credentials since | |
562 ;; smtpmail-auth-credentials is not a string | |
563 (smtpmail-find-credentials | |
564 smtpmail-auth-credentials host port)))) | |
553 (prompt (when cred (format "SMTP password for %s:%s: " | 565 (prompt (when cred (format "SMTP password for %s:%s: " |
554 (smtpmail-cred-server cred) | 566 (smtpmail-cred-server cred) |
555 (smtpmail-cred-port cred)))) | 567 (smtpmail-cred-port cred)))) |
556 (passwd (when cred | 568 (passwd (when cred |
557 (or (smtpmail-cred-passwd cred) | 569 (or (smtpmail-cred-passwd cred) |