NeoMutt  2018-07-16 +1783-b00bd9
Teaching an old dog new tricks
DOXYGEN
remailer.c File Reference

Support of Mixmaster anonymous remailer. More...

#include "config.h"
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "mutt/mutt.h"
#include "address/lib.h"
#include "email/lib.h"
#include "mutt.h"
#include "curs_lib.h"
#include "filter.h"
#include "format_flags.h"
#include "keymap.h"
#include "mutt_curses.h"
#include "mutt_menu.h"
#include "mutt_window.h"
#include "muttlib.h"
#include "opcodes.h"
#include "options.h"
#include "protos.h"
#include "recvattach.h"
#include "sendlib.h"
+ Include dependency graph for remailer.c:

Go to the source code of this file.

Data Structures

struct  Coord
 Screen coordinates. More...
 

Macros

#define MIX_HOFFSET   2
 
#define MIX_VOFFSET   (MuttIndexWindow->rows - 4)
 
#define MIX_MAXROW   (MuttIndexWindow->rows - 1)
 

Functions

static MixCapFlags mix_get_caps (const char *capstr)
 Get Mixmaster Capabilities. More...
 
static void mix_add_entry (struct Remailer ***type2_list, struct Remailer *entry, size_t *slots, size_t *used)
 Add an entry to the Remailer list. More...
 
static struct Remailermix_new_remailer (void)
 Create a new Remailer. More...
 
static void mix_free_remailer (struct Remailer **r)
 Free a Remailer. More...
 
static struct Remailer ** mix_type2_list (size_t *l)
 parse the type2.list as given by mixmaster -T More...
 
static void mix_free_type2_list (struct Remailer ***ttlp)
 Free a Remailer List. More...
 
static void mix_screen_coordinates (struct Remailer **type2_list, struct Coord **coordsp, struct MixChain *chain, int i)
 Get the screen coordinates to place a chain. More...
 
static void mix_redraw_ce (struct Remailer **type2_list, struct Coord *coords, struct MixChain *chain, int i, bool selected)
 Redraw the Remailer chain. More...
 
static void mix_redraw_chain (struct Remailer **type2_list, struct Coord *coords, struct MixChain *chain, int cur)
 Redraw the chain on screen. More...
 
static void mix_redraw_head (struct MixChain *chain)
 Redraw the Chain info. More...
 
static const char * mix_format_caps (struct Remailer *r)
 Turn flags into a MixMaster capability string. More...
 
static const char * mix_format_str (char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, unsigned long data, MuttFormatFlags flags)
 Format a string for the remailer menu - Implements format_t. More...
 
static void mix_entry (char *buf, size_t buflen, struct Menu *menu, int num)
 Format a menu item for the mixmaster chain list. More...
 
static int mix_chain_add (struct MixChain *chain, const char *s, struct Remailer **type2_list)
 Add a host to the chain. More...
 
void mix_make_chain (struct ListHead *chainhead)
 Create a Mixmaster chain. More...
 
int mix_check_message (struct Email *msg)
 Safety-check the message before passing it to mixmaster. More...
 
int mix_send_message (struct ListHead *chain, const char *tempfile)
 Send an email via Mixmaster. More...
 

Variables

char * C_MixEntryFormat
 Config: (mixmaster) printf-like format string for the mixmaster chain. More...
 
char * C_Mixmaster
 Config: (mixmaster) External command to route a mixmaster message. More...
 
static const struct Mapping RemailerHelp []
 

Detailed Description

Support of Mixmaster anonymous remailer.

Authors
  • Thomas Roessler

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file remailer.c.

Macro Definition Documentation

#define MIX_HOFFSET   2

Definition at line 259 of file remailer.c.

#define MIX_VOFFSET   (MuttIndexWindow->rows - 4)

Definition at line 260 of file remailer.c.

#define MIX_MAXROW   (MuttIndexWindow->rows - 1)

Definition at line 261 of file remailer.c.

Function Documentation

static MixCapFlags mix_get_caps ( const char *  capstr)
static

Get Mixmaster Capabilities.

Parameters
capstrCapability string to parse
Return values
numCapabilities, see MixCapFlags

Definition at line 74 of file remailer.c.

