[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#24274: 24.5; Use auth-source library for remote passwords in Rmail
From: |
Lars Ingebrigtsen |
Subject: |
bug#24274: 24.5; Use auth-source library for remote passwords in Rmail |
Date: |
Tue, 11 Aug 2020 16:12:45 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Lars Ingebrigtsen <larsi@gnus.org> writes:
> This makes sense to me -- all password things in Emacs should go through
> auth-source, I think.
>
> But I'm not an rmail user, so I can't test this...
I've re-spun the patch for Emacs 28. Can somebody that uses rmail test
this?
diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el
index 44cde7cb5a..fc670ebe2b 100644
--- a/lisp/mail/rmail.el
+++ b/lisp/mail/rmail.el
@@ -39,6 +39,7 @@
(require 'mail-utils)
(require 'rfc2047)
+(require 'auth-source)
(require 'rmail-loaddefs)
@@ -1917,7 +1918,8 @@ rmail-parse-url
(when rmail-remote-password-required
(setq got-password (not (rmail-have-password)))
(setq supplied-password (rmail-get-remote-password
- (string-match "^imaps?" proto))))
+ (string-match "^imaps?" proto)
+ user host)))
;; FIXME
;; The password is embedded. Strip it out since movemail
;; does not really like it, in spite of the movemail spec.
@@ -1938,13 +1940,13 @@ rmail-parse-url
((string-match "^po:\\([^:]+\\)\\(:\\(.*\\)\\)?" file)
(let (got-password supplied-password
;; (proto "pop")
- ;; (user (match-string 1 file))
- ;; (host (match-string 3 file))
+ (user (match-string 1 file))
+ (host (match-string 3 file))
)
(when rmail-remote-password-required
(setq got-password (not (rmail-have-password)))
- (setq supplied-password (rmail-get-remote-password nil)))
+ (setq supplied-password (rmail-get-remote-password nil user host)))
(list file "pop" supplied-password got-password)))
@@ -4498,15 +4500,32 @@ rmail-set-remote-password
(setq rmail-remote-password nil)
(setq rmail-encoded-remote-password nil)))
-(defun rmail-get-remote-password (imap)
- "Get the password for retrieving mail from a POP or IMAP server. If none
-has been set, then prompt the user for one."
+(defun rmail-get-remote-password (imap user host)
+ "Get the password for retrieving mail from a POP or IMAP server.
+If none has been set, the password is found via auth-source. If
+you use ~/.authinfo as your auth-source backend, then put
+something like the following in that file:
+
+machine mymachine login myloginname password mypassword
+
+If auth-source search yields no result, prompt the user for the
+password."
(when (not rmail-encoded-remote-password)
(if (not rmail-remote-password)
- (setq rmail-remote-password
- (read-passwd (if imap
- "IMAP password: "
- "POP password: "))))
+ (setq rmail-remote-password
+ (let ((found (nth 0 (auth-source-search :max 1
+ :user user
+ :host host
+ :require '(:secret))))
+ (secret))
+ (if found
+ (progn
+ (setq secret (plist-get found :secret))
+ (if (functionp secret)
+ (funcall secret)))
+ (read-passwd (if imap
+ "IMAP password: "
+ "POP password: "))))))
(rmail-set-remote-password rmail-remote-password)
(setq rmail-remote-password nil))
(rmail-encode-string rmail-encoded-remote-password (emacs-pid)))
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bug#24274: 24.5; Use auth-source library for remote passwords in Rmail,
Lars Ingebrigtsen <=