NeoMutt  2021-02-05-89-gabe350
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 
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 
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 }
ConnAccount
Login details for a remote server.
Definition: connaccount.h:51
ConnAccount::host
char host[128]
Server to login to.
Definition: connaccount.h:53
U_IMAP
@ U_IMAP
Url is imap://.
Definition: url.h:38
MUTT_ACCT_TYPE_SMTP
@ MUTT_ACCT_TYPE_SMTP
Smtp Account.
Definition: mutt_account.h:39
mutt_account_fromurl
int mutt_account_fromurl(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
Definition: mutt_account.c:43
U_NNTPS
@ U_NNTPS
Url is nntps://.
Definition: url.h:41
MUTT_ACCT_PORT
#define MUTT_ACCT_PORT
Port field has been set.
Definition: connaccount.h:42
mutt_account_tourl
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:79
U_UNKNOWN
@ U_UNKNOWN
Url wasn't recognised.
Definition: url.h:34
mutt_account.h
Url::scheme
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
Definition: url.h:69
Url::pass
char * pass
Password.
Definition: url.h:71
U_SMTPS
@ U_SMTPS
Url is smtps://.
Definition: url.h:43
lib.h
Url
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:67
MUTT_ACCT_TYPE_IMAP
@ MUTT_ACCT_TYPE_IMAP
Imap Account.
Definition: mutt_account.h:37
MUTT_ACCT_TYPE_POP
@ MUTT_ACCT_TYPE_POP
Pop Account.
Definition: mutt_account.h:38
U_IMAPS
@ U_IMAPS
Url is imaps://.
Definition: url.h:39
U_SMTP
@ U_SMTP
Url is smtp://.
Definition: url.h:42
ConnAccount::type
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
Definition: connaccount.h:58
Url::port
unsigned short port
Port.
Definition: url.h:73
Url::user
char * user
Username.
Definition: url.h:70
MUTT_ACCT_USER
#define MUTT_ACCT_USER
User field has been set.
Definition: connaccount.h:43
ConnAccount::flags
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition: connaccount.h:59
lib.h
MUTT_ACCT_SSL
#define MUTT_ACCT_SSL
Account uses SSL/TLS.
Definition: connaccount.h:46
U_POP
@ U_POP
Url is pop://.
Definition: url.h:36
ConnAccount::port
unsigned short port
Port to connect to.
Definition: connaccount.h:57
MUTT_ACCT_PASS
#define MUTT_ACCT_PASS
Password field has been set.
Definition: connaccount.h:45
U_POPS
@ U_POPS
Url is pops://.
Definition: url.h:37
U_NNTP
@ U_NNTP
Url is nntp://.
Definition: url.h:40
Url::host
char * host
Host.
Definition: url.h:72
ConnAccount::pass
char pass[256]
Password.
Definition: connaccount.h:56
MUTT_ACCT_TYPE_NNTP
@ MUTT_ACCT_TYPE_NNTP
Nntp (Usenet) Account.
Definition: mutt_account.h:40
Url::path
char * path
Path.
Definition: url.h:74
lib.h
ConnAccount::user
char user[128]
Username.
Definition: connaccount.h:55
mutt_str_copy
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:716