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