NeoMutt  2018-07-16 +952-a2da0a
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 "menu.h"
#include "mutt_curses.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_CAP_COMPRESS   (1 << 0)
 
#define MIX_CAP_MIDDLEMAN   (1 << 1)
 
#define MIX_CAP_NEWSPOST   (1 << 2)
 
#define MIX_CAP_NEWSMAIL   (1 << 3)
 
#define MIX_HOFFSET   2
 
#define MIX_VOFFSET   (MuttIndexWindow->rows - 4)
 
#define MIX_MAXROW   (MuttIndexWindow->rows - 1)
 

Functions

static int 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, enum FormatFlag 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 * MixEntryFormat
 Config: (mixmaster) printf-like format string for the mixmaster chain. More...
 
char * 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_CAP_COMPRESS   (1 << 0)

Definition at line 59 of file remailer.c.

#define MIX_CAP_MIDDLEMAN   (1 << 1)

Definition at line 60 of file remailer.c.

#define MIX_CAP_NEWSPOST   (1 << 2)

Definition at line 61 of file remailer.c.

#define MIX_CAP_NEWSMAIL   (1 << 3)

Definition at line 62 of file remailer.c.

#define MIX_HOFFSET   2

Definition at line 262 of file remailer.c.

#define MIX_VOFFSET   (MuttIndexWindow->rows - 4)

Definition at line 263 of file remailer.c.

#define MIX_MAXROW   (MuttIndexWindow->rows - 1)

Definition at line 264 of file remailer.c.

Function Documentation

static int mix_get_caps ( const char *  capstr)
static

Get Mixmaster Capabilities.

Parameters
capstrCapability string to parse
Return values
numCapabilities, e.g. MIX_CAP_COMPRESS

Definition at line 78 of file remailer.c.

79 {
80  int caps = 0;
81 
82  while (*capstr)
83  {
84  switch (*capstr)
85  {
86  case 'C':
87  caps |= MIX_CAP_COMPRESS;
88  break;
89 
90  case 'M':
91  caps |= MIX_CAP_MIDDLEMAN;
92  break;
93 
94  case 'N':
95  {
96  switch (*++capstr)
97  {
98  case 'm':
99  caps |= MIX_CAP_NEWSMAIL;
100  break;
101 
102  case 'p':
103  caps |= MIX_CAP_NEWSPOST;
104  break;
105  }
106  }
107  }
108 
109  if (*capstr)
110  capstr++;
111  }
112 
113  return caps;
114 }
#define MIX_CAP_NEWSMAIL
Definition: remailer.c:62
#define MIX_CAP_MIDDLEMAN
Definition: remailer.c:60
#define MIX_CAP_NEWSPOST
Definition: remailer.c:61
#define MIX_CAP_COMPRESS
Definition: remailer.c:59

+ 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
[in]type2_listRemailer list to add to
[in]entryRemailer to add
[out]slotsTotal number of slots
[out]usedNumber of slots used

Definition at line 123 of file remailer.c.

125 {
126  if (*used == *slots)
127  {
128  *slots += 5;
129  mutt_mem_realloc(type2_list, sizeof(struct Remailer *) * (*slots));
130  }
131 
132  (*type2_list)[(*used)++] = entry;
133  if (entry)
134  entry->num = *used;
135 }
int num
Definition: remailer.h:44
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:42

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

142 {
143  return mutt_mem_calloc(1, sizeof(struct Remailer));
144 }
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:42

+ 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
rRemailer to free

Definition at line 150 of file remailer.c.

151 {
152  FREE(&(*r)->shortname);
153  FREE(&(*r)->addr);
154  FREE(&(*r)->ver);
155 
156  FREE(r);
157 }
#define FREE(x)
Definition: memory.h:46

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

165 {
166  FILE *fp = NULL;
167  pid_t mm_pid;
168  int devnull;
169 
170  char cmd[HUGE_STRING];
171  char line[HUGE_STRING];
172  char *t = NULL;
173 
174  struct Remailer **type2_list = NULL, *p = NULL;
175  size_t slots = 0, used = 0;
176 
177  if (!l)
178  return NULL;
179 
180  devnull = open("/dev/null", O_RDWR);
181  if (devnull == -1)
182  return NULL;
183 
184  snprintf(cmd, sizeof(cmd), "%s -T", Mixmaster);
185 
186  mm_pid = mutt_create_filter_fd(cmd, NULL, &fp, NULL, devnull, -1, devnull);
187  if (mm_pid == -1)
188  {
189  close(devnull);
190  return NULL;
191  }
192 
193  /* first, generate the "random" remailer */
194 
195  p = mix_new_remailer();
196  p->shortname = mutt_str_strdup(_("<random>"));
197  mix_add_entry(&type2_list, p, &slots, &used);
198 
199  while (fgets(line, sizeof(line), fp))
200  {
201  p = mix_new_remailer();
202 
203  t = strtok(line, " \t\n");
204  if (!t)
205  goto problem;
206 
207  p->shortname = mutt_str_strdup(t);
208 
209  t = strtok(NULL, " \t\n");
210  if (!t)
211  goto problem;
212 
213  p->addr = mutt_str_strdup(t);
214 
215  t = strtok(NULL, " \t\n");
216  if (!t)
217  goto problem;
218 
219  t = strtok(NULL, " \t\n");
220  if (!t)
221  goto problem;
222 
223  p->ver = mutt_str_strdup(t);
224 
225  t = strtok(NULL, " \t\n");
226  if (!t)
227  goto problem;
228 
229  p->caps = mix_get_caps(t);
230 
231  mix_add_entry(&type2_list, p, &slots, &used);
232  continue;
233 
234  problem:
235  mix_free_remailer(&p);
236  }
237 
238  *l = used;
239 
240  mix_add_entry(&type2_list, NULL, &slots, &used);
241  mutt_wait_filter(mm_pid);
242 
243  close(devnull);
244 
245  return type2_list;
246 }
char * Mixmaster
Config: (mixmaster) External command to route a mixmaster message.
Definition: remailer.c:57
static struct Remailer * mix_new_remailer(void)
Create a new Remailer.
Definition: remailer.c:141
static void mix_free_remailer(struct Remailer **r)
Free a Remailer.
Definition: remailer.c:150
#define _(a)
Definition: message.h:28
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:123
#define HUGE_STRING
Definition: string2.h:37
static int mix_get_caps(const char *capstr)
Get Mixmaster Capabilities.
Definition: remailer.c:78
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:384
pid_t mutt_create_filter_fd(const char *cmd, FILE **in, FILE **out, FILE **err, int fdin, int fdout, int fderr)
Run a command on a pipe (optionally connect stdin/stdout)
Definition: filter.c:64
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:42

+ 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
ttlpRemailer List to free

Definition at line 252 of file remailer.c.

253 {
254  struct Remailer **type2_list = *ttlp;
255 
256  for (int i = 0; type2_list[i]; i++)
257  mix_free_remailer(&type2_list[i]);
258 
259  FREE(type2_list);
260 }
static void mix_free_remailer(struct Remailer **r)
Free a Remailer.
Definition: remailer.c:150
#define FREE(x)
Definition: memory.h:46
A Mixmaster remailer.
Definition: remailer.h:42

+ 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
type2_listRemailer List
coordspOn screen coordinates
chainChain
iIndex in chain

Definition at line 273 of file remailer.c.

275 {
276  short c, r;
277 
278  if (!chain->cl)
279  return;
280 
281  mutt_mem_realloc(coordsp, sizeof(struct Coord) * chain->cl);
282 
283  struct Coord *coords = *coordsp;
284 
285  if (i)
286  {
287  c = coords[i - 1].c + strlen(type2_list[chain->ch[i - 1]]->shortname) + 2;
288  r = coords[i - 1].r;
289  }
290  else
291  {
292  r = MIX_VOFFSET;
293  c = MIX_HOFFSET;
294  }
295 
296  for (; i < chain->cl; i++)
297  {
298  short oc = c;
299  c += strlen(type2_list[chain->ch[i]]->shortname) + 2;
300 
301  if (c >= MuttIndexWindow->cols)
302  {
303  oc = MIX_HOFFSET;
304  c = MIX_HOFFSET;
305  r++;
306  }
307 
308  coords[i].c = oc;
309  coords[i].r = r;
310  }
311 }
#define MIX_VOFFSET
Definition: remailer.c:263
short r
row
Definition: remailer.c:69
int ch[MAXMIXES]
Definition: remailer.h:57
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:45
size_t cl
Definition: remailer.h:56
#define MIX_HOFFSET
Definition: remailer.c:262
Screen coordinates.
Definition: remailer.c:67
short c
column
Definition: remailer.c:70

+ 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
type2_listRemailer List
coordsScreen Coordinates
chainChain
iIndex in chain
selectedtrue, if this item is selected

Definition at line 321 of file remailer.c.

