NeoMutt  2018-07-16 +2225-8687db
Teaching an old dog new tricks
DOXYGEN
remailer.c File Reference

Support of Mixmaster anonymous remailer. More...

#include "config.h"
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "mutt/mutt.h"
#include "address/lib.h"
#include "email/lib.h"
#include "mutt.h"
#include "curs_lib.h"
#include "filter.h"
#include "format_flags.h"
#include "keymap.h"
#include "mutt_curses.h"
#include "mutt_menu.h"
#include "mutt_window.h"
#include "muttlib.h"
#include "opcodes.h"
#include "options.h"
#include "protos.h"
#include "recvattach.h"
#include "sendlib.h"

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 *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

#define MIX_HOFFSET   2

Definition at line 261 of file remailer.c.

#define MIX_VOFFSET   (MuttIndexWindow->rows - 4)

Definition at line 262 of file remailer.c.

#define MIX_MAXROW   (MuttIndexWindow->rows - 1)

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

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

122 {
123  if (*used == *slots)
124  {
125  *slots += 5;
126  mutt_mem_realloc(type2_list, sizeof(struct Remailer *) * (*slots));
127  }
128 
129  (*type2_list)[(*used)++] = entry;
130  if (entry)
131  entry->num = *used;
132 }
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:114
A Mixmaster remailer.
Definition: remailer.h:49
static struct Remailer* mix_new_remailer ( void  )
static

Create a new Remailer.

Return values
ptrNewly allocated Remailer

Definition at line 138 of file remailer.c.

139 {
140  return mutt_mem_calloc(1, sizeof(struct Remailer));
141 }
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:49
static void mix_free_remailer ( struct Remailer **  r)
static

Free a Remailer.

Parameters
[out]rRemailer to free

Definition at line 147 of file remailer.c.

148 {
149  FREE(&(*r)->shortname);
150  FREE(&(*r)->addr);
151  FREE(&(*r)->ver);
152 
153  FREE(r);
154 }
#define FREE(x)
Definition: memory.h:40
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 161 of file remailer.c.

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

Free a Remailer List.

Parameters
[out]ttlpRemailer List to free

Definition at line 251 of file remailer.c.

252 {
253  struct Remailer **type2_list = *ttlp;
254 
255  for (int i = 0; type2_list[i]; i++)
256  mix_free_remailer(&type2_list[i]);
257 
258  FREE(type2_list);
259 }
static void mix_free_remailer(struct Remailer **r)
Free a Remailer.
Definition: remailer.c:147
#define FREE(x)
Definition: memory.h:40
A Mixmaster remailer.
Definition: remailer.h:49
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 272 of file remailer.c.

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

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

351 {
352  for (int i = MIX_VOFFSET; i < MIX_MAXROW; i++)
353  {
356  }
357 
358  for (int i = 0; i < chain->cl; i++)
359  mix_redraw_ce(type2_list, coords, chain, i, i == cur);
360 }
#define MIX_VOFFSET
Definition: remailer.c:262
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:263
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:320
static void mix_redraw_head ( struct MixChain chain)
static

Redraw the Chain info.

Parameters
chainChain

Definition at line 366 of file remailer.c.

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

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

438 {
439  char fmt[128];
440  struct Remailer *remailer = (struct Remailer *) data;
441  int optional = (flags & MUTT_FORMAT_OPTIONAL);
442 
443  switch (op)
444  {
445  case 'a':
446  if (!optional)
447  {
448  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
449  snprintf(buf, buflen, fmt, NONULL(remailer->addr));
450  }
451  else if (!remailer->addr)
452  optional = 0;
453  break;
454 
455  case 'c':
456  if (!optional)
457  {
458  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
459  snprintf(buf, buflen, fmt, mix_format_caps(remailer));
460  }
461  break;
462 
463  case 'n':
464  if (!optional)
465  {
466  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
467  snprintf(buf, buflen, fmt, remailer->num);
468  }
469  break;
470 
471  case 's':
472  if (!optional)
473  {
474  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
475  snprintf(buf, buflen, fmt, NONULL(remailer->shortname));
476  }
477  else if (!remailer->shortname)
478  optional = 0;
479  break;
480 
481  default:
482  *buf = '\0';
483  }
484 
485  if (optional)
486  mutt_expando_format(buf, buflen, col, cols, if_str, attach_format_str, data,
488  else if (flags & MUTT_FORMAT_OPTIONAL)
489  mutt_expando_format(buf, buflen, col, cols, else_str, attach_format_str,
490  data, MUTT_FORMAT_NO_FLAGS);
491  return src;
492 }
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:841
#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:382
int num
Definition: remailer.h:51
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
char * shortname
Definition: remailer.h:52
const char * attach_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, unsigned long data, MuttFormatFlags flags)
Format a string for the attachment menu - Implements format_t.
Definition: recvattach.c:210
#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
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 501 of file remailer.c.

