2 * Copyright notice from original mutt:
3 * Copyright (C) 2000-5 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/login) */
25 int mutt_account_match (const ACCOUNT * a1, const ACCOUNT * a2)
27 const char* user = NONULL (Username);
28 const char* login = NONULL (Username);
30 if (a1->type != a2->type)
32 if (ascii_strcasecmp (a1->host, a2->host))
34 if (a1->port != a2->port)
38 if (a1->type == M_ACCT_TYPE_IMAP) {
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 (!mutt_strcmp (a1->user, a2->user));
58 if (a1->flags & M_ACCT_USER)
59 return (!mutt_strcmp (a1->user, user));
60 if (a2->flags & M_ACCT_USER)
61 return (!mutt_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 necessary */
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 int mutt_account_getlogin (ACCOUNT* account)
174 if (account->flags & M_ACCT_LOGIN)
177 else if (account->type == M_ACCT_TYPE_IMAP)
180 strfcpy (account->login, ImapLogin, sizeof (account->login));
182 mutt_account_getuser (account);
183 strfcpy (account->login, account->user, sizeof (account->login));
188 account->flags |= M_ACCT_LOGIN;
193 /* mutt_account_getpass: fetch password into ACCOUNT, if neccessary */
194 int mutt_account_getpass (ACCOUNT * account)
196 char prompt[SHORT_STRING];
198 if (account->flags & M_ACCT_PASS)
201 else if ((account->type == M_ACCT_TYPE_IMAP) && ImapPass)
202 strfcpy (account->pass, ImapPass, sizeof (account->pass));
205 else if ((account->type == M_ACCT_TYPE_POP) && PopPass)
206 strfcpy (account->pass, PopPass, sizeof (account->pass));
209 else if ((account->type == M_ACCT_TYPE_NNTP) && NntpPass)
210 strfcpy (account->pass, NntpPass, sizeof (account->pass));
213 snprintf (prompt, sizeof (prompt), _("Password for %s@%s: "),
214 account->login, account->host);
215 account->pass[0] = '\0';
216 if (mutt_get_password (prompt, account->pass, sizeof (account->pass)))
220 account->flags |= M_ACCT_PASS;
225 void mutt_account_unsetpass (ACCOUNT * account)
227 account->flags &= !M_ACCT_PASS;