NeoMutt  2024-03-23-147-g885fbc
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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#include "globals.h"
40
45void remailer_free(struct Remailer **ptr)
46{
47 if (!ptr || !*ptr)
48 return;
49
50 struct Remailer *r = *ptr;
51 FREE(&r->shortname);
52 FREE(&r->addr);
53 FREE(&r->ver);
54
55 FREE(ptr);
56}
57
63{
64 return mutt_mem_calloc(1, sizeof(struct Remailer));
65}
66
72static MixCapFlags mix_get_caps(const char *capstr)
73{
75
76 while (*capstr)
77 {
78 switch (*capstr)
79 {
80 case 'C':
82 break;
83
84 case 'M':
86 break;
87
88 case 'N':
89 {
90 switch (*++capstr)
91 {
92 case 'm':
94 break;
95
96 case 'p':
98 break;
99 }
100 }
101 }
102
103 if (*capstr)
104 capstr++;
105 }
106
107 return caps;
108}
109
114struct RemailerArray remailer_get_hosts(void)
115{
116 struct RemailerArray ra = ARRAY_HEAD_INITIALIZER;
117 FILE *fp = NULL;
118 char line[8192] = { 0 };
119 char *t = NULL;
120 struct Remailer *p = NULL;
121
122 const char *const c_mixmaster = cs_subset_string(NeoMutt->sub, "mixmaster");
123 if (!c_mixmaster)
124 return ra;
125
126 int fd_null = open("/dev/null", O_RDWR);
127 if (fd_null == -1)
128 return ra;
129
130 struct Buffer *cmd = buf_pool_get();
131 buf_printf(cmd, "%s -T", c_mixmaster);
132
133 pid_t mm_pid = filter_create_fd(buf_string(cmd), NULL, &fp, NULL, fd_null, -1,
134 fd_null, EnvList);
136 if (mm_pid == -1)
137 {
138 buf_pool_release(&cmd);
139 close(fd_null);
140 return ra;
141 }
142
143 buf_pool_release(&cmd);
144
145 /* first, generate the "random" remailer */
146
147 p = remailer_new();
148 p->shortname = mutt_str_dup(_("<random>"));
149 p->num = 0;
150 ARRAY_ADD(&ra, p);
151
152 while (fgets(line, sizeof(line), fp))
153 {
154 p = remailer_new();
155
156 t = strtok(line, " \t\n");
157 if (!t)
158 goto problem;
159
160 p->shortname = mutt_str_dup(t);
161
162 t = strtok(NULL, " \t\n");
163 if (!t)
164 goto problem;
165
166 p->addr = mutt_str_dup(t);
167
168 t = strtok(NULL, " \t\n");
169 if (!t)
170 goto problem;
171
172 t = strtok(NULL, " \t\n");
173 if (!t)
174 goto problem;
175
176 p->ver = mutt_str_dup(t);
177
178 t = strtok(NULL, " \t\n");
179 if (!t)
180 goto problem;
181
182 p->caps = mix_get_caps(t);
183
184 p->num = ARRAY_SIZE(&ra);
185 ARRAY_ADD(&ra, p);
186 continue;
187
188 problem:
189 remailer_free(&p);
190 }
191
192 filter_wait(mm_pid);
193
194 close(fd_null);
195
196 return ra;
197}
198
205void remailer_clear_hosts(struct RemailerArray *ra)
206{
207 struct Remailer **r = NULL;
208 ARRAY_FOREACH(r, ra)
209 {
210 remailer_free(r);
211 }
212
213 ARRAY_FREE(ra);
214}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:156
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:204
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:58
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
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:220
pid_t filter_create_fd(const char *cmd, FILE **fp_in, FILE **fp_out, FILE **fp_err, int fdin, int fdout, int fderr, char **envlist)
Run a command on a pipe (optionally connect stdin/stdout)
Definition: filter.c:62
char ** EnvList
Private copy of the environment variables.
Definition: globals.c:78
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:45
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:253
void window_invalidate_all(void)
Mark all windows as in need of repaint.
Definition: mutt_window.c:767
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
static MixCapFlags mix_get_caps(const char *capstr)
Get Mixmaster Capabilities.
Definition: remailer.c:72
struct RemailerArray remailer_get_hosts(void)
Parse the type2.list as given by mixmaster -T.
Definition: remailer.c:114
void remailer_clear_hosts(struct RemailerArray *ra)
Clear a Remailer List.
Definition: remailer.c:205
struct Remailer * remailer_new(void)
Create a new Remailer.
Definition: remailer.c:62
void remailer_free(struct Remailer **ptr)
Free a Remailer.
Definition: remailer.c:45
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:36
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
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