From: Lars Ingebrigtsen <larsi@gnus.org>
To: Viktor Slavkovik <viktor.slavkovik@gmail.com>
Cc: 24274@debbugs.gnu.org, zhtvk@gmx.com, Ivan Shmakov <ivan@siamics.net>
Subject: bug#24274: 24.5; Use auth-source library for remote passwords in Rmail
Date: Tue, 11 Aug 2020 16:12:45 +0200 [thread overview]
Message-ID: <87364tuv8i.fsf@gnus.org> (raw)
In-Reply-To: <m3blylev8i.fsf@gnus.org> (Lars Ingebrigtsen's message of "Tue, 25 Jun 2019 13:54:05 +0200")
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
next prev parent reply other threads:[~2020-08-11 14:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-20 18:12 bug#24274: 24.5; Use auth-source library for remote passwords in Rmail Viktor Slavkovikj
2016-08-20 19:45 ` Ivan Shmakov
2016-08-21 14:26 ` Viktor Slavkovik
2016-08-21 19:30 ` Ivan Shmakov
2016-08-22 13:00 ` Ted Zlatanov
2019-06-25 11:54 ` Lars Ingebrigtsen
2020-08-11 14:12 ` Lars Ingebrigtsen [this message]
2020-09-07 15:29 ` Antoine Kalmbach
2020-09-07 15:58 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87364tuv8i.fsf@gnus.org \
--to=larsi@gnus.org \
--cc=24274@debbugs.gnu.org \
--cc=ivan@siamics.net \
--cc=viktor.slavkovik@gmail.com \
--cc=zhtvk@gmx.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).