75 {
77 
78  while (*capstr)
79  {
80  switch (*capstr)
81  {
82  case 'C':
83  caps |= MIX_CAP_COMPRESS;
84  break;
85 
86  case 'M':
87  caps |= MIX_CAP_MIDDLEMAN;
88  break;
89 
90  case 'N':
91  {
92  switch (*++capstr)
93  {
94  case 'm':
95  caps |= MIX_CAP_NEWSMAIL;
96  break;
97 
98  case 'p':
99  caps |= MIX_CAP_NEWSPOST;
100  break;
101  }
102  }
103  }
104 
105  if (*capstr)
106  capstr++;
107  }
108 
109  return caps;
110 }
#define MIX_CAP_NEWSPOST
Definition: remailer.h:43
uint8_t MixCapFlags
Flags, e.g. MIX_CAP_NO_FLAGS.
Definition: remailer.h:39
#define MIX_CAP_NO_FLAGS
No flags are set.
Definition: remailer.h:40
#define MIX_CAP_NEWSMAIL
Definition: remailer.h:44
#define MIX_CAP_MIDDLEMAN
Definition: remailer.h:42
#define MIX_CAP_COMPRESS
Definition: remailer.h:41

+ Here is the caller graph for this function:

static void mix_add_entry ( struct Remailer ***  type2_list,
struct Remailer entry,
size_t *  slots,
size_t *  used 
)
static

Add an entry to the Remailer list.

Parameters
[out]type2_listRemailer list to add to
[in]entryRemailer to add
[out]slotsTotal number of slots
[out]usedNumber of slots used

Definition at line 119 of file remailer.c.

121 {
122  if (*used == *slots)
123  {
124  *slots += 5;
125  mutt_mem_realloc(type2_list, sizeof(struct Remailer *) * (*slots));
126  }
127 
128  (*type2_list)[(*used)++] = entry;
129  if (entry)
130  entry->num = *used;
131 }
int num
Definition: remailer.h:51
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:121
A Mixmaster remailer.
Definition: remailer.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static struct Remailer* mix_new_remailer ( void  )
static

Create a new Remailer.

Return values
ptrNewly allocated Remailer

Definition at line 137 of file remailer.c.

