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) */
20 /* mutt_account_match: compare account info (host/port/user) */
21 int mutt_account_match (const ACCOUNT * a1, const ACCOUNT * a2)
23 const char *user = NONULL (Username);
25 if (a1->type != a2->type)
27 if (ascii_strcasecmp (a1->host, a2->host))
29 if (a1->port != a2->port)
33 if (a1->type == M_ACCT_TYPE_IMAP && ImapUser)
38 if (a1->type == M_ACCT_TYPE_POP && PopUser)
43 if (a1->type == M_ACCT_TYPE_NNTP && NntpUser)
47 if (a1->flags & a2->flags & M_ACCT_USER)
48 return (!strcmp (a1->user, a2->user));
49 if (a1->flags & M_ACCT_USER)
50 return (!strcmp (a1->user, user));
51 if (a2->flags & M_ACCT_USER)
52 return (!strcmp (a2->user, user));
57 /* mutt_account_fromurl: fill account with information from url. */
58 int mutt_account_fromurl (ACCOUNT * account, ciss_url_t * url)
62 strfcpy (account->host, url->host, sizeof (account->host));
67 strfcpy (account->user, url->user, sizeof (account->user));
68 account->flags |= M_ACCT_USER;
71 strfcpy (account->pass, url->pass, sizeof (account->pass));
72 account->flags |= M_ACCT_PASS;
75 account->port = url->port;
76 account->flags |= M_ACCT_PORT;
82 /* mutt_account_tourl: fill URL with info from account. The URL information
83 * is a set of pointers into account - don't free or edit account until
84 * you've finished with url (make a copy of account if you need it for
86 void mutt_account_tourl (ACCOUNT * account, ciss_url_t * url)
88 url->scheme = U_UNKNOWN;
94 if (account->type == M_ACCT_TYPE_IMAP) {
95 if (account->flags & M_ACCT_SSL)
96 url->scheme = U_IMAPS;
103 if (account->type == M_ACCT_TYPE_POP) {
104 if (account->flags & M_ACCT_SSL)
105 url->scheme = U_POPS;
112 if (account->type == M_ACCT_TYPE_NNTP) {
113 if (account->flags & M_ACCT_SSL)
114 url->scheme = U_NNTPS;
116 url->scheme = U_NNTP;
120 url->host = account->host;
121 if (account->flags & M_ACCT_PORT)
122 url->port = account->port;
123 if (account->flags & M_ACCT_USER)
124 url->user = account->user;
125 if (account->flags & M_ACCT_PASS)
126 url->pass = account->pass;
129 /* mutt_account_getuser: retrieve username into ACCOUNT, if neccessary */
130 int mutt_account_getuser (ACCOUNT * account)
132 char prompt[SHORT_STRING];
135 if (account->flags & M_ACCT_USER)
138 else if ((account->type == M_ACCT_TYPE_IMAP) && ImapUser)
139 strfcpy (account->user, ImapUser, sizeof (account->user));
142 else if ((account->type == M_ACCT_TYPE_POP) && PopUser)
143 strfcpy (account->user, PopUser, sizeof (account->user));
146 else if ((account->type == M_ACCT_TYPE_NNTP) && NntpUser)
147 strfcpy (account->user, NntpUser, sizeof (account->user));
149 /* prompt (defaults to unix username), copy into account->user */
151 snprintf (prompt, sizeof (prompt), _("Username at %s: "), account->host);
152 strfcpy (account->user, NONULL (Username), sizeof (account->user));
153 if (mutt_get_field (prompt, account->user, sizeof (account->user), 0))
157 account->flags |= M_ACCT_USER;
162 /* mutt_account_getpass: fetch password into ACCOUNT, if neccessary */
163 int mutt_account_getpass (ACCOUNT * account)
165 char prompt[SHORT_STRING];
167 if (account->flags & M_ACCT_PASS)
170 else if ((account->type == M_ACCT_TYPE_IMAP) && ImapPass)
171 strfcpy (account->pass, ImapPass, sizeof (account->pass));
174 else if ((account->type == M_ACCT_TYPE_POP) && PopPass)
175 strfcpy (account->pass, PopPass, sizeof (account->pass));
178 else if ((account->type == M_ACCT_TYPE_NNTP) && NntpPass)
179 strfcpy (account->pass, NntpPass, sizeof (account->pass));
182 snprintf (prompt, sizeof (prompt), _("Password for %s@%s: "),
183 account->user, account->host);
184 account->pass[0] = '\0';
185 if (mutt_get_password (prompt, account->pass, sizeof (account->pass)))
189 account->flags |= M_ACCT_PASS;
194 void mutt_account_unsetpass (ACCOUNT * account)
196 account->flags &= !M_ACCT_PASS;