Commit b23e7608 authored by Brendan Cully's avatar Brendan Cully

Add $imap_login variable to specify which user to authenticate as

($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).
parent 5b2eacd3
/*
* 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
......@@ -26,10 +26,11 @@
#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;
......
/*
* 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);
......
......@@ -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
......
......@@ -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.
*/
......
......@@ -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))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment