NeoMutt  2020-06-26-30-g76c339
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 "email/lib.h"
33 #include "conn/lib.h"
34 #include "mutt_socket.h"
35 #include "hook.h"
36 #include "mutt_account.h"
37 #ifndef USE_SSL
38 #include "mutt/lib.h"
39 #endif
40 
46 struct Connection *mutt_conn_new(const struct ConnAccount *cac)
47 {
48  enum ConnectionType conn_type;
49 
50  if (C_Tunnel)
51  conn_type = MUTT_CONNECTION_TUNNEL;
52  else if (cac->flags & MUTT_ACCT_SSL)
53  conn_type = MUTT_CONNECTION_SSL;
54  else
55  conn_type = MUTT_CONNECTION_SIMPLE;
56 
57  struct Connection *conn = mutt_socket_new(conn_type);
58  if (conn)
59  {
60  memcpy(&conn->account, cac, sizeof(struct ConnAccount));
61  }
62  else
63  {
64  if (conn_type == MUTT_CONNECTION_SSL)
65  {
66 #ifndef USE_SSL
67  /* that's probably why it failed */
68  mutt_error(_("SSL is unavailable, can't connect to %s"), cac->host);
69 #endif
70  }
71  }
72  return conn;
73 }
74 
86 struct Connection *mutt_conn_find(const struct ConnAccount *cac)
87 {
88  struct Url url = { 0 };
89  char hook[1024];
90 
91  /* cac isn't actually modified, since url isn't either */
92  mutt_account_tourl((struct ConnAccount *) cac, &url);
93  url.path = NULL;
94  url_tostring(&url, hook, sizeof(hook), 0);
95  mutt_account_hook(hook);
96 
97  return mutt_conn_new(cac);
98 }
Tunnelled connection.
Definition: socket.h:37
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:36
Structs that make up an email.
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:66
const char * C_Tunnel
Config: Shell command to establish a tunnel.
Definition: conn_globals.c:57
struct Connection * mutt_socket_new(enum ConnectionType type)
allocate and initialise a new connection
Definition: socket.c:278
An open network connection (socket)
Definition: connection.h:34
#define _(a)
Definition: message.h:28
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.
struct Connection * mutt_conn_find(const struct ConnAccount *cac)
Find a connection from a list.
Definition: mutt_socket.c:86
struct Connection * mutt_conn_new(const struct ConnAccount *cac)
Create a new Connection.
Definition: mutt_socket.c:46
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:755
Simple TCP socket connection.
Definition: socket.h:36
Login details for a remote server.
Definition: connaccount.h:51
char * path
Path.
Definition: url.h:73
#define mutt_error(...)
Definition: logging.h:84
Connection Library.
int url_tostring(struct Url *url, char *dest, size_t len, int flags)
Output the URL string for a given Url object.
Definition: url.c:418
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