323 {
324  if (!coords || !chain)
325  return;
326 
327  if (coords[i].r < MIX_MAXROW)
328  {
329  if (selected)
331  else
332  NORMAL_COLOR;
333 
334  mutt_window_mvaddstr(MuttIndexWindow, coords[i].r, coords[i].c,
335  type2_list[chain->ch[i]]->shortname);
336  NORMAL_COLOR;
337 
338  if (i + 1 < chain->cl)
339  addstr(", ");
340  }
341 }
#define NORMAL_COLOR
Definition: mutt_curses.h:235
short r
row
Definition: remailer.c:69
int ch[MAXMIXES]
Definition: remailer.h:57
#define MIX_MAXROW
Definition: remailer.c:264
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
char * shortname
Definition: remailer.h:45
size_t cl
Definition: remailer.h:56
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:220
Selected item in list.
Definition: mutt_curses.h:127
short c
column
Definition: remailer.c:70

+ 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
type2_listRemailer List
coordsWhere to draw the list on screen
chainChain to display
curChain index of current selection

Definition at line 350 of file remailer.c.

352 {
353  for (int i = MIX_VOFFSET; i < MIX_MAXROW; i++)
354  {
357  }
358 
359  for (int i = 0; i < chain->cl; i++)
360  mix_redraw_ce(type2_list, coords, chain, i, i == cur);
361 }
#define MIX_VOFFSET
Definition: remailer.c:263
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:264
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
size_t cl
Definition: remailer.h:56
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:321

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

368 {
371  "-- Remailer chain [Length: %d]", chain ? chain->cl : 0);
373  NORMAL_COLOR;
374 }
#define MIX_VOFFSET
Definition: remailer.c:263
#define NORMAL_COLOR
Definition: mutt_curses.h:235
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:56
#define SETCOLOR(X)
Definition: mutt_curses.h:220
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 383 of file remailer.c.

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

+ 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,
enum FormatFlag  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 435 of file remailer.c.

439 {
440  char fmt[SHORT_STRING];
441  struct Remailer *remailer = (struct Remailer *) data;
442  int optional = (flags & MUTT_FORMAT_OPTIONAL);
443 
444  switch (op)
445  {
446  case 'a':
447  if (!optional)
448  {
449  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
450  snprintf(buf, buflen, fmt, NONULL(remailer->addr));
451  }
452  else if (!remailer->addr)
453  optional = 0;
454  break;
455 
456  case 'c':
457  if (!optional)
458  {
459  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
460  snprintf(buf, buflen, fmt, mix_format_caps(remailer));
461  }
462  break;
463 
464  case 'n':
465  if (!optional)
466  {
467  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
468  snprintf(buf, buflen, fmt, remailer->num);
469  }
470  break;
471 
472  case 's':
473  if (!optional)
474  {
475  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
476  snprintf(buf, buflen, fmt, NONULL(remailer->shortname));
477  }
478  else if (!remailer->shortname)
479  optional = 0;
480  break;
481 
482  default:
483  *buf = '\0';
484  }
485 
486  if (optional)
487  mutt_expando_format(buf, buflen, col, cols, if_str, attach_format_str, data, 0);
488  else if (flags & MUTT_FORMAT_OPTIONAL)
489  mutt_expando_format(buf, buflen, col, cols, else_str, attach_format_str, data, 0);
490  return src;
491 }
#define NONULL(x)
Definition: string2.h:39
#define SHORT_STRING
Definition: string2.h:34
static const char * mix_format_caps(struct Remailer *r)
Turn flags into a MixMaster capability string.
Definition: remailer.c:383
int num
Definition: remailer.h:44
allow optional field processing
Definition: format_flags.h:36
char * shortname
Definition: remailer.h:45
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, enum FormatFlag flags)
Format a string for the attachment menu - Implements format_t.
Definition: recvattach.c:208
char * addr
Definition: remailer.h:46
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, enum FormatFlag flags)
Expand expandos (x) in a string.
Definition: muttlib.c:816
A Mixmaster remailer.
Definition: remailer.h:42

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

501 {
502  struct Remailer **type2_list = menu->data;
503  mutt_expando_format(buf, buflen, 0, MuttIndexWindow->cols,
505  (unsigned long) type2_list[num], MUTT_FORMAT_ARROWCURSOR);
506 }
#define NONULL(x)
Definition: string2.h:39
int num
Definition: remailer.h:44
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
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, enum FormatFlag flags)
Format a string for the remailer menu - Implements format_t.
Definition: remailer.c:435
reserve space for arrow_cursor
Definition: format_flags.h:38
void * data
extra data for the current menu
Definition: menu.h:60
char * MixEntryFormat
Config: (mixmaster) printf-like format string for the mixmaster chain.
Definition: remailer.c:56
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, enum FormatFlag flags)
Expand expandos (x) in a string.
Definition: muttlib.c:816
A Mixmaster remailer.
Definition: remailer.h:42