502 {
503  struct Remailer **type2_list = menu->data;
504  mutt_expando_format(buf, buflen, 0, MuttIndexWindow->cols,
506  (unsigned long) type2_list[num], MUTT_FORMAT_ARROWCURSOR);
507 }
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:841
#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:51
char * C_MixEntryFormat
Config: (mixmaster) printf-like format string for the mixmaster chain.
Definition: remailer.c:58
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:434
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
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 517 of file remailer.c.

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

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

777 {
778  bool need_hostname = false;
779 
780  if (!TAILQ_EMPTY(&e->env->cc) || !TAILQ_EMPTY(&e->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  struct Address *a = NULL;
793  TAILQ_FOREACH(a, &e->env->to, entries)
794  {
795  if (!a->group && !strchr(a->mailbox, '@'))
796  {
797  need_hostname = true;
798  break;
799  }
800  }
801 
802  if (need_hostname)
803  {
804  const char *fqdn = mutt_fqdn(true);
805  if (!fqdn)
806  {
807  mutt_error(_("Please set the hostname variable to a proper value when "
808  "using mixmaster"));
809  return -1;
810  }
811 
812  /* Cc and Bcc are empty at this point. */
813  mutt_addrlist_qualify(&e->env->to, fqdn);
814  mutt_addrlist_qualify(&e->env->reply_to, fqdn);
816  }
817 
818  return 0;
819 }
struct AddressList mail_followup_to
Email&#39;s &#39;mail-followup-to&#39;.
Definition: envelope.h:49
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
struct AddressList reply_to
Email&#39;s &#39;reply-to&#39;.
Definition: envelope.h:48
struct AddressList bcc
Email&#39;s &#39;Bcc&#39; list.
Definition: envelope.h:46
#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:45
const char * mutt_fqdn(bool may_hide_host)
Get the Fully-Qualified Domain Name.
Definition: sendlib.c:2449
void mutt_addrlist_qualify(struct AddressList *al, const char *host)
Expand local names in an Address list using a hostname.
Definition: address.c:637
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:44
#define TAILQ_EMPTY(head)
Definition: queue.h:715
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 828 of file remailer.c.

829 {
830  int i = 0;
831  struct Buffer *cmd = mutt_buffer_pool_get();
832  struct Buffer *cd_quoted = mutt_buffer_pool_get();
833 
834  mutt_buffer_printf(cmd, "cat %s | %s -m ", tempfile, C_Mixmaster);
835 
836  struct ListNode *np = NULL;
837  STAILQ_FOREACH(np, chain, entries)
838  {
839  mutt_buffer_addstr(cmd, (i != 0) ? "," : " -l ");
840  mutt_buffer_quote_filename(cd_quoted, (char *) np->data, true);
841  mutt_buffer_addstr(cmd, mutt_b2s(cd_quoted));
842  i = 1;
843  }
844 
845  mutt_endwin();
846 
847  i = mutt_system(cmd->data);
848  if (i != 0)
849  {
850  fprintf(stderr, _("Error sending message, child exited %d.\n"), i);
851  if (!OptNoCurses)
852  {
854  mutt_error(_("Error sending message"));
855  }
856  }
857 
859  mutt_buffer_pool_release(&cd_quoted);
860  unlink(tempfile);
861  return i;
862 }
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:833
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:75
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:86
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:191
char * C_Mixmaster
Config: (mixmaster) External command to route a mixmaster message.
Definition: remailer.c:59
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:256
#define mutt_b2s(buf)
Definition: buffer.h:42
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:499
char * data
Pointer to data.
Definition: buffer.h:35
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:544
char * data
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:50

Variable Documentation

char* C_MixEntryFormat

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

Definition at line 58 of file remailer.c.

char* C_Mixmaster

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

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