2 * Copyright (C) 2000-3 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., 59 Temple Place - Suite 330, Boston, MA 02111, 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 && ImapUser)
47 if (a1->type == M_ACCT_TYPE_POP && PopUser)
52 if (a1->type == M_ACCT_TYPE_NNTP && NntpUser)
56 if (a1->flags & a2->flags & M_ACCT_USER)
57 return (!strcmp (a1->user, a2->user));
58 if (a1->flags & M_ACCT_USER)
59 return (!strcmp (a1->user, user));
60 if (a2->flags & M_ACCT_USER)
61 return (!strcmp (a2->user, user));
66 /* mutt_account_fromurl: fill account with information from url. */
67 int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url)
71 strfcpy (account->host, url->host, sizeof (account->host));
77 strfcpy (account->user, url->user, sizeof (account->user));
78 account->flags |= M_ACCT_USER;
82 strfcpy (account->pass, url->pass, sizeof (account->pass));
83 account->flags |= M_ACCT_PASS;
87 account->port = url->port;
88 account->flags |= M_ACCT_PORT;
94 /* mutt_account_tourl: fill URL with info from account. The URL information
95 * is a set of pointers into account - don't free or edit account until
96 * you've finished with url (make a copy of account if you need it for
98 void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url)
100 url->scheme = U_UNKNOWN;
106 if (account->type == M_ACCT_TYPE_IMAP)
108 if (account->flags & M_ACCT_SSL)
109 url->scheme = U_IMAPS;
111 url->scheme = U_IMAP;
116 if (account->type == M_ACCT_TYPE_POP)
118 if (account->flags & M_ACCT_SSL)
119 url->scheme = U_POPS;
126 if (account->type == M_ACCT_TYPE_NNTP)
128 if (account->flags & M_ACCT_SSL)
129 url->scheme = U_NNTPS;
131 url->scheme = U_NNTP;
135 url->host = account->host;
136 if (account->flags & M_ACCT_PORT)
137 url->port = account->port;
138 if (account->flags & M_ACCT_USER)
139 url->user = account->user;
140 if (account->flags & M_ACCT_PASS)
141 url->pass = account->pass;
144 /* mutt_account_getuser: retrieve username into ACCOUNT, if neccessary */
145 int mutt_account_getuser (ACCOUNT* account)
147 char prompt[SHORT_STRING];
150 if (account->flags & M_ACCT_USER)
153 else if ((account->type == M_ACCT_TYPE_IMAP) && ImapUser)
154 strfcpy (account->user, ImapUser, sizeof (account->user));
157 else if ((account->type == M_ACCT_TYPE_POP) && PopUser)
158 strfcpy (account->user, PopUser, sizeof (account->user));
161 else if ((account->type == M_ACCT_TYPE_NNTP) && NntpUser)
162 strfcpy (account->user, NntpUser, sizeof (account->user));
164 /* prompt (defaults to unix username), copy into account->user */
167 snprintf (prompt, sizeof (prompt), _("Username at %s: "), account->host);
168 strfcpy (account->user, NONULL (Username), sizeof (account->user));
169 if (mutt_get_field (prompt, account->user, sizeof (account->user), 0))
173 account->flags |= M_ACCT_USER;
178 /* mutt_account_getpass: fetch password into ACCOUNT, if neccessary */
179 int mutt_account_getpass (ACCOUNT* account)
181 char prompt[SHORT_STRING];
183 if (account->flags & M_ACCT_PASS)
186 else if ((account->type == M_ACCT_TYPE_IMAP) && ImapPass)
187 strfcpy (account->pass, ImapPass, sizeof (account->pass));
190 else if ((account->type == M_ACCT_TYPE_POP) && PopPass)
191 strfcpy (account->pass, PopPass, sizeof (account->pass));
194 else if ((account->type == M_ACCT_TYPE_NNTP) && NntpPass)
195 strfcpy (account->pass, NntpPass, sizeof (account->pass));
199 snprintf (prompt, sizeof (prompt), _("Password for %s@%s: "),
200 account->user, account->host);
201 account->pass[0] = '\0';
202 if (mutt_get_password (prompt, account->pass, sizeof (account->pass)))
206 account->flags |= M_ACCT_PASS;
211 void mutt_account_unsetpass (ACCOUNT* account)
213 account->flags &= !M_ACCT_PASS;