138 {
139  return mutt_mem_calloc(1, sizeof(struct Remailer));
140 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
A Mixmaster remailer.
Definition: remailer.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void mix_free_remailer ( struct Remailer **  r)
static

Free a Remailer.

Parameters
[out]rRemailer to free

Definition at line 146 of file remailer.c.

147 {
148  FREE(&(*r)->shortname);
149  FREE(&(*r)->addr);
150  FREE(&(*r)->ver);
151 
152  FREE(r);
153 }
#define FREE(x)
Definition: memory.h:40

+ Here is the caller graph for this function:

static struct Remailer** mix_type2_list ( size_t *  l)
static

parse the type2.list as given by mixmaster -T

Parameters
[out]lLength of list
Return values
ptrtype2.list

Definition at line 160 of file remailer.c.

161 {
162  if (!l)
163  return NULL;
164 
165  FILE *fp = NULL;
166  char line[8192];
167  char *t = NULL;
168 
169  struct Remailer **type2_list = NULL, *p = NULL;
170  size_t slots = 0, used = 0;
171 
172  int fd_null = open("/dev/null", O_RDWR);
173  if (fd_null == -1)
174  return NULL;
175 
176  struct Buffer *cmd = mutt_buffer_pool_get();
177  mutt_buffer_printf(cmd, "%s -T", C_Mixmaster);
178 
179  pid_t mm_pid =
180  mutt_create_filter_fd(mutt_b2s(cmd), NULL, &fp, NULL, fd_null, -1, fd_null);
181  if (mm_pid == -1)
182  {
184  close(fd_null);
185  return NULL;
186  }
187 
189 
190  /* first, generate the "random" remailer */
191 
192  p = mix_new_remailer();
193  p->shortname = mutt_str_strdup(_("<random>"));
194  mix_add_entry(&type2_list, p, &slots, &used);
195 
196  while (fgets(line, sizeof(line), fp))
197  {
198  p = mix_new_remailer();
199 
200  t = strtok(line, " \t\n");
201  if (!t)
202  goto problem;
203 
204  p->shortname = mutt_str_strdup(t);
205 
206  t = strtok(NULL, " \t\n");
207  if (!t)
208  goto problem;
209 
210  p->addr = mutt_str_strdup(t);
211 
212  t = strtok(NULL, " \t\n");
213  if (!t)
214  goto problem;
215 
216  t = strtok(NULL, " \t\n");
217  if (!t)
218  goto problem;
219 
220  p->ver = mutt_str_strdup(t);
221 
222  t = strtok(NULL, " \t\n");
223  if (!t)
224  goto problem;
225 
226  p->caps = mix_get_caps(t);
227 
228  mix_add_entry(&type2_list, p, &slots, &used);
229  continue;
230 
231  problem:
232  mix_free_remailer(&p);
233  }
234 
235  *l = used;
236 
237  mix_add_entry(&type2_list, NULL, &slots, &used);
238  mutt_wait_filter(mm_pid);
239 
240  close(fd_null);
241 
242  return type2_list;
243 }
static struct Remailer * mix_new_remailer(void)
Create a new Remailer.
Definition: remailer.c:137
static void mix_free_remailer(struct Remailer **r)
Free a Remailer.
Definition: remailer.c:146
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:200
char * C_Mixmaster
Config: (mixmaster) External command to route a mixmaster message.
Definition: remailer.c:58
static void mix_add_entry(struct Remailer ***type2_list, struct Remailer *entry, size_t *slots, size_t *used)
Add an entry to the Remailer list.
Definition: remailer.c:119
#define mutt_b2s(buf)
Definition: buffer.h:42
const char * line
Definition: common.c:35
pid_t mutt_create_filter_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:64
static MixCapFlags mix_get_caps(const char *capstr)
Get Mixmaster Capabilities.
Definition: remailer.c:74
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
int mutt_wait_filter(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:227
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: buffer.c:409
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: buffer.c:398
A Mixmaster remailer.
Definition: remailer.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void mix_free_type2_list ( struct Remailer ***  ttlp)
static

Free a Remailer List.

Parameters
[out]ttlpRemailer List to free

Definition at line 249 of file remailer.c.

250 {
251  struct Remailer **type2_list = *ttlp;
252 
253  for (int i = 0; type2_list[i]; i++)
254  mix_free_remailer(&type2_list[i]);
255 
256  FREE(type2_list);
257 }
static void mix_free_remailer(struct Remailer **r)
Free a Remailer.
Definition: remailer.c:146
#define FREE(x)
Definition: memory.h:40
A Mixmaster remailer.
Definition: remailer.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void mix_screen_coordinates ( struct Remailer **  type2_list,
struct Coord **  coordsp,
struct MixChain chain,
int  i 
)
static

Get the screen coordinates to place a chain.

Parameters
[out]type2_listRemailer List
[out]coordspOn screen coordinates
[in]chainChain
[in]iIndex in chain

Definition at line 270 of file remailer.c.

272 {
273  if (!chain->cl)
274  return;
275 
276  short c, r;
277 
278  mutt_mem_realloc(coordsp, sizeof(struct Coord) * chain->cl);
279 
280  struct Coord *coords = *coordsp;
281 
282  if (i)
283  {
284  c = coords[i - 1].c + strlen(type2_list[chain->ch[i - 1]]->shortname) + 2;
285  r = coords[i - 1].r;
286  }
287  else
288  {
289  r = MIX_VOFFSET;
290  c = MIX_HOFFSET;
291  }
292 
293  for (; i < chain->cl; i++)
294  {
295  short oc = c;
296  c += strlen(type2_list[chain->ch[i]]->shortname) + 2;
297 
298  if (c >= MuttIndexWindow->cols)
299  {
300  oc = MIX_HOFFSET;
301  c = MIX_HOFFSET;
302  r++;
303  }
304 
305  coords[i].c = oc;
306  coords[i].r = r;
307  }
308 }
#define MIX_VOFFSET
Definition: remailer.c:260
int ch[MAX_MIXES]
Definition: remailer.h:64
short r
row
Definition: remailer.c:65
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:121
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
char * shortname
Definition: remailer.h:52
size_t cl
Definition: remailer.h:63
#define MIX_HOFFSET
Definition: remailer.c:259
Screen coordinates.
Definition: remailer.c:63
short c
column
Definition: remailer.c:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void mix_redraw_ce ( struct Remailer **  type2_list,
struct Coord coords,
struct MixChain chain,
int  i,
bool  selected 
)
static

Redraw the Remailer chain.

Parameters
[out]type2_listRemailer List
[in]coordsScreen Coordinates
[in]chainChain
[in]iIndex in chain
[in]selectedtrue, if this item is selected

Definition at line 318 of file remailer.c.

320 {
321  if (!coords || !chain)
322  return;
323 
324  if (coords[i].r < MIX_MAXROW)
325  {
326  if (selected)
328  else
329  NORMAL_COLOR;
330 
331  mutt_window_mvaddstr(MuttIndexWindow, coords[i].r, coords[i].c,
332  type2_list[chain->ch[i]]->shortname);
333  NORMAL_COLOR;
334 
335  if (i + 1 < chain->cl)
336  addstr(", ");
337  }
338 }
int ch[MAX_MIXES]
Definition: remailer.h:64
#define NORMAL_COLOR
Definition: mutt_curses.h:239
short r
row
Definition: remailer.c:65
#define MIX_MAXROW
Definition: remailer.c:261
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
char * shortname
Definition: remailer.h:52
size_t cl
Definition: remailer.h:63
#define SET_COLOR(X)
Definition: mutt_curses.h:224
int mutt_window_mvaddstr(struct MuttWindow *win, int row, int col, const char *str)
Move the cursor and write a fixed string to a Window.
Definition: mutt_window.c:190
Selected item in list.
Definition: mutt_curses.h:128
short c
column
Definition: remailer.c:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void mix_redraw_chain ( struct Remailer **  type2_list,
struct Coord coords,
struct MixChain chain,
int  cur 
)
static

Redraw the chain on screen.

Parameters
[out]type2_listRemailer List
[in]coordsWhere to draw the list on screen
[in]chainChain to display
[in]curChain index of current selection

Definition at line 347 of file remailer.c.

349 {
350  for (int i = MIX_VOFFSET; i < MIX_MAXROW; i++)
351  {
354  }
355 
356  for (int i = 0; i < chain->cl; i++)
357  mix_redraw_ce(type2_list, coords, chain, i, i == cur);
358 }
#define MIX_VOFFSET
Definition: remailer.c:260
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:81
#define MIX_MAXROW
Definition: remailer.c:261
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
size_t cl
Definition: remailer.h:63
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:162
static void mix_redraw_ce(struct Remailer **type2_list, struct Coord *coords, struct MixChain *chain, int i, bool selected)
Redraw the Remailer chain.
Definition: remailer.c:318

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void mix_redraw_head ( struct MixChain chain)
static

Redraw the Chain info.

Parameters
chainChain

Definition at line 364 of file remailer.c.

365 {
368  "-- Remailer chain [Length: %d]", chain ? chain->cl : 0);
370  NORMAL_COLOR;
371 }
#define MIX_VOFFSET
Definition: remailer.c:260
#define NORMAL_COLOR
Definition: mutt_curses.h:239
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:81
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
size_t cl
Definition: remailer.h:63
#define SET_COLOR(X)
Definition: mutt_curses.h:224
Status bar.
Definition: mutt_curses.h:129
int mutt_window_mvprintw(struct MuttWindow *win, int row, int col, const char *fmt,...)
Move the cursor and write a formatted string to a Window.
Definition: mutt_window.c:220

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static const char* mix_format_caps ( struct Remailer r)
static

Turn flags into a MixMaster capability string.

Parameters
rRemailer to use
Return values
ptrCapability string
Note
The string is a static buffer

Definition at line 380 of file remailer.c.

381 {
382  static char capbuf[10];
383  char *t = capbuf;
384 
385  if (r->caps & MIX_CAP_COMPRESS)
386  *t++ = 'C';
387  else
388  *t++ = ' ';
389 
390  if (r->caps & MIX_CAP_MIDDLEMAN)
391  *t++ = 'M';
392  else
393  *t++ = ' ';
394 
395  if (r->caps & MIX_CAP_NEWSPOST)
396  {
397  *t++ = 'N';
398  *t++ = 'p';
399  }
400  else
401  {
402  *t++ = ' ';
403  *t++ = ' ';
404  }
405 
406  if (r->caps & MIX_CAP_NEWSMAIL)
407  {
408  *t++ = 'N';
409  *t++ = 'm';
410  }
411  else
412  {
413  *t++ = ' ';
414  *t++ = ' ';
415  }
416 
417  *t = '\0';
418 
419  return capbuf;
420 }
#define MIX_CAP_NEWSPOST
Definition: remailer.h:43
MixCapFlags caps
Definition: remailer.h:55
#define MIX_CAP_NEWSMAIL
Definition: remailer.h:44
#define MIX_CAP_MIDDLEMAN
Definition: remailer.h:42
#define MIX_CAP_COMPRESS
Definition: remailer.h:41

+ Here is the caller graph for this function:

static const char* mix_format_str ( char *  buf,
size_t  buflen,
size_t  col,
int  cols,
char  op,
const char *  src,
const char *  prec,
const char *  if_str,
const char *  else_str,
unsigned long  data,
MuttFormatFlags  flags 
)
static

Format a string for the remailer menu - Implements format_t.

Expando Description
%a The remailer's e-mail address
%c Remailer capabilities
%n The running number on the menu
%s The remailer's short name

Definition at line 432 of file remailer.c.

436 {
437  char fmt[128];
438  struct Remailer *remailer = (struct Remailer *) data;
439  int optional = (flags & MUTT_FORMAT_OPTIONAL);
440 
441  switch (op)
442  {
443  case 'a':
444  if (!optional)
445  {
446  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
447  snprintf(buf, buflen, fmt, NONULL(remailer->addr));
448  }
449  else if (!remailer->addr)
450  optional = 0;
451  break;
452 
453  case 'c':
454  if (!optional)
455  {
456  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
457  snprintf(buf, buflen, fmt, mix_format_caps(remailer));
458  }
459  break;
460 
461  case 'n':
462  if (!optional)
463  {
464  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
465  snprintf(buf, buflen, fmt, remailer->num);
466  }
467  break;
468 
469  case 's':
470  if (!optional)
471  {
472  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
473  snprintf(buf, buflen, fmt, NONULL(remailer->shortname));
474  }
475  else if (!remailer->shortname)
476  optional = 0;
477  break;
478 
479  default:
480  *buf = '\0';
481  }
482 
483  if (optional)
484  mutt_expando_format(buf, buflen, col, cols, if_str, attach_format_str, data,
486  else if (flags & MUTT_FORMAT_OPTIONAL)
487  mutt_expando_format(buf, buflen, col, cols, else_str, attach_format_str,
488  data, MUTT_FORMAT_NO_FLAGS);
489  return src;
490 }
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, MuttFormatFlags flags)
Expand expandos (x) in a string.
Definition: muttlib.c:836
#define NONULL(x)
Definition: string2.h:36
static const char * mix_format_caps(struct Remailer *r)
Turn flags into a MixMaster capability string.
Definition: remailer.c:380
int num
Definition: remailer.h:51
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
char * shortname
Definition: remailer.h:52
const char * attach_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, unsigned long data, MuttFormatFlags flags)
Format a string for the attachment menu - Implements format_t.
Definition: recvattach.c:209
#define MUTT_FORMAT_OPTIONAL
Allow optional field processing.
Definition: format_flags.h:33
char * addr
Definition: remailer.h:53
A Mixmaster remailer.
Definition: remailer.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void mix_entry ( char *  buf,
size_t  buflen,
struct Menu menu,
int  num 
)
static

