NeoMutt  2021-10-29-43-g6b8931
Teaching an old dog new tricks
DOXYGEN
remailer.h File Reference

Support of Mixmaster anonymous remailer. More...

#include <stddef.h>
#include <stdint.h>
+ Include dependency graph for remailer.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Remailer
 A Mixmaster remailer. More...
 
struct  MixChain
 A Mixmaster chain. More...
 

Macros

#define MAX_MIXES   19
 
#define MIX_CAP_NO_FLAGS   0
 No flags are set. More...
 
#define MIX_CAP_COMPRESS   (1 << 0)
 
#define MIX_CAP_MIDDLEMAN   (1 << 1)
 
#define MIX_CAP_NEWSPOST   (1 << 2)
 
#define MIX_CAP_NEWSMAIL   (1 << 3)
 

Typedefs

typedef uint8_t MixCapFlags
 Flags, e.g. MIX_CAP_NO_FLAGS. More...
 

Functions

int mix_send_message (struct ListHead *chain, const char *tempfile)
 Send an email via Mixmaster. More...
 
int mix_check_message (struct Email *e)
 Safety-check the message before passing it to mixmaster. More...
 
void dlg_select_mixmaster_chain (struct ListHead *chainhead)
 Create a Mixmaster chain. More...
 

Detailed Description

Support of Mixmaster anonymous remailer.

Authors
  • Thomas Roessler

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file remailer.h.

Macro Definition Documentation

◆ MAX_MIXES

#define MAX_MIXES   19

Definition at line 33 of file remailer.h.

◆ MIX_CAP_NO_FLAGS

#define MIX_CAP_NO_FLAGS   0

No flags are set.

Definition at line 36 of file remailer.h.

◆ MIX_CAP_COMPRESS

#define MIX_CAP_COMPRESS   (1 << 0)

Definition at line 37 of file remailer.h.

◆ MIX_CAP_MIDDLEMAN

#define MIX_CAP_MIDDLEMAN   (1 << 1)

Definition at line 38 of file remailer.h.

◆ MIX_CAP_NEWSPOST

#define MIX_CAP_NEWSPOST   (1 << 2)

Definition at line 39 of file remailer.h.

◆ MIX_CAP_NEWSMAIL

#define MIX_CAP_NEWSMAIL   (1 << 3)

Definition at line 40 of file remailer.h.

Typedef Documentation

◆ MixCapFlags

typedef uint8_t MixCapFlags

Flags, e.g. MIX_CAP_NO_FLAGS.

Definition at line 35 of file remailer.h.

Function Documentation

◆ 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_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 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:866
#define mutt_error(...)
Definition: logging.h:87
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
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:53
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
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:51
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
String manipulation buffer.
Definition: buffer.h:34
char * data
Pointer to data.
Definition: buffer.h:35
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ 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 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:1194
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:

◆ 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
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
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define FREE(x)
Definition: memory.h:40
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
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:181
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
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 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
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
#define MIX_CAP_MIDDLEMAN
Definition: remailer.h:38
#define MAX_MIXES
Definition: remailer.h:33
struct MuttWindow * sbar_new(void)
Add the Simple Bar (status)
Definition: sbar.c:195
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:219
Screen coordinates.
Definition: remailer.c:91
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
size_t cl
Length of chain.
Definition: remailer.h:59
int ch[MAX_MIXES]
Indexes of chain hosts.
Definition: remailer.h:60
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
A Mixmaster remailer.
Definition: remailer.h:46
char * shortname
Short name of remailer host.
Definition: remailer.h:48
@ MENU_MIX
Create/edit a Mixmaster chain.
Definition: type.h:52
+ Here is the call graph for this function: