Gnus development mailing list
 help / color / mirror / Atom feed
From: Ted Zlatanov <tzz@lifelogs.com>
To: ding@gnus.org
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	[thread overview]
Message-ID: <87aahmc7ij.fsf@lifelogs.com> (raw)
In-Reply-To: <87y6562uif.fsf@gnus.org>

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

On Wed, 23 Feb 2011 15:36:40 -0800 Lars Ingebrigtsen <larsi@gnus.org> wrote: 

LI> Ted Zlatanov <tzz@lifelogs.com> 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 <larsi@gnus.org> wrote: 

LI> Ted Zlatanov <tzz@lifelogs.com> 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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: auth-source-prompting.patch --]
[-- Type: text/x-diff, Size: 7053 bytes --]

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

  reply	other threads:[~2011-02-24  5:43 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-15  2:06 Raphael Kubo da Costa
2011-02-15 13:46 ` Ted Zlatanov
2011-02-15 20:57   ` Raphael Kubo da Costa
2011-02-16 19:13     ` Ted Zlatanov
2011-02-16 20:39       ` Matt Lundin
2011-02-16 20:46         ` Ted Zlatanov
2011-02-17  1:15           ` Matt Lundin
2011-02-17 11:03             ` Ted Zlatanov
2011-02-17 13:49               ` Matt Lundin
2011-02-17 14:20                 ` Matt Lundin
2011-02-17 15:22                   ` Steinar Bang
2011-02-18 20:21                     ` Ted Zlatanov
2011-02-21 19:40                       ` Steinar Bang
2011-02-17  3:34       ` Raphael Kubo da Costa
2011-02-17 11:44         ` Ted Zlatanov
2011-02-17 13:34           ` Raphael Kubo da Costa
2011-02-17 14:16             ` Ted Zlatanov
2011-02-17 23:54               ` Lars Ingebrigtsen
2011-02-18 20:19                 ` Ted Zlatanov
2011-02-18 23:10                   ` Lars Ingebrigtsen
2011-02-22 21:52                     ` Ted Zlatanov
2011-02-23  8:52                       ` Lars Ingebrigtsen
2011-02-23 14:47                         ` Ted Zlatanov
2011-02-23 17:00                           ` Raphael Kubo da Costa
2011-02-23 17:09                             ` Ted Zlatanov
2011-02-23 17:56                               ` Raphael Kubo da Costa
2011-02-23 18:56                                 ` Ted Zlatanov
2011-02-25  4:42                                   ` Lars Ingebrigtsen
2011-02-25 11:31                                     ` Ted Zlatanov
2011-03-05 12:15                                       ` Lars Magne Ingebrigtsen
2011-03-08 18:26                                         ` Ted Zlatanov
2011-03-15 16:28                                           ` Lars Magne Ingebrigtsen
2011-03-15 16:43                                             ` Ted Zlatanov
2011-02-23 23:35                           ` Lars Ingebrigtsen
2011-02-23 23:36                           ` Lars Ingebrigtsen
2011-02-24  5:43                             ` Ted Zlatanov [this message]
2011-02-24 11:35                               ` Lars Ingebrigtsen
2011-02-24 13:06                                 ` Ted Zlatanov
2011-02-24 13:48                                   ` Raphael Kubo da Costa
2011-02-24 16:42                                   ` Ted Zlatanov
2011-02-25  4:47                                     ` 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=87aahmc7ij.fsf@lifelogs.com \
    --to=tzz@lifelogs.com \
    --cc=ding@gnus.org \
    /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.
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 NNTP newsgroup(s).