NeoMutt  2023-05-17-16-g61469c
Teaching an old dog new tricks
DOXYGEN
remailer.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <fcntl.h>
31#include <stdio.h>
32#include <string.h>
33#include <unistd.h>
34#include "mutt/lib.h"
35#include "config/lib.h"
36#include "core/lib.h"
37#include "gui/lib.h"
38#include "remailer.h"
39
44void remailer_free(struct Remailer **ptr)
45{
46 if (!ptr || !*ptr)
47 return;
48
49 struct Remailer *r = *ptr;
50
51 FREE(&r->shortname);
52 FREE(&r->addr);
53 FREE(&r->ver);
54 FREE(ptr);
55}
56
62{
63 return mutt_mem_calloc(1, sizeof(struct Remailer));
64}
65
71static MixCapFlags mix_get_caps(const char *capstr)
72{
74
75 while (*capstr)
76 {
77 switch (*capstr)
78 {
79 case 'C':
81 break;
82
83 case 'M':
85 break;
86
87 case 'N':
88 {
89 switch (*++capstr)
90 {
91 case 'm':
93 break;
94
95 case 'p':
97 break;
98 }
99 }
100 }
101
102 if (*capstr)
103 capstr++;
104 }
105
106 return caps;
107}
108
113struct RemailerArray remailer_get_hosts(void)
114{
115 struct RemailerArray ra = ARRAY_HEAD_INITIALIZER;
116 FILE *fp = NULL;
117 char line[8192] = { 0 };
118 char *t = NULL;
119 struct Remailer *p = NULL;
120
121 const char *const c_mixmaster = cs_subset_string(NeoMutt->sub, "mixmaster");
122 if (!c_mixmaster)
123 return ra;
124
125 int fd_null = open("/dev/null", O_RDWR);
126 if (fd_null == -1)
127 return ra;
128
129 struct Buffer *cmd = buf_pool_get();
130 buf_printf(cmd, "%s -T", c_mixmaster);
131
132 pid_t mm_pid = filter_create_fd(buf_string(cmd), NULL, &fp, NULL, fd_null, -1, fd_null);
134 if (mm_pid == -1)
135 {
136 buf_pool_release(&cmd);
137 close(fd_null);
138 return ra;
139 }
140
141 buf_pool_release(&cmd);
142
143 /* first, generate the "random" remailer */
144
145 p = remailer_new();
146 p->shortname = mutt_str_dup(_("<random>"));
147 p->num = 0;
148 ARRAY_ADD(&ra, p);
149
150 while (fgets(line, sizeof(line), fp))
151 {
152 p = remailer_new();
153
154 t = strtok(line, " \t\n");
155 if (!t)
156 goto problem;
157
158 p->shortname = mutt_str_dup(t);
159
160 t = strtok(NULL, " \t\n");
161 if (!t)
162 goto problem;
163
164 p->addr = mutt_str_dup(t);
165
166 t = strtok(NULL, " \t\n");
167 if (!t)
168 goto problem;
169
170 t = strtok(NULL, " \t\n");
171 if (!t)
172 goto problem;
173
174 p->ver = mutt_str_dup(t);
175
176 t = strtok(NULL, " \t\n");
177 if (!t)
178 goto problem;
179
180 p->caps = mix_get_caps(t);
181
182 p->num = ARRAY_SIZE(&ra);
183 ARRAY_ADD(&ra, p);
184 continue;
185
186 problem:
187 remailer_free(&p);
188 }
189
190 filter_wait(mm_pid);
191
192 close(fd_null);
193
194 return ra;
195}
196
203void remailer_clear_hosts(struct RemailerArray *ra)
204{
205 struct Remailer **r = NULL;
206 ARRAY_FOREACH(r, ra)
207 {
208 remailer_free(r);
209 }
210
211 ARRAY_FREE(ra);
212}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:155
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:211
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:86
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:203
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:57
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:171
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:78
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:217
pid_t filter_create_fd(const char *cmd, FILE **fp_in, FILE **fp_out, FILE **fp_err, int fdin, int fdout, int fderr)
Run a command on a pipe (optionally connect stdin/stdout)
Definition: filter.c:61
Convenience wrapper for the gui headers.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define FREE(x)
Definition: memory.h:43
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
void window_invalidate_all(void)
Mark all windows as in need of repaint.
Definition: mutt_window.c:743
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:106
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:119
static MixCapFlags mix_get_caps(const char *capstr)
Get Mixmaster Capabilities.
Definition: remailer.c:71
struct RemailerArray remailer_get_hosts(void)
Parse the type2.list as given by mixmaster -T.
Definition: remailer.c:113
void remailer_clear_hosts(struct RemailerArray *ra)
Clear a Remailer List.
Definition: remailer.c:203
struct Remailer * remailer_new(void)
Create a new Remailer.
Definition: remailer.c:61
void remailer_free(struct Remailer **ptr)
Free a Remailer.
Definition: remailer.c:44
Mixmaster Remailer.
#define MIX_CAP_MIDDLEMAN
Must be a middle-man (not at the end of a chain)
Definition: remailer.h:32
#define MIX_CAP_NEWSMAIL
Supports posting to Usenet through a mail-to-news gateway.
Definition: remailer.h:34
#define MIX_CAP_NO_FLAGS
No flags are set.
Definition: remailer.h:30
#define MIX_CAP_COMPRESS
Accepts compressed messages.
Definition: remailer.h:31
uint8_t MixCapFlags
Flags, e.g. MIX_CAP_NO_FLAGS.
Definition: remailer.h:29
#define MIX_CAP_NEWSPOST
Supports direct posting to Usenet.
Definition: remailer.h:33
String manipulation buffer.
Definition: buffer.h:34
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
A Mixmaster remailer.
Definition: remailer.h:40
int num
Index number.
Definition: remailer.h:41
char * addr
Address of host.
Definition: remailer.h:43
char * shortname
Short name of remailer host.
Definition: remailer.h:42
MixCapFlags caps
Capabilities of host.
Definition: remailer.h:45
char * ver
Version of host.
Definition: remailer.h:44