NeoMutt  2018-07-16 +1360-3df4a2
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 "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 257 of file remailer.c.

#define MIX_VOFFSET   (MuttIndexWindow->rows - 4)

Definition at line 258 of file remailer.c.

#define MIX_MAXROW   (MuttIndexWindow->rows - 1)

Definition at line 259 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 73 of file remailer.c.

74 {
76 
77  while (*capstr)
78  {
79  switch (*capstr)
80  {
81  case 'C':
82  caps |= MIX_CAP_COMPRESS;
83  break;
84 
85  case 'M':
86  caps |= MIX_CAP_MIDDLEMAN;
87  break;
88 
89  case 'N':
90  {
91  switch (*++capstr)
92  {
93  case 'm':
94  caps |= MIX_CAP_NEWSMAIL;
95  break;
96 
97  case 'p':
98  caps |= MIX_CAP_NEWSPOST;
99  break;
100  }
101  }
102  }
103 
104  if (*capstr)
105  capstr++;
106  }
107 
108  return caps;
109 }
#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 118 of file remailer.c.

120 {
121  if (*used == *slots)
122  {
123  *slots += 5;
124  mutt_mem_realloc(type2_list, sizeof(struct Remailer *) * (*slots));
125  }
126 
127  (*type2_list)[(*used)++] = entry;
128  if (entry)
129  entry->num = *used;
130 }
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:124
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 136 of file remailer.c.

137 {
138  return mutt_mem_calloc(1, sizeof(struct Remailer));
139 }
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 145 of file remailer.c.

146 {
147  FREE(&(*r)->shortname);
148  FREE(&(*r)->addr);
149  FREE(&(*r)->ver);
150 
151  FREE(r);
152 }
#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 159 of file remailer.c.

