]> granicus.if.org Git - neomutt/commitdiff
Add $imap_login variable to specify which user to authenticate as
authorBrendan Cully <brendan@kublai.com>
Tue, 28 Jun 2005 19:26:54 +0000 (19:26 +0000)
committerBrendan Cully <brendan@kublai.com>
Tue, 28 Jun 2005 19:26:54 +0000 (19:26 +0000)
($imap_user controls which user's mail gets accessed). Currently
this can't be specified interactively, since I can't think of a way
to do it that wouldn't annoy users where login == user (the default
value of $imap_login).

account.c
account.h
globals.h
init.h
mutt_sasl.c

index 4a7493ff73a2f117f58aca1b755bc54433ed415f..3b4a4fa97009658a2d44e1e183462ecbdaca0b1a 100644 (file)
--- a/account.c
+++ b/account.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2000-3 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 2000-5 Brendan Cully <brendan@kublai.com>
  * 
  *     This program is free software; you can redistribute it and/or modify
  *     it under the terms of the GNU General Public License as published by
 #include "account.h"
 #include "url.h"
 
-/* mutt_account_match: compare account info (host/port/user) */
+/* mutt_account_match: compare account info (host/port/user/login) */
 int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* a2)
 {
   const char* user = NONULL (Username);
+  const char* login = NONULL (Username);
 
   if (a1->type != a2->type)
     return 0;
@@ -39,8 +40,13 @@ int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* a2)
     return 0;
 
 #ifdef USE_IMAP
-  if (a1->type == M_ACCT_TYPE_IMAP && ImapUser)
-    user = ImapUser;
+  if (a1->type == M_ACCT_TYPE_IMAP)
+  {
+    if (ImapUser)
+      user = ImapUser;
+    if (ImapLogin)
+      login = ImapLogin;
+  }
 #endif
 
 #ifdef USE_POP
@@ -126,7 +132,7 @@ void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url)
     url->pass = account->pass;
 }
 
-/* mutt_account_getuser: retrieve username into ACCOUNT, if neccessary */
+/* mutt_account_getuser: retrieve username into ACCOUNT, if necessary */
 int mutt_account_getuser (ACCOUNT* account)
 {
   char prompt[SHORT_STRING];
@@ -156,7 +162,27 @@ int mutt_account_getuser (ACCOUNT* account)
   return 0;
 }
 
-/* mutt_account_getpass: fetch password into ACCOUNT, if neccessary */
+int mutt_account_getlogin (ACCOUNT* account)
+{
+  /* already set */
+  if (account->flags & M_ACCT_LOGIN)
+    return 0;
+#ifdef USE_IMAP
+  else if (account->type == M_ACCT_TYPE_IMAP)
+  {
+    if (ImapLogin)
+      strfcpy (account->login, ImapLogin, sizeof (account->login));
+    else
+      strfcpy (account->login, ImapUser, sizeof (account->login));
+  }
+#endif
+
+  account->flags |= M_ACCT_LOGIN;
+
+  return 0;
+}
+
+/* mutt_account_getpass: fetch password into ACCOUNT, if necessary */
 int mutt_account_getpass (ACCOUNT* account)
 {
   char prompt[SHORT_STRING];
@@ -174,7 +200,7 @@ int mutt_account_getpass (ACCOUNT* account)
   else
   {
     snprintf (prompt, sizeof (prompt), _("Password for %s@%s: "),
-      account->user, account->host);
+      account->login, account->host);
     account->pass[0] = '\0';
     if (mutt_get_password (prompt, account->pass, sizeof (account->pass)))
       return -1;
index 145e5145d757c40554a4f92d286240bb462777d1..e9fac082cfca3d9ecd2cb0ff3cb3c52f731d00fa 100644 (file)
--- a/account.h
+++ b/account.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2000-3 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 2000-5 Brendan Cully <brendan@kublai.com>
  * 
  *     This program is free software; you can redistribute it and/or modify
  *     it under the terms of the GNU General Public License as published by
@@ -32,14 +32,16 @@ enum
 };
 
 /* account flags */
-#define M_ACCT_PORT (1<<0)
-#define M_ACCT_USER (1<<1)
-#define M_ACCT_PASS (1<<2)
-#define M_ACCT_SSL  (1<<3)
+#define M_ACCT_PORT  (1<<0)
+#define M_ACCT_USER  (1<<1)
+#define M_ACCT_LOGIN (1<<2)
+#define M_ACCT_PASS  (1<<3)
+#define M_ACCT_SSL   (1<<4)
 
 typedef struct
 {
   char user[64];
+  char login[64];
   char pass[64];
   char host[128];
   unsigned short port;
@@ -51,6 +53,7 @@ int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* m2);
 int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url);
 void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url);
 int mutt_account_getuser (ACCOUNT* account);
