all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Viktor Slavkovik <viktor.slavkovik@gmail.com>
To: Ivan Shmakov <ivan@siamics.net>
Cc: 24274@debbugs.gnu.org, zhtvk@gmx.com
Subject: bug#24274: 24.5; Use auth-source library for remote passwords in Rmail
Date: Sun, 21 Aug 2016 16:26:31 +0200	[thread overview]
Message-ID: <87a8g6nqp4.fsf@gmail.com> (raw)
In-Reply-To: <87pop3rzpt.fsf@violet.siamics.net> (message from Ivan Shmakov on Sat, 20 Aug 2016 19:45:50 +0000)

[-- Attachment #1: Type: text/plain, Size: 2858 bytes --]

Ivan Shmakov <ivan@siamics.net> writes:

>>>>>> Viktor Slavkovikj <zhtvk@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.


[-- Attachment #2: updated patch --]
[-- Type: application/octet-stream, Size: 3758 bytes --]

*** /usr/local/src/emacs-24.5/lisp/mail/rmail.el	2015-04-02 09:23:06.000000000 +0200
--- /usr/local/src/emacs-24.5/lisp/mail/rmail-new.el	2016-08-21 16:01:04.151928967 +0200
***************
*** 1892,1898 ****
  	    (when rmail-remote-password-required
  	      (setq got-password (not (rmail-have-password)))
  	      (setq supplied-password (rmail-get-remote-password
! 				       (string-equal proto "imap"))))
  	  ;; The password is embedded.  Strip it out since movemail
  	  ;; does not really like it, in spite of the movemail spec.
  	  (setq file (concat proto "://" user "@" host)))
--- 1892,1898 ----
  	    (when rmail-remote-password-required
  	      (setq got-password (not (rmail-have-password)))
  	      (setq supplied-password (rmail-get-remote-password
! 				       (string-equal proto "imap") user host)))
  	  ;; The password is embedded.  Strip it out since movemail
  	  ;; does not really like it, in spite of the movemail spec.
  	  (setq file (concat proto "://" user "@" host)))
***************
*** 1917,1923 ****
  
        (when rmail-remote-password-required
  	(setq got-password (not (rmail-have-password)))
! 	(setq supplied-password (rmail-get-remote-password nil)))
  
        (list file "pop" supplied-password got-password)))
  
--- 1917,1923 ----
  
        (when rmail-remote-password-required
  	(setq got-password (not (rmail-have-password)))
! 	(setq supplied-password (rmail-get-remote-password nil user host)))
  
        (list file "pop" supplied-password got-password)))
  
***************
*** 4459,4473 ****
      (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."
    (when (not rmail-encoded-remote-password)
      (if (not rmail-remote-password)
! 	(setq rmail-remote-password
! 	      (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)))
--- 4459,4490 ----
      (setq rmail-remote-password nil)
      (setq rmail-encoded-remote-password nil)))
  
! (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
!               (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)))

  reply	other threads:[~2016-08-21 14:26 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 [this message]
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
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a8g6nqp4.fsf@gmail.com \
    --to=viktor.slavkovik@gmail.com \
    --cc=24274@debbugs.gnu.org \
    --cc=ivan@siamics.net \
    --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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.