160 {
161  FILE *fp = NULL;
162  pid_t mm_pid;
163  int devnull;
164 
165  char cmd[STR_COMMAND];
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  if (!l)
173  return NULL;
174 
175  devnull = open("/dev/null", O_RDWR);
176  if (devnull == -1)
177  return NULL;
178 
179  snprintf(cmd, sizeof(cmd), "%s -T", C_Mixmaster);
180 
181  mm_pid = mutt_create_filter_fd(cmd, NULL, &fp, NULL, devnull, -1, devnull);
182  if (mm_pid == -1)
183  {
184  close(devnull);
185  return NULL;
186  }
187 
188  /* first, generate the "random" remailer */
189 
190  p = mix_new_remailer();
191  p->shortname = mutt_str_strdup(_("<random>"));
192  mix_add_entry(&type2_list, p, &slots, &used);
193 
194  while (fgets(line, sizeof(line), fp))
195  {
196  p = mix_new_remailer();
197 
198  t = strtok(line, " \t\n");
199  if (!t)
200  goto problem;
201 
202  p->shortname = mutt_str_strdup(t);
203 
204  t = strtok(NULL, " \t\n");
205  if (!t)
206  goto problem;
207 
208  p->addr = mutt_str_strdup(t);
209 
210  t = strtok(NULL, " \t\n");
211  if (!t)
212  goto problem;
213 
214  t = strtok(NULL, " \t\n");
215  if (!t)
216  goto problem;
217 
218  p->ver = mutt_str_strdup(t);
219 
220  t = strtok(NULL, " \t\n");
221  if (!t)
222  goto problem;
223 
224  p->caps = mix_get_caps(t);
225 
226  mix_add_entry(&type2_list, p, &slots, &used);
227  continue;
228 
229  problem:
230  mix_free_remailer(&p);
231  }
232 
233  *l = used;
234 
235  mix_add_entry(&type2_list, NULL, &slots, &used);
236  mutt_wait_filter(mm_pid);
237 
238  close(devnull);
239 
240  return type2_list;
241 }
static struct Remailer * mix_new_remailer(void)
Create a new Remailer.
Definition: remailer.c:136
static void mix_free_remailer(struct Remailer **r)
Free a Remailer.
Definition: remailer.c:145
#define _(a)
Definition: message.h:28
char * C_Mixmaster
Config: (mixmaster) External command to route a mixmaster message.
Definition: remailer.c:57
const char * line
Definition: common.c:35
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:118
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
#define STR_COMMAND
Enough space for a long command line.
Definition: string2.h:34
static MixCapFlags mix_get_caps(const char *capstr)
Get Mixmaster Capabilities.
Definition: remailer.c:73
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:383
int mutt_wait_filter(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:227
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 247 of file remailer.c.

248 {
249  struct Remailer **type2_list = *ttlp;
250 
251  for (int i = 0; type2_list[i]; i++)
252  mix_free_remailer(&type2_list[i]);
253 
254  FREE(type2_list);
255 }
static void mix_free_remailer(struct Remailer **r)
Free a Remailer.
Definition: remailer.c:145
#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 268 of file remailer.c.

270 {
271  short c, r;
272 
273  if (!chain->cl)
274  return;
275 
276  mutt_mem_realloc(coordsp, sizeof(struct Coord) * chain->cl);
277 
278  struct Coord *coords = *coordsp;
279 
280  if (i)
281  {
282  c = coords[i - 1].c + strlen(type2_list[chain->ch[i - 1]]->shortname) + 2;
283  r = coords[i - 1].r;
284  }
285  else
286  {
287  r = MIX_VOFFSET;
288  c = MIX_HOFFSET;
289  }
290 
291  for (; i < chain->cl; i++)
292  {
293  short oc = c;
294  c += strlen(type2_list[chain->ch[i]]->shortname) + 2;
295 
296  if (c >= MuttIndexWindow->cols)
297  {
298  oc = MIX_HOFFSET;
299  c = MIX_HOFFSET;
300  r++;
301  }
302 
303  coords[i].c = oc;
304  coords[i].r = r;
305  }
306 }
#define MIX_VOFFSET
Definition: remailer.c:258
short r
row
Definition: remailer.c:64
int ch[MAXMIXES]
Definition: remailer.h:64
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:124
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:257
Screen coordinates.
Definition: remailer.c:62
short c
column
Definition: remailer.c:65

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

318 {
319  if (!coords || !chain)
320  return;
321 
322  if (coords[i].r < MIX_MAXROW)
323  {
324  if (selected)
326  else
327  NORMAL_COLOR;
328 
329  mutt_window_mvaddstr(MuttIndexWindow, coords[i].r, coords[i].c,
330  type2_list[chain->ch[i]]->shortname);
331  NORMAL_COLOR;
332 
333  if (i + 1 < chain->cl)
334  addstr(", ");
335  }
336 }
#define NORMAL_COLOR
Definition: mutt_curses.h:237
short r
row
Definition: remailer.c:64
int ch[MAXMIXES]
Definition: remailer.h:64
#define MIX_MAXROW
Definition: remailer.c:259
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
char * shortname
Definition: remailer.h:52
size_t cl
Definition: remailer.h:63
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
#define SETCOLOR(X)
Definition: mutt_curses.h:222
Selected item in list.
Definition: mutt_curses.h:127
short c
column
Definition: remailer.c:65

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

347 {
348  for (int i = MIX_VOFFSET; i < MIX_MAXROW; i++)
349  {
352  }
353 
354  for (int i = 0; i < chain->cl; i++)
355  mix_redraw_ce(type2_list, coords, chain, i, i == cur);
356 }
#define MIX_VOFFSET
Definition: remailer.c:258
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:259
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:316

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

363 {
366  "-- Remailer chain [Length: %d]", chain ? chain->cl : 0);
368  NORMAL_COLOR;
369 }
#define MIX_VOFFSET
Definition: remailer.c:258
#define NORMAL_COLOR
Definition: mutt_curses.h:237
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 SETCOLOR(X)
Definition: mutt_curses.h:222
Status bar.
Definition: mutt_curses.h:128
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:205

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

379 {
380  static char capbuf[10];
381  char *t = capbuf;
382 
383  if (r->caps & MIX_CAP_COMPRESS)
384  *t++ = 'C';
385  else
386  *t++ = ' ';
387 
388  if (r->caps & MIX_CAP_MIDDLEMAN)
389  *t++ = 'M';
390  else
391  *t++ = ' ';
392 
393  if (r->caps & MIX_CAP_NEWSPOST)
394  {
395  *t++ = 'N';
396  *t++ = 'p';
397  }
398  else
399  {
400  *t++ = ' ';
401  *t++ = ' ';
402  }
403 
404  if (r->caps & MIX_CAP_NEWSMAIL)
405  {
406  *t++ = 'N';
407  *t++ = 'm';
408  }
409  else
410  {
411  *t++ = ' ';
412  *t++ = ' ';
413  }
414 
415  *t = '\0';
416 
417  return capbuf;
418 }
#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 430 of file remailer.c.

434 {
435  char fmt[128];
436  struct Remailer *remailer = (struct Remailer *) data;
437  int optional = (flags & MUTT_FORMAT_OPTIONAL);
438 
439  switch (op)
440  {
441  case 'a':
442  if (!optional)
443  {
444  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
445  snprintf(buf, buflen, fmt, NONULL(remailer->addr));
446  }
447  else if (!remailer->addr)
448  optional = 0;
449  break;
450 
451  case 'c':
452  if (!optional)
453  {
454  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
455  snprintf(buf, buflen, fmt, mix_format_caps(remailer));
456  }
457  break;
458 
459  case 'n':
460  if (!optional)
461  {
462  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
463  snprintf(buf, buflen, fmt, remailer->num);
464  }
465  break;
466 
467  case 's':
468  if (!optional)
469  {
470  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
471  snprintf(buf, buflen, fmt, NONULL(remailer->shortname));
472  }
473  else if (!remailer->shortname)
474  optional = 0;
475  break;
476 
477  default:
478  *buf = '\0';
479  }
480 
481  if (optional)
482  mutt_expando_format(buf, buflen, col, cols, if_str, attach_format_str, data, 0);
483  else if (flags & MUTT_FORMAT_OPTIONAL)
484  mutt_expando_format(buf, buflen, col, cols, else_str, attach_format_str, data, 0);
485  return src;
486 }
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:811
#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:378
int num
Definition: remailer.h:51
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 495 of file remailer.c.

496 {
497  struct Remailer **type2_list = menu->data;
498  mutt_expando_format(buf, buflen, 0, MuttIndexWindow->cols,
500  (unsigned long) type2_list[num], MUTT_FORMAT_ARROWCURSOR);
501 }
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:811
#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:56
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:430
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 511 of file remailer.c.

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

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

