NeoMutt  2024-11-14-151-g38259e
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
expando_newsrc.c
Go to the documentation of this file.
1
31#include "config.h"
32#include <stdio.h>
33#include <string.h>
34#include "mutt/lib.h"
35#include "email/lib.h"
36#include "conn/lib.h"
37#include "lib.h"
38#include "expando/lib.h"
39#include "adata.h"
40
44static void nntp_account(const struct ExpandoNode *node, void *data,
45 MuttFormatFlags flags, struct Buffer *buf)
46{
47 struct NntpAccountData *adata = data;
48 struct ConnAccount *cac = &adata->conn->account;
49
50 char tmp[128] = { 0 };
51
52 struct Url url = { 0 };
53 account_to_url(cac, &url);
54 url_tostring(&url, tmp, sizeof(tmp), U_PATH);
55 char *p = strchr(tmp, '/');
56 if (p)
57 {
58 *p = '\0';
59 }
60
61 buf_strcpy(buf, tmp);
62}
63
67static long nntp_port(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
68{
69 const struct NntpAccountData *adata = data;
70 const struct ConnAccount *cac = &adata->conn->account;
71
72 return cac->port;
73}
74
78static long nntp_port_if_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
79{
80 const struct NntpAccountData *adata = data;
81 const struct ConnAccount *cac = &adata->conn->account;
82
83 if (cac->flags & MUTT_ACCT_PORT)
84 return cac->port;
85
86 return 0;
87}
88
92static void nntp_port_if(const struct ExpandoNode *node, void *data,
93 MuttFormatFlags flags, struct Buffer *buf)
94{
95 const struct NntpAccountData *adata = data;
96 const struct ConnAccount *cac = &adata->conn->account;
97
98 if (cac->flags & MUTT_ACCT_PORT)
99 {
100 buf_add_printf(buf, "%hd", cac->port);
101 }
102}
103
107static void nntp_schema(const struct ExpandoNode *node, void *data,
108 MuttFormatFlags flags, struct Buffer *buf)
109{
110 struct NntpAccountData *adata = data;
111 struct ConnAccount *cac = &adata->conn->account;
112
113 char tmp[128] = { 0 };
114
115 struct Url url = { 0 };
116 account_to_url(cac, &url);
117 url_tostring(&url, tmp, sizeof(tmp), U_PATH);
118 char *p = strchr(tmp, ':');
119 if (p)
120 {
121 *p = '\0';
122 }
123
124 buf_strcpy(buf, tmp);
125}
126
130static void nntp_server(const struct ExpandoNode *node, void *data,
131 MuttFormatFlags flags, struct Buffer *buf)
132{
133 const struct NntpAccountData *adata = data;
134 const struct ConnAccount *cac = &adata->conn->account;
135
136 char tmp[128] = { 0 };
137
138 mutt_str_copy(tmp, cac->host, sizeof(tmp));
139 mutt_str_lower(tmp);
140
141 buf_strcpy(buf, tmp);
142}
143
147static void nntp_username(const struct ExpandoNode *node, void *data,
148 MuttFormatFlags flags, struct Buffer *buf)
149{
150 const struct NntpAccountData *adata = data;
151 const struct ConnAccount *cac = &adata->conn->account;
152
153 const char *s = cac->user;
154 buf_strcpy(buf, s);
155}
156
163 // clang-format off
165 { ED_NNTP, ED_NTP_PORT, NULL, nntp_port },
170 { -1, -1, NULL, NULL },
171 // clang-format on
172};
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:204
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:395
Connection Library.
@ ED_NTP_SCHEMA
ConnAccount.account.
Definition: connaccount.h:85
@ ED_NTP_USERNAME
ConnAccount.user.
Definition: connaccount.h:87
@ ED_NTP_PORT_IF
ConnAccount.port.
Definition: connaccount.h:84
@ ED_NTP_SERVER
ConnAccount.account.
Definition: connaccount.h:86
@ ED_NTP_ACCOUNT
ConnAccount.account.
Definition: connaccount.h:82
@ ED_NTP_PORT
ConnAccount.port.
Definition: connaccount.h:83
#define MUTT_ACCT_PORT
Port field has been set.
Definition: connaccount.h:43
@ ED_NNTP
Nntp ED_NTP_ ExpandoDataNntp.
Definition: domain.h:49
Structs that make up an email.
Parse Expando string.
const struct ExpandoRenderCallback NntpRenderCallbacks[]
Callbacks for Newsrc Expandos.
static long nntp_port(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Newsrc: Port - Implements get_number_t -.
static long nntp_port_if_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Newsrc: Port if specified - Implements get_number_t -.
static void nntp_account(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Newsrc: Account url - Implements get_string_t -.
static void nntp_port_if(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Newsrc: Port if specified - Implements get_string_t -.
static void nntp_username(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Newsrc: Username - Implements get_string_t -.
static void nntp_server(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Newsrc: News server name - Implements get_string_t -.
static void nntp_schema(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Newsrc: Url schema - Implements get_string_t -.
Convenience wrapper for the library headers.
char * mutt_str_lower(char *str)
Convert all characters in the string to lowercase.
Definition: string.c:313
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:581
void account_to_url(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:80
Pop-specific Account data.
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: render.h:32
Key value store.
void * adata
Private data (for Mailbox backends)
Definition: account.h:42
String manipulation buffer.
Definition: buffer.h:36
Login details for a remote server.
Definition: connaccount.h:53
char user[128]
Username.
Definition: connaccount.h:56
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
unsigned short port
Port to connect to.
Definition: connaccount.h:58
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:49
Basic Expando Node.
Definition: node.h:67
NNTP-specific Account data -.
Definition: adata.h:36
struct Connection * conn
Connection to NNTP Server.
Definition: adata.h:62
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:69
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_PATH
Definition: url.h:50