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/login) */
30 int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* a2)
32 const char* user = NONULL (Username);
33 const char* login = NONULL (Username);
35 if (a1->type != a2->type)
37 if (ascii_strcasecmp (a1->host, a2->host))
39 if (a1->port != a2->port)
43 if (a1->type == M_ACCT_TYPE_IMAP)
53 if (a1->type == M_ACCT_TYPE_POP && PopUser)
57 if (a1->flags & a2->flags & M_ACCT_USER)
58 return (!strcmp (a1->user, a2->user));
59 if (a1->flags & M_ACCT_USER)
60 return (!strcmp (a1->user, user));
61 if (a2->flags & M_ACCT_USER)
62 return (!strcmp (a2->user, user));
67 /* mutt_account_fromurl: fill account with information from url. */
68 int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url)
72 strfcpy (account->host, url->host, sizeof (account->host));
78 strfcpy (account->user, url->user, sizeof (account->user));
79 account->flags |= M_ACCT_USER;
83 strfcpy (account->pass, url->pass, sizeof (account->pass));
84 account->flags |= M_ACCT_PASS;
88 account->port = url->port;
89 account->flags |= M_ACCT_PORT;
95 /* mutt_account_tourl: fill URL with info from account. The URL information
96 * is a set of pointers into account - don't free or edit account until
97 * you've finished with url (make a copy of account if you need it for
99 void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url)
101 url->scheme = U_UNKNOWN;
107 if (account->type == M_ACCT_TYPE_IMAP)
109 if (account->flags & M_ACCT_SSL)
110 url->scheme = U_IMAPS;
112 url->scheme = U_IMAP;
117 if (account->type == M_ACCT_TYPE_POP)
119 if (account->flags & M_ACCT_SSL)
120 url->scheme = U_POPS;
127 if (account->type == M_ACCT_TYPE_SMTP)
129 if (account->flags & M_ACCT_SSL)
130 url->scheme = U_SMTPS;
132 url->scheme = U_SMTP;
136 url->host = account->host;
137 if (account->flags & M_ACCT_PORT)
138 url->port = account->port;
139 if (account->flags & M_ACCT_USER)
140 url->user = account->user;
141 if (account->flags & M_ACCT_PASS)
142 url->pass = account->pass;
145 /* mutt_account_getuser: retrieve username into ACCOUNT, if necessary */
146 int mutt_account_getuser (ACCOUNT* account)
148 char prompt[SHORT_STRING];
151 if (account->flags & M_ACCT_USER)
154 else if ((account->type == M_ACCT_TYPE_IMAP) && ImapUser)
155 strfcpy (account->user, ImapUser, sizeof (account->user));
158 else if ((account->type == M_ACCT_TYPE_POP) && PopUser)
159 strfcpy (account->user, PopUser, sizeof (account->user));
161 /* prompt (defaults to unix username), copy into account->user */
164 snprintf (prompt, sizeof (prompt), _("Username at %s: "), account->host);
165 strfcpy (account->user, NONULL (Username), sizeof (account->user));
166 if (mutt_get_field_unbuffered (prompt, account->user, sizeof (account->user), 0))
170 account->flags |= M_ACCT_USER;
175 int mutt_account_getlogin (ACCOUNT* account)
178 if (account->flags & M_ACCT_LOGIN)
181 else if (account->type == M_ACCT_TYPE_IMAP)
185 strfcpy (account->login, ImapLogin, sizeof (account->login));
186 account->flags |= M_ACCT_LOGIN;
191 if (!(account->flags & M_ACCT_LOGIN))
193 mutt_account_getuser (account);
194 strfcpy (account->login, account->user, sizeof (account->login));
197 account->flags |= M_ACCT_LOGIN;
202 /* mutt_account_getpass: fetch password into ACCOUNT, if necessary */
203 int mutt_account_getpass (ACCOUNT* account)
205 char prompt[SHORT_STRING];
207 if (account->flags & M_ACCT_PASS)
210 else if ((account->type == M_ACCT_TYPE_IMAP) && ImapPass)
211 strfcpy (account->pass, ImapPass, sizeof (account->pass));
214 else if ((account->type == M_ACCT_TYPE_POP) && PopPass)
215 strfcpy (account->pass, PopPass, sizeof (account->pass));
218 else if ((account->type == M_ACCT_TYPE_SMTP) && SmtpPass)
219 strfcpy (account->pass, SmtpPass, sizeof (account->pass));
223 snprintf (prompt, sizeof (prompt), _("Password for %s@%s: "),
224 account->flags & M_ACCT_LOGIN ? account->login : account->user,
226 account->pass[0] = '\0';
227 if (mutt_get_password (prompt, account->pass, sizeof (account->pass)))
231 account->flags |= M_ACCT_PASS;
236 void mutt_account_unsetpass (ACCOUNT* account)
238 account->flags &= ~M_ACCT_PASS;