NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
remailer.c File Reference

Mixmaster Remailer Dialog. More...

#include "config.h"
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "menu/lib.h"
#include "send/lib.h"
#include "format_flags.h"
#include "muttlib.h"
#include "opcodes.h"
#include "options.h"
#include "protos.h"
#include "remailer.h"
+ Include dependency graph for remailer.c:

Go to the source code of this file.

Data Structures

struct  Coord
 Screen coordinates. More...
 

Functions

static MixCapFlags mix_get_caps (const char *capstr)
 Get Mixmaster Capabilities. More...
 
static void mix_add_entry (struct Remailer ***type2_list, struct Remailer *entry, size_t *slots, size_t *used)
 Add an entry to the Remailer list. More...
 
static struct Remailerremailer_new (void)
 Create a new Remailer. More...
 
static void remailer_free (struct Remailer **ptr)
 Free a Remailer. More...
 
static struct Remailer ** mix_type2_list (size_t *l)
 parse the type2.list as given by mixmaster -T More...
 
static void mix_type2_list_free (struct Remailer ***ttlp)
 Free a Remailer List. More...
 
static void mix_screen_coordinates (struct MuttWindow *win, struct Remailer **type2_list, struct Coord **coordsp, struct MixChain *chain, int i)
 Get the screen coordinates to place a chain. More...
 
static void mix_redraw_ce (struct MuttWindow *win, struct Remailer **type2_list, struct Coord *coords, struct MixChain *chain, int i, bool selected)
 Redraw the Remailer chain. More...
 
static void mix_redraw_chain (struct MuttWindow *win, struct Remailer **type2_list, struct Coord *coords, struct MixChain *chain, int cur)
 Redraw the chain on screen. More...
 
static void mix_redraw_head (struct MuttWindow *win, struct MixChain *chain)
 Redraw the Chain info. More...
 
static const char * mix_format_caps (struct Remailer *r)
 Turn flags into a MixMaster capability string. More...
 
static const char * mix_format_str (char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
 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
More...
 
static void mix_make_entry (struct Menu *menu, char *buf, size_t buflen, int num)
 Format a menu item for the mixmaster chain list - Implements Menu::make_entry() -. More...
 
static int mix_chain_add (struct MixChain *chain, const char *s, struct Remailer **type2_list)
 Add a host to the chain. More...
 
static int remailer_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t. More...
 
static int remailer_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t. More...
 
void dlg_select_mixmaster_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

static const struct Mapping RemailerHelp []
 Help Bar for the Mixmaster dialog. More...
 

Detailed Description

Mixmaster Remailer Dialog.

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.

Function Documentation

◆ mix_get_caps()

static MixCapFlags mix_get_caps ( const char *  capstr)
static

Get Mixmaster Capabilities.

Parameters
capstrCapability string to parse
Return values
numCapabilities, see MixCapFlags

Definition at line 114 of file remailer.c.

115 {
117 
118  while (*capstr)
119  {
120  switch (*capstr)
121  {
122  case 'C':
123  caps |= MIX_CAP_COMPRESS;
124  break;
125 
126  case 'M':
127  caps |= MIX_CAP_MIDDLEMAN;
128  break;
129 
130  case 'N':
131  {
132  switch (*++capstr)
133  {
134  case 'm':
135  caps |= MIX_CAP_NEWSMAIL;
136  break;
137 
138  case 'p':
139  caps |= MIX_CAP_NEWSPOST;
140  break;
141  }
142  }
143  }
144 
145  if (*capstr)
146  capstr++;
147  }
148 
149  return caps;
150 }
#define MIX_CAP_NEWSPOST
Definition: remailer.h:39
uint8_t MixCapFlags
Flags, e.g. MIX_CAP_NO_FLAGS.
Definition: remailer.h:35
#define MIX_CAP_NO_FLAGS
No flags are set.
Definition: remailer.h:36
#define MIX_CAP_NEWSMAIL
Definition: remailer.h:40
#define MIX_CAP_MIDDLEMAN
Definition: remailer.h:38
#define MIX_CAP_COMPRESS
Definition: remailer.h:37
+ Here is the caller graph for this function:

◆ mix_add_entry()

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

Add an entry to the Remailer list.

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

Definition at line 159 of file remailer.c.

161 {
162  if (*used == *slots)
163  {
164  *slots += 5;
165  mutt_mem_realloc(type2_list, sizeof(struct Remailer *) * (*slots));
166  }
167 
168  (*type2_list)[(*used)++] = entry;
169  if (entry)
170  entry->num = *used;
171 }
int num
Definition: remailer.h:47
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:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remailer_new()

static struct Remailer* remailer_new ( void  )
static

Create a new Remailer.

Return values
ptrNewly allocated Remailer

Definition at line 177 of file remailer.c.

178 {
179  return mutt_mem_calloc(1, sizeof(struct Remailer));
180 }
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:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remailer_free()

static void remailer_free ( struct Remailer **  ptr)
static

Free a Remailer.

Parameters
[out]ptrRemailer to free

Definition at line 186 of file remailer.c.

187 {
188  if (!ptr || !*ptr)
189  return;
190 
191  struct Remailer *r = *ptr;
192 
193  FREE(&r->shortname);
194  FREE(&r->addr);
195  FREE(&r->ver);
196  FREE(ptr);
197 }
char * shortname
Definition: remailer.h:48
#define FREE(x)
Definition: memory.h:40
char * addr
Definition: remailer.h:49
char * ver
Definition: remailer.h:50
A Mixmaster remailer.
Definition: remailer.h:45
+ Here is the caller graph for this function:

◆ mix_type2_list()

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

parse the type2.list as given by mixmaster -T

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

Definition at line 204 of file remailer.c.

205 {
206  if (!l)
207  return NULL;
208 
209  FILE *fp = NULL;
210  char line[8192];
211  char *t = NULL;
212 
213  struct Remailer **type2_list = NULL;
214  struct Remailer *p = NULL;
215  size_t slots = 0, used = 0;
216 
217  int fd_null = open("/dev/null", O_RDWR);
218  if (fd_null == -1)
219  return NULL;
220 
221  struct Buffer *cmd = mutt_buffer_pool_get();
222  const char *const c_mixmaster = cs_subset_string(NeoMutt->sub, "mixmaster");
223  mutt_buffer_printf(cmd, "%s -T", c_mixmaster);
224 
225  pid_t mm_pid =
226  filter_create_fd(mutt_buffer_string(cmd), NULL, &fp, NULL, fd_null, -1, fd_null);
227  if (mm_pid == -1)
228  {
230  close(fd_null);
231  return NULL;
232  }
233 
235 
236  /* first, generate the "random" remailer */
237 
238  p = remailer_new();
239  p->shortname = mutt_str_dup(_("<random>"));
240  mix_add_entry(&type2_list, p, &slots, &used);
241 
242  while (fgets(line, sizeof(line), fp))
243  {
244  p = remailer_new();
245 
246  t = strtok(line, " \t\n");
247  if (!t)
248  goto problem;
249 
250  p->shortname = mutt_str_dup(t);
251 
252  t = strtok(NULL, " \t\n");
253  if (!t)
254  goto problem;
255 
256  p->addr = mutt_str_dup(t);
257 
258  t = strtok(NULL, " \t\n");
259  if (!t)
260  goto problem;
261 
262  t = strtok(NULL, " \t\n");
263  if (!t)
264  goto problem;
265 
266  p->ver = mutt_str_dup(t);
267 
268  t = strtok(NULL, " \t\n");
269  if (!t)
270  goto problem;
271 
272  p->caps = mix_get_caps(t);
273 
274  mix_add_entry(&type2_list, p, &slots, &used);
275  continue;
276 
277  problem:
278  remailer_free(&p);
279  }
280 
281  *l = used;
282 
283  mix_add_entry(&type2_list, NULL, &slots, &used);
284  filter_wait(mm_pid);
285 
286  close(fd_null);
287 
288  return type2_list;
289 }
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
MixCapFlags caps
Definition: remailer.h:51
String manipulation buffer.
Definition: buffer.h:33
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
static void remailer_free(struct Remailer **ptr)
Free a Remailer.
Definition: remailer.c:186
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:159
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
char * shortname
Definition: remailer.h:48
static MixCapFlags mix_get_caps(const char *capstr)
Get Mixmaster Capabilities.
Definition: remailer.c:114
pid_t filter_create_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:61
static struct Remailer * remailer_new(void)
Create a new Remailer.
Definition: remailer.c:177
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
char * addr
Definition: remailer.h:49
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:217
char * ver
Definition: remailer.h:50
A Mixmaster remailer.
Definition: remailer.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_type2_list_free()

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

Free a Remailer List.

Parameters
[out]ttlpRemailer List to free

Definition at line 295 of file remailer.c.

296 {
297  struct Remailer **type2_list = *ttlp;
298 
299  for (int i = 0; type2_list[i]; i++)
300  remailer_free(&type2_list[i]);
301 
302  FREE(ttlp);
303 }
static void remailer_free(struct Remailer **ptr)
Free a Remailer.
Definition: remailer.c:186
#define FREE(x)
Definition: memory.h:40
A Mixmaster remailer.
Definition: remailer.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_screen_coordinates()

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

Get the screen coordinates to place a chain.

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

Definition at line 313 of file remailer.c.

315 {
316  const int wrap_indent = 2;
317 
318  if (!chain->cl)
319  return;
320 
321  short c, r;
322 
323  mutt_mem_realloc(coordsp, sizeof(struct Coord) * chain->cl);
324 
325  struct Coord *coords = *coordsp;
326 
327  if (i == 0)
328  {
329  r = 0;
330  c = 0;
331  }
332  else
333  {
334  c = coords[i - 1].c + strlen(type2_list[chain->ch[i - 1]]->shortname) + 2;
335  r = coords[i - 1].r;
336  }
337 
338  for (; i < chain->cl; i++)
339  {
340  short oc = c;
341  c += strlen(type2_list[chain->ch[i]]->shortname) + 2;
342 
343  if (c >= win->state.cols)
344  {
345  oc = wrap_indent;
346  c = wrap_indent;
347  r++;
348  }
349 
350  coords[i].c = oc;
351  coords[i].r = r;
352  }
353 }
int ch[MAX_MIXES]
Definition: remailer.h:60
short r
row
Definition: remailer.c:93
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
char * shortname
Definition: remailer.h:48
size_t cl
Definition: remailer.h:59
Screen coordinates.
Definition: remailer.c:91
short c
column
Definition: remailer.c:94
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_redraw_ce()

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

Redraw the Remailer chain.

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

Definition at line 364 of file remailer.c.

366 {
367  if (!coords || !chain)
368  return;
369 
370  if (coords[i].r < win->state.rows)
371  {
372  if (selected)
374  else
376 
377  mutt_window_mvaddstr(win, coords[i].c, coords[i].r, type2_list[chain->ch[i]]->shortname);
379 
380  if (i + 1 < chain->cl)
381  mutt_window_addstr(win, ", ");
382  }
383 }
int ch[MAX_MIXES]
Definition: remailer.h:60
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:56
short r
row
Definition: remailer.c:93
int mutt_window_mvaddstr(struct MuttWindow *win, int col, int row, const char *str)
Move the cursor and write a fixed string to a Window.
Definition: mutt_window.c:324
int mutt_window_addstr(struct MuttWindow *win, const char *str)
Write a string to a Window.
Definition: mutt_window.c:434
Plain text.
Definition: color.h:58
Selected item in list.
Definition: color.h:54
char * shortname
Definition: remailer.h:48
size_t cl
Definition: remailer.h:59
short c
column
Definition: remailer.c:94
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_redraw_chain()

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

Redraw the chain on screen.

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

Definition at line 393 of file remailer.c.

395 {
396  for (int i = 0; i < win->state.rows; i++)
397  {
398  mutt_window_move(win, 0, i);
400  }
401 
402  for (int i = 0; i < chain->cl; i++)
403  mix_redraw_ce(win, type2_list, coords, chain, i, i == cur);
404 }
static void mix_redraw_ce(struct MuttWindow *win, struct Remailer **type2_list, struct Coord *coords, struct MixChain *chain, int i, bool selected)
Redraw the Remailer chain.
Definition: remailer.c:364
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:259
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:310
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
size_t cl
Definition: remailer.h:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_redraw_head()

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

Redraw the Chain info.

Parameters
winWindow
chainChain

Definition at line 411 of file remailer.c.

412 {
413  char buf[1024];
414  snprintf(buf, sizeof(buf), "-- Remailer chain [Length: %ld]", chain ? chain->cl : 0);
415  sbar_set_title(win, buf);
416 }
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:221
size_t cl
Definition: remailer.h:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_format_caps()

static const char* mix_format_caps ( struct Remailer r)
static

Turn flags into a MixMaster capability string.

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

Definition at line 425 of file remailer.c.

426 {
427  static char capbuf[10];
428  char *t = capbuf;
429 
430  if (r->caps & MIX_CAP_COMPRESS)
431  *t++ = 'C';
432  else
433  *t++ = ' ';
434 
435  if (r->caps & MIX_CAP_MIDDLEMAN)
436  *t++ = 'M';
437  else
438  *t++ = ' ';
439 
440  if (r->caps & MIX_CAP_NEWSPOST)
441  {
442  *t++ = 'N';
443  *t++ = 'p';
444  }
445  else
446  {
447  *t++ = ' ';
448  *t++ = ' ';
449  }
450 
451  if (r->caps & MIX_CAP_NEWSMAIL)
452  {
453  *t++ = 'N';
454  *t++ = 'm';
455  }
456  else
457  {
458  *t++ = ' ';
459  *t++ = ' ';
460  }
461 
462  *t = '\0';
463 
464  return capbuf;
465 }
#define MIX_CAP_NEWSPOST
Definition: remailer.h:39
MixCapFlags caps
Definition: remailer.h:51
#define MIX_CAP_NEWSMAIL
Definition: remailer.h:40
#define MIX_CAP_MIDDLEMAN
Definition: remailer.h:38
#define MIX_CAP_COMPRESS
Definition: remailer.h:37
+ Here is the caller graph for this function:

◆ mix_chain_add()

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

Add a host to the chain.

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

Definition at line 564 of file remailer.c.

565 {
566  int i;
567 
568  if (chain->cl >= MAX_MIXES)
569  return -1;
570 
571  if (mutt_str_equal(s, "0") || mutt_istr_equal(s, "<random>"))
572  {
573  chain->ch[chain->cl++] = 0;
574  return 0;
575  }
576 
577  for (i = 0; type2_list[i]; i++)
578  {
579  if (mutt_istr_equal(s, type2_list[i]->shortname))
580  {
581  chain->ch[chain->cl++] = i;
582  return 0;
583  }
584  }
585 
586  /* replace unknown remailers by <random> */
587 
588  if (!type2_list[i])
589  chain->ch[chain->cl++] = 0;
590 
591  return 0;
592 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
int ch[MAX_MIXES]
Definition: remailer.h:60
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
size_t cl
Definition: remailer.h:59
#define MAX_MIXES
Definition: remailer.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remailer_config_observer()

static int remailer_config_observer ( struct NotifyCallback nc)
static

Notification that a Config Variable has changed - Implements observer_t.

Definition at line 597 of file remailer.c.

598 {
599  if ((nc->event_type != NT_CONFIG) || !nc->global_data || !nc->event_data)
600  return -1;
601 
602  struct EventConfig *ev_c = nc->event_data;
603  if (!mutt_str_equal(ev_c->name, "status_on_top"))
604  return 0;
605 
606  struct MuttWindow *dlg = nc->global_data;
608  mutt_debug(LL_DEBUG5, "config done\n");
609  return 0;
610 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
bool window_status_on_top(struct MuttWindow *panel, struct ConfigSubset *sub)
Organise windows according to config variable.
Definition: mutt_window.c:780
A config-change event.
Definition: subset.h:69
Container for Accounts, Notifications.
Definition: neomutt.h:36
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
Log at debug level 5.
Definition: logging.h:44
const char * name
Name of config item that changed.
Definition: subset.h:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remailer_window_observer()

static int remailer_window_observer ( struct NotifyCallback nc)
static

Notification that a Window has changed - Implements observer_t.

Definition at line 615 of file remailer.c.

616 {
617  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
618  return -1;
619 
620  if (nc->event_subtype != NT_WINDOW_DELETE)
621  return 0;
622 
623  struct MuttWindow *dlg = nc->global_data;
624  struct EventWindow *ev_w = nc->event_data;
625  if (ev_w->win != dlg)
626  return 0;
627 
630  mutt_debug(LL_DEBUG5, "window delete done\n");
631 
632  return 0;
633 }
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
An Event that happened to a Window.
Definition: mutt_window.h:215
Window is about to be deleted.
Definition: mutt_window.h:206
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
static int remailer_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: remailer.c:615
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
Log at debug level 5.
Definition: logging.h:44
static int remailer_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: remailer.c:597
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dlg_select_mixmaster_chain()

void dlg_select_mixmaster_chain ( struct ListHead *  chainhead)

Create a Mixmaster chain.

Parameters
chainheadList of chain links

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

Definition at line 641 of file remailer.c.

642 {
643  int c_cur = 0, c_old = 0;
644  bool c_redraw = true;
645  size_t ttll = 0;
646 
647  struct Coord *coords = NULL;
648 
649  struct Menu *menu = NULL;
650  bool loop = true;
651 
652  char *t = NULL;
653 
654  struct Remailer **type2_list = mix_type2_list(&ttll);
655  if (!type2_list)
656  {
657  mutt_error(_("Can't get mixmaster's type2.list"));
658  return;
659  }
660 
661  struct MixChain *chain = mutt_mem_calloc(1, sizeof(struct MixChain));
662 
663  struct ListNode *p = NULL;
664  STAILQ_FOREACH(p, chainhead, entries)
665  {
666  mix_chain_add(chain, p->data, type2_list);
667  }
668  mutt_list_free(chainhead);
669 
670  /* safety check */
671  for (int i = 0; i < chain->cl; i++)
672  {
673  if (chain->ch[i] >= ttll)
674  chain->ch[i] = 0;
675  }
676 
677  struct MuttWindow *dlg =
680  dlg->help_menu = MENU_MIX;
681  dlg->help_data = RemailerHelp;
682 
683  struct MuttWindow *win_hosts = menu_new_window(MENU_MIX, NeoMutt->sub);
684  win_hosts->focus = win_hosts;
685 
686  struct MuttWindow *win_chain =
689 
690  struct MuttWindow *win_cbar = sbar_new(dlg);
691  struct MuttWindow *win_rbar = sbar_new(dlg);
692 
693  const bool c_status_on_top = cs_subset_bool(NeoMutt->sub, "status_on_top");
694  if (c_status_on_top)
695  {
696  mutt_window_add_child(dlg, win_rbar);
697  mutt_window_add_child(dlg, win_hosts);
698  mutt_window_add_child(dlg, win_cbar);
699  mutt_window_add_child(dlg, win_chain);
700  }
701  else
702  {
703  mutt_window_add_child(dlg, win_hosts);
704  mutt_window_add_child(dlg, win_cbar);
705  mutt_window_add_child(dlg, win_chain);
706  mutt_window_add_child(dlg, win_rbar);
707  }
708  sbar_set_title(win_rbar, _("Select a remailer chain"));
709 
710  mix_screen_coordinates(dlg, type2_list, &coords, chain, 0);
711 
712  menu = win_hosts->wdata;
713  menu->max = ttll;
714  menu->make_entry = mix_make_entry;
715  menu->tag = NULL;
716  menu->mdata = type2_list;
717 
720  dialog_push(dlg);
721 
722  while (loop)
723  {
724  if (c_redraw)
725  {
726  mix_redraw_head(win_cbar, chain);
727  mix_redraw_chain(win_chain, type2_list, coords, chain, c_cur);
728  c_redraw = false;
729  }
730  else if (c_cur != c_old)
731  {
732  mix_redraw_ce(win_chain, type2_list, coords, chain, c_old, false);
733  mix_redraw_ce(win_chain, type2_list, coords, chain, c_cur, true);
734  }
735 
736  c_old = c_cur;
737 
738  window_redraw(dlg);
739  const int op = menu_loop(menu);
740  switch (op)
741  {
742  case OP_REDRAW:
743  {
744  mix_redraw_head(win_cbar, chain);
745  mix_screen_coordinates(menu->win, type2_list, &coords, chain, 0);
746  mix_redraw_chain(win_chain, type2_list, coords, chain, c_cur);
747  break;
748  }
749 
750  case OP_EXIT:
751  {
752  chain->cl = 0;
753  loop = false;
754  break;
755  }
756 
757  case OP_MIX_USE:
758  {
759  if (!chain->cl)
760  {
761  chain->cl++;
762  chain->ch[0] = menu_get_index(menu);
763  mix_screen_coordinates(menu->win, type2_list, &coords, chain, c_cur);
764  c_redraw = true;
765  }
766 
767  if (chain->cl && chain->ch[chain->cl - 1] &&
768  (type2_list[chain->ch[chain->cl - 1]]->caps & MIX_CAP_MIDDLEMAN))
769  {
770  mutt_error(
771  _("Error: %s can't be used as the final remailer of a chain"),
772  type2_list[chain->ch[chain->cl - 1]]->shortname);
773  }
774  else
775  {
776  loop = false;
777  }
778  break;
779  }
780 
781  case OP_GENERIC_SELECT_ENTRY:
782  case OP_MIX_APPEND:
783  {
784  if ((chain->cl < MAX_MIXES) && (c_cur < chain->cl))
785  c_cur++;
786  }
787  /* fallthrough */
788  case OP_MIX_INSERT:
789  {
790  if (chain->cl < MAX_MIXES)
791  {
792  chain->cl++;
793  for (int i = chain->cl - 1; i > c_cur; i--)
794  chain->ch[i] = chain->ch[i - 1];
795 
796  chain->ch[c_cur] = menu_get_index(menu);
797  mix_screen_coordinates(menu->win, type2_list, &coords, chain, c_cur);
798  c_redraw = true;
799  }
800  else
801  {
802  /* L10N The '%d' here hard-coded to 19 */
803  mutt_error(_("Mixmaster chains are limited to %d elements"), MAX_MIXES);
804  }
805 
806  break;
807  }
808 
809  case OP_MIX_DELETE:
810  {
811  if (chain->cl)
812  {
813  chain->cl--;
814 
815  for (int i = c_cur; i < chain->cl; i++)
816  chain->ch[i] = chain->ch[i + 1];
817 
818  if ((c_cur == chain->cl) && c_cur)
819  c_cur--;
820 
821  mix_screen_coordinates(menu->win, type2_list, &coords, chain, c_cur);
822  c_redraw = true;
823  }
824  else
825  {
826  mutt_error(_("The remailer chain is already empty"));
827  }
828  break;
829  }
830 
831  case OP_MIX_CHAIN_PREV:
832  {
833  if (c_cur)
834  c_cur--;
835  else
836  mutt_error(_("You already have the first chain element selected"));
837 
838  break;
839  }
840 
841  case OP_MIX_CHAIN_NEXT:
842  {
843  if (chain->cl && (c_cur < chain->cl - 1))
844  c_cur++;
845  else
846  mutt_error(_("You already have the last chain element selected"));
847 
848  break;
849  }
850  }
851  }
852 
853  dialog_pop();
854  mutt_window_free(&dlg);
855 
856  /* construct the remailer list */
857 
858  if (chain->cl)
859  {
860  for (int i = 0; i < chain->cl; i++)
861  {
862  const int j = chain->ch[i];
863  if (j != 0)
864  t = type2_list[j]->shortname;
865  else
866  t = "*";
867 
868  mutt_list_insert_tail(chainhead, mutt_str_dup(t));
869  }
870  }
871 
872  mix_type2_list_free(&type2_list);
873  FREE(&coords);
874  FREE(&chain);
875 }
static void mix_redraw_ce(struct MuttWindow *win, struct Remailer **type2_list, struct Coord *coords, struct MixChain *chain, int i, bool selected)
Redraw the Remailer chain.
Definition: remailer.c:364
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
Definition: lib.h:67
A Mixmaster chain.
Definition: remailer.h:57
int ch[MAX_MIXES]
Definition: remailer.h:60
#define mutt_error(...)
Definition: logging.h:88
int help_menu
Menu for key bindings, e.g. MENU_PAGER.
Definition: mutt_window.h:141
Window uses all available vertical space.
Definition: mutt_window.h:38
struct MuttWindow * sbar_new(struct MuttWindow *parent)
Add the Simple Bar (status)
Definition: sbar.c:197
MixCapFlags caps
Definition: remailer.h:51
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define _(a)
Definition: message.h:28
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:632
static void mix_redraw_chain(struct MuttWindow *win, struct Remailer **type2_list, struct Coord *coords, struct MixChain *chain, int cur)
Redraw the chain on screen.
Definition: remailer.c:393
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:105
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:200
struct MuttWindow * focus
Focussed Window.
Definition: mutt_window.h:140
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition: dialog.c:105
Window with a custom drawing function.
Definition: mutt_window.h:95
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:189
Window has a fixed size.
Definition: mutt_window.h:47
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:64
static int remailer_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: remailer.c:615
void * mdata
Private data.
Definition: lib.h:155
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
const struct Mapping * help_data
Data for the Help Bar.
Definition: mutt_window.h:142
Create/edit a Mixmaster chain.
Definition: type.h:52
char * shortname
Definition: remailer.h:48
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:221
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
int(* tag)(struct Menu *menu, int sel, int act)
Definition: lib.h:130
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
size_t cl
Definition: remailer.h:59
#define MIX_CAP_MIDDLEMAN
Definition: remailer.h:38
int max
Number of entries in the menu.
Definition: lib.h:71
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:468
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
static void mix_type2_list_free(struct Remailer ***ttlp)
Free a Remailer List.
Definition: remailer.c:295
char * data
String.
Definition: list.h:36
void dialog_pop(void)
Hide a Window from the user.
Definition: dialog.c:139
static void mix_make_entry(struct Menu *menu, char *buf, size_t buflen, int num)
Format a menu item for the mixmaster chain list - Implements Menu::make_entry() -.
Definition: remailer.c:546
#define FREE(x)
Definition: memory.h:40
static void mix_redraw_head(struct MuttWindow *win, struct MixChain *chain)
Redraw the Chain info.
Definition: remailer.c:411
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
static int mix_chain_add(struct MixChain *chain, const char *s, struct Remailer **type2_list)
Add a host to the chain.
Definition: remailer.c:564
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Definition: mutt_window.c:180
A List node for strings.
Definition: list.h:34
Window wants as much space as possible.
Definition: mutt_window.h:48
static void mix_screen_coordinates(struct MuttWindow *win, struct Remailer **type2_list, struct Coord **coordsp, struct MixChain *chain, int i)
Get the screen coordinates to place a chain.
Definition: remailer.c:313
void * wdata
Private data.
Definition: mutt_window.h:145
static struct Remailer ** mix_type2_list(size_t *l)
parse the type2.list as given by mixmaster -T
Definition: remailer.c:204
static int remailer_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: remailer.c:597
#define MAX_MIXES
Definition: remailer.h:33
Screen coordinates.
Definition: remailer.c:91
static const struct Mapping RemailerHelp[]
Help Bar for the Mixmaster dialog.
Definition: remailer.c:98
Remailer Dialog, dlg_select_mixmaster_chain()
Definition: mutt_window.h:91
A Mixmaster remailer.
Definition: remailer.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_check_message()

int mix_check_message ( struct Email e)

Safety-check the message before passing it to mixmaster.

Parameters
eEmail
Return values
0Success
-1Error

Definition at line 883 of file remailer.c.

884 {
885  bool need_hostname = false;
886 
887  if (!TAILQ_EMPTY(&e->env->cc) || !TAILQ_EMPTY(&e->env->bcc))
888  {
889  mutt_error(_("Mixmaster doesn't accept Cc or Bcc headers"));
890  return -1;
891  }
892 
893  /* When using mixmaster, we MUST qualify any addresses since
894  * the message will be delivered through remote systems.
895  *
896  * use_domain won't be respected at this point, hidden_host will.
897  */
898 
899  struct Address *a = NULL;
900  TAILQ_FOREACH(a, &e->env->to, entries)
901  {
902  if (!a->group && !strchr(a->mailbox, '@'))
903  {
904  need_hostname = true;
905  break;
906  }
907  }
908 
909  if (need_hostname)
910  {
911  const char *fqdn = mutt_fqdn(true, NeoMutt->sub);
912  if (!fqdn)
913  {
914  mutt_error(_("Please set the hostname variable to a proper value when "
915  "using mixmaster"));
916  return -1;
917  }
918 
919  /* Cc and Bcc are empty at this point. */
920  mutt_addrlist_qualify(&e->env->to, fqdn);
921  mutt_addrlist_qualify(&e->env->reply_to, fqdn);
923  }
924 
925  return 0;
926 }
struct AddressList mail_followup_to
Email&#39;s &#39;mail-followup-to&#39;.
Definition: envelope.h:63
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define mutt_error(...)
Definition: logging.h:88
struct AddressList reply_to
Email&#39;s &#39;reply-to&#39;.
Definition: envelope.h:62
struct AddressList bcc
Email&#39;s &#39;Bcc&#39; list.
Definition: envelope.h:60
#define _(a)
Definition: message.h:28
An email address.
Definition: address.h:35
char * mailbox
Mailbox and host address.
Definition: address.h:38
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct Envelope * env
Envelope information.
Definition: email.h:90
struct AddressList cc
Email&#39;s &#39;Cc&#39; list.
Definition: envelope.h:59
void mutt_addrlist_qualify(struct AddressList *al, const char *host)
Expand local names in an Address list using a hostname.
Definition: address.c:650
const char * mutt_fqdn(bool may_hide_host, const struct ConfigSubset *sub)
Get the Fully-Qualified Domain Name.
Definition: sendlib.c:1187
bool group
Group mailbox?
Definition: address.h:39
struct AddressList to
Email&#39;s &#39;To&#39; list.
Definition: envelope.h:58
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
#define TAILQ_EMPTY(head)
Definition: queue.h:721
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_send_message()

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

Send an email via Mixmaster.

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

Definition at line 935 of file remailer.c.

936 {
937  int i = 0;
938  struct Buffer *cmd = mutt_buffer_pool_get();
939  struct Buffer *cd_quoted = mutt_buffer_pool_get();
940 
941  const char *const c_mixmaster = cs_subset_string(NeoMutt->sub, "mixmaster");
942  mutt_buffer_printf(cmd, "cat %s | %s -m ", tempfile, c_mixmaster);
943 
944  struct ListNode *np = NULL;
945  STAILQ_FOREACH(np, chain, entries)
946  {
947  mutt_buffer_addstr(cmd, (i != 0) ? "," : " -l ");
948  mutt_buffer_quote_filename(cd_quoted, (char *) np->data, true);
949  mutt_buffer_addstr(cmd, mutt_buffer_string(cd_quoted));
950  i = 1;
951  }
952 
953  mutt_endwin();
954 
955  i = mutt_system(cmd->data);
956  if (i != 0)
957  {
958  fprintf(stderr, _("Error sending message, child exited %d\n"), i);
959  if (!OptNoCurses)
960  {
962  mutt_error(_("Error sending message"));
963  }
964  }
965 
967  mutt_buffer_pool_release(&cd_quoted);
968  unlink(tempfile);
969  return i;
970 }
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:838
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define mutt_error(...)
Definition: logging.h:88
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
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:47
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:422
char * data
Pointer to data.
Definition: buffer.h:35
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:455
char * data
String.
Definition: list.h:36
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
A List node for strings.
Definition: list.h:34
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ RemailerHelp

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

Help Bar for the Mixmaster dialog.

Definition at line 98 of file remailer.c.