2 * Copyright notice from original mutt:
3 * Copyright (C) 2000-3 Brendan Cully <brendan@kublai.com>
5 * This file is part of mutt-ng, see http://www.muttng.org/.
6 * It's licensed under the GNU General Public License,
7 * please see the file GPL in the top level source directory.
10 /* remote host account manipulation (POP/IMAP) */
24 /* mutt_account_match: compare account info (host/port/user) */
25 int mutt_account_match (const ACCOUNT * a1, const ACCOUNT * a2)
27 const char *user = NONULL (Username);
29 if (a1->type != a2->type)
31 if (ascii_strcasecmp (a1->host, a2->host))
33 if (a1->port != a2->port)
37 if (a1->type == M_ACCT_TYPE_IMAP && ImapUser)
42 if (a1->type == M_ACCT_TYPE_POP && PopUser)
47 if (a1->type == M_ACCT_TYPE_NNTP && NntpUser)
51 if (a1->flags & a2->flags & M_ACCT_USER)
52 return (!safe_strcmp (a1->user, a2->user));
53 if (a1->flags & M_ACCT_USER)
54 return (!safe_strcmp (a1->user, user));
55 if (a2->flags & M_ACCT_USER)
56 return (!safe_strcmp (a2->user, user));
61 /* mutt_account_fromurl: fill account with information from url. */
62 int mutt_account_fromurl (ACCOUNT * account, ciss_url_t * url)
66 strfcpy (account->host, url->host, sizeof (account->host));
71 strfcpy (account->user, url->user, sizeof (account->user));
72 account->flags |= M_ACCT_USER;
75 strfcpy (account->pass, url->pass, sizeof (account->pass));
76 account->flags |= M_ACCT_PASS;
79 account->port = url->port;
80 account->flags |= M_ACCT_PORT;
86 /* mutt_account_tourl: fill URL with info from account. The URL information
87 * is a set of pointers into account - don't free or edit account until
88 * you've finished with url (make a copy of account if you need it for
90 void mutt_account_tourl (ACCOUNT * account, ciss_url_t * url)
92 url->scheme = U_UNKNOWN;
98 if (account->type == M_ACCT_TYPE_IMAP) {
99 if (account->flags & M_ACCT_SSL)
100 url->scheme = U_IMAPS;
102 url->scheme = U_IMAP;
107 if (account->type == M_ACCT_TYPE_POP) {
108 if (account->flags & M_ACCT_SSL)
109 url->scheme = U_POPS;
116 if (account->type == M_ACCT_TYPE_NNTP) {
117 if (account->flags & M_ACCT_SSL)
118 url->scheme = U_NNTPS;
120 url->scheme = U_NNTP;
124 url->host = account->host;
125 if (account->flags & M_ACCT_PORT)
126 url->port = account->port;
127 if (account->flags & M_ACCT_USER)
128 url->user = account->user;
129 if (account->flags & M_ACCT_PASS)
130 url->pass = account->pass;
133 /* mutt_account_getuser: retrieve username into ACCOUNT, if neccessary */
134 int mutt_account_getuser (ACCOUNT * account)
136 char prompt[SHORT_STRING];
139 if (account->flags & M_ACCT_USER)
142 else if ((account->type == M_ACCT_TYPE_IMAP) && ImapUser)
143 strfcpy (account->user, ImapUser, sizeof (account->user));
146 else if ((account->type == M_ACCT_TYPE_POP) && PopUser)
147 strfcpy (account->user, PopUser, sizeof (account->user));
150 else if ((account->type == M_ACCT_TYPE_NNTP) && NntpUser)
151 strfcpy (account->user, NntpUser, sizeof (account->user));
153 /* prompt (defaults to unix username), copy into account->user */
155 snprintf (prompt, sizeof (prompt), _("Username at %s: "), account->host);
156 strfcpy (account->user, NONULL (Username), sizeof (account->user));
157 if (mutt_get_field (prompt, account->user, sizeof (account->user), 0))
161 account->flags |= M_ACCT_USER;
166 /* mutt_account_getpass: fetch password into ACCOUNT, if neccessary */
167 int mutt_account_getpass (ACCOUNT * account)
169 char prompt[SHORT_STRING];
171 if (account->flags & M_ACCT_PASS)
174 else if ((account->type == M_ACCT_TYPE_IMAP) && ImapPass)
175 strfcpy (account->pass, ImapPass, sizeof (account->pass));
178 else if ((account->type == M_ACCT_TYPE_POP) && PopPass)
179 strfcpy (account->pass, PopPass, sizeof (account->pass));
182 else if ((account->type == M_ACCT_TYPE_NNTP) && NntpPass)
183 strfcpy (account->pass, NntpPass, sizeof (account->pass));
186 snprintf (prompt, sizeof (prompt), _("Password for %s@%s: "),
187 account->user, account->host);
188 account->pass[0] = '\0';
189 if (mutt_get_password (prompt, account->pass, sizeof (account->pass)))
193 account->flags |= M_ACCT_PASS;
198 void mutt_account_unsetpass (ACCOUNT * account)
200 account->flags &= !M_ACCT_PASS;