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>
14 #include <lib-ui/curses.h>
19 /* mutt_account_match: compare account info (host/port/user/login) */
20 int mutt_account_match (const ACCOUNT * a1, const ACCOUNT * a2)
22 const char* user = NONULL(MCore.username);
23 const char* login = NONULL(MCore.username);
25 if (a1->type != a2->type)
27 if (ascii_strcasecmp (a1->host, a2->host))
29 if (a1->port != a2->port)
32 if (a1->type == M_ACCT_TYPE_IMAP) {
33 if (ImapUser && (ImapUser[0] != '\0'))
35 if (ImapLogin && (ImapLogin[0] != '\0'))
39 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 (!m_strcmp(a1->user, a2->user));
49 if (a1->flags & M_ACCT_USER)
50 return (!m_strcmp(a1->user, user));
51 if (a2->flags & M_ACCT_USER)
52 return (!m_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)
63 m_strcpy(account->host, sizeof(account->host), url->host);
66 m_strcpy(account->user, sizeof(account->user), url->user);
67 account->flags |= M_ACCT_USER;
70 m_strcpy(account->pass, sizeof(account->pass), url->pass);
71 account->flags |= M_ACCT_PASS;
74 account->port = url->port;
75 account->flags |= M_ACCT_PORT;
81 /* mutt_account_tourl: fill URL with info from account. The URL information
82 * is a set of pointers into account - don't free or edit account until
83 * you've finished with url (make a copy of account if you need it for
85 void mutt_account_tourl (ACCOUNT * account, ciss_url_t * url)
87 url->scheme = U_UNKNOWN;
92 if (account->type == M_ACCT_TYPE_IMAP) {
93 if (account->flags & M_ACCT_SSL)
94 url->scheme = U_IMAPS;
99 if (account->type == M_ACCT_TYPE_POP) {
100 if (account->flags & M_ACCT_SSL)
101 url->scheme = U_POPS;
107 if (account->type == M_ACCT_TYPE_NNTP) {
108 if (account->flags & M_ACCT_SSL)
109 url->scheme = U_NNTPS;
111 url->scheme = U_NNTP;
115 url->host = account->host;
116 if (account->flags & M_ACCT_PORT)
117 url->port = account->port;
118 if (account->flags & M_ACCT_USER)
119 url->user = account->user;
120 if (account->flags & M_ACCT_PASS)
121 url->pass = account->pass;
124 /* mutt_account_getuser: retrieve username into ACCOUNT, if necessary */
125 int mutt_account_getuser (ACCOUNT * account)
130 if (account->flags & M_ACCT_USER)
132 else if ((account->type == M_ACCT_TYPE_IMAP) && !m_strisempty(ImapUser))
133 m_strcpy(account->user, sizeof(account->user), ImapUser);
134 else if ((account->type == M_ACCT_TYPE_POP) && !m_strisempty(PopUser))
135 m_strcpy(account->user, sizeof(account->user), PopUser);
137 else if ((account->type == M_ACCT_TYPE_NNTP) && !m_strisempty(NntpUser))
138 m_strcpy(account->user, sizeof(account->user), NntpUser);
140 /* prompt (defaults to unix username), copy into account->user */
142 snprintf(prompt, sizeof(prompt), _("Username at %s: "), account->host);
143 m_strcpy(account->user, sizeof(account->user), NONULL(MCore.username));
144 if (mutt_get_field_unbuffered(prompt, account->user,
145 sizeof(account->user), 0))
149 account->flags |= M_ACCT_USER;
154 int mutt_account_getlogin (ACCOUNT* account)
157 if (account->flags & M_ACCT_LOGIN)
159 else if (account->type == M_ACCT_TYPE_IMAP)
161 if (!m_strisempty(ImapLogin)) {
162 m_strcpy(account->login, sizeof(account->login), ImapLogin);
163 account->flags |= M_ACCT_LOGIN;
167 if (!(account->flags & M_ACCT_LOGIN)) {
168 mutt_account_getuser (account);
169 m_strcpy(account->login, sizeof(account->login), account->user);
172 account->flags |= M_ACCT_LOGIN;
177 /* mutt_account_getpass: fetch password into ACCOUNT, if neccessary */
178 int mutt_account_getpass (ACCOUNT * account)
182 if (account->flags & M_ACCT_PASS)
184 else if ((account->type == M_ACCT_TYPE_IMAP) && !m_strisempty(ImapPass))
185 m_strcpy(account->pass, sizeof(account->pass), ImapPass);
186 else if ((account->type == M_ACCT_TYPE_POP) && !m_strisempty(PopPass))
187 m_strcpy(account->pass, sizeof(account->pass), PopPass);
189 else if ((account->type == M_ACCT_TYPE_NNTP) && !m_strisempty(NntpPass))
190 m_strcpy(account->pass, sizeof(account->pass), NntpPass);
193 snprintf(prompt, sizeof(prompt), _("Password for %s@%s: "),
194 account->flags & M_ACCT_LOGIN ? account->login : account->user,
196 account->pass[0] = '\0';
197 if (mutt_get_field_unbuffered(prompt, account->pass,
198 sizeof(account->pass), M_PASS))
202 account->flags |= M_ACCT_PASS;
207 void mutt_account_unsetpass (ACCOUNT * account)
209 account->flags &= ~M_ACCT_PASS;