+int mutt_account_getlogin (ACCOUNT* account);
 int mutt_account_getpass (ACCOUNT* account);
 void mutt_account_unsetpass (ACCOUNT* account);
 
index 03c7d241fee0f50b2b08f35e7c46a5a41cb4d909..1e570d314227a4e76645b5ac0fa55843e081bd54 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -57,6 +57,7 @@ WHERE char *ImapAuthenticators INITVAL (NULL);
 WHERE char *ImapDelimChars INITVAL (NULL);
 WHERE char *ImapHeaders;
 WHERE char *ImapHomeNamespace INITVAL (NULL);
+WHERE char *ImapLogin INITVAL (NULL);
 WHERE char *ImapPass INITVAL (NULL);
 WHERE char *ImapUser INITVAL (NULL);
 #endif
diff --git a/init.h b/init.h
index 13d04eac65a80b192474f535f6a92777043154e8..66ca068dcf325f86a09ca32d108629ba4228f9be 100644 (file)
--- a/init.h
+++ b/init.h
@@ -851,6 +851,13 @@ struct option_t MuttVars[] = {
   ** only subscribed folders or all folders.  This can be toggled in the
   ** IMAP browser with the \fItoggle-subscribed\fP function.
   */
+  { "imap_login",      DT_STR,  R_NONE, UL &ImapLogin, UL 0 },
+  /*
+  ** .pp
+  ** Your login name on the IMAP server.
+  ** .pp
+  ** This variable defaults to the value of \fIimap_user\fP.
+  */
   { "imap_pass",       DT_STR,  R_NONE, UL &ImapPass, UL 0 },
   /*
   ** .pp
@@ -889,7 +896,8 @@ struct option_t MuttVars[] = {
   { "imap_user",       DT_STR,  R_NONE, UL &ImapUser, UL 0 },
   /*
   ** .pp
-  ** Your login name on the IMAP server.
+  ** The name of the user whose mail you intend to access on the IMAP
+  ** server.
   ** .pp
   ** This variable defaults to your user name on the local machine.
   */
index 435b4bd8be661bc205bf22b86d699e4b544c7e90..cd5c1aa9e558aa64b9e4b126db4356e71ddd5b23 100644 (file)
@@ -334,12 +334,12 @@ sasl_callback_t* mutt_sasl_get_callbacks (ACCOUNT* account)
 
   callback = mutt_sasl_callbacks;
 
-  callback->id = SASL_CB_AUTHNAME;
+  callback->id = SASL_CB_USER;
   callback->proc = mutt_sasl_cb_authname;
   callback->context = account;
   callback++;
 
-  callback->id = SASL_CB_USER;
+  callback->id = SASL_CB_AUTHNAME;
   callback->proc = mutt_sasl_cb_authname;
   callback->context = account;
   callback++;
@@ -450,8 +450,7 @@ static int mutt_sasl_cb_log (void* context, int priority, const char* message)
   return SASL_OK;
 }
 
-/* mutt_sasl_cb_authname: callback to retrieve authname or user (mutt
- *   doesn't distinguish, even if some SASL plugins do) from ACCOUNT */
+/* mutt_sasl_cb_authname: callback to retrieve authname or user from ACCOUNT */
 static int mutt_sasl_cb_authname (void* context, int id, const char** result,
   unsigned* len)
 {
@@ -468,11 +467,19 @@ static int mutt_sasl_cb_authname (void* context, int id, const char** result,
              id == SASL_CB_AUTHNAME ? "authname" : "user",
              account->host, account->port));
 
-  if (mutt_account_getuser (account))
-    return SASL_FAIL;
-
-  *result = account->user;
-
+  if (id == SASL_CB_AUTHNAME)
+  {
+    if (mutt_account_getlogin (account))
+      return SASL_FAIL;
+    *result = account->login;
+  }
+  else
+  {
+    if (mutt_account_getuser (account))
+      return SASL_FAIL;
+    *result = account->user;
+  }
+  
   if (len)
     *len = strlen (*result);
 
@@ -489,7 +496,7 @@ static int mutt_sasl_cb_pass (sasl_conn_t* conn, void* context, int id,
     return SASL_BADPARAM;
 
   dprint (2, (debugfile,
-    "mutt_sasl_cb_pass: getting password for %s@%s:%u\n", account->user,
+    "mutt_sasl_cb_pass: getting password for %s@%s:%u\n", account->login,
     account->host, account->port));
 
   if (mutt_account_getpass (account))