554 {
555  int c_cur = 0, c_old = 0;
556  bool c_redraw = true;
557  size_t ttll = 0;
558 
559  struct Coord *coords = NULL;
560 
561  struct Menu *menu = NULL;
562  char helpstr[1024];
563  bool loop = true;
564 
565  char *t = NULL;
566 
567  struct Remailer **type2_list = mix_type2_list(&ttll);
568  if (!type2_list)
569  {
570  mutt_error(_("Can't get mixmaster's type2.list"));
571  return;
572  }
573 
574  struct MixChain *chain = mutt_mem_calloc(1, sizeof(struct MixChain));
575 
576  struct ListNode *p = NULL;
577  STAILQ_FOREACH(p, chainhead, entries)
578  {
579  mix_chain_add(chain, p->data, type2_list);
580  }
581  mutt_list_free(chainhead);
582 
583  /* safety check */
584  for (int i = 0; i < chain->cl; i++)
585  {
586  if (chain->ch[i] >= ttll)
587  chain->ch[i] = 0;
588  }
589 
590  mix_screen_coordinates(type2_list, &coords, chain, 0);
591 
592  menu = mutt_menu_new(MENU_MIX);
593  menu->max = ttll;
594  menu->menu_make_entry = mix_entry;
595  menu->menu_tag = NULL;
596  menu->title = _("Select a remailer chain");
597  menu->data = type2_list;
598  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_MIX, RemailerHelp);
599  menu->pagelen = MIX_VOFFSET - 1;
601 
602  while (loop)
603  {
604  if (menu->pagelen != MIX_VOFFSET - 1)
605  {
606  menu->pagelen = MIX_VOFFSET - 1;
607  menu->redraw = REDRAW_FULL;
608  }
609 
610  if (c_redraw)
611  {
612  mix_redraw_head(chain);
613  mix_redraw_chain(type2_list, coords, chain, c_cur);
614  c_redraw = false;
615  }
616  else if (c_cur != c_old)
617  {
618  mix_redraw_ce(type2_list, coords, chain, c_old, false);
619  mix_redraw_ce(type2_list, coords, chain, c_cur, true);
620  }
621 
622  c_old = c_cur;
623 
624  const int op = mutt_menu_loop(menu);
625  switch (op)
626  {
627  case OP_REDRAW:
628  {
629  menu_redraw_status(menu);
630  mix_redraw_head(chain);
631  mix_screen_coordinates(type2_list, &coords, chain, 0);
632  mix_redraw_chain(type2_list, coords, chain, c_cur);
633  menu->pagelen = MIX_VOFFSET - 1;
634  break;
635  }
636 
637  case OP_EXIT:
638  {
639  chain->cl = 0;
640  loop = false;
641  break;
642  }
643 
644  case OP_MIX_USE:
645  {
646  if (!chain->cl)
647  {
648  chain->cl++;
649  chain->ch[0] = menu->current;
650  mix_screen_coordinates(type2_list, &coords, chain, c_cur);
651  c_redraw = true;
652  }
653 
654  if (chain->cl && chain->ch[chain->cl - 1] &&
655  (type2_list[chain->ch[chain->cl - 1]]->caps & MIX_CAP_MIDDLEMAN))
656  {
657  mutt_error(
658  _("Error: %s can't be used as the final remailer of a chain"),
659  type2_list[chain->ch[chain->cl - 1]]->shortname);
660  }
661  else
662  {
663  loop = false;
664  }
665  break;
666  }
667 
668  case OP_GENERIC_SELECT_ENTRY:
669  case OP_MIX_APPEND:
670  {
671  if ((chain->cl < MAXMIXES) && (c_cur < chain->cl))
672  c_cur++;
673  }
674  /* fallthrough */
675  case OP_MIX_INSERT:
676  {
677  if (chain->cl < MAXMIXES)
678  {
679  chain->cl++;
680  for (int i = chain->cl - 1; i > c_cur; i--)
681  chain->ch[i] = chain->ch[i - 1];
682 
683  chain->ch[c_cur] = menu->current;
684  mix_screen_coordinates(type2_list, &coords, chain, c_cur);
685  c_redraw = true;
686  }
687  else
688  {
689  /* L10N The '%d' here hard-coded to 19 */
690  mutt_error(_("Mixmaster chains are limited to %d elements"), MAXMIXES);
691  }
692 
693  break;
694  }
695 
696  case OP_MIX_DELETE:
697  {
698  if (chain->cl)
699  {
700  chain->cl--;
701 
702  for (int i = c_cur; i < chain->cl; i++)
703  chain->ch[i] = chain->ch[i + 1];
704 
705  if ((c_cur == chain->cl) && c_cur)
706  c_cur--;
707 
708  mix_screen_coordinates(type2_list, &coords, chain, c_cur);
709  c_redraw = true;
710  }
711  else
712  {
713  mutt_error(_("The remailer chain is already empty"));
714  }
715  break;
716  }
717 
718  case OP_MIX_CHAIN_PREV:
719  {
720  if (c_cur)
721  c_cur--;
722  else
723  mutt_error(_("You already have the first chain element selected"));
724 
725  break;
726  }
727 
728  case OP_MIX_CHAIN_NEXT:
729  {
730  if (chain->cl && (c_cur < chain->cl - 1))
731  c_cur++;
732  else
733  mutt_error(_("You already have the last chain element selected"));
734 
735  break;
736  }
737  }
738  }
739 
740  mutt_menu_pop_current(menu);
741  mutt_menu_destroy(&menu);
742 
743  /* construct the remailer list */
744 
745  if (chain->cl)
746  {
747  for (int i = 0; i < chain->cl; i++)
748  {
749  const int j = chain->ch[i];
750  if (j != 0)
751  t = type2_list[j]->shortname;
752  else
753  t = "*";
754 
755  mutt_list_insert_tail(chainhead, mutt_str_strdup(t));
756  }
757  }
758 
759  mix_free_type2_list(&type2_list);
760  FREE(&coords);
761  FREE(&chain);
762 }
#define MIX_VOFFSET
Definition: remailer.c:258
#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
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:345
MixCapFlags caps
Definition: remailer.h:55
int ch[MAXMIXES]
Definition: remailer.h:64
#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:268
static void mix_redraw_head(struct MixChain *chain)
Redraw the Chain info.
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:121
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:105
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:247
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:495
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:58
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 MAXMIXES
Definition: remailer.h:37
#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:138
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:316
char * data
Definition: list.h:35
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:383
#define mutt_error(...)
Definition: logging.h:88
#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:511
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:159
char * help
quickref for the current menu
Definition: mutt_menu.h:85
Screen coordinates.
Definition: remailer.c:62
static const struct Mapping RemailerHelp[]
Definition: remailer.c:541
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 770 of file remailer.c.