+ 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
chainChain to add to
sHostname
type2_listRemailer List
Return values
0Success
-1Error

Definition at line 516 of file remailer.c.

517 {
518  int i;
519 
520  if (chain->cl >= MAXMIXES)
521  return -1;
522 
523  if ((mutt_str_strcmp(s, "0") == 0) || (mutt_str_strcasecmp(s, "<random>") == 0))
524  {
525  chain->ch[chain->cl++] = 0;
526  return 0;
527  }
528 
529  for (i = 0; type2_list[i]; i++)
530  {
531  if (mutt_str_strcasecmp(s, type2_list[i]->shortname) == 0)
532  {
533  chain->ch[chain->cl++] = i;
534  return 0;
535  }
536  }
537 
538  /* replace unknown remailers by <random> */
539 
540  if (!type2_list[i])
541  chain->ch[chain->cl++] = 0;
542 
543  return 0;
544 }
int ch[MAXMIXES]
Definition: remailer.h:57
char * shortname
Definition: remailer.h:45
size_t cl
Definition: remailer.h:56
#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:625
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:612

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

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

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

776 {
777  const char *fqdn = NULL;
778  bool need_hostname = false;
779 
780  if (msg->env->cc || msg->env->bcc)
781  {
782  mutt_error(_("Mixmaster doesn't accept Cc or Bcc headers"));
783  return -1;
784  }
785 
786  /* When using mixmaster, we MUST qualify any addresses since
787  * the message will be delivered through remote systems.
788  *
789  * use_domain won't be respected at this point, hidden_host will.
790  */
791 
792  for (struct Address *a = msg->env->to; a; a = a->next)
793  {
794  if (!a->group && !strchr(a->mailbox, '@'))
795  {
796  need_hostname = true;
797  break;
798  }
799  }
800 
801  if (need_hostname)
802  {
803  fqdn = mutt_fqdn(true);
804  if (!fqdn)
805  {
806  mutt_error(_("Please set the hostname variable to a proper value when "
807  "using mixmaster"));
808  return -1;
809  }
810 
811  /* Cc and Bcc are empty at this point. */
812  mutt_addr_qualify(msg->env->to, fqdn);
813  mutt_addr_qualify(msg->env->reply_to, fqdn);
815  }
816 
817  return 0;
818 }
struct Address * to
Definition: envelope.h:36
#define _(a)
Definition: message.h:28
An email address.
Definition: address.h:32
struct Address * reply_to
Definition: envelope.h:40
struct Address * mail_followup_to
Definition: envelope.h:41
struct Envelope * env
envelope information
Definition: email.h:91
struct Address * bcc
Definition: envelope.h:38
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:2425
#define mutt_error(...)
Definition: logging.h:88
struct Address * cc
Definition: envelope.h:37
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 827 of file remailer.c.

828 {
829  char cd_quoted[STRING];
830  int i = 0;
831 
832  struct Buffer *cmd = mutt_buffer_pool_get();
833  mutt_buffer_printf(cmd, "cat %s | %s -m ", tempfile, Mixmaster);
834 
835  struct ListNode *np = NULL;
836  STAILQ_FOREACH(np, chain, entries)
837  {
838  mutt_buffer_addstr(cmd, i ? "," : " -l ");
839  mutt_file_quote_filename(np->data, cd_quoted, sizeof(cd_quoted));
840  mutt_buffer_addstr(cmd, cd_quoted);
841  i = 1;
842  }
843 
844  mutt_endwin();
845 
846  i = mutt_system(cmd->data);
847  if (i != 0)
848  {
849  fprintf(stderr, _("Error sending message, child exited %d.\n"), i);
850  if (!OptNoCurses)
851  {
853  mutt_error(_("Error sending message"));
854  }
855  }
856 
858  unlink(tempfile);
859  return i;
860 }
char * Mixmaster
Config: (mixmaster) External command to route a mixmaster message.
Definition: remailer.c:57
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
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:498
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:531
char * data
Definition: list.h:35
#define STRING
Definition: string2.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:749
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* MixEntryFormat

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

Definition at line 56 of file remailer.c.

char* 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 546 of file remailer.c.