NeoMutt  2019-11-11
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 "color.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   (win->rows - 4)
 
#define MIX_MAXROW   (win->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 Remailerremailer_new (void)
 Create a new Remailer. More...
 
static void remailer_free (struct Remailer **ptr)
 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_type2_list_free (struct Remailer ***ttlp)
 Free a Remailer List. More...
 
static void mix_screen_coordinates (struct MuttWindow *win, 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 MuttWindow *win, 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 MuttWindow *win, struct Remailer **type2_list, struct Coord *coords, struct MixChain *chain, int cur)
 Redraw the chain on screen. More...
 
static void mix_redraw_head (struct MuttWindow *win, 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 MuttWindow *win, struct ListHead *chainhead, int cols)
 Create a Mixmaster chain. More...
 
int mix_check_message (struct Email *e)
 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
  • Pietro Cerutti

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

◆ MIX_HOFFSET

#define MIX_HOFFSET   2

Definition at line 62 of file remailer.c.

◆ MIX_VOFFSET

#define MIX_VOFFSET   (win->rows - 4)

Definition at line 63 of file remailer.c.

◆ MIX_MAXROW

#define MIX_MAXROW   (win->rows - 1)

Definition at line 64 of file remailer.c.

Function Documentation

◆ mix_get_caps()

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 86 of file remailer.c.

87 {
89 
90  while (*capstr)
91  {
92  switch (*capstr)
93  {
94  case 'C':
95  caps |= MIX_CAP_COMPRESS;
96  break;
97 
98  case 'M':
99  caps |= MIX_CAP_MIDDLEMAN;
100  break;
101 
102  case 'N':
103  {
104  switch (*++capstr)
105  {
106  case 'm':
107  caps |= MIX_CAP_NEWSMAIL;
108  break;
109 
110  case 'p':
111  caps |= MIX_CAP_NEWSPOST;
112  break;
113  }
114  }
115  }
116 
117  if (*capstr)
118  capstr++;
119  }
120 
121  return caps;
122 }
#define MIX_CAP_NEWSPOST
Definition: remailer.h:44
uint8_t MixCapFlags
Flags, e.g. MIX_CAP_NO_FLAGS.
Definition: remailer.h:40
#define MIX_CAP_NO_FLAGS
No flags are set.
Definition: remailer.h:41
#define MIX_CAP_NEWSMAIL
Definition: remailer.h:45
#define MIX_CAP_MIDDLEMAN
Definition: remailer.h:43
#define MIX_CAP_COMPRESS
Definition: remailer.h:42
+ Here is the caller graph for this function:

◆ mix_add_entry()

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 131 of file remailer.c.

133 {
134  if (*used == *slots)
135  {
136  *slots += 5;
137  mutt_mem_realloc(type2_list, sizeof(struct Remailer *) * (*slots));
138  }
139 
140  (*type2_list)[(*used)++] = entry;
141  if (entry)
142  entry->num = *used;
143 }
int num
Definition: remailer.h:52
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
A Mixmaster remailer.
Definition: remailer.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remailer_new()

static struct Remailer* remailer_new ( void  )
static

Create a new Remailer.

Return values
ptrNewly allocated Remailer

Definition at line 149 of file remailer.c.

