unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* nnimap-user setting?
@ 2011-04-13 17:22 Stefan Monnier
  2011-04-14 15:05 ` Ted Zlatanov
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2011-04-13 17:22 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen, Simon Josefsson; +Cc: emacs-devel

I'm apparently among the very few users who resist the temptation to
save their IMAP password into the authinfo file, but I find that in such
a case it is annoying to have to confirm the user name each and
every time.

So I think a patch like the one below would make sense (tho re-using
nnimap-authenticator to store the user name would work as well).


        Stefan


--- lisp/gnus/nnimap.el	2011-04-02 23:41:03 +0000
+++ lisp/gnus/nnimap.el	2011-04-12 13:43:13 +0000
@@ -58,6 +58,9 @@
 (defvoo nnimap-address nil
   "The address of the IMAP server.")
 
+(defvoo nnimap-user nil
+  "Username to use for authentication to the IMAP server.")
+
 (defvoo nnimap-server-port nil
   "The IMAP port used.
 If nnimap-stream is `ssl', this will default to `imaps'.  If not,
@@ -283,13 +286,14 @@
     (push (current-buffer) nnimap-process-buffers)
     (current-buffer)))
 
-(defun nnimap-credentials (address ports)
+(defun nnimap-credentials (address ports user)
   (let* ((auth-source-creation-prompts
           '((user  . "IMAP user at %h: ")
             (secret . "IMAP password for %u@%h: ")))
          (found (nth 0 (auth-source-search :max 1
                                            :host address
                                            :port ports
+                                           :user user
                                            :require '(:user :secret)
                                            :create t))))
     (if found
@@ -408,7 +412,8 @@
 				 (list
 				  nnimap-address
 				  (nnoo-current-server 'nnimap)))
-                                ports))))
+                                ports
+                                nnimap-user))))
 		  (setq nnimap-object nil)
 		(let ((nnimap-inhibit-logging t))
 		  (setq login-result




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

* Re: nnimap-user setting?
  2011-04-13 17:22 nnimap-user setting? Stefan Monnier
@ 2011-04-14 15:05 ` Ted Zlatanov
  2011-04-15 19:52   ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Ted Zlatanov @ 2011-04-14 15:05 UTC (permalink / raw)
  To: emacs-devel

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

On Wed, 13 Apr 2011 14:22:47 -0300 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

SM> I'm apparently among the very few users who resist the temptation to
SM> save their IMAP password into the authinfo file, but I find that in such
SM> a case it is annoying to have to confirm the user name each and
SM> every time.

SM> So I think a patch like the one below would make sense (tho re-using
SM> nnimap-authenticator to store the user name would work as well).

Maybe it's better to use this new `nnimap-user' backend variable
directly.  IOW, if it's set, it should override anything from
auth-source, and the auth-source search should not use `nnimap-user',
just the host and the ports.  WDYT?

Ted


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: nnimap-user.patch --]
[-- Type: text/x-diff, Size: 787 bytes --]

diff --git a/lisp/nnimap.el b/lisp/nnimap.el
index afdea18..1cf275d 100644
--- a/lisp/nnimap.el
+++ b/lisp/nnimap.el
@@ -55,6 +55,9 @@
 
 (nnoo-declare nnimap)
 
+(defvoo nnimap-user nil
+  "Username to use for authentication to the IMAP server.  Overrides the username obtained from auth-source-search.")
+
 (defvoo nnimap-address nil
   "The address of the IMAP server.")
 
@@ -412,7 +415,8 @@ textual parts.")
 		  (setq nnimap-object nil)
 		(let ((nnimap-inhibit-logging t))
 		  (setq login-result
-			(nnimap-login (car credentials) (cadr credentials))))
+			(nnimap-login (or nnimap-user (car credentials))
+                                      (cadr credentials))))
 		(if (car login-result)
 		    (progn
                     ;; Save the credentials if a save function exists

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

* Re: nnimap-user setting?
  2011-04-14 15:05 ` Ted Zlatanov
@ 2011-04-15 19:52   ` Stefan Monnier
  2011-04-15 20:31     ` Ted Zlatanov
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2011-04-15 19:52 UTC (permalink / raw)
  To: Ted Zlatanov; +Cc: emacs-devel

> Maybe it's better to use this new `nnimap-user' backend variable
> directly.  IOW, if it's set, it should override anything from
> auth-source, and the auth-source search should not use `nnimap-user',
> just the host and the ports.  WDYT?

Doesn't sound right: what if you have several accounts on the same
IMAP server?  auto-info needs to know the username in order to find the
right password.


        Stefan



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

* Re: nnimap-user setting?
  2011-04-15 19:52   ` Stefan Monnier
@ 2011-04-15 20:31     ` Ted Zlatanov
  2011-04-16 15:14       ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Ted Zlatanov @ 2011-04-15 20:31 UTC (permalink / raw)
  To: emacs-devel

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

On Fri, 15 Apr 2011 16:52:45 -0300 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

>> Maybe it's better to use this new `nnimap-user' backend variable
>> directly.  IOW, if it's set, it should override anything from
>> auth-source, and the auth-source search should not use `nnimap-user',
>> just the host and the ports.  WDYT?

SM> Doesn't sound right: what if you have several accounts on the same
SM> IMAP server?  auto-info needs to know the username in order to find the
SM> right password.

In Gnus, you'd set up multiple secondary servers with the same machine
address and each one has its own nnimap-user.  Then `auth-source-search'
is passed the server name and the machine name, and will use the server
name first.  IOW:

Gnus: server1 = (machine.domain.com, nnimap-user "user1")
      server2 = (machine.domain.com, nnimap-user "user2")

.netrc/.authinfo{,.gpg}: 
machine server1 password password1
machine server2 password password2

But what bugged you is the auth-source prompting for the user name,
right?  See the attached patch, it will also set
`auth-source-creation-defaults' if `nnimap-user' is set, so you won't be
asked for the user name every time a virtual auth-source entry is
created.  You should only be asked for the password and whether you want
to save the entry (as per `auth-source-save-behavior').

Ted


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: nnimap-user.patch --]
[-- Type: text/x-diff, Size: 1223 bytes --]

diff --git a/lisp/nnimap.el b/lisp/nnimap.el
index afdea18..5709f92 100644
--- a/lisp/nnimap.el
+++ b/lisp/nnimap.el
@@ -55,6 +55,9 @@
 
 (nnoo-declare nnimap)
 
+(defvoo nnimap-user nil
+  "Username to use for authentication to the IMAP server.  Overrides the username obtained from auth-source-search.")
+
 (defvoo nnimap-address nil
   "The address of the IMAP server.")
 
@@ -287,6 +290,8 @@ textual parts.")
   (let* ((auth-source-creation-prompts
           '((user  . "IMAP user at %h: ")
             (secret . "IMAP password for %u@%h: ")))
+         (auth-source-creation-defaults
+          (when nnimap-user `((user . ,nnimap-user))))
          (found (nth 0 (auth-source-search :max 1
                                            :host address
                                            :port ports
@@ -412,7 +417,8 @@ textual parts.")
 		  (setq nnimap-object nil)
 		(let ((nnimap-inhibit-logging t))
 		  (setq login-result
-			(nnimap-login (car credentials) (cadr credentials))))
+			(nnimap-login (or nnimap-user (car credentials))
+                                      (cadr credentials))))
 		(if (car login-result)
 		    (progn
                     ;; Save the credentials if a save function exists

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

* Re: nnimap-user setting?
  2011-04-15 20:31     ` Ted Zlatanov
@ 2011-04-16 15:14       ` Stefan Monnier
  2011-04-16 15:27         ` Ted Zlatanov
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2011-04-16 15:14 UTC (permalink / raw)
  To: Ted Zlatanov; +Cc: emacs-devel

SM> Doesn't sound right: what if you have several accounts on the same
SM> IMAP server?  auto-info needs to know the username in order to find the
SM> right password.

> In Gnus, you'd set up multiple secondary servers with the same machine
> address and each one has its own nnimap-user.

That's one way to do it, but not the only way.  The user may only want
one of the accounts in his list of secondary servers.

> But what bugged you is the auth-source prompting for the user name, right?

Partly, but I don't understand what annoys you in the patch I sent.


        Stefan



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

* Re: nnimap-user setting?
  2011-04-16 15:14       ` Stefan Monnier
@ 2011-04-16 15:27         ` Ted Zlatanov
  2011-04-18 19:12           ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Ted Zlatanov @ 2011-04-16 15:27 UTC (permalink / raw)
  To: emacs-devel

On Sat, 16 Apr 2011 12:14:17 -0300 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

SM> Doesn't sound right: what if you have several accounts on the same
SM> IMAP server?  auto-info needs to know the username in order to find the
SM> right password.

>> In Gnus, you'd set up multiple secondary servers with the same machine
>> address and each one has its own nnimap-user.

SM> That's one way to do it, but not the only way.  The user may only want
SM> one of the accounts in his list of secondary servers.

Can you give a specific example of what you mean and how it should work?
I may be missing your point.

>> But what bugged you is the auth-source prompting for the user name, right?

SM> Partly, but I don't understand what annoys you in the patch I sent.

Two potential problems with your patch:

You always put `:user nnimap-user' in the `auth-source-search' spec.
That means that a line like "machine x password y" won't work if
`nnimap-user' is set.  It's not annoying, just unnecessarily
restrictive.

Also if the `nnimap-user' is set it should override anything else coming
from `auth-source-search'.  I think your patch allows it to be
overridden.

Ted




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

* Re: nnimap-user setting?
  2011-04-16 15:27         ` Ted Zlatanov
@ 2011-04-18 19:12           ` Stefan Monnier
  2011-04-19 13:05             ` Ted Zlatanov
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2011-04-18 19:12 UTC (permalink / raw)
  To: Ted Zlatanov; +Cc: emacs-devel

SM> Doesn't sound right: what if you have several accounts on the same
SM> IMAP server?  auto-info needs to know the username in order to find the
SM> right password.
>>> In Gnus, you'd set up multiple secondary servers with the same machine
>>> address and each one has its own nnimap-user.
SM> That's one way to do it, but not the only way.  The user may only want
SM> one of the accounts in his list of secondary servers.
> Can you give a specific example of what you mean and how it should work?
> I may be missing your point.

The autoinfo file has data for toto@foo.bar and titi@foo.bar, and the
user wants to setup his .gnus to connect to titi@foo.bar and nothing
else (maybe he has another .gnus elsewhere configured to only connect
to toto@foo.bar).

> You always put `:user nnimap-user' in the `auth-source-search' spec.
> That means that a line like "machine x password y" won't work if
> `nnimap-user' is set.  It's not annoying, just
> unnecessarily restrictive.

I'd expect a ":user nil" argument to work just like when there's
no :user keyword argument, so as long as the user doesn't set
nnimap-user the behavior should stay unchanged.

> Also if the `nnimap-user' is set it should override anything else coming
> from `auth-source-search'.  I think your patch allows it to be
> overridden.

I'm not sure what you mean here.  If I specify ":host foo.bar :user
titi" I would expect auto-source to ignore an entry for toto@foo.bar.
So either auto-source works differently than what I expect or you're
talking about another case of override.


        Stefan



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

* Re: nnimap-user setting?
  2011-04-18 19:12           ` Stefan Monnier
@ 2011-04-19 13:05             ` Ted Zlatanov
  2011-04-19 13:46               ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Ted Zlatanov @ 2011-04-19 13:05 UTC (permalink / raw)
  To: emacs-devel

On Mon, 18 Apr 2011 16:12:45 -0300 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

SM> Doesn't sound right: what if you have several accounts on the same
SM> IMAP server?  auto-info needs to know the username in order to find the
SM> right password.
>>>> In Gnus, you'd set up multiple secondary servers with the same machine
>>>> address and each one has its own nnimap-user.
SM> That's one way to do it, but not the only way.  The user may only want
SM> one of the accounts in his list of secondary servers.
>> Can you give a specific example of what you mean and how it should work?
>> I may be missing your point.

SM> The autoinfo file has data for toto@foo.bar and titi@foo.bar, and the
SM> user wants to setup his .gnus to connect to titi@foo.bar and nothing
SM> else (maybe he has another .gnus elsewhere configured to only connect
SM> to toto@foo.bar).

I see.

>> You always put `:user nnimap-user' in the `auth-source-search' spec.
>> That means that a line like "machine x password y" won't work if
>> `nnimap-user' is set.  It's not annoying, just
>> unnecessarily restrictive.

SM> I'd expect a ":user nil" argument to work just like when there's
SM> no :user keyword argument, so as long as the user doesn't set
SM> nnimap-user the behavior should stay unchanged.

You're right.

>> Also if the `nnimap-user' is set it should override anything else coming
>> from `auth-source-search'.  I think your patch allows it to be
>> overridden.

SM> I'm not sure what you mean here.  If I specify ":host foo.bar :user
SM> titi" I would expect auto-source to ignore an entry for toto@foo.bar.
SM> So either auto-source works differently than what I expect or you're
SM> talking about another case of override.

s/auto-source/auth-source/g :)

Your patch is correct.  I was thinking incorrectly about the :user nil
search case, which will DTRT as you said.  Sorry for
the... interjection.

Ted




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

* Re: nnimap-user setting?
  2011-04-19 13:05             ` Ted Zlatanov
@ 2011-04-19 13:46               ` Stefan Monnier
  2011-04-22  0:38                 ` Ted Zlatanov
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2011-04-19 13:46 UTC (permalink / raw)
  To: Ted Zlatanov; +Cc: emacs-devel

> Your patch is correct.  I was thinking incorrectly about the :user nil
> search case, which will DTRT as you said.  Sorry for
> the... interjection.

Good, thanks.  Feel free to install it, then,


        Stefan "with connectivity problems"



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

* Re: nnimap-user setting?
  2011-04-19 13:46               ` Stefan Monnier
@ 2011-04-22  0:38                 ` Ted Zlatanov
  2011-04-22 13:14                   ` Ted Zlatanov
  0 siblings, 1 reply; 11+ messages in thread
From: Ted Zlatanov @ 2011-04-22  0:38 UTC (permalink / raw)
  To: emacs-devel

On Tue, 19 Apr 2011 10:46:52 -0300 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

>> Your patch is correct.  I was thinking incorrectly about the :user nil
>> search case, which will DTRT as you said.  Sorry for
>> the... interjection.

SM> Good, thanks.  Feel free to install it, then,

I put it into Gnus; it will be synchronized with Emacs soon.

Thanks
Ted




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

* Re: nnimap-user setting?
  2011-04-22  0:38                 ` Ted Zlatanov
@ 2011-04-22 13:14                   ` Ted Zlatanov
  0 siblings, 0 replies; 11+ messages in thread
From: Ted Zlatanov @ 2011-04-22 13:14 UTC (permalink / raw)
  To: emacs-devel

On Thu, 21 Apr 2011 19:38:45 -0500 Ted Zlatanov <tzz@lifelogs.com> wrote: 

TZ> On Tue, 19 Apr 2011 10:46:52 -0300 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 
>>> Your patch is correct.  I was thinking incorrectly about the :user nil
>>> search case, which will DTRT as you said.  Sorry for
>>> the... interjection.

SM> Good, thanks.  Feel free to install it, then,

TZ> I put it into Gnus; it will be synchronized with Emacs soon.

I just realized I listed myself as the author accidentally.  It's a tiny
change so I'll assume you don't need me to adjust the ChangeLog and do
an extra commit, but let me know if otherwise please.

Ted




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

end of thread, other threads:[~2011-04-22 13:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-13 17:22 nnimap-user setting? Stefan Monnier
2011-04-14 15:05 ` Ted Zlatanov
2011-04-15 19:52   ` Stefan Monnier
2011-04-15 20:31     ` Ted Zlatanov
2011-04-16 15:14       ` Stefan Monnier
2011-04-16 15:27         ` Ted Zlatanov
2011-04-18 19:12           ` Stefan Monnier
2011-04-19 13:05             ` Ted Zlatanov
2011-04-19 13:46               ` Stefan Monnier
2011-04-22  0:38                 ` Ted Zlatanov
2011-04-22 13:14                   ` Ted Zlatanov

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