NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
mutt_socket.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include <stdio.h>
31 #include <string.h>
32 #include "config/lib.h"
33 #include "email/lib.h"
34 #include "core/lib.h"
35 #include "conn/lib.h"
36 #include "mutt_socket.h"
37 #include "hook.h"
38 #include "mutt_account.h"
39 #ifndef USE_SSL
40 #include "mutt/lib.h"
41 #endif
42 
48 struct Connection *mutt_conn_new(const struct ConnAccount *cac)
49 {
50  enum ConnectionType conn_type;
51 
52  const char *const c_tunnel = cs_subset_string(NeoMutt->sub, "tunnel");
53  if (c_tunnel)
54  conn_type = MUTT_CONNECTION_TUNNEL;
55  else if (cac->flags & MUTT_ACCT_SSL)
56  conn_type = MUTT_CONNECTION_SSL;
57  else
58  conn_type = MUTT_CONNECTION_SIMPLE;
59 
60  struct Connection *conn = mutt_socket_new(conn_type);
61  if (conn)
62  {
63  memcpy(&conn->account, cac, sizeof(struct ConnAccount));
64  }
65  else
66  {
67  if (conn_type == MUTT_CONNECTION_SSL)
68  {
69 #ifndef USE_SSL
70  /* that's probably why it failed */
71  mutt_error(_("SSL is unavailable, can't connect to %s"), cac->host);
72 #endif
73  }
74  }
75  return conn;
76 }
77 
89 struct Connection *mutt_conn_find(const struct ConnAccount *cac)
90 {
91  struct Url url = { 0 };
92  char hook[1024];
93 
94  /* cac isn't actually modified, since url isn't either */
95  mutt_account_tourl((struct ConnAccount *) cac, &url);
96  url.path = NULL;
97  url_tostring(&url, hook, sizeof(hook), U_NO_FLAGS);
98  mutt_account_hook(hook);
99 
100  return mutt_conn_new(cac);
101 }
Tunnelled connection.
Definition: socket.h:37
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:40
Structs that make up an email.
#define mutt_error(...)
Definition: logging.h:88
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:68
struct Connection * mutt_socket_new(enum ConnectionType type)
allocate and initialise a new connection
Definition: socket.c:280
#define _(a)
Definition: message.h:28
#define U_NO_FLAGS
Definition: url.h:49
Container for Accounts, Notifications.
Definition: neomutt.h:36
Convenience wrapper for the config headers.
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
Parse and execute user-defined hooks.
Convenience wrapper for the core headers.
struct Connection * mutt_conn_find(const struct ConnAccount *cac)
Find a connection from a list.
Definition: mutt_socket.c:89
struct Connection * mutt_conn_new(const struct ConnAccount *cac)
Create a new Connection.
Definition: mutt_socket.c:48
SSL/TLS-encrypted connection.
Definition: socket.h:38
ConnAccount object used by POP and IMAP.
void mutt_account_hook(const char *url)
Perform an account hook.
Definition: hook.c:782
Simple TCP socket connection.
Definition: socket.h:36
int url_tostring(struct Url *url, char *dest, size_t len, uint8_t flags)
Output the URL string for a given Url object.
Definition: url.c:418
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
Login details for a remote server.
Definition: connaccount.h:51
char * path
Path.
Definition: url.h:75
Connection Library.
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
NeoMutt connections.
Convenience wrapper for the library headers.
ConnectionType
Type of connection.
Definition: socket.h:34
#define MUTT_ACCT_SSL
Account uses SSL/TLS.
Definition: connaccount.h:46
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition: connaccount.h:59