1 /**
2 * @file
3 * ConnAccount object used by POP and IMAP
4 *
5 * @authors
6 * Copyright (C) 2000-2007 Brendan Cully <brendan@kublai.com>
7 *
8 * @copyright
9 * This program is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 2 of the License, or (at your option) any later
12 * version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 /**
24 * @page neo_mutt_account ConnAccount object used by POP and IMAP
25 *
26 * ConnAccount object used by POP and IMAP
27 */
28
29 #include "config.h"
30 #include <stdio.h>
31 #include "mutt/lib.h"
32 #include "email/lib.h"
33 #include "conn/lib.h"
34 #include "mutt_account.h"
35
36 /**
37 * mutt_account_fromurl - Fill ConnAccount with information from url
38 * @param cac ConnAccount to fill
39 * @param url Url to parse
40 * @retval 0 Success
41 * @retval -1 Error
42 */
mutt_account_fromurl(struct ConnAccount * cac,const struct Url * url)43 int mutt_account_fromurl(struct ConnAccount *cac, const struct Url *url)
44 {
45 /* must be present */
46 if (url->host)
47 mutt_str_copy(cac->host, url->host, sizeof(cac->host));
48 else
49 return -1;
50
51 if (url->user)
52 {
53 mutt_str_copy(cac->user, url->user, sizeof(cac->user));
54 cac->flags |= MUTT_ACCT_USER;
55 }
56 if (url->pass)
57 {
58 mutt_str_copy(cac->pass, url->pass, sizeof(cac->pass));
59 cac->flags |= MUTT_ACCT_PASS;
60 }
61 if (url->port)
62 {
63 cac->port = url->port;
64 cac->flags |= MUTT_ACCT_PORT;
65 }
66
67 return 0;
68 }
69
70 /**
71 * mutt_account_tourl - Fill URL with info from account
72 * @param cac Source ConnAccount
73 * @param url Url to fill
74 *
75 * The URL information is a set of pointers into cac. Don't free or edit cac
76 * until you've finished with url (make a copy of cac if you need it for a
77 * while).
78 */
mutt_account_tourl(struct ConnAccount * cac,struct Url * url)79 void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
80 {
81 url->scheme = U_UNKNOWN;
82 url->user = NULL;
83 url->pass = NULL;
84 url->port = 0;
85 url->path = NULL;
86
87 #ifdef USE_IMAP
88 if (cac->type == MUTT_ACCT_TYPE_IMAP)
89 {
90 if (cac->flags & MUTT_ACCT_SSL)
91 url->scheme = U_IMAPS;
92 else
93 url->scheme = U_IMAP;
94 }
95 #endif
96
97 #ifdef USE_POP
98 if (cac->type == MUTT_ACCT_TYPE_POP)
99 {
100 if (cac->flags & MUTT_ACCT_SSL)
101 url->scheme = U_POPS;
102 else
103 url->scheme = U_POP;
104 }
105 #endif
106
107 #ifdef USE_SMTP
108 if (cac->type == MUTT_ACCT_TYPE_SMTP)
109 {
110 if (cac->flags & MUTT_ACCT_SSL)
111 url->scheme = U_SMTPS;
112 else
113 url->scheme = U_SMTP;
114 }
115 #endif
116
117 #ifdef USE_NNTP
118 if (cac->type == MUTT_ACCT_TYPE_NNTP)
119 {
120 if (cac->flags & MUTT_ACCT_SSL)
121 url->scheme = U_NNTPS;
122 else
123 url->scheme = U_NNTP;
124 }
125 #endif
126
127 url->host = cac->host;
128 if (cac->flags & MUTT_ACCT_PORT)
129 url->port = cac->port;
130 if (cac->flags & MUTT_ACCT_USER)
131 url->user = cac->user;
132 if (cac->flags & MUTT_ACCT_PASS)
133 url->pass = cac->pass;
134 }
135