2 * Copyright (C) 2000-3 Brendan Cully <brendan@kublai.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 /* remote host account manipulation (POP/IMAP) */
25 /* mutt_account_match: compare account info (host/port/user) */
26 int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* a2)
28 const char* user = 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 && ImapUser)
43 if (a1->type == M_ACCT_TYPE_POP && PopUser)
48 if (a1->type == M_ACCT_TYPE_NNTP && NntpUser)
52 if (a1->flags & a2->flags & M_ACCT_USER)
53 return (!strcmp (a1->user, a2->user));
54 if (a1->flags & M_ACCT_USER)
55 return (!strcmp (a1->user, user));
56 if (a2->flags & M_ACCT_USER)
57 return (!strcmp (a2->user, user));
62 /* mutt_account_fromurl: fill account with information from url. */
63 int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url)
67 strfcpy (account->host, url->host, sizeof (account->host));
73 strfcpy (account->user, url->user, sizeof (account->user));
74 account->flags |= M_ACCT_USER;
78 strfcpy (account->pass, url->pass, sizeof (account->pass));
79 account->flags |= M_ACCT_PASS;
83 account->port = url->port;
84 account->flags |= M_ACCT_PORT;
90 /* mutt_account_tourl: fill URL with info from account. The URL information
91 * is a set of pointers into account - don't free or edit account until
92 * you've finished with url (make a copy of account if you need it for
94 void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url)
96 url->scheme = U_UNKNOWN;
102 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)
114 if (account->flags & M_ACCT_SSL)
115 url->scheme = U_POPS;
122 if (account->type == M_ACCT_TYPE_NNTP)
124 if (account->flags & M_ACCT_SSL)
125 url->scheme = U_NNTPS;
127 url->scheme = U_NNTP;
131 url->host = account->host;
132 if (account->flags & M_ACCT_PORT)
133 url->port = account->port;
134 if (account->flags & M_ACCT_USER)
135 url->user = account->user;
136 if (account->flags & M_ACCT_PASS)
137 url->pass = account->pass;
140 /* mutt_account_getuser: retrieve username into ACCOUNT, if neccessary */
141 int mutt_account_getuser (ACCOUNT* account)
143 char prompt[SHORT_STRING];
146 if (account->flags & M_ACCT_USER)
149 else if ((account->type == M_ACCT_TYPE_IMAP) && ImapUser)
150 strfcpy (account->user, ImapUser, sizeof (account->user));
153 else if ((account->type == M_ACCT_TYPE_POP) && PopUser)
154 strfcpy (account->user, PopUser, sizeof (account->user));
157 else if ((account->type == M_ACCT_TYPE_NNTP) && NntpUser)
158 strfcpy (account->user, NntpUser, sizeof (account->user));
160 /* prompt (defaults to unix username), copy into account->user */
163 snprintf (prompt, sizeof (prompt), _("Username at %s: "), account->host);
164 strfcpy (account->user, NONULL (Username), sizeof (account->user));
165 if (mutt_get_field (prompt, account->user, sizeof (account->user), 0))
169 account->flags |= M_ACCT_USER;
174 /* mutt_account_getpass: fetch password into ACCOUNT, if neccessary */
175 int mutt_account_getpass (ACCOUNT* account)
177 char prompt[SHORT_STRING];
179 if (account->flags & M_ACCT_PASS)
182 else if ((account->type == M_ACCT_TYPE_IMAP) && ImapPass)
183 strfcpy (account->pass, ImapPass, sizeof (account->pass));
186 else if ((account->type == M_ACCT_TYPE_POP) && PopPass)
187 strfcpy (account->pass, PopPass, sizeof (account->pass));
190 else if ((account->type == M_ACCT_TYPE_NNTP) && NntpPass)
191 strfcpy (account->pass, NntpPass, sizeof (account->pass));
195 snprintf (prompt, sizeof (prompt), _("Password for %s@%s: "),
196 account->user, account->host);
197 account->pass[0] = '\0';
198 if (mutt_get_password (prompt, account->pass, sizeof (account->pass)))
202 account->flags |= M_ACCT_PASS;
207 void mutt_account_unsetpass (ACCOUNT* account)
209 account->flags &= !M_ACCT_PASS;