150 {
151  return mutt_mem_calloc(1, sizeof(struct Remailer));
152 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
A Mixmaster remailer.
Definition: remailer.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remailer_free()

static void remailer_free ( struct Remailer **  ptr)
static

Free a Remailer.

Parameters
[out]ptrRemailer to free

Definition at line 158 of file remailer.c.

159 {
160  if (!ptr || !*ptr)
161  return;
162 
163  struct Remailer *r = *ptr;
164 
165  FREE(&r->shortname);
166  FREE(&r->addr);
167  FREE(&r->ver);
168  FREE(ptr);
169 }
char * shortname
Definition: remailer.h:53
#define FREE(x)
Definition: memory.h:40
char * addr
Definition: remailer.h:54
char * ver
Definition: remailer.h:55
A Mixmaster remailer.
Definition: remailer.h:50
+ Here is the caller graph for this function:

◆ mix_type2_list()

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 176 of file remailer.c.

177 {
178  if (!l)
179  return NULL;
180 
181  FILE *fp = NULL;
182  char line[8192];
183  char *t = NULL;
184 
185  struct Remailer **type2_list = NULL;
186  struct Remailer *p = NULL;
187  size_t slots = 0, used = 0;
188 
189  int fd_null = open("/dev/null", O_RDWR);
190  if (fd_null == -1)
191  return NULL;
192 
193  struct Buffer *cmd = mutt_buffer_pool_get();
194  mutt_buffer_printf(cmd, "%s -T", C_Mixmaster);
195 
196  pid_t mm_pid =
197  mutt_create_filter_fd(mutt_b2s(cmd), NULL, &fp, NULL, fd_null, -1, fd_null);
198  if (mm_pid == -1)
199  {
201  close(fd_null);
202  return NULL;
203  }
204 
206 
207  /* first, generate the "random" remailer */
208 
209  p = remailer_new();
210  p->shortname = mutt_str_strdup(_("<random>"));
211  mix_add_entry(&type2_list, p, &slots, &used);
212 
213  while (fgets(line, sizeof(line), fp))
214  {
215  p = remailer_new();
216 
217  t = strtok(line, " \t\n");
218  if (!t)
219  goto problem;
220 
221  p->shortname = mutt_str_strdup(t);
222 
223  t = strtok(NULL, " \t\n");
224  if (!t)
225  goto problem;
226 
227  p->addr = mutt_str_strdup(t);
228 
229  t = strtok(NULL, " \t\n");
230  if (!t)
231  goto problem;
232 
233  t = strtok(NULL, " \t\n");
234  if (!t)
235  goto problem;
236 
237  p->ver = mutt_str_strdup(t);
238 
239  t = strtok(NULL, " \t\n");
240  if (!t)
241  goto problem;
242 
243  p->caps = mix_get_caps(t);
244 
245  mix_add_entry(&type2_list, p, &slots, &used);
246  continue;
247 
248  problem:
249  remailer_free(&p);
250  }
251 
252  *l = used;
253 
254  mix_add_entry(&type2_list, NULL, &slots, &used);
255  mutt_wait_filter(mm_pid);
256 
257  close(fd_null);
258 
259  return type2_list;
260 }
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:100
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:111
MixCapFlags caps
Definition: remailer.h:56
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:160
char * C_Mixmaster
Config: (mixmaster) External command to route a mixmaster message.
Definition: remailer.c:60
static void remailer_free(struct Remailer **ptr)
Free a Remailer.
Definition: remailer.c:158
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:131
#define mutt_b2s(buf)
Definition: buffer.h:41
const char * line
Definition: common.c:36
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:65
char * shortname
Definition: remailer.h:53
static MixCapFlags mix_get_caps(const char *capstr)
Get Mixmaster Capabilities.
Definition: remailer.c:86
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
static struct Remailer * remailer_new(void)
Create a new Remailer.
Definition: remailer.c:149
char * addr
Definition: remailer.h:54
int mutt_wait_filter(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:221
char * ver
Definition: remailer.h:55
A Mixmaster remailer.
Definition: remailer.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_type2_list_free()

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

Free a Remailer List.

Parameters
[out]ttlpRemailer List to free

Definition at line 266 of file remailer.c.

267 {
268  struct Remailer **type2_list = *ttlp;
269 
270  for (int i = 0; type2_list[i]; i++)
271  remailer_free(&type2_list[i]);
272 
273  FREE(type2_list);
274 }
static void remailer_free(struct Remailer **ptr)
Free a Remailer.
Definition: remailer.c:158
#define FREE(x)
Definition: memory.h:40
A Mixmaster remailer.
Definition: remailer.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_screen_coordinates()

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

Get the screen coordinates to place a chain.

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

Definition at line 284 of file remailer.c.

286 {
287  if (!chain->cl)
288  return;
289 
290  short c, r;
291 
292  mutt_mem_realloc(coordsp, sizeof(struct Coord) * chain->cl);
293 
294  struct Coord *coords = *coordsp;
295 
296  if (i)
297  {
298  c = coords[i - 1].c + strlen(type2_list[chain->ch[i - 1]]->shortname) + 2;
299  r = coords[i - 1].r;
300  }
301  else
302  {
303  r = MIX_VOFFSET;
304  c = MIX_HOFFSET;
305  }
306 
307  for (; i < chain->cl; i++)
308  {
309  short oc = c;
310  c += strlen(type2_list[chain->ch[i]]->shortname) + 2;
311 
312  if (c >= win->cols)
313  {
314  oc = MIX_HOFFSET;
315  c = MIX_HOFFSET;
316  r++;
317  }
318 
319  coords[i].c = oc;
320  coords[i].r = r;
321  }
322 }
#define MIX_VOFFSET
Definition: remailer.c:63
int ch[MAX_MIXES]
Definition: remailer.h:65
short r
row
Definition: remailer.c:71
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
char * shortname
Definition: remailer.h:53
size_t cl
Definition: remailer.h:64
#define MIX_HOFFSET
Definition: remailer.c:62
Screen coordinates.
Definition: remailer.c:69
short c
column
Definition: remailer.c:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_redraw_ce()

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

Redraw the Remailer chain.

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

Definition at line 333 of file remailer.c.

335 {
336  if (!coords || !chain)
337  return;
338 
339  if (coords[i].r < MIX_MAXROW)
340  {
341  if (selected)
343  else
345 
346  mutt_window_mvaddstr(win, coords[i].r, coords[i].c, type2_list[chain->ch[i]]->shortname);
348 
349  if (i + 1 < chain->cl)
350  mutt_window_addstr(", ");
351  }
352 }
int ch[MAX_MIXES]
Definition: remailer.h:65
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:49
short r
row
Definition: remailer.c:71
#define MIX_MAXROW
Definition: remailer.c:64
Plain text.
Definition: color.h:78
Selected item in list.
Definition: color.h:74
char * shortname
Definition: remailer.h:53
size_t cl
Definition: remailer.h:64
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:212
int mutt_window_addstr(const char *str)
Write a string to a Window.
Definition: mutt_window.c:396
short c
column
Definition: remailer.c:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_redraw_chain()

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

Redraw the chain on screen.

Parameters
[in]winWindow
[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 362 of file remailer.c.

364 {
365  for (int i = MIX_VOFFSET; i < MIX_MAXROW; i++)
366  {
367  mutt_window_move(win, i, 0);
369  }
370 
371  for (int i = 0; i < chain->cl; i++)
372  mix_redraw_ce(win, type2_list, coords, chain, i, i == cur);
373 }
static void mix_redraw_ce(struct MuttWindow *win, struct Remailer **type2_list, struct Coord *coords, struct MixChain *chain, int i, bool selected)
Redraw the Remailer chain.
Definition: remailer.c:333
#define MIX_VOFFSET
Definition: remailer.c:63
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:117
#define MIX_MAXROW
Definition: remailer.c:64
size_t cl
Definition: remailer.h:64
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:198
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_redraw_head()

static void mix_redraw_head ( struct MuttWindow win,
struct MixChain chain 
)
static

Redraw the Chain info.

Parameters
winWindow
chainChain

Definition at line 380 of file remailer.c.

381 {
383  mutt_window_mvprintw(win, MIX_VOFFSET - 1, 0,
384  "-- Remailer chain [Length: %d]", chain ? chain->cl : 0);
387 }
#define MIX_VOFFSET
Definition: remailer.c:63
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:49
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:117
Plain text.
Definition: color.h:78
Status bar (takes a pattern)
Definition: color.h:95
size_t cl
Definition: remailer.h:64
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:231
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_format_caps()

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 396 of file remailer.c.

397 {
398  static char capbuf[10];
399  char *t = capbuf;
400 
401  if (r->caps & MIX_CAP_COMPRESS)
402  *t++ = 'C';
403  else
404  *t++ = ' ';
405 
406  if (r->caps & MIX_CAP_MIDDLEMAN)
407  *t++ = 'M';
408  else
409  *t++ = ' ';
410 
411  if (r->caps & MIX_CAP_NEWSPOST)
412  {
413  *t++ = 'N';
414  *t++ = 'p';
415  }
416  else
417  {
418  *t++ = ' ';
419  *t++ = ' ';
420  }
421 
422  if (r->caps & MIX_CAP_NEWSMAIL)
423  {
424  *t++ = 'N';
425  *t++ = 'm';
426  }
427  else
428  {
429  *t++ = ' ';
430  *t++ = ' ';
431  }
432 
433  *t = '\0';
434 
435  return capbuf;
436 }
#define MIX_CAP_NEWSPOST
Definition: remailer.h:44
MixCapFlags caps
Definition: remailer.h:56
#define MIX_CAP_NEWSMAIL
Definition: remailer.h:45
#define MIX_CAP_MIDDLEMAN
Definition: remailer.h:43
#define MIX_CAP_COMPRESS
Definition: remailer.h:42
+ Here is the caller graph for this function:

◆ mix_format_str()

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 448 of file remailer.c.

452 {
453  char fmt[128];
454  struct Remailer *remailer = (struct Remailer *) data;
455  bool optional = (flags & MUTT_FORMAT_OPTIONAL);
456 
457  switch (op)
458  {
459  case 'a':
460  if (!optional)
461  {
462  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
463  snprintf(buf, buflen, fmt, NONULL(remailer->addr));
464  }
465  else if (!remailer->addr)
466  optional = false;
467  break;
468 
469  case 'c':
470  if (!optional)
471  {
472  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
473  snprintf(buf, buflen, fmt, mix_format_caps(remailer));
474  }
475  break;
476 
477  case 'n':
478  if (!optional)
479  {
480  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
481  snprintf(buf, buflen, fmt, remailer->num);
482  }
483  break;
484 
485  case 's':
486  if (!optional)
487  {
488  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
489  snprintf(buf, buflen, fmt, NONULL(remailer->shortname));
490  }
491  else if (!remailer->shortname)
492  optional = false;
493  break;
494 
495  default:
496  *buf = '\0';
497  }
498 
499  if (optional)
500  mutt_expando_format(buf, buflen, col, cols, if_str, attach_format_str, data,
502  else if (flags & MUTT_FORMAT_OPTIONAL)
503  mutt_expando_format(buf, buflen, col, cols, else_str, attach_format_str,
504  data, MUTT_FORMAT_NO_FLAGS);
505  return src;
506 }
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:878
#define NONULL(x)
Definition: string2.h:37
static const char * mix_format_caps(struct Remailer *r)
Turn flags into a MixMaster capability string.
Definition: remailer.c:396
int num
Definition: remailer.h:52
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
char * shortname
Definition: remailer.h:53
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:54
A Mixmaster remailer.
Definition: remailer.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_entry()

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 515 of file remailer.c.

516 {
517  struct Remailer **type2_list = menu->data;
518  mutt_expando_format(buf, buflen, 0, menu->indexwin->cols,
520  (unsigned long) type2_list[num], MUTT_FORMAT_ARROWCURSOR);
521 }
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:878
#define NONULL(x)
Definition: string2.h:37
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: format_flags.h:35
int num
Definition: remailer.h:52
char * C_MixEntryFormat
Config: (mixmaster) printf-like format string for the mixmaster chain.
Definition: remailer.c:59
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:448
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
void * data
Extra data for the current menu.
Definition: mutt_menu.h:86
A Mixmaster remailer.
Definition: remailer.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_chain_add()

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 531 of file remailer.c.

532 {
533  int i;
534 
535  if (chain->cl >= MAX_MIXES)
536  return -1;
537 
538  if ((mutt_str_strcmp(s, "0") == 0) || (mutt_str_strcasecmp(s, "<random>") == 0))
539  {
540  chain->ch[chain->cl++] = 0;
541  return 0;
542  }
543 
544  for (i = 0; type2_list[i]; i++)
545  {
546  if (mutt_str_strcasecmp(s, type2_list[i]->shortname) == 0)
547  {
548  chain->ch[chain->cl++] = i;
549  return 0;
550  }
551  }
552 
553  /* replace unknown remailers by <random> */
554 
555  if (!type2_list[i])
556  chain->ch[chain->cl++] = 0;
557 
558  return 0;
559 }
int ch[MAX_MIXES]
Definition: remailer.h:65
char * shortname
Definition: remailer.h:53
size_t cl
Definition: remailer.h:64
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MAX_MIXES
Definition: remailer.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_make_chain()

void mix_make_chain ( struct MuttWindow win,
struct ListHead *  chainhead,
int  cols 
)

Create a Mixmaster chain.

Parameters
winWindow
chainheadList if chain links
colsNumber of screen columns

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

Definition at line 569 of file remailer.c.

570 {
571  int c_cur = 0, c_old = 0;
572  bool c_redraw = true;
573  size_t ttll = 0;
574 
575  struct Coord *coords = NULL;
576 
577  struct Menu *menu = NULL;
578  char helpstr[1024];
579  bool loop = true;
580 
581  char *t = NULL;
582 
583  struct Remailer **type2_list = mix_type2_list(&ttll);
584  if (!type2_list)
585  {
586  mutt_error(_("Can't get mixmaster's type2.list"));
587  return;
588  }
589 
590  struct MixChain *chain = mutt_mem_calloc(1, sizeof(struct MixChain));
591 
592  struct ListNode *p = NULL;
593  STAILQ_FOREACH(p, chainhead, entries)
594  {
595  mix_chain_add(chain, p->data, type2_list);
596  }
597  mutt_list_free(chainhead);
598 
599  /* safety check */
600  for (int i = 0; i < chain->cl; i++)
601  {
602  if (chain->ch[i] >= ttll)
603  chain->ch[i] = 0;
604  }
605 
606  mix_screen_coordinates(win, type2_list, &coords, chain, 0);
607 
608  menu = mutt_menu_new(MENU_MIX);
609  menu->max = ttll;
610  menu->menu_make_entry = mix_entry;
611  menu->menu_tag = NULL;
612  menu->title = _("Select a remailer chain");
613  menu->data = type2_list;
614  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_MIX, RemailerHelp);
615  menu->pagelen = MIX_VOFFSET - 1;
617 
618  while (loop)
619  {
620  if (menu->pagelen != MIX_VOFFSET - 1)
621  {
622  menu->pagelen = MIX_VOFFSET - 1;
623  menu->redraw = REDRAW_FULL;
624  }
625 
626  if (c_redraw)
627  {
628  mix_redraw_head(menu->indexwin, chain);
629  mix_redraw_chain(menu->indexwin, type2_list, coords, chain, c_cur);
630  c_redraw = false;
631  }
632  else if (c_cur != c_old)
633  {
634  mix_redraw_ce(menu->indexwin, type2_list, coords, chain, c_old, false);
635  mix_redraw_ce(menu->indexwin, type2_list, coords, chain, c_cur, true);
636  }
637 
638  c_old = c_cur;
639 
640  const int op = mutt_menu_loop(menu);
641  switch (op)
642  {
643  case OP_REDRAW:
644  {
645  menu_redraw_status(menu);
646  mix_redraw_head(menu->indexwin, chain);
647  mix_screen_coordinates(menu->indexwin, type2_list, &coords, chain, 0);
648  mix_redraw_chain(menu->indexwin, type2_list, coords, chain, c_cur);
649  menu->pagelen = MIX_VOFFSET - 1;
650  break;
651  }
652 
653  case OP_EXIT:
654  {
655  chain->cl = 0;
656  loop = false;
657  break;
658  }
659 
660  case OP_MIX_USE:
661  {
662  if (!chain->cl)
663  {
664  chain->cl++;
665  chain->ch[0] = menu->current;
666  mix_screen_coordinates(menu->indexwin, type2_list, &coords, chain, c_cur);
667  c_redraw = true;
668  }
669 
670  if (chain->cl && chain->ch[chain->cl - 1] &&
671  (type2_list[chain->ch[chain->cl - 1]]->caps & MIX_CAP_MIDDLEMAN))
672  {
673  mutt_error(
674  _("Error: %s can't be used as the final remailer of a chain"),
675  type2_list[chain->ch[chain->cl - 1]]->shortname);
676  }
677  else
678  {
679  loop = false;
680  }
681  break;
682  }
683 
684  case OP_GENERIC_SELECT_ENTRY:
685  case OP_MIX_APPEND:
686  {
687  if ((chain->cl < MAX_MIXES) && (c_cur < chain->cl))
688  c_cur++;
689  }
690  /* fallthrough */
691  case OP_MIX_INSERT:
692  {
693  if (chain->cl < MAX_MIXES)
694  {
695  chain->cl++;
696  for (int i = chain->cl - 1; i > c_cur; i--)
697  chain->ch[i] = chain->ch[i - 1];
698 
699  chain->ch[c_cur] = menu->current;
700  mix_screen_coordinates(menu->indexwin, type2_list, &coords, chain, c_cur);
701  c_redraw = true;
702  }
703  else
704  {
705  /* L10N The '%d' here hard-coded to 19 */
706  mutt_error(_("Mixmaster chains are limited to %d elements"), MAX_MIXES);
707  }
708 
709  break;
710  }
711 
712  case OP_MIX_DELETE:
713  {
714  if (chain->cl)
715  {
716  chain->cl--;
717 
718  for (int i = c_cur; i < chain->cl; i++)
719  chain->ch[i] = chain->ch[i + 1];
720 
721  if ((c_cur == chain->cl) && c_cur)
722  c_cur--;
723 
724  mix_screen_coordinates(menu->indexwin, type2_list, &coords, chain, c_cur);
725  c_redraw = true;
726  }
727  else
728  {
729  mutt_error(_("The remailer chain is already empty"));
730  }
731  break;
732  }
733 
734  case OP_MIX_CHAIN_PREV:
735  {
736  if (c_cur)
737  c_cur--;
738  else
739  mutt_error(_("You already have the first chain element selected"));
740 
741  break;
742  }
743 
744  case OP_MIX_CHAIN_NEXT:
745  {
746  if (chain->cl && (c_cur < chain->cl - 1))
747  c_cur++;
748  else
749  mutt_error(_("You already have the last chain element selected"));
750 
751  break;
752  }
753  }
754  }
755 
756  mutt_menu_pop_current(menu);
757  mutt_menu_free(&menu);
758 
759  /* construct the remailer list */
760 
761  if (chain->cl)
762  {
763  for (int i = 0; i < chain->cl; i++)
764  {
765  const int j = chain->ch[i];
766  if (j != 0)
767  t = type2_list[j]->shortname;
768  else
769  t = "*";
770 
771  mutt_list_insert_tail(chainhead, mutt_str_strdup(t));
772  }
773  }
774 
775  mix_type2_list_free(&type2_list);
776  FREE(&coords);
777  FREE(&chain);
778 }
static void mix_redraw_ce(struct MuttWindow *win, struct Remailer **type2_list, struct Coord *coords, struct MixChain *chain, int i, bool selected)
Redraw the Remailer chain.
Definition: remailer.c:333
#define MIX_VOFFSET
Definition: remailer.c:63
#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:50
GUI selectable list of items.
Definition: mutt_menu.h:82
A Mixmaster chain.
Definition: remailer.h:62
int ch[MAX_MIXES]
Definition: remailer.h:65
MixCapFlags caps
Definition: remailer.h:56
#define _(a)
Definition: message.h:28
static void mix_redraw_chain(struct MuttWindow *win, struct Remailer **type2_list, struct Coord *coords, struct MixChain *chain, int cur)
Redraw the chain on screen.
Definition: remailer.c:362
void(* menu_make_entry)(char *buf, size_t buflen, struct Menu *menu, int line)
Format a item for a menu.
Definition: mutt_menu.h:120
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:123
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:515
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:65
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
char * shortname
Definition: remailer.h:53
#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:64
#define MIX_CAP_MIDDLEMAN
Definition: remailer.h:43
int max
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:137
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
char * title
Title of this menu.
Definition: mutt_menu.h:84
static void mix_type2_list_free(struct Remailer ***ttlp)
Free a Remailer List.
Definition: remailer.c:266
char * data
String.
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:84
#define FREE(x)
Definition: memory.h:40
void * data
Extra data for the current menu.
Definition: mutt_menu.h:86
static void mix_redraw_head(struct MuttWindow *win, struct MixChain *chain)
Redraw the Chain info.
Definition: remailer.c:380
static int mix_chain_add(struct MixChain *chain, const char *s, struct Remailer **type2_list)
Add a host to the chain.
Definition: remailer.c:531
int current
Current entry.
Definition: mutt_menu.h:87
char * mutt_compile_help(char *buf, size_t buflen, enum MenuType menu, const struct Mapping *items)
Create the text for the help menu.
Definition: help.c:115
A List node for strings.
Definition: list.h:33
static void mix_screen_coordinates(struct MuttWindow *win, struct Remailer **type2_list, struct Coord **coordsp, struct MixChain *chain, int i)
Get the screen coordinates to place a chain.
Definition: remailer.c:284
static struct Remailer ** mix_type2_list(size_t *l)
parse the type2.list as given by mixmaster -T
Definition: remailer.c:176
char * help
Quickref for the current menu.
Definition: mutt_menu.h:85
#define MAX_MIXES
Definition: remailer.h:38
Screen coordinates.
Definition: remailer.c:69
static const struct Mapping RemailerHelp[]
Definition: remailer.c:75
A Mixmaster remailer.
Definition: remailer.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_check_message()

int mix_check_message ( struct Email e)

Safety-check the message before passing it to mixmaster.

Parameters
eEmail
Return values
0Success
-1Error

Definition at line 786 of file remailer.c.

787 {
788  bool need_hostname = false;
789 
790  if (!TAILQ_EMPTY(&e->env->cc) || !TAILQ_EMPTY(&e->env->bcc))
791  {
792  mutt_error(_("Mixmaster doesn't accept Cc or Bcc headers"));
793  return -1;
794  }
795 
796  /* When using mixmaster, we MUST qualify any addresses since
797  * the message will be delivered through remote systems.
798  *
799  * use_domain won't be respected at this point, hidden_host will.
800  */
801 
802  struct Address *a = NULL;
803  TAILQ_FOREACH(a, &e->env->to, entries)
804  {
805  if (!a->group && !strchr(a->mailbox, '@'))
806  {
807  need_hostname = true;
808  break;
809  }
810  }
811 
812  if (need_hostname)
813  {
814  const char *fqdn = mutt_fqdn(true);
815  if (!fqdn)
816  {
817  mutt_error(_("Please set the hostname variable to a proper value when "
818  "using mixmaster"));
819  return -1;
820  }
821 
822  /* Cc and Bcc are empty at this point. */
823  mutt_addrlist_qualify(&e->env->to, fqdn);
824  mutt_addrlist_qualify(&e->env->reply_to, fqdn);
826  }
827 
828  return 0;
829 }
struct AddressList mail_followup_to
Email&#39;s &#39;mail-followup-to&#39;.
Definition: envelope.h:63
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
struct AddressList reply_to
Email&#39;s &#39;reply-to&#39;.
Definition: envelope.h:62
struct AddressList bcc
Email&#39;s &#39;Bcc&#39; list.
Definition: envelope.h:60
#define _(a)
Definition: message.h:28
An email address.
Definition: address.h:34
char * mailbox
Mailbox and host address.
Definition: address.h:37
struct Envelope * env
Envelope information.
Definition: email.h:89
struct AddressList cc
Email&#39;s &#39;Cc&#39; list.
Definition: envelope.h:59
const char * mutt_fqdn(bool may_hide_host)
Get the Fully-Qualified Domain Name.
Definition: sendlib.c:2537
void mutt_addrlist_qualify(struct AddressList *al, const char *host)
Expand local names in an Address list using a hostname.
Definition: address.c:640
bool group
Group mailbox?
Definition: address.h:38
#define mutt_error(...)
Definition: logging.h:84
struct AddressList to
Email&#39;s &#39;To&#39; list.
Definition: envelope.h:58
#define TAILQ_EMPTY(head)
Definition: queue.h:715
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_send_message()

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 838 of file remailer.c.

839 {
840  int i = 0;
841  struct Buffer *cmd = mutt_buffer_pool_get();
842  struct Buffer *cd_quoted = mutt_buffer_pool_get();
843 
844  mutt_buffer_printf(cmd, "cat %s | %s -m ", tempfile, C_Mixmaster);
845 
846  struct ListNode *np = NULL;
847  STAILQ_FOREACH(np, chain, entries)
848  {
849  mutt_buffer_addstr(cmd, (i != 0) ? "," : " -l ");
850  mutt_buffer_quote_filename(cd_quoted, (char *) np->data, true);
851  mutt_buffer_addstr(cmd, mutt_b2s(cd_quoted));
852  i = 1;
853  }
854 
855  mutt_endwin();
856 
857  i = mutt_system(cmd->data);
858  if (i != 0)
859  {
860  fprintf(stderr, _("Error sending message, child exited %d.\n"), i);
861  if (!OptNoCurses)
862  {
864  mutt_error(_("Error sending message"));
865  }
866  }
867 
869  mutt_buffer_pool_release(&cd_quoted);
870  unlink(tempfile);
871  return i;
872 }
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:834
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:100
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:111
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:46
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
char * C_Mixmaster
Config: (mixmaster) External command to route a mixmaster message.
Definition: remailer.c:60
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
#define mutt_b2s(buf)
Definition: buffer.h:41
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:544
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:577
char * data
String.
Definition: list.h:35
#define mutt_error(...)
Definition: logging.h:84
A List node for strings.
Definition: list.h:33
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ C_MixEntryFormat

char* C_MixEntryFormat

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

Definition at line 59 of file remailer.c.

◆ C_Mixmaster

char* C_Mixmaster

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

Definition at line 60 of file remailer.c.

◆ RemailerHelp

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 75 of file remailer.c.