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