NeoMutt  2021-10-22-8-g9cb437
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 "color/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 -. 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 113 of file remailer.c.

114 {
116 
117  while (*capstr)
118  {
119  switch (*capstr)
120  {
121  case 'C':
122  caps |= MIX_CAP_COMPRESS;
123  break;
124 
125  case 'M':
126  caps |= MIX_CAP_MIDDLEMAN;
127  break;
128 
129  case 'N':
130  {
131  switch (*++capstr)
132  {
133  case 'm':
134  caps |= MIX_CAP_NEWSMAIL;
135  break;
136 
137  case 'p':
138  caps |= MIX_CAP_NEWSPOST;
139  break;
140  }
141  }
142  }
143 
144  if (*capstr)
145  capstr++;
146  }
147 
148  return caps;
149 }
#define MIX_CAP_MIDDLEMAN
Definition: remailer.h:38
#define MIX_CAP_NEWSMAIL
Definition: remailer.h:40
#define MIX_CAP_NO_FLAGS
No flags are set.
Definition: remailer.h:36
#define MIX_CAP_COMPRESS
Definition: remailer.h:37
uint8_t MixCapFlags
Flags, e.g. MIX_CAP_NO_FLAGS.
Definition: remailer.h:35
#define MIX_CAP_NEWSPOST
Definition: remailer.h:39
+ 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 158 of file remailer.c.

160 {
161  if (*used == *slots)
162  {
163  *slots += 5;
164  mutt_mem_realloc(type2_list, sizeof(struct Remailer *) * (*slots));
165  }
166 
167  (*type2_list)[(*used)++] = entry;
168  if (entry)
169  entry->num = *used;
170 }
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:46
int num
Index number.
Definition: remailer.h:47
+ 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 176 of file remailer.c.