Format a menu item for the mixmaster chain list.

Parameters
[out]bufBuffer in which to save string
[in]buflenBuffer length
[in]menuMenu containing aliases
[in]numIndex into the menu

Definition at line 499 of file remailer.c.

500 {
501  struct Remailer **type2_list = menu->data;
502  mutt_expando_format(buf, buflen, 0, MuttIndexWindow->cols,
504  (unsigned long) type2_list[num], MUTT_FORMAT_ARROWCURSOR);
505 }
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, MuttFormatFlags flags)
Expand expandos (x) in a string.
Definition: muttlib.c:836
#define NONULL(x)
Definition: string2.h:36
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: format_flags.h:35
int num
Definition: remailer.h:51
char * C_MixEntryFormat
Config: (mixmaster) printf-like format string for the mixmaster chain.
Definition: remailer.c:57
static const char * mix_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, unsigned long data, MuttFormatFlags flags)
Format a string for the remailer menu - Implements format_t.
Definition: remailer.c:432
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
void * data
extra data for the current menu
Definition: mutt_menu.h:86
A Mixmaster remailer.
Definition: remailer.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int mix_chain_add ( struct MixChain chain,
const char *  s,
struct Remailer **  type2_list 
)
static

Add a host to the chain.

Parameters
[in]chainChain to add to
[in]sHostname
[out]type2_listRemailer List
Return values
0Success
-1Error

Definition at line 515 of file remailer.c.

516 {
517  int i;
518 
519  if (chain->cl >= MAX_MIXES)
520  return -1;
521 
522  if ((mutt_str_strcmp(s, "0") == 0) || (mutt_str_strcasecmp(s, "<random>") == 0))
523  {
524  chain->ch[chain->cl++] = 0;
525  return 0;
526  }
527 
528  for (i = 0; type2_list[i]; i++)
529  {
530  if (mutt_str_strcasecmp(s, type2_list[i]->shortname) == 0)
531  {
532  chain->ch[chain->cl++] = i;
533  return 0;
534  }
535  }
536 
537  /* replace unknown remailers by <random> */
538 
539  if (!type2_list[i])
540  chain->ch[chain->cl++] = 0;
541 
542  return 0;
543 }
int ch[MAX_MIXES]
Definition: remailer.h:64
char * shortname
Definition: remailer.h:52
size_t cl
Definition: remailer.h:63
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:631
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:618
#define MAX_MIXES
Definition: remailer.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mix_make_chain ( struct ListHead *  chainhead)

Create a Mixmaster chain.

Parameters
chainheadList if chain links

Ask the user to select Mixmaster hosts to create a chain.

Definition at line 557 of file remailer.c.

558 {
559  int c_cur = 0, c_old = 0;
560  bool c_redraw = true;
561  size_t ttll = 0;
562 
563  struct Coord *coords = NULL;
564 
565  struct Menu *menu = NULL;
566  char helpstr[1024];
567  bool loop = true;
568 
569  char *t = NULL;
570 
571  struct Remailer **type2_list = mix_type2_list(&ttll);
572  if (!type2_list)
573  {
574  mutt_error(_("Can't get mixmaster's type2.list"));
575  return;
576  }
577 
578  struct MixChain *chain = mutt_mem_calloc(1, sizeof(struct MixChain));
579 
580  struct ListNode *p = NULL;
581  STAILQ_FOREACH(p, chainhead, entries)
582  {
583  mix_chain_add(chain, p->data, type2_list);
584  }
585  mutt_list_free(chainhead);
586 
587  /* safety check */
588  for (int i = 0; i < chain->cl; i++)
589  {
590  if (chain->ch[i] >= ttll)
591  chain->ch[i] = 0;
592  }
593 
594  mix_screen_coordinates(type2_list, &coords, chain, 0);
595 
596  menu = mutt_menu_new(MENU_MIX);
597  menu->max = ttll;
598  menu->menu_make_entry = mix_entry;
599  menu->menu_tag = NULL;
600  menu->title = _("Select a remailer chain");
601  menu->data = type2_list;
602  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_MIX, RemailerHelp);
603  menu->pagelen = MIX_VOFFSET - 1;
605 
606  while (loop)
607  {
608  if (menu->pagelen != MIX_VOFFSET - 1)
609  {
610  menu->pagelen = MIX_VOFFSET - 1;
611  menu->redraw = REDRAW_FULL;
612  }
613 
614  if (c_redraw)
615  {
616  mix_redraw_head(chain);
617  mix_redraw_chain(type2_list, coords, chain, c_cur);
618  c_redraw = false;
619  }
620  else if (c_cur != c_old)
621  {
622  mix_redraw_ce(type2_list, coords, chain, c_old, false);
623  mix_redraw_ce(type2_list, coords, chain, c_cur, true);
624  }
625 
626  c_old = c_cur;
627 
628  const int op = mutt_menu_loop(menu);
629  switch (op)
630  {
631  case OP_REDRAW:
632  {
633  menu_redraw_status(menu);
634  mix_redraw_head(chain);
635  mix_screen_coordinates(type2_list, &coords, chain, 0);
636  mix_redraw_chain(type2_list, coords, chain, c_cur);
637  menu->pagelen = MIX_VOFFSET - 1;
638  break;
639  }
640 
641  case OP_EXIT:
642  {
643  chain->cl = 0;
644  loop = false;
645  break;
646  }
647 
648  case OP_MIX_USE:
649  {
650  if (!chain->cl)
651  {
652  chain->cl++;
653  chain->ch[0] = menu->current;
654  mix_screen_coordinates(type2_list, &coords, chain, c_cur);
655  c_redraw = true;
656  }
657 
658  if (chain->cl && chain->ch[chain->cl - 1] &&
659  (type2_list[chain->ch[chain->cl - 1]]->caps & MIX_CAP_MIDDLEMAN))
660  {
661  mutt_error(
662  _("Error: %s can't be used as the final remailer of a chain"),
663  type2_list[chain->ch[chain->cl - 1]]->shortname);
664  }
665  else
666  {
667  loop = false;
668  }
669  break;
670  }
671 
672  case OP_GENERIC_SELECT_ENTRY:
673  case OP_MIX_APPEND:
674  {
675  if ((chain->cl < MAX_MIXES) && (c_cur < chain->cl))
676  c_cur++;
677  }
678  /* fallthrough */
679  case OP_MIX_INSERT:
680  {
681  if (chain->cl < MAX_MIXES)
682  {
683  chain->cl++;
684  for (int i = chain->cl - 1; i > c_cur; i--)
685  chain->ch[i] = chain->ch[i - 1];
686 
687  chain->ch[c_cur] = menu->current;
688  mix_screen_coordinates(type2_list, &coords, chain, c_cur);
689  c_redraw = true;
690  }
691  else
692  {
693  /* L10N The '%d' here hard-coded to 19 */
694  mutt_error(_("Mixmaster chains are limited to %d elements"), MAX_MIXES);
695  }
696 
697  break;
698  }
699 
700  case OP_MIX_DELETE:
701  {
702  if (chain->cl)
703  {
704  chain->cl--;
705 
706  for (int i = c_cur; i < chain->cl; i++)
707  chain->ch[i] = chain->ch[i + 1];
708 
709  if ((c_cur == chain->cl) && c_cur)
710  c_cur--;
711 
712  mix_screen_coordinates(type2_list, &coords, chain, c_cur);
713  c_redraw = true;
714  }
715  else
716  {
717  mutt_error(_("The remailer chain is already empty"));
718  }
719  break;
720  }
721 
722  case OP_MIX_CHAIN_PREV:
723  {
724  if (c_cur)
725  c_cur--;
726  else
727  mutt_error(_("You already have the first chain element selected"));
728 
729  break;
730  }
731 
732  case OP_MIX_CHAIN_NEXT:
733  {
734  if (chain->cl && (c_cur < chain->cl - 1))
735  c_cur++;
736  else
737  mutt_error(_("You already have the last chain element selected"));
738 
739  break;
740  }
741  }
742  }
743 
744  mutt_menu_pop_current(menu);
745  mutt_menu_destroy(&menu);
746 
747  /* construct the remailer list */
748 
749  if (chain->cl)
750  {
751  for (int i = 0; i < chain->cl; i++)
752  {
753  const int j = chain->ch[i];
754  if (j != 0)
755  t = type2_list[j]->shortname;
756  else
757  t = "*";
758 
759  mutt_list_insert_tail(chainhead, mutt_str_strdup(t));
760  }
761  }
762 
763  mix_free_type2_list(&type2_list);
764  FREE(&coords);
765  FREE(&chain);
766 }
#define MIX_VOFFSET
Definition: remailer.c:260
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:47
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
GUI selectable list of items.
Definition: mutt_menu.h:82
A Mixmaster chain.
Definition: remailer.h:61
int ch[MAX_MIXES]
Definition: remailer.h:64
static void mix_redraw_chain(struct Remailer **type2_list, struct Coord *coords, struct MixChain *chain, int cur)
Redraw the chain on screen.
Definition: remailer.c:347
MixCapFlags caps
Definition: remailer.h:55
#define _(a)
Definition: message.h:28
int menu
menu definition for keymap entries.
Definition: mutt_menu.h:90
static void mix_screen_coordinates(struct Remailer **type2_list, struct Coord **coordsp, struct MixChain *chain, int i)
Get the screen coordinates to place a chain.
Definition: remailer.c:270
static void mix_redraw_head(struct MixChain *chain)
Redraw the Chain info.
Definition: remailer.c:364
void(* menu_make_entry)(char *buf, size_t buflen, struct Menu *menu, int line)
Format a item for a menu.
Definition: mutt_menu.h:122
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:117
char * mutt_compile_help(char *buf, size_t buflen, int menu, const struct Mapping *items)
Create the text for the help menu.
Definition: help.c:115
static void mix_free_type2_list(struct Remailer ***ttlp)
Free a Remailer List.
Definition: remailer.c:249
static void mix_entry(char *buf, size_t buflen, struct Menu *menu, int num)
Format a menu item for the mixmaster chain list.
Definition: remailer.c:499
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:61
char * shortname
Definition: remailer.h:52
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
int pagelen
number of entries per screen
Definition: mutt_menu.h:92
size_t cl
Definition: remailer.h:63
#define MIX_CAP_MIDDLEMAN
Definition: remailer.h:42
int max
the number of entries in the menu
Definition: mutt_menu.h:88
int(* menu_tag)(struct Menu *menu, int sel, int act)
Tag some menu items.
Definition: mutt_menu.h:139
MuttRedrawFlags redraw
when to redraw the screen
Definition: mutt_menu.h:89
char * title
the title of this menu
Definition: mutt_menu.h:84
static void mix_redraw_ce(struct Remailer **type2_list, struct Coord *coords, struct MixChain *chain, int i, bool selected)
Redraw the Remailer chain.
Definition: remailer.c:318
char * data
Definition: list.h:35
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define mutt_error(...)
Definition: logging.h:83
#define FREE(x)
Definition: memory.h:40
void * data
extra data for the current menu
Definition: mutt_menu.h:86
static int mix_chain_add(struct MixChain *chain, const char *s, struct Remailer **type2_list)
Add a host to the chain.
Definition: remailer.c:515
int current
current entry
Definition: mutt_menu.h:87
A List node for strings.
Definition: list.h:33
static struct Remailer ** mix_type2_list(size_t *l)
parse the type2.list as given by mixmaster -T
Definition: remailer.c:160
char * help
quickref for the current menu
Definition: mutt_menu.h:85
#define MAX_MIXES
Definition: remailer.h:37
Screen coordinates.
Definition: remailer.c:63
static const struct Mapping RemailerHelp[]
Definition: remailer.c:545
A Mixmaster remailer.
Definition: remailer.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mix_check_message ( struct Email msg)

