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