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) */
16 #include <lib-lib/lib-lib.h>
17 #include <lib-ui/enter.h>
22 /* mutt_account_match: compare account info (host/port/user/login) */
23 int mutt_account_match (const ACCOUNT * a1, const ACCOUNT * a2)
25 const char* user = NONULL (Username);
26 const char* login = NONULL (Username);
28 if (a1->type != a2->type)
30 if (ascii_strcasecmp (a1->host, a2->host))
32 if (a1->port != a2->port)
35 if (a1->type == M_ACCT_TYPE_IMAP) {
36 if (ImapUser && (ImapUser[0] != '\0'))
38 if (ImapLogin && (ImapLogin[0] != '\0'))
42 if (a1->type == M_ACCT_TYPE_POP && PopUser)
46 if (a1->type == M_ACCT_TYPE_NNTP && NntpUser)
50 if (a1->flags & a2->flags & M_ACCT_USER)
51 return (!m_strcmp(a1->user, a2->user));
52 if (a1->flags & M_ACCT_USER)
53 return (!m_strcmp(a1->user, user));
54 if (a2->flags & M_ACCT_USER)
55 return (!m_strcmp(a2->user, user));
60 /* mutt_account_fromurl: fill account with information from url. */
61 int mutt_account_fromurl(ACCOUNT *account, ciss_url_t *url)
66 m_strcpy(account->host, sizeof(account->host), url->host);
69 m_strcpy(account->user, sizeof(account->user), url->user);
70 account->flags |= M_ACCT_USER;
73 m_strcpy(account->pass, sizeof(account->pass), url->pass);
74 account->flags |= M_ACCT_PASS;
77 account->port = url->port;
78 account->flags |= M_ACCT_PORT;
84 /* mutt_account_tourl: fill URL with info from account. The URL information
85 * is a set of pointers into account - don't free or edit account until
86 * you've finished with url (make a copy of account if you need it for
88 void mutt_account_tourl (ACCOUNT * account, ciss_url_t * url)
90 url->scheme = U_UNKNOWN;
95 if (account->type == M_ACCT_TYPE_IMAP) {
96 if (account->flags & M_ACCT_SSL)
97 url->scheme = U_IMAPS;
102 if (account->type == M_ACCT_TYPE_POP) {
103 if (account->flags & M_ACCT_SSL)
104 url->scheme = U_POPS;
110 if (account->type == M_ACCT_TYPE_NNTP) {
111 if (account->flags & M_ACCT_SSL)
112 url->scheme = U_NNTPS;
114 url->scheme = U_NNTP;
118 url->host = account->host;
119 if (account->flags & M_ACCT_PORT)
120 url->port = account->port;
121 if (account->flags & M_ACCT_USER)
122 url->user = account->user;
123 if (account->flags & M_ACCT_PASS)
124 url->pass = account->pass;
127 /* mutt_account_getuser: retrieve username into ACCOUNT, if necessary */
128 int mutt_account_getuser (ACCOUNT * account)
130 char prompt[SHORT_STRING];
133 if (account->flags & M_ACCT_USER)
135 else if ((account->type == M_ACCT_TYPE_IMAP) && !m_strisempty(ImapUser))
136 m_strcpy(account->user, sizeof(account->user), ImapUser);
137 else if ((account->type == M_ACCT_TYPE_POP) && !m_strisempty(PopUser))
138 m_strcpy(account->user, sizeof(account->user), PopUser);
140 else if ((account->type == M_ACCT_TYPE_NNTP) && !m_strisempty(NntpUser))
141 m_strcpy(account->user, sizeof(account->user), NntpUser);
143 /* prompt (defaults to unix username), copy into account->user */
145 snprintf(prompt, sizeof(prompt), _("Username at %s: "), account->host);
146 m_strcpy(account->user, sizeof(account->user), NONULL(Username));
147 if (mutt_get_field_unbuffered(prompt, account->user,
148 sizeof(account->user), 0))
152 account->flags |= M_ACCT_USER;
157 int mutt_account_getlogin (ACCOUNT* account)
160 if (account->flags & M_ACCT_LOGIN)
162 else if (account->type == M_ACCT_TYPE_IMAP)
164 if (!m_strisempty(ImapLogin)) {
165 m_strcpy(account->login, sizeof(account->login), ImapLogin);
166 account->flags |= M_ACCT_LOGIN;
170 if (!(account->flags & M_ACCT_LOGIN)) {
171 mutt_account_getuser (account);
172 m_strcpy(account->login, sizeof(account->login), account->user);
175 account->flags |= M_ACCT_LOGIN;
180 /* mutt_account_getpass: fetch password into ACCOUNT, if neccessary */
181 int mutt_account_getpass (ACCOUNT * account)
183 char prompt[SHORT_STRING];
185 if (account->flags & M_ACCT_PASS)
187 else if ((account->type == M_ACCT_TYPE_IMAP) && !m_strisempty(ImapPass))
188 m_strcpy(account->pass, sizeof(account->pass), ImapPass);
189 else if ((account->type == M_ACCT_TYPE_POP) && !m_strisempty(PopPass))
190 m_strcpy(account->pass, sizeof(account->pass), PopPass);
192 else if ((account->type == M_ACCT_TYPE_NNTP) && !m_strisempty(NntpPass))
193 m_strcpy(account->pass, sizeof(account->pass), NntpPass);
196 snprintf(prompt, sizeof(prompt), _("Password for %s@%s: "),
197 account->flags & M_ACCT_LOGIN ? account->login : account->user,
199 account->pass[0] = '\0';
200 if (mutt_get_field_unbuffered(prompt, account->pass,
201 sizeof(account->pass), M_PASS))
205 account->flags |= M_ACCT_PASS;
210 void mutt_account_unsetpass (ACCOUNT * account)
212 account->flags &= !M_ACCT_PASS;