771 {
772  bool need_hostname = false;
773 
774  if (msg->env->cc || msg->env->bcc)
775  {
776  mutt_error(_("Mixmaster doesn't accept Cc or Bcc headers"));
777  return -1;
778  }
779 
780  /* When using mixmaster, we MUST qualify any addresses since
781  * the message will be delivered through remote systems.
782  *
783  * use_domain won't be respected at this point, hidden_host will.
784  */
785 
786  for (struct Address *a = msg->env->to; a; a = a->next)
787  {
788  if (!a->group && !strchr(a->mailbox, '@'))
789  {
790  need_hostname = true;
791  break;
792  }
793  }
794 
795  if (need_hostname)
796  {
797  const char *fqdn = mutt_fqdn(true);
798  if (!fqdn)
799  {
800  mutt_error(_("Please set the hostname variable to a proper value when "
801  "using mixmaster"));
802  return -1;
803  }
804 
805  /* Cc and Bcc are empty at this point. */
806  mutt_addr_qualify(msg->env->to, fqdn);
807  mutt_addr_qualify(msg->env->reply_to, fqdn);
809  }
810 
811  return 0;
812 }
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
void mutt_addr_qualify(struct Address *addr, const char *host)
Expand local names in an Address list using a hostname.
Definition: address.c:660
const char * mutt_fqdn(bool may_hide_host)
Get the Fully-Qualified Domain Name.
Definition: sendlib.c:2432
#define mutt_error(...)
Definition: logging.h:88
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 821 of file remailer.c.

822 {
823  char cd_quoted[256];
824  int i = 0;
825 
826  struct Buffer *cmd = mutt_buffer_pool_get();
827  mutt_buffer_printf(cmd, "cat %s | %s -m ", tempfile, C_Mixmaster);
828 
829  struct ListNode *np = NULL;
830  STAILQ_FOREACH(np, chain, entries)
831  {
832  mutt_buffer_addstr(cmd, i ? "," : " -l ");
833  mutt_file_quote_filename(np->data, cd_quoted, sizeof(cd_quoted));
834  mutt_buffer_addstr(cmd, cd_quoted);
835  i = 1;
836  }
837 
838  mutt_endwin();
839 
840  i = mutt_system(cmd->data);
841  if (i != 0)
842  {
843  fprintf(stderr, _("Error sending message, child exited %d.\n"), i);
844  if (!OptNoCurses)
845  {
847  mutt_error(_("Error sending message"));
848  }
849  }
850 
852  unlink(tempfile);
853  return i;
854 }
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:57
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:258
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:497
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:530
char * data
Definition: list.h:35
#define mutt_error(...)
Definition: logging.h:88
size_t mutt_file_quote_filename(const char *filename, char *buf, size_t buflen)
Quote a filename to survive the shell&#39;s quoting rules.
Definition: file.c:747
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:396
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:385

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

char* C_Mixmaster

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

Definition at line 57 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 541 of file remailer.c.