2 * Copyright (C) 2000-7 Brendan Cully <brendan@kublai.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 /* remote host account manipulation (POP/IMAP) */
29 /* mutt_account_match: compare account info (host/port/user) */
30 int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* a2)
32 const char* user = NONULL (Username);
34 if (a1->type != a2->type)
36 if (ascii_strcasecmp (a1->host, a2->host))
38 if (a1->port != a2->port)
42 if (a1->type == M_ACCT_TYPE_IMAP)
50 if (a1->type == M_ACCT_TYPE_POP && PopUser)
54 if (a1->flags & a2->flags & M_ACCT_USER)
55 return (!strcmp (a1->user, a2->user));
56 if (a1->flags & M_ACCT_USER)
57 return (!strcmp (a1->user, user));
58 if (a2->flags & M_ACCT_USER)
59 return (!strcmp (a2->user, user));
64 /* mutt_account_fromurl: fill account with information from url. */
65 int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url)
69 strfcpy (account->host, url->host, sizeof (account->host));
75 strfcpy (account->user, url->user, sizeof (account->user));
76 account->flags |= M_ACCT_USER;
80 strfcpy (account->pass, url->pass, sizeof (account->pass));
81 account->flags |= M_ACCT_PASS;
85 account->port = url->port;
86 account->flags |= M_ACCT_PORT;
92 /* mutt_account_tourl: fill URL with info from account. The URL information
93 * is a set of pointers into account - don't free or edit account until
94 * you've finished with url (make a copy of account if you need it for
96 void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url)
98 url->scheme = U_UNKNOWN;
104 if (account->type == M_ACCT_TYPE_IMAP)
106 if (account->flags & M_ACCT_SSL)
107 url->scheme = U_IMAPS;
109 url->scheme = U_IMAP;
114 if (account->type == M_ACCT_TYPE_POP)
116 if (account->flags & M_ACCT_SSL)
117 url->scheme = U_POPS;
124 if (account->type == M_ACCT_TYPE_SMTP)
126 if (account->flags & M_ACCT_SSL)
127 url->scheme = U_SMTPS;
129 url->scheme = U_SMTP;
133 url->host = account->host;
134 if (account->flags & M_ACCT_PORT)
135 url->port = account->port;
136 if (account->flags & M_ACCT_USER)
137 url->user = account->user;
138 if (account->flags & M_ACCT_PASS)
139 url->pass = account->pass;
142 /* mutt_account_getuser: retrieve username into ACCOUNT, if necessary */
143 int mutt_account_getuser (ACCOUNT* account)
145 char prompt[SHORT_STRING];
148 if (account->flags & M_ACCT_USER)
151 else if ((account->type == M_ACCT_TYPE_IMAP) && ImapUser)
152 strfcpy (account->user, ImapUser, sizeof (account->user));
155 else if ((account->type == M_ACCT_TYPE_POP) && PopUser)
156 strfcpy (account->user, PopUser, sizeof (account->user));
158 else if (option (OPTNOCURSES))
160 /* prompt (defaults to unix username), copy into account->user */
163 snprintf (prompt, sizeof (prompt), _("Username at %s: "), account->host);
164 strfcpy (account->user, NONULL (Username), sizeof (account->user));
165 if (mutt_get_field_unbuffered (prompt, account->user, sizeof (account->user), 0))
169 account->flags |= M_ACCT_USER;
174 int mutt_account_getlogin (ACCOUNT* account)
177 if (account->flags & M_ACCT_LOGIN)
180 else if (account->type == M_ACCT_TYPE_IMAP)
184 strfcpy (account->login, ImapLogin, sizeof (account->login));
185 account->flags |= M_ACCT_LOGIN;
190 if (!(account->flags & M_ACCT_LOGIN))
192 mutt_account_getuser (account);
193 strfcpy (account->login, account->user, sizeof (account->login));
196 account->flags |= M_ACCT_LOGIN;
201 /* mutt_account_getpass: fetch password into ACCOUNT, if necessary */
202 int mutt_account_getpass (ACCOUNT* account)
204 char prompt[SHORT_STRING];
206 if (account->flags & M_ACCT_PASS)
209 else if ((account->type == M_ACCT_TYPE_IMAP) && ImapPass)
210 strfcpy (account->pass, ImapPass, sizeof (account->pass));
213 else if ((account->type == M_ACCT_TYPE_POP) && PopPass)
214 strfcpy (account->pass, PopPass, sizeof (account->pass));
217 else if ((account->type == M_ACCT_TYPE_SMTP) && SmtpPass)
218 strfcpy (account->pass, SmtpPass, sizeof (account->pass));
220 else if (option (OPTNOCURSES))
224 snprintf (prompt, sizeof (prompt), _("Password for %s@%s: "),
225 account->flags & M_ACCT_LOGIN ? account->login : account->user,
227 account->pass[0] = '\0';
228 if (mutt_get_password (prompt, account->pass, sizeof (account->pass)))
232 account->flags |= M_ACCT_PASS;
237 void mutt_account_unsetpass (ACCOUNT* account)
239 account->flags &= ~M_ACCT_PASS;