From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#24274: 24.5; Use auth-source library for remote passwords in Rmail Date: Tue, 11 Aug 2020 16:12:45 +0200 Message-ID: <87364tuv8i.fsf@gnus.org> References: <87vayvqphr.fsf@gmail.com> <87a8g6nqp4.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12713"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 24274@debbugs.gnu.org, zhtvk@gmx.com, Ivan Shmakov To: Viktor Slavkovik Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 11 16:18:08 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k5V6N-000361-MO for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 11 Aug 2020 16:18:07 +0200 Original-Received: from localhost ([::1]:40202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k5V6M-00074x-Gs for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 11 Aug 2020 10:18:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k5V1S-0003zo-FP for bug-gnu-emacs@gnu.org; Tue, 11 Aug 2020 10:13:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57988) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k5V1S-00014K-5P for bug-gnu-emacs@gnu.org; Tue, 11 Aug 2020 10:13:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1k5V1R-00054C-WE for bug-gnu-emacs@gnu.org; Tue, 11 Aug 2020 10:13:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 11 Aug 2020 14:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24274 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 24274-submit@debbugs.gnu.org id=B24274.159715517919467 (code B ref 24274); Tue, 11 Aug 2020 14:13:01 +0000 Original-Received: (at 24274) by debbugs.gnu.org; 11 Aug 2020 14:12:59 +0000 Original-Received: from localhost ([127.0.0.1]:41301 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k5V1P-00053v-AY for submit@debbugs.gnu.org; Tue, 11 Aug 2020 10:12:59 -0400 Original-Received: from quimby.gnus.org ([95.216.78.240]:33006) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k5V1N-00053g-5G for 24274@debbugs.gnu.org; Tue, 11 Aug 2020 10:12:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Dc+vwzj239AtjRpjpRge0aDw2c58aDWBxGkqbjgHbmw=; b=C11062F9/ftMDKTP8k8KrMmJ2J Q3be4SOKuJYspvdnc1/A8un/o0q0dCTqAcY6u6Q3oL0WmNojQ/aLrts7pLpR9T/5KqBiwJ0OeNoUM s1jGbaV7jfp+JltCwMzjOtbvzi0n0awne0VHcGXJDW+nWaiaYhDrRb0PkBnU+QZouQDs=; Original-Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo) by quimby with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k5V1D-00047C-70; Tue, 11 Aug 2020 16:12:49 +0200 In-Reply-To: (Lars Ingebrigtsen's message of "Tue, 25 Jun 2019 13:54:05 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:184655 Archived-At: Lars Ingebrigtsen 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