NeoMutt  2020-06-26-30-g76c339
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 }
int mutt_account_fromurl(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
Definition: mutt_account.c:43
char * pass
Password.
Definition: url.h:70
Structs that make up an email.
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:66
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
Definition: url.h:68
Url is imaps://.
Definition: url.h:39
char user[128]
Username.
Definition: connaccount.h:55
Url wasn&#39;t recognised.
Definition: url.h:34
Url is imap://.
Definition: url.h:38
#define MUTT_ACCT_USER
User field has been set.
Definition: connaccount.h:43
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:79
char host[128]
Server to login to.
Definition: connaccount.h:53
#define MUTT_ACCT_PASS
Password field has been set.
Definition: connaccount.h:45
char pass[256]
Password.
Definition: connaccount.h:56
Url is nntps://.
Definition: url.h:41
unsigned short port
Port to connect to.
Definition: connaccount.h:57
#define MUTT_ACCT_PORT
Port field has been set.
Definition: connaccount.h:42
ConnAccount object used by POP and IMAP.
char * user
Username.
Definition: url.h:69
Url is smtps://.
Definition: url.h:43
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
Definition: connaccount.h:58
char * host
Host.
Definition: url.h:71
Login details for a remote server.
Definition: connaccount.h:51
Imap Account.
Definition: mutt_account.h:37
char * path
Path.
Definition: url.h:73
Nntp (Usenet) Account.
Definition: mutt_account.h:40
Pop Account.
Definition: mutt_account.h:38
Url is pop://.
Definition: url.h:36
unsigned short port
Port.
Definition: url.h:72
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:724
Url is nntp://.
Definition: url.h:40
Connection Library.
Url is smtp://.
Definition: url.h:42
Smtp Account.
Definition: mutt_account.h:39
Convenience wrapper for the library headers.
#define MUTT_ACCT_SSL
Account uses SSL/TLS.
Definition: connaccount.h:46
Url is pops://.
Definition: url.h:37
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition: connaccount.h:59