Safety-check the message before passing it to mixmaster.

Parameters
msgEmail
Return values
0Success
-1Error

Definition at line 774 of file remailer.c.

775 {
776  bool need_hostname = false;
777 
778  if (msg->env->cc || msg->env->bcc)
779  {
780  mutt_error(_("Mixmaster doesn't accept Cc or Bcc headers"));
781  return -1;
782  }
783 
784  /* When using mixmaster, we MUST qualify any addresses since
785  * the message will be delivered through remote systems.
786  *
787  * use_domain won't be respected at this point, hidden_host will.
788  */
789 
790  for (struct Address *a = msg->env->to; a; a = a->next)
791  {
792  if (!a->group && !strchr(a->mailbox, '@'))
793  {
794  need_hostname = true;
795  break;
796  }
797  }
798 
799  if (need_hostname)
800  {
801  const char *fqdn = mutt_fqdn(true);
802  if (!fqdn)
803  {
804  mutt_error(_("Please set the hostname variable to a proper value when "
805  "using mixmaster"));
806  return -1;
807  }
808 
809  /* Cc and Bcc are empty at this point. */
810  mutt_addr_qualify(msg->env->to, fqdn);
811  mutt_addr_qualify(msg->env->reply_to, fqdn);
813  }
814 
815  return 0;
816 }
struct Address * to
Definition: envelope.h:42
#define _(a)
Definition: message.h:28
An email address.
Definition: address.h:32
struct Address * reply_to
Definition: envelope.h:46
struct Address * mail_followup_to
Definition: envelope.h:47
struct Envelope * env
envelope information
Definition: email.h:92
struct Address * bcc
Definition: envelope.h:44
const char * mutt_fqdn(bool may_hide_host)
Get the Fully-Qualified Domain Name.
Definition: sendlib.c:2453
void mutt_addr_qualify(struct Address *addr, const char *host)
Expand local names in an Address list using a hostname.
Definition: address.c:674
#define mutt_error(...)
Definition: logging.h:83
struct Address * cc
Definition: envelope.h:43
struct Address * next
Definition: address.h:39

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mix_send_message ( struct ListHead *  chain,
const char *  tempfile 
)

