GNU bug report logs -
#24274
24.5; Use auth-source library for remote passwords in Rmail
Previous Next
Reported by: Viktor Slavkovikj <zhtvk <at> gmx.com>
Date: Sat, 20 Aug 2016 18:15:02 UTC
Severity: wishlist
Tags: fixed, patch
Found in version 24.5
Fixed in version 28.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 24274 in the body.
You can then email your comments to 24274 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24274
; Package
emacs
.
(Sat, 20 Aug 2016 18:15:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Viktor Slavkovikj <zhtvk <at> gmx.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sat, 20 Aug 2016 18:15:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi,
I thought that it would be convenient to obtain remote passwords in
Rmail from an authinfo file. Therefore, I modified rmail.el to make use
of the auth-source library. I include a patch for this small feature in
attachment. Do you think that there could be any drawbacks to using this
approach?
Thanks,
Viktor
[patch_rmail_auth_source (application/octet-stream, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24274
; Package
emacs
.
(Sat, 20 Aug 2016 19:47:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 24274 <at> debbugs.gnu.org (full text, mbox):
>>>>> Viktor Slavkovikj <zhtvk <at> gmx.com> writes:
> Hi, I thought that it would be convenient to obtain remote passwords
> in Rmail from an authinfo file. Therefore, I modified rmail.el to
> make use of the auth-source library. I include a patch for this
> small feature in attachment. Do you think that there could be any
> drawbacks to using this approach?
Personally, I can’t readily think of any. (Not that I’m
particularly familiar with either.)
One issue I see with your patch is that it expands TABs into
spaces outside of the actual code changes. If deliberate, I’d
rather see such whitespace changes in a separate patch.
> ! (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, check authinfo for one. If authinfo search
> ! yields no result, prompt the user for the password."
The auth-source library allows access to other backends beside
plain ~/.authinfo, which is why I think it makes sense to
mention the library by name here. See the docstring for the
erc-autojoin-channels-alist variable for an example.
> (when (not rmail-encoded-remote-password)
> (if (not rmail-remote-password)
> ! (setq rmail-remote-password
> ! (let ((found (nth 0 (auth-source-search :max 1
> ! :user user
> ! :host host
> ! :require '(:secret)))))
> ! (if found
> ! (funcall (plist-get found :secret))
> ! (read-passwd (if imap
> ! "IMAP password: "
> ! "POP password: "))))))
The auth-source-search function will prompt for password
automatically if given ‘:create t’ among its parameters, making
explicit read-passwd unnecessary. (But check also the
auth-source-creation-prompts variable.)
> (rmail-set-remote-password rmail-remote-password)
> (setq rmail-remote-password nil))
> (rmail-encode-string rmail-encoded-remote-password (emacs-pid)))
--
FSF associate member #7257 http://am-1.org/~ivan/ … 3013 B6A0 230E 334A
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24274
; Package
emacs
.
(Sun, 21 Aug 2016 16:55:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 24274 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Ivan Shmakov <ivan <at> siamics.net> writes:
>>>>>> Viktor Slavkovikj <zhtvk <at> gmx.com> writes:
>
> > Hi, I thought that it would be convenient to obtain remote passwords
> > in Rmail from an authinfo file. Therefore, I modified rmail.el to
> > make use of the auth-source library. I include a patch for this
> > small feature in attachment. Do you think that there could be any
> > drawbacks to using this approach?
>
> Personally, I can’t readily think of any. (Not that I’m
> particularly familiar with either.)
>
> One issue I see with your patch is that it expands TABs into
> spaces outside of the actual code changes. If deliberate, I’d
> rather see such whitespace changes in a separate patch.
>
> > ! (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, check authinfo for one. If authinfo search
> > ! yields no result, prompt the user for the password."
>
> The auth-source library allows access to other backends beside
> plain ~/.authinfo, which is why I think it makes sense to
> mention the library by name here. See the docstring for the
> erc-autojoin-channels-alist variable for an example.
>
> > (when (not rmail-encoded-remote-password)
> > (if (not rmail-remote-password)
> > ! (setq rmail-remote-password
> > ! (let ((found (nth 0 (auth-source-search :max 1
> > ! :user user
> > ! :host host
> > ! :require '(:secret)))))
> > ! (if found
> > ! (funcall (plist-get found :secret))
> > ! (read-passwd (if imap
> > ! "IMAP password: "
> > ! "POP password: "))))))
>
> The auth-source-search function will prompt for password
> automatically if given ‘:create t’ among its parameters, making
> explicit read-passwd unnecessary. (But check also the
> auth-source-creation-prompts variable.)
>
> > (rmail-set-remote-password rmail-remote-password)
> > (setq rmail-remote-password nil))
> > (rmail-encode-string rmail-encoded-remote-password (emacs-pid)))
I've made an update (attached) to the previous patch. I removed the code
indentation spaces and changed the docstring to be more
descriptive. Also, I included a function check for the auth-source
password which was missing before.
I don't think that the ':create' parameter of auth-source-search should
be used here, since we don't know if the authentication will be
successful.
[patch_update (application/octet-stream, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24274
; Package
emacs
.
(Sun, 21 Aug 2016 19:31:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 24274 <at> debbugs.gnu.org (full text, mbox):
>>>>> Viktor Slavkovik <viktor.slavkovik <at> gmail.com> writes:
>>>>> Ivan Shmakov <ivan <at> siamics.net> writes:
[…]
>> The auth-source-search function will prompt for password
>> automatically if given ‘:create t’ among its parameters, making
>> explicit read-passwd unnecessary. (But check also the
>> auth-source-creation-prompts variable.)
[…]
> I've made an update (attached) to the previous patch. I removed the
> code indentation spaces and changed the docstring to be more
> descriptive. Also, I included a function check for the auth-source
> password which was missing before.
> ! (if found
> ! (progn
> ! (setq secret (plist-get found :secret))
> ! (if (functionp secret)
> ! (funcall secret)))
There, rmail-remote-password will end up being set to nil if
‘secret’ is /not/ a function. Compare:
(progn
(setq secret (plist-get found :secret))
(if (functionp secret)
(funcall secret)
secret))
> I don't think that the ':create' parameter of auth-source-search
> should be used here, since we don't know if the authentication will
> be successful.
We can call auth-source-forget+ if necessary once we figure it
out; just like it’s done in gnus/nnimap.el and mail/smtpmail.el.
> Content-Type: application/octet-stream
I’d appreciate for the patches to come marked as something
text/*, so that MIME-aware mail user agents could just display
them (as opposed to: ask user to save one into a file.) I guess
that such a Content-Type: will be emitted automatically when the
filename of the file being attached ends with .diff or .patch.
> Content-Disposition: attachment; filename=patch_update
> Content-Transfer-Encoding: base64
> Content-Description: updated patch
--
FSF associate member #7257 http://am-1.org/~ivan/ … 3013 B6A0 230E 334A
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24274
; Package
emacs
.
(Mon, 22 Aug 2016 13:01:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 24274 <at> debbugs.gnu.org (full text, mbox):
On Sun, 21 Aug 2016 19:30:43 +0000 Ivan Shmakov <ivan <at> siamics.net> wrote:
>> I've made an update (attached) to the previous patch. I removed the
>> code indentation spaces and changed the docstring to be more
>> descriptive. Also, I included a function check for the auth-source
>> password which was missing before.
Thank you!
IS> We can call auth-source-forget+ if necessary once we figure it
IS> out; just like it’s done in gnus/nnimap.el and mail/smtpmail.el.
Right, those are the typical uses of auth-source.
IS> The auth-source library allows access to other backends beside
IS> plain ~/.authinfo, which is why I think it makes sense to
IS> mention the library by name here. See the docstring for the
IS> erc-autojoin-channels-alist variable for an example.
Agreed! The authinfo file *format* is a default, but there are actually
three of them: '("~/.authinfo" "~/.authinfo.gpg" "~/.netrc")
Thanks
Ted
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24274
; Package
emacs
.
(Tue, 25 Jun 2019 11:55:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 24274 <at> debbugs.gnu.org (full text, mbox):
Viktor Slavkovik <viktor.slavkovik <at> gmail.com> writes:
> I've made an update (attached) to the previous patch. I removed the code
> indentation spaces and changed the docstring to be more
> descriptive. Also, I included a function check for the auth-source
> password which was missing before.
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...
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24274
; Package
emacs
.
(Tue, 11 Aug 2020 14:13:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 24274 <at> debbugs.gnu.org (full text, mbox):
Lars Ingebrigtsen <larsi <at> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24274
; Package
emacs
.
(Mon, 07 Sep 2020 15:59:01 GMT)
Full text and
rfc822 format available.
Message #26 received at 24274 <at> debbugs.gnu.org (full text, mbox):
Antoine Kalmbach <ane <at> iki.fi> writes:
> I can confirm it works. Applied the patch and it works
> perfectly. Tested with both passwords in ~/.authinfo and the macOS
> keychain, the value of auth-sources was:
Thanks for testing. I've now applied the patch to Emacs 28. (It was
almost too long to apply without copyright assignment papers, but
squeaked in.)
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Added tag(s) fixed.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Mon, 07 Sep 2020 16:00:02 GMT)
Full text and
rfc822 format available.
bug marked as fixed in version 28.1, send any further explanations to
24274 <at> debbugs.gnu.org and Viktor Slavkovikj <zhtvk <at> gmx.com>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Mon, 07 Sep 2020 16:00:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24274
; Package
emacs
.
(Mon, 07 Sep 2020 16:09:02 GMT)
Full text and
rfc822 format available.
Message #33 received at 24274 <at> debbugs.gnu.org (full text, mbox):
Lars Ingebrigtsen writes:
> I've re-spun the patch for Emacs 28. Can somebody that uses rmail
> test this?
I can confirm it works. Applied the patch and it works perfectly. Tested with
both passwords in ~/.authinfo and the macOS keychain, the value of auth-sources
was:
(macos-keychain-generic macos-keychain-internet "~/.authinfo" "~/.authinfo.gpg" "~/.netrc")
The version of Emacs used was
GNU Emacs 27.1 (build 1, x86_64-apple-darwin18.7.0, Carbon Version 158 AppKit 1671.6) of 2020-08-16
--
Antoine Kalmbach
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 06 Oct 2020 11:24:08 GMT)
Full text and
rfc822 format available.
This bug report was last modified 3 years and 202 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.