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));
76 strfcpy (account->user, url->user, sizeof (account->user));
77 account->flags |= M_ACCT_USER;
80 strfcpy (account->pass, url->pass, sizeof (account->pass));
81 account->flags |= M_ACCT_PASS;
84 account->port = url->port;
85 account->flags |= M_ACCT_PORT;
91 /* mutt_account_tourl: fill URL with info from account. The URL information
92 * is a set of pointers into account - don't free or edit account until
93 * you've finished with url (make a copy of account if you need it for
95 void mutt_account_tourl (ACCOUNT * account, ciss_url_t * url)
97 url->scheme = U_UNKNOWN;
103 if (account->type == M_ACCT_TYPE_IMAP) {
104 if (account->flags & M_ACCT_SSL)
105 url->scheme = U_IMAPS;
107 url->scheme = U_IMAP;
112 if (account->type == M_ACCT_TYPE_POP) {
113 if (account->flags & M_ACCT_SSL)
114 url->scheme = U_POPS;
121 if (account->type == M_ACCT_TYPE_NNTP) {
122 if (account->flags & M_ACCT_SSL)
123 url->scheme = U_NNTPS;
125 url->scheme = U_NNTP;
129 url->host = account->host;
130 if (account->flags & M_ACCT_PORT)
131 url->port = account->port;
132 if (account->flags & M_ACCT_USER)
133 url->user = account->user;
134 if (account->flags & M_ACCT_PASS)
135 url->pass = account->pass;
138 /* mutt_account_getuser: retrieve username into ACCOUNT, if neccessary */
139 int mutt_account_getuser (ACCOUNT * account)
141 char prompt[SHORT_STRING];
144 if (account->flags & M_ACCT_USER)
147 else if ((account->type == M_ACCT_TYPE_IMAP) && ImapUser)
148 strfcpy (account->user, ImapUser, sizeof (account->user));
151 else if ((account->type == M_ACCT_TYPE_POP) && PopUser)
152 strfcpy (account->user, PopUser, sizeof (account->user));
155 else if ((account->type == M_ACCT_TYPE_NNTP) && NntpUser)
156 strfcpy (account->user, NntpUser, sizeof (account->user));
158 /* prompt (defaults to unix username), copy into account->user */
160 snprintf (prompt, sizeof (prompt), _("Username at %s: "), account->host);
161 strfcpy (account->user, NONULL (Username), sizeof (account->user));
162 if (mutt_get_field (prompt, account->user, sizeof (account->user), 0))
166 account->flags |= M_ACCT_USER;
171 /* mutt_account_getpass: fetch password into ACCOUNT, if neccessary */
172 int mutt_account_getpass (ACCOUNT * account)
174 char prompt[SHORT_STRING];
176 if (account->flags & M_ACCT_PASS)
179 else if ((account->type == M_ACCT_TYPE_IMAP) && ImapPass)
180 strfcpy (account->pass, ImapPass, sizeof (account->pass));
183 else if ((account->type == M_ACCT_TYPE_POP) && PopPass)
184 strfcpy (account->pass, PopPass, sizeof (account->pass));
187 else if ((account->type == M_ACCT_TYPE_NNTP) && NntpPass)
188 strfcpy (account->pass, NntpPass, sizeof (account->pass));
191 snprintf (prompt, sizeof (prompt), _("Password for %s@%s: "),
192 account->user, account->host);
193 account->pass[0] = '\0';
194 if (mutt_get_password (prompt, account->pass, sizeof (account->pass)))
198 account->flags |= M_ACCT_PASS;
203 void mutt_account_unsetpass (ACCOUNT * account)
205 account->flags &= !M_ACCT_PASS;