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) */
12 #include <lib-lib/lib-lib.h>
13 #include <lib-ui/enter.h>
18 /* mutt_account_match: compare account info (host/port/user/login) */
19 int mutt_account_match (const ACCOUNT * a1, const ACCOUNT * a2)
21 const char* user = NONULL (Username);
22 const char* login = NONULL (Username);
24 if (a1->type != a2->type)
26 if (ascii_strcasecmp (a1->host, a2->host))
28 if (a1->port != a2->port)
31 if (a1->type == M_ACCT_TYPE_IMAP) {
32 if (ImapUser && (ImapUser[0] != '\0'))
34 if (ImapLogin && (ImapLogin[0] != '\0'))
38 if (a1->type == M_ACCT_TYPE_POP && PopUser)
42 if (a1->type == M_ACCT_TYPE_NNTP && NntpUser)
46 if (a1->flags & a2->flags & M_ACCT_USER)
47 return (!m_strcmp(a1->user, a2->user));
48 if (a1->flags & M_ACCT_USER)
49 return (!m_strcmp(a1->user, user));
50 if (a2->flags & M_ACCT_USER)
51 return (!m_strcmp(a2->user, user));
56 /* mutt_account_fromurl: fill account with information from url. */
57 int mutt_account_fromurl(ACCOUNT *account, ciss_url_t *url)
62 m_strcpy(account->host, sizeof(account->host), url->host);
65 m_strcpy(account->user, sizeof(account->user), url->user);
66 account->flags |= M_ACCT_USER;
69 m_strcpy(account->pass, sizeof(account->pass), url->pass);
70 account->flags |= M_ACCT_PASS;
73 account->port = url->port;
74 account->flags |= M_ACCT_PORT;
80 /* mutt_account_tourl: fill URL with info from account. The URL information
81 * is a set of pointers into account - don't free or edit account until
82 * you've finished with url (make a copy of account if you need it for
84 void mutt_account_tourl (ACCOUNT * account, ciss_url_t * url)
86 url->scheme = U_UNKNOWN;
91 if (account->type == M_ACCT_TYPE_IMAP) {
92 if (account->flags & M_ACCT_SSL)
93 url->scheme = U_IMAPS;
98 if (account->type == M_ACCT_TYPE_POP) {
99 if (account->flags & M_ACCT_SSL)
100 url->scheme = U_POPS;
106 if (account->type == M_ACCT_TYPE_NNTP) {
107 if (account->flags & M_ACCT_SSL)
108 url->scheme = U_NNTPS;
110 url->scheme = U_NNTP;
114 url->host = account->host;
115 if (account->flags & M_ACCT_PORT)
116 url->port = account->port;
117 if (account->flags & M_ACCT_USER)
118 url->user = account->user;
119 if (account->flags & M_ACCT_PASS)
120 url->pass = account->pass;
123 /* mutt_account_getuser: retrieve username into ACCOUNT, if necessary */
124 int mutt_account_getuser (ACCOUNT * account)
126 char prompt[SHORT_STRING];
129 if (account->flags & M_ACCT_USER)
131 else if ((account->type == M_ACCT_TYPE_IMAP) && !m_strisempty(ImapUser))
132 m_strcpy(account->user, sizeof(account->user), ImapUser);
133 else if ((account->type == M_ACCT_TYPE_POP) && !m_strisempty(PopUser))
134 m_strcpy(account->user, sizeof(account->user), PopUser);
136 else if ((account->type == M_ACCT_TYPE_NNTP) && !m_strisempty(NntpUser))
137 m_strcpy(account->user, sizeof(account->user), NntpUser);
139 /* prompt (defaults to unix username), copy into account->user */
141 snprintf(prompt, sizeof(prompt), _("Username at %s: "), account->host);
142 m_strcpy(account->user, sizeof(account->user), NONULL(Username));
143 if (mutt_get_field_unbuffered(prompt, account->user,
144 sizeof(account->user), 0))
148 account->flags |= M_ACCT_USER;
153 int mutt_account_getlogin (ACCOUNT* account)
156 if (account->flags & M_ACCT_LOGIN)
158 else if (account->type == M_ACCT_TYPE_IMAP)
160 if (!m_strisempty(ImapLogin)) {
161 m_strcpy(account->login, sizeof(account->login), ImapLogin);
162 account->flags |= M_ACCT_LOGIN;
166 if (!(account->flags & M_ACCT_LOGIN)) {
167 mutt_account_getuser (account);
168 m_strcpy(account->login, sizeof(account->login), account->user);
171 account->flags |= M_ACCT_LOGIN;
176 /* mutt_account_getpass: fetch password into ACCOUNT, if neccessary */
177 int mutt_account_getpass (ACCOUNT * account)
179 char prompt[SHORT_STRING];
181 if (account->flags & M_ACCT_PASS)
183 else if ((account->type == M_ACCT_TYPE_IMAP) && !m_strisempty(ImapPass))
184 m_strcpy(account->pass, sizeof(account->pass), ImapPass);
185 else if ((account->type == M_ACCT_TYPE_POP) && !m_strisempty(PopPass))
186 m_strcpy(account->pass, sizeof(account->pass), PopPass);
188 else if ((account->type == M_ACCT_TYPE_NNTP) && !m_strisempty(NntpPass))
189 m_strcpy(account->pass, sizeof(account->pass), NntpPass);
192 snprintf(prompt, sizeof(prompt), _("Password for %s@%s: "),
193 account->flags & M_ACCT_LOGIN ? account->login : account->user,
195 account->pass[0] = '\0';
196 if (mutt_get_field_unbuffered(prompt, account->pass,
197 sizeof(account->pass), M_PASS))
201 account->flags |= M_ACCT_PASS;
206 void mutt_account_unsetpass (ACCOUNT * account)
208 account->flags &= !M_ACCT_PASS;