unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#24274: 24.5; Use auth-source library for remote passwords in Rmail
@ 2016-08-20 18:12 Viktor Slavkovikj
  2016-08-20 19:45 ` Ivan Shmakov
  2020-09-07 15:29 ` Antoine Kalmbach
  0 siblings, 2 replies; 9+ messages in thread
From: Viktor Slavkovikj @ 2016-08-20 18:12 UTC (permalink / raw)
  To: 24274

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

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


[-- Attachment #2: patch --]
[-- Type: application/octet-stream, Size: 5920 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-20 18:59:06.944161712 +0200
***************
*** 1881,1923 ****
  "
    (cond
     ((string-match "^\\([^:]+\\)://\\(\\([^:@]+\\)\\(:\\([^@]+\\)\\)?@\\)?.*" file)
!       (let (got-password supplied-password
! 	    (proto (match-string 1 file))
! 	    (user  (match-string 3 file))
! 	    (pass  (match-string 5 file))
! 	    (host  (substring file (or (match-end 2)
! 				       (+ 3 (match-end 1))))))
! 
! 	(if (not pass)
! 	    (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)))
! 
! 	(if (rmail-movemail-variant-p 'emacs)
! 	    (if (string-equal proto "pop")
! 		(list (concat "po:" user ":" host)
! 		      t
! 		      (or pass supplied-password)
! 		      got-password)
! 	      (error "Emacs movemail does not support %s protocol" proto))
! 	  (list file
! 		(or (string-equal proto "pop") (string-equal proto "imap"))
! 		(or supplied-password pass)
! 		got-password))))
  
     ((string-match "^po:\\([^:]+\\)\\(:\\(.*\\)\\)?" file)
      (let (got-password supplied-password
!           (proto "pop")
! 	  (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)))
  
        (list file "pop" supplied-password got-password)))
  
--- 1881,1923 ----
  "
    (cond
     ((string-match "^\\([^:]+\\)://\\(\\([^:@]+\\)\\(:\\([^@]+\\)\\)?@\\)?.*" file)
!     (let (got-password supplied-password
!                        (proto (match-string 1 file))
!                        (user  (match-string 3 file))
!                        (pass  (match-string 5 file))
!                        (host  (substring file (or (match-end 2)
!                                                   (+ 3 (match-end 1))))))
! 
!       (if (not pass)
!           (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)))
! 
!       (if (rmail-movemail-variant-p 'emacs)
!           (if (string-equal proto "pop")
!               (list (concat "po:" user ":" host)
!                     t
!                     (or pass supplied-password)
!                     got-password)
!             (error "Emacs movemail does not support %s protocol" proto))
!         (list file
!               (or (string-equal proto "pop") (string-equal proto "imap"))
!               (or supplied-password pass)
!               got-password))))
  
     ((string-match "^po:\\([^:]+\\)\\(:\\(.*\\)\\)?" file)
      (let (got-password supplied-password
!                        (proto "pop")
!                        (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 user host)))
  
        (list file "pop" supplied-password got-password)))
  
***************
*** 4455,4473 ****
    (interactive "sPassword: ")
    (if password
        (setq rmail-encoded-remote-password
! 	    (rmail-encode-string password (emacs-pid)))
      (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)))
--- 4455,4480 ----
    (interactive "sPassword: ")
    (if password
        (setq rmail-encoded-remote-password
!             (rmail-encode-string password (emacs-pid)))
      (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, check authinfo for one. If authinfo 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)))))
!                    (if found
!                        (funcall (plist-get found :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)))

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-09-07 15:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2020-09-07 15:29 ` Antoine Kalmbach
2020-09-07 15:58   ` Lars Ingebrigtsen

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).