NeoMutt  2025-09-05-53-g1e05a3
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
expando_newsrc.c
Go to the documentation of this file.
1
24
30
31#include "config.h"
32#include <string.h>
33#include "mutt/lib.h"
34#include "email/lib.h"
35#include "conn/lib.h"
36#include "lib.h"
37#include "expando/lib.h"
38#include "adata.h"
39
43static void nntp_account(const struct ExpandoNode *node, void *data,
44 MuttFormatFlags flags, struct Buffer *buf)
45{
46 struct NntpAccountData *adata = data;
47 struct ConnAccount *cac = &adata->conn->account;
48
49 char tmp[128] = { 0 };
50
51 struct Url url = { 0 };
52 account_to_url(cac, &url);
53 url_tostring(&url, tmp, sizeof(tmp), U_PATH);
54 char *p = strchr(tmp, '/');
55 if (p)
56 {
57 *p = '\0';
58 }
59
60 buf_strcpy(buf, tmp);
61}
62
66static long nntp_port(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
67{
68 const struct NntpAccountData *adata = data;
69 const struct ConnAccount *cac = &adata->conn->account;
70
71 return cac->port;
72}
73
77static long nntp_port_if_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
78{
79 const struct NntpAccountData *adata = data;
80 const struct ConnAccount *cac = &adata->conn->account;
81
82 if (cac->flags & MUTT_ACCT_PORT)
83 return cac->port;
84
85 return 0;
86}
87
91static void nntp_port_if(const struct ExpandoNode *node, void *data,
92 MuttFormatFlags flags, struct Buffer *buf)
93{
94 const struct NntpAccountData *adata = data;
95 const struct ConnAccount *cac = &adata->conn->account;
96
97 if (cac->flags & MUTT_ACCT_PORT)
98 {
99 buf_add_printf(buf, "%hd", cac->port);
100 }
101}
102
106static void nntp_schema(const struct ExpandoNode *node, void *data,
107 MuttFormatFlags flags, struct Buffer *buf)
108{
109 struct NntpAccountData *adata = data;
110 struct ConnAccount *cac = &adata->conn->account;
111
112 char tmp[128] = { 0 };
113
114 struct Url url = { 0 };
115 account_to_url(cac, &url);
116 url_tostring(&url, tmp, sizeof(tmp), U_PATH);
117 char *p = strchr(tmp, ':');
118 if (p)
119 {
120 *p = '\0';
121 }
122
123 buf_strcpy(buf, tmp);
124}
125
129static void nntp_server(const struct ExpandoNode *node, void *data,
130 MuttFormatFlags flags, struct Buffer *buf)
131{
132 const struct NntpAccountData *adata = data;
133 const struct ConnAccount *cac = &adata->conn->account;
134
135 char tmp[128] = { 0 };
136
137 mutt_str_copy(tmp, cac->host, sizeof(tmp));
138 mutt_str_lower(tmp);
139
140 buf_strcpy(buf, tmp);
141}
142
146static void nntp_username(const struct ExpandoNode *node, void *data,
147 MuttFormatFlags flags, struct Buffer *buf)
148{
149 const struct NntpAccountData *adata = data;
150 const struct ConnAccount *cac = &adata->conn->account;
151
152 const char *s = cac->user;
153 buf_strcpy(buf, s);
154}
155
162 // clang-format off
164 { ED_NNTP, ED_NTP_PORT, NULL, nntp_port },
169 { -1, -1, NULL, NULL },
170 // clang-format on
171};
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:315
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.
Nntp-specific Account data.
Usenet network mailbox type; talk to an NNTP server.
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition render.h:32
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:422
#define U_PATH
Definition url.h:50