Send an email via Mixmaster.

Parameters
chainString list of hosts
tempfileTemporary file containing email
Return values
-1Error
>=0Success (Mixmaster's return code)

Definition at line 825 of file remailer.c.

826 {
827  int i = 0;
828  struct Buffer *cmd = mutt_buffer_pool_get();
829  struct Buffer *cd_quoted = mutt_buffer_pool_get();
830 
831  mutt_buffer_printf(cmd, "cat %s | %s -m ", tempfile, C_Mixmaster);
832 
833  struct ListNode *np = NULL;
834  STAILQ_FOREACH(np, chain, entries)
835  {
836  mutt_buffer_addstr(cmd, i ? "," : " -l ");
837  mutt_buffer_quote_filename(cd_quoted, (char *) np->data, true);
838  mutt_buffer_addstr(cmd, mutt_b2s(cd_quoted));
839  i = 1;
840  }
841 
842  mutt_endwin();
843 
844  i = mutt_system(cmd->data);
845  if (i != 0)
846  {
847  fprintf(stderr, _("Error sending message, child exited %d.\n"), i);
848  if (!OptNoCurses)
849  {
851  mutt_error(_("Error sending message"));
852  }
853  }
854 
856  mutt_buffer_pool_release(&cd_quoted);
857  unlink(tempfile);
858  return i;
859 }
void mutt_buffer_quote_filename(struct Buffer *buf, const char *filename, bool add_outer)
Quote a filename to survive the shell&#39;s quoting rules.
Definition: file.c:827
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:45
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:200
char * C_Mixmaster
Config: (mixmaster) External command to route a mixmaster message.
Definition: remailer.c:58
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:264
#define mutt_b2s(buf)
Definition: buffer.h:42
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:499
char * data
pointer to data
Definition: buffer.h:35
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:532
char * data
Definition: list.h:35
#define mutt_error(...)
Definition: logging.h:83
A List node for strings.
Definition: list.h:33
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: buffer.c:409
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:50
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: buffer.c:398

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

char* C_MixEntryFormat

Config: (mixmaster) printf-like format string for the mixmaster chain.

Definition at line 57 of file remailer.c.

char* C_Mixmaster

Config: (mixmaster) External command to route a mixmaster message.

Definition at line 58 of file remailer.c.

const struct Mapping RemailerHelp[]
static
Initial value:
= {
{ N_("Append"), OP_MIX_APPEND }, { N_("Insert"), OP_MIX_INSERT },
{ N_("Delete"), OP_MIX_DELETE }, { N_("Abort"), OP_EXIT },
{ N_("OK"), OP_MIX_USE }, { NULL, 0 },
}
#define N_(a)
Definition: message.h:32

Definition at line 545 of file remailer.c.