NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
DOXYGEN
mutt_account.c
Go to the documentation of this file.
1
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
43int 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
79void 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}
Connection Library.
#define MUTT_ACCT_SSL
Account uses SSL/TLS.
Definition: connaccount.h:47
#define MUTT_ACCT_PASS
Password field has been set.
Definition: connaccount.h:46
#define MUTT_ACCT_USER
User field has been set.
Definition: connaccount.h:44
#define MUTT_ACCT_PORT
Port field has been set.
Definition: connaccount.h:43
Structs that make up an email.
Convenience wrapper for the library headers.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:652
int mutt_account_fromurl(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
Definition: mutt_account.c:43
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:79
ConnAccount object used by POP and IMAP.
@ MUTT_ACCT_TYPE_SMTP
Smtp Account.
Definition: mutt_account.h:39
@ MUTT_ACCT_TYPE_POP
Pop Account.
Definition: mutt_account.h:38
@ MUTT_ACCT_TYPE_NNTP
Nntp (Usenet) Account.
Definition: mutt_account.h:40
@ MUTT_ACCT_TYPE_IMAP
Imap Account.
Definition: mutt_account.h:37
Login details for a remote server.
Definition: connaccount.h:53
char user[128]
Username.
Definition: connaccount.h:56
char pass[256]
Password.
Definition: connaccount.h:57
char host[128]
Server to login to.
Definition: connaccount.h:54
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
Definition: connaccount.h:59
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition: connaccount.h:60
unsigned short port
Port to connect to.
Definition: connaccount.h:58
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:69
char * user
Username.
Definition: url.h:71
unsigned short port
Port.
Definition: url.h:74
char * host
Host.
Definition: url.h:73
char * pass
Password.
Definition: url.h:72
char * path
Path.
Definition: url.h:75
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
Definition: url.h:70
@ U_UNKNOWN
Url wasn't recognised.
Definition: url.h:35
@ U_NNTPS
Url is nntps://.
Definition: url.h:42
@ U_SMTPS
Url is smtps://.
Definition: url.h:44
@ U_SMTP
Url is smtp://.
Definition: url.h:43
@ U_NNTP
Url is nntp://.
Definition: url.h:41
@ U_IMAP
Url is imap://.
Definition: url.h:39
@ U_POPS
Url is pops://.
Definition: url.h:38
@ U_IMAPS
Url is imaps://.
Definition: url.h:40
@ U_POP
Url is pop://.
Definition: url.h:37