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/lib-ui.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(mod_core.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 && !m_strisempty(ImapUser))
34 if (a1->type == M_ACCT_TYPE_POP && !m_strisempty(PopUser))
37 if (a1->has_user && a2->has_user)
38 return !m_strcmp(a1->user, a2->user);
40 return !m_strcmp(a1->user, user);
42 return !m_strcmp(a2->user, user);
47 /* mutt_account_fromurl: fill account with information from url. */
48 int mutt_account_fromurl(ACCOUNT *account, ciss_url_t *url)
53 m_strcpy(account->host, sizeof(account->host), url->host);
56 m_strcpy(account->user, sizeof(account->user), url->user);
57 account->has_user = 1;
60 m_strcpy(account->pass, sizeof(account->pass), url->pass);
61 account->has_pass = 1;
64 account->port = url->port;
65 account->has_port = 1;
71 /* mutt_account_tourl: fill URL with info from account. The URL information
72 * is a set of pointers into account - don't free or edit account until
73 * you've finished with url (make a copy of account if you need it for
75 void mutt_account_tourl(ACCOUNT *account, ciss_url_t *url)
77 url->scheme = U_UNKNOWN;
82 if (account->type == M_ACCT_TYPE_IMAP) {
83 url->scheme = account->has_ssl ? U_IMAPS : U_IMAP;
86 if (account->type == M_ACCT_TYPE_POP) {
87 url->scheme = account->has_ssl ? U_POPS : U_POP;
90 url->host = account->host;
91 if (account->has_port)
92 url->port = account->port;
93 if (account->has_user)
94 url->user = account->user;
95 if (account->has_pass)
96 url->pass = account->pass;
99 /* mutt_account_getuser: retrieve username into ACCOUNT, if necessary */
100 int mutt_account_getuser (ACCOUNT * account)
105 if (account->has_user)
107 else if ((account->type == M_ACCT_TYPE_IMAP) && !m_strisempty(ImapUser))
108 m_strcpy(account->user, sizeof(account->user), ImapUser);
109 else if ((account->type == M_ACCT_TYPE_POP) && !m_strisempty(PopUser))
110 m_strcpy(account->user, sizeof(account->user), PopUser);
111 /* prompt (defaults to unix username), copy into account->user */
113 snprintf(prompt, sizeof(prompt), _("Username at %s: "), account->host);
114 m_strcpy(account->user, sizeof(account->user), NONULL(mod_core.username));
115 if (mutt_get_field_unbuffered(prompt, account->user,
116 sizeof(account->user), 0))
120 account->has_user = 1;
125 int mutt_account_getlogin (ACCOUNT* account)
128 if (account->has_login)
131 if (account->type == M_ACCT_TYPE_IMAP && !m_strisempty(ImapLogin)) {
132 m_strcpy(account->login, sizeof(account->login), ImapLogin);
133 account->has_login = 1;
135 mutt_account_getuser (account);
136 m_strcpy(account->login, sizeof(account->login), account->user);
139 account->has_login = 1;
144 /* mutt_account_getpass: fetch password into ACCOUNT, if neccessary */
145 int mutt_account_getpass (ACCOUNT * account)
149 if (account->has_pass)
151 else if ((account->type == M_ACCT_TYPE_IMAP) && !m_strisempty(ImapPass))
152 m_strcpy(account->pass, sizeof(account->pass), ImapPass);
153 else if ((account->type == M_ACCT_TYPE_POP) && !m_strisempty(PopPass))
154 m_strcpy(account->pass, sizeof(account->pass), PopPass);
156 snprintf(prompt, sizeof(prompt), _("Password for %s@%s: "),
157 account->has_login ? account->login : account->user,
159 account->pass[0] = '\0';
160 if (mutt_get_field_unbuffered(prompt, account->pass,
161 sizeof(account->pass), M_PASS))
165 account->has_pass = 1;