From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/77254 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.gnus.general Subject: Re: Making Gnus ask my IMAP username and password after the recent auth-source changes Date: Wed, 23 Feb 2011 23:43:16 -0600 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <87aahmc7ij.fsf@lifelogs.com> References: <87sjvq127b.fsf@gmail.com> <878vxhmmvj.fsf@lifelogs.com> <87tyg53tju.fsf@gmail.com> <87ipwj4wu8.fsf@lifelogs.com> <87hbc39vwe.fsf@gmail.com> <87d3mqj36i.fsf@lifelogs.com> <87aahu3fwp.fsf@lifelogs.com> <87pqqq8bfk.fsf@gnus.org> <87zkptw0ws.fsf@lifelogs.com> <87fwrl0wj6.fsf@gnus.org> <87hbbvybwp.fsf@lifelogs.com> <87d3mj3zfs.fsf@gnus.org> <871v2yq040.fsf@lifelogs.com> <87y6562uif.fsf@gnus.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1298526287 20830 80.91.229.12 (24 Feb 2011 05:44:47 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 24 Feb 2011 05:44:47 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M25582@lists.math.uh.edu Thu Feb 24 06:44:40 2011 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PsU0F-000201-Jf for ding-account@gmane.org; Thu, 24 Feb 2011 06:44:40 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1PsTzL-0000Nx-8s; Wed, 23 Feb 2011 23:43:43 -0600 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1PsTzI-0000NW-KJ for ding@lists.math.uh.edu; Wed, 23 Feb 2011 23:43:40 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtp (Exim 4.72) (envelope-from ) id 1PsTzD-0005c4-8e for ding@lists.math.uh.edu; Wed, 23 Feb 2011 23:43:40 -0600 Original-Received: from lo.gmane.org ([80.91.229.12]) by quimby.gnus.org with esmtp (Exim 4.72) (envelope-from ) id 1PsTzA-0001Fv-5e for ding@gnus.org; Thu, 24 Feb 2011 06:43:32 +0100 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1PsTz9-0001dz-VZ for ding@gnus.org; Thu, 24 Feb 2011 06:43:31 +0100 Original-Received: from c-67-186-102-106.hsd1.il.comcast.net ([67.186.102.106]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 24 Feb 2011 06:43:31 +0100 Original-Received: from tzz by c-67-186-102-106.hsd1.il.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 24 Feb 2011 06:43:31 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 219 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: c-67-186-102-106.hsd1.il.comcast.net X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6;d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" User-Agent: Gnus/5.110014 (No Gnus v0.14) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:H68WRCYk6uJe7NNvYXPDfWBEglw= X-Spam-Score: -1.9 (-) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:77254 Archived-At: --=-=-= Content-Type: text/plain On Wed, 23 Feb 2011 15:36:40 -0800 Lars Ingebrigtsen wrote: LI> Ted Zlatanov writes: LI> It needs to ask for the user name, too, doesn't it? >> >> Maybe. Right now it's guessed. People seem to prefer fewer prompts and >> you can always `e'dit the line afterwards. I mentioned that in my reply >> to Simon Josefsson just now, too. LI> It needs to prompt for the user name. I mean, really. It needs to. LI> Otherwise most people will not have a working setup if they connect to LI> gmail, for instance. OK. I added a user name prompt and removed that default. The default prompts are not great but should be OK. I wrote `auth-source-format-prompt' in the attached patch because I don't want to depend on all the Gnus format spec stuff. I figured it was a simple enough task and it seems to work. On Wed, 23 Feb 2011 15:35:34 -0800 Lars Ingebrigtsen wrote: LI> Ted Zlatanov writes: >> It should have said "Password for [any user]@foo:imap?" and I guess >> that's a bug (fix just went in) . The "any user" and "any port" part is >> necessary IMO to make the intent clear. >> >> If the port is numeric your proposal is not so good: >> >> "143 password at foo: " LI> But it'll never be "143 password" -- since "imap" is first in the list. LI> It's a good point, though -- I think it would be way more readable if LI> there's a parameter to auth-source that lets the caller specify what LI> we're asking the user for. LI> So a :service "IMAP" would be nice, and then you can just drop showing LI> the port number at all. Yeah, that sounds good. I don't like that it pollutes the search spec, though. How about something like (let ((auth-source-creation-prompts '(user "IMAP user name for %h? "))) ... auth-source-search invocation ... Remember we support more than user, host, port, and password. The query string can have any parameter and the prompts need to support it. I attach a patch that does all this. See what you think. >> The user doesn't necessarily know to edit the .authinfo file. He may >> not even know what that is. LI> The prompt asks whether to save it to the .authinfo.gpg file, so the LI> user knows that it exists. It's a very easily readable file, so 1) the LI> user knows it exists, 2) the user can open it all they want, and 3) they LI> can edit it trivially, if they so choose. LI> Instead they're faced with this rather complex choice where any normal LI> user will surmise that they're somehow supposed to edit the line for LI> Gnus to work. And that's not good. The problem is, I don't know how to make it less complex and don't want to make it less functional. Ted --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=auth-source-prompting.patch diff --git a/lisp/auth-source.el b/lisp/auth-source.el index 1db6b56..a40b4d2 100644 --- a/lisp/auth-source.el +++ b/lisp/auth-source.el @@ -147,6 +147,9 @@ let-binding." (defvar auth-source-creation-defaults nil "Defaults for creating token values. Usually let-bound.") +(defvar auth-source-creation-prompts nil + "Default prompts for token values. Usually let-bound.") + (make-obsolete 'auth-source-hide-passwords nil "Emacs 24.1") (defvar auth-source-magic "auth-source-magic ") @@ -445,12 +448,18 @@ parameter, that parameter will be required in the resulting token. The value for that parameter will be obtained from the search parameters or from user input. If any queries are needed, the alist `auth-source-creation-defaults' will be checked for the -default prompt. +default value. If the user, host, or port are missing, the alist +`auth-source-creation-prompts' will be used to look up the +prompts IN THAT ORDER (so the 'user prompt will be queried first, +then 'host, then 'port, and finally 'secret). Each prompt string +can use %u, %h, and %p to show the user, host, and port. Here's an example: \(let ((auth-source-creation-defaults '((user . \"defaultUser\") - (A . \"default A\")))) + (A . \"default A\"))) + (auth-source-creation-prompts + '((password . \"Enter IMAP password for %h:%p: \")))) (auth-source-search :host '(\"nonesuch\" \"twosuch\") :type 'netrc :max 1 :P \"pppp\" :Q \"qqqq\" :create '(A B Q))) @@ -462,12 +471,11 @@ which says: Create a new entry if you found none. The netrc backend will automatically require host, user, and port. The host will be - 'nonesuch' and Q will be 'qqqq'. We prompt for A with default - 'default A', for B and port with default nil, and for the - user with default 'defaultUser'. We will not prompt for Q. The - resulting token will have keys user, host, port, A, B, and Q. - It will not have P with any value, even though P is used in the - search to find only entries that have P set to 'pppp'.\" + 'nonesuch' and Q will be 'qqqq'. We prompt for the password + with the shown prompt. We will not prompt for Q. The resulting + token will have keys user, host, port, A, B, and Q. It will not + have P with any value, even though P is used in the search to + find only entries that have P set to 'pppp'.\" When multiple values are specified in the search parameter, the user is prompted for which one. So :host (X Y Z) would ask the @@ -913,6 +921,17 @@ See `auth-source-search' for details on SPEC." (nth 0 v) v)) +;; (auth-source-format-prompt "test %u %h %p" '((?u "user") (?h "host"))) + +(defun auth-source-format-prompt (prompt alist) + "Format PROMPT using %x (for any character x) specifiers in ALIST." + (dolist (cell alist) + (let ((c (nth 0 cell)) + (v (nth 1 cell))) + (when (and c v) + (setq prompt (replace-regexp-in-string (format "%%%c" c) v prompt))))) + prompt) + ;;; (auth-source-search :host "nonesuch" :type 'netrc :max 1 :create t) ;;; (auth-source-search :host "nonesuch" :type 'netrc :max 1 :create t :create-extra-keys '((A "default A") (B))) @@ -964,31 +983,50 @@ See `auth-source-search' for details on SPEC." ;; the default supplementals are simple: for the user, ;; try (user-login-name), otherwise take given-default (default (cond - ((and (not given-default) (eq r 'user)) - (user-login-name)) - (t given-default)))) + ;; don't default the user name + ;; ((and (not given-default) (eq r 'user)) + ;; (user-login-name)) + (t given-default))) + (printable-defaults (list + (cons 'user + (or + (auth-source-netrc-element-or-first + (aget valist 'user)) + (plist-get artificial :user) + "[any user]")) + (cons 'host + (or + (auth-source-netrc-element-or-first + (aget valist 'host)) + (plist-get artificial :host) + "[any host]")) + (cons 'port + (or + (auth-source-netrc-element-or-first + (aget valist 'port)) + (plist-get artificial :port) + "[any port]")))) + (prompt (or (aget auth-source-creation-prompts r) + (case r + ('secret "%p password for user %u, host %h: ") + ('user "%p user name: ") + ('host "%p host name for user %u: ") + ('port "%p port for user %u and host %h: ")) + (format "Enter %s (%%u@%%h:%%p): " r))) + (prompt (auth-source-format-prompt + prompt + `((?u ,(aget printable-defaults 'user)) + (?h ,(aget printable-defaults 'host)) + (?p ,(aget printable-defaults 'port)))))) ;; store the data, prompting for the password if needed (setq data (cond ((and (null data) (eq r 'secret)) ;; special case prompt for passwords - (read-passwd (format "Password for %s@%s:%s: " - (or - (auth-source-netrc-element-or-first - (aget valist 'user)) - (plist-get artificial :user) - "[any user]") - (or - (auth-source-netrc-element-or-first - (aget valist 'host)) - (plist-get artificial :host) - "[any host]") - (or - (auth-source-netrc-element-or-first - (aget valist 'port)) - (plist-get artificial :port) - "[any port]")))) + (read-passwd prompt)) + ((null data) + (read-string prompt default)) (t (or data default)))) (when data --=-=-=--