177 {
178  return mutt_mem_calloc(1, sizeof(struct Remailer));
179 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remailer_free()

static void remailer_free ( struct Remailer **  ptr)
static

Free a Remailer.

Parameters
[out]ptrRemailer to free

Definition at line 185 of file remailer.c.

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

◆ mix_type2_list()

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

Parse the type2.list as given by mixmaster -T.

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

Definition at line 203 of file remailer.c.

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

295 {
296  struct Remailer **type2_list = *ttlp;
297 
298  for (int i = 0; type2_list[i]; i++)
299  remailer_free(&type2_list[i]);
300 
301  FREE(ttlp);
302 }
+ 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 312 of file remailer.c.

314 {
315  const int wrap_indent = 2;
316 
317  if (!chain->cl)
318  return;
319 
320  short c, r;
321 
322  mutt_mem_realloc(coordsp, sizeof(struct Coord) * chain->cl);
323 
324  struct Coord *coords = *coordsp;
325 
326  if (i == 0)
327  {
328  r = 0;
329  c = 0;
330  }
331  else
332  {
333  c = coords[i - 1].c + strlen(type2_list[chain->ch[i - 1]]->shortname) + 2;
334  r = coords[i - 1].r;
335  }
336 
337  for (; i < chain->cl; i++)
338  {
339  short oc = c;
340  c += strlen(type2_list[chain->ch[i]]->shortname) + 2;
341 
342  if (c >= win->state.cols)
343  {
344  oc = wrap_indent;
345  c = wrap_indent;
346  r++;
347  }
348 
349  coords[i].c = oc;
350  coords[i].r = r;
351  }
352 }
Screen coordinates.
Definition: remailer.c:91
short c
column
Definition: remailer.c:93
short r
row
Definition: remailer.c:92
size_t cl
Length of chain.
Definition: remailer.h:59
int ch[MAX_MIXES]
Indexes of chain hosts.
Definition: remailer.h:60
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
+ 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 363 of file remailer.c.

365 {
366  if (!coords || !chain)
367  return;
368 
369  if (coords[i].r < win->state.rows)
370  {
371  if (selected)
373  else
375 
376  mutt_window_mvaddstr(win, coords[i].c, coords[i].r, type2_list[chain->ch[i]]->shortname);
378 
379  if (i + 1 < chain->cl)
380  mutt_window_addstr(win, ", ");
381  }
382 }
@ MT_COLOR_INDICATOR
Selected item in list.
Definition: color.h:49
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:53
void mutt_curses_set_color_by_id(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:52
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:306
int mutt_window_addstr(struct MuttWindow *win, const char *str)
Write a string to a Window.
Definition: mutt_window.c:408
+ 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 392 of file remailer.c.

394 {
395  for (int i = 0; i < win->state.rows; i++)
396  {
397  mutt_window_move(win, 0, i);
399  }
400 
401  for (int i = 0; i < chain->cl; i++)
402  mix_redraw_ce(win, type2_list, coords, chain, i, i == cur);
403 }
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:292
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:241
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:363
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
+ 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 410 of file remailer.c.

411 {
412  char buf[1024];
413  snprintf(buf, sizeof(buf), "-- Remailer chain [Length: %ld]", chain ? chain->cl : 0);
414  sbar_set_title(win, buf);
415 }
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:219
+ 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 424 of file remailer.c.

425 {
426  static char capbuf[10];
427  char *t = capbuf;
428 
429  if (r->caps & MIX_CAP_COMPRESS)
430  *t++ = 'C';
431  else
432  *t++ = ' ';
433 
434  if (r->caps & MIX_CAP_MIDDLEMAN)
435  *t++ = 'M';
436  else
437  *t++ = ' ';
438 
439  if (r->caps & MIX_CAP_NEWSPOST)
440  {
441  *t++ = 'N';
442  *t++ = 'p';
443  }
444  else
445  {
446  *t++ = ' ';
447  *t++ = ' ';
448  }
449 
450  if (r->caps & MIX_CAP_NEWSMAIL)
451  {
452  *t++ = 'N';
453  *t++ = 'm';
454  }
455  else
456  {
457  *t++ = ' ';
458  *t++ = ' ';
459  }
460 
461  *t = '\0';
462 
463  return capbuf;
464 }
+ 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 563 of file remailer.c.

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

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

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

935 {
936  int i = 0;
937  struct Buffer *cmd = mutt_buffer_pool_get();
938  struct Buffer *cd_quoted = mutt_buffer_pool_get();
939 
940  const char *const c_mixmaster = cs_subset_string(NeoMutt->sub, "mixmaster");
941  mutt_buffer_printf(cmd, "cat %s | %s -m ", tempfile, c_mixmaster);
942 
943  struct ListNode *np = NULL;
944  STAILQ_FOREACH(np, chain, entries)
945  {
946  mutt_buffer_addstr(cmd, (i != 0) ? "," : " -l ");
947  mutt_buffer_quote_filename(cd_quoted, (char *) np->data, true);
948  mutt_buffer_addstr(cmd, mutt_buffer_string(cd_quoted));
949  i = 1;
950  }
951 
952  mutt_endwin();
953 
954  i = mutt_system(cmd->data);
955  if (i != 0)
956  {
957  fprintf(stderr, _("Error sending message, child exited %d\n"), i);
958  if (!OptNoCurses)
959  {
961  mutt_error(_("Error sending message"));
962  }
963  }
964 
966  mutt_buffer_pool_release(&cd_quoted);
967  unlink(tempfile);
968  return i;
969 }
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
Definition: curs_lib.c:455
void mutt_endwin(void)
Shutdown curses.
Definition: curs_lib.c:422
void mutt_buffer_quote_filename(struct Buffer *buf, const char *filename, bool add_outer)
Quote a filename to survive the shell's quoting rules.
Definition: file.c:842
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:53
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:51
char * data
Pointer to data.
Definition: buffer.h:35
+ 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 1 of file remailer.c.