NeoMutt  2020-06-26-89-g172cd3
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 mix_make_chain (struct MuttWindow *win, struct ListHead *chainhead, int cols)
 Create a Mixmaster chain. More...
 

Variables

char * C_MixEntryFormat
 Config: (mixmaster) printf-like format string for the mixmaster chain. More...
 
char * C_Mixmaster
 Config: (mixmaster) External command to route a mixmaster message. More...
 

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 38 of file remailer.h.

◆ MIX_CAP_NO_FLAGS

#define MIX_CAP_NO_FLAGS   0

No flags are set.

Definition at line 41 of file remailer.h.

◆ MIX_CAP_COMPRESS

#define MIX_CAP_COMPRESS   (1 << 0)

Definition at line 42 of file remailer.h.

◆ MIX_CAP_MIDDLEMAN

#define MIX_CAP_MIDDLEMAN   (1 << 1)

Definition at line 43 of file remailer.h.

◆ MIX_CAP_NEWSPOST

#define MIX_CAP_NEWSPOST   (1 << 2)

Definition at line 44 of file remailer.h.

◆ MIX_CAP_NEWSMAIL

#define MIX_CAP_NEWSMAIL   (1 << 3)

Definition at line 45 of file remailer.h.

Typedef Documentation

◆ MixCapFlags

typedef uint8_t MixCapFlags

Flags, e.g. MIX_CAP_NO_FLAGS.

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

904 {
905  int i = 0;
906  struct Buffer *cmd = mutt_buffer_pool_get();
907  struct Buffer *cd_quoted = mutt_buffer_pool_get();
908 
909  mutt_buffer_printf(cmd, "cat %s | %s -m ", tempfile, C_Mixmaster);
910 
911  struct ListNode *np = NULL;
912  STAILQ_FOREACH(np, chain, entries)
913  {
914  mutt_buffer_addstr(cmd, (i != 0) ? "," : " -l ");
915  mutt_buffer_quote_filename(cd_quoted, (char *) np->data, true);
916  mutt_buffer_addstr(cmd, mutt_b2s(cd_quoted));
917  i = 1;
918  }
919 
920  mutt_endwin();
921 
922  i = mutt_system(cmd->data);
923  if (i != 0)
924  {
925  fprintf(stderr, _("Error sending message, child exited %d.\n"), i);
926  if (!OptNoCurses)
927  {
929  mutt_error(_("Error sending message"));
930  }
931  }
932 
934  mutt_buffer_pool_release(&cd_quoted);
935  unlink(tempfile);
936  return i;
937 }
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:836
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
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:48
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
char * C_Mixmaster
Config: (mixmaster) External command to route a mixmaster message.
Definition: remailer.c:59
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
#define mutt_b2s(buf)
Definition: buffer.h:41
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:569
char * data
Pointer to data.
Definition: buffer.h:35
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:602
char * data
String.
Definition: list.h:36
#define mutt_error(...)
Definition: logging.h:84
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:

◆ 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 851 of file remailer.c.

852 {
853  bool need_hostname = false;
854 
855  if (!TAILQ_EMPTY(&e->env->cc) || !TAILQ_EMPTY(&e->env->bcc))
856  {
857  mutt_error(_("Mixmaster doesn't accept Cc or Bcc headers"));
858  return -1;
859  }
860 
861  /* When using mixmaster, we MUST qualify any addresses since
862  * the message will be delivered through remote systems.
863  *
864  * use_domain won't be respected at this point, hidden_host will.
865  */
866 
867  struct Address *a = NULL;
868  TAILQ_FOREACH(a, &e->env->to, entries)
869  {
870  if (!a->group && !strchr(a->mailbox, '@'))
871  {
872  need_hostname = true;
873  break;
874  }
875  }
876 
877  if (need_hostname)
878  {
879  const char *fqdn = mutt_fqdn(true, NeoMutt->sub);
880  if (!fqdn)
881  {
882  mutt_error(_("Please set the hostname variable to a proper value when "
883  "using mixmaster"));
884  return -1;
885  }
886 
887  /* Cc and Bcc are empty at this point. */
888  mutt_addrlist_qualify(&e->env->to, fqdn);
889  mutt_addrlist_qualify(&e->env->reply_to, fqdn);
891  }
892 
893  return 0;
894 }
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:718
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:34
char * mailbox
Mailbox and host address.
Definition: address.h:37
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct Envelope * env
Envelope information.
Definition: email.h:89
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:1179
bool group
Group mailbox?
Definition: address.h:38
#define mutt_error(...)
Definition: logging.h:84
struct AddressList to
Email&#39;s &#39;To&#39; list.
Definition: envelope.h:58
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
#define TAILQ_EMPTY(head)
Definition: queue.h:714
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix_make_chain()

void mix_make_chain ( struct MuttWindow win,
struct ListHead *  chainhead,
int  cols 
)

Create a Mixmaster chain.

Parameters
winWindow
chainheadList of chain links
colsNumber of screen columns

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

Definition at line 601 of file remailer.c.

602 {
603  int c_cur = 0, c_old = 0;
604  bool c_redraw = true;
605  size_t ttll = 0;
606 
607  struct Coord *coords = NULL;
608 
609  struct Menu *menu = NULL;
610  char helpstr[1024];
611  bool loop = true;
612 
613  char *t = NULL;
614 
615  struct Remailer **type2_list = mix_type2_list(&ttll);
616  if (!type2_list)
617  {
618  mutt_error(_("Can't get mixmaster's type2.list"));
619  return;
620  }
621 
622  struct MixChain *chain = mutt_mem_calloc(1, sizeof(struct MixChain));
623 
624  struct ListNode *p = NULL;
625  STAILQ_FOREACH(p, chainhead, entries)
626  {
627  mix_chain_add(chain, p->data, type2_list);
628  }
629  mutt_list_free(chainhead);
630 
631  /* safety check */
632  for (int i = 0; i < chain->cl; i++)
633  {
634  if (chain->ch[i] >= ttll)
635  chain->ch[i] = 0;
636  }
637 
638  mix_screen_coordinates(win, type2_list, &coords, chain, 0);
639 
640  struct MuttWindow *dlg =
643 
644  struct MuttWindow *index =
647 
648  struct MuttWindow *ibar =
651 
652  if (C_StatusOnTop)
653  {
654  mutt_window_add_child(dlg, ibar);
655  mutt_window_add_child(dlg, index);
656  }
657  else
658  {
659  mutt_window_add_child(dlg, index);
660  mutt_window_add_child(dlg, ibar);
661  }
662 
664  dialog_push(dlg);
665 
666  menu = mutt_menu_new(MENU_MIX);
667  menu->pagelen = index->state.rows;
668  menu->win_index = index;
669  menu->win_ibar = ibar;
670 
671  menu->max = ttll;
672  menu->make_entry = mix_make_entry;
673  menu->tag = NULL;
674  menu->title = _("Select a remailer chain");
675  menu->mdata = type2_list;
676  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_MIX, RemailerHelp);
677  menu->pagelen = MIX_VOFFSET - 1;
679 
680  while (loop)
681  {
682  if (menu->pagelen != MIX_VOFFSET - 1)
683  {
684  menu->pagelen = MIX_VOFFSET - 1;
685  menu->redraw = REDRAW_FULL;
686  }
687 
688  if (c_redraw)
689  {
690  mix_redraw_head(menu->win_index, chain);
691  mix_redraw_chain(menu->win_index, type2_list, coords, chain, c_cur);
692  c_redraw = false;
693  }
694  else if (c_cur != c_old)
695  {
696  mix_redraw_ce(menu->win_index, type2_list, coords, chain, c_old, false);
697  mix_redraw_ce(menu->win_index, type2_list, coords, chain, c_cur, true);
698  }
699 
700  c_old = c_cur;
701 
702  const int op = mutt_menu_loop(menu);
703  switch (op)
704  {
705  case OP_REDRAW:
706  {
707  menu_redraw_status(menu);
708  mix_redraw_head(menu->win_index, chain);
709  mix_screen_coordinates(menu->win_index, type2_list, &coords, chain, 0);
710  mix_redraw_chain(menu->win_index, type2_list, coords, chain, c_cur);
711  menu->pagelen = MIX_VOFFSET - 1;
712  break;
713  }
714 
715  case OP_EXIT:
716  {
717  chain->cl = 0;
718  loop = false;
719  break;
720  }
721 
722  case OP_MIX_USE:
723  {
724  if (!chain->cl)
725  {
726  chain->cl++;
727  chain->ch[0] = menu->current;
728  mix_screen_coordinates(menu->win_index, type2_list, &coords, chain, c_cur);
729  c_redraw = true;
730  }
731 
732  if (chain->cl && chain->ch[chain->cl - 1] &&
733  (type2_list[chain->ch[chain->cl - 1]]->caps & MIX_CAP_MIDDLEMAN))
734  {
735  mutt_error(
736  _("Error: %s can't be used as the final remailer of a chain"),
737  type2_list[chain->ch[chain->cl - 1]]->shortname);
738  }
739  else
740  {
741  loop = false;
742  }
743  break;
744  }
745 
746  case OP_GENERIC_SELECT_ENTRY:
747  case OP_MIX_APPEND:
748  {
749  if ((chain->cl < MAX_MIXES) && (c_cur < chain->cl))
750  c_cur++;
751  }
752  /* fallthrough */
753  case OP_MIX_INSERT:
754  {
755  if (chain->cl < MAX_MIXES)
756  {
757  chain->cl++;
758  for (int i = chain->cl - 1; i > c_cur; i--)
759  chain->ch[i] = chain->ch[i - 1];
760 
761  chain->ch[c_cur] = menu->current;
762  mix_screen_coordinates(menu->win_index, type2_list, &coords, chain, c_cur);
763  c_redraw = true;
764  }
765  else
766  {
767  /* L10N The '%d' here hard-coded to 19 */
768  mutt_error(_("Mixmaster chains are limited to %d elements"), MAX_MIXES);
769  }
770 
771  break;
772  }
773 
774  case OP_MIX_DELETE:
775  {
776  if (chain->cl)
777  {
778  chain->cl--;
779 
780  for (int i = c_cur; i < chain->cl; i++)
781  chain->ch[i] = chain->ch[i + 1];
782 
783  if ((c_cur == chain->cl) && c_cur)
784  c_cur--;
785 
786  mix_screen_coordinates(menu->win_index, type2_list, &coords, chain, c_cur);
787  c_redraw = true;
788  }
789  else
790  {
791  mutt_error(_("The remailer chain is already empty"));
792  }
793  break;
794  }
795 
796  case OP_MIX_CHAIN_PREV:
797  {
798  if (c_cur)
799  c_cur--;
800  else
801  mutt_error(_("You already have the first chain element selected"));
802 
803  break;
804  }
805 
806  case OP_MIX_CHAIN_NEXT:
807  {
808  if (chain->cl && (c_cur < chain->cl - 1))
809  c_cur++;
810  else
811  mutt_error(_("You already have the last chain element selected"));
812 
813  break;
814  }
815  }
816  }
817 
818  mutt_menu_pop_current(menu);
819  mutt_menu_free(&menu);
820  dialog_pop();
822  mutt_window_free(&dlg);
823 
824  /* construct the remailer list */
825 
826  if (chain->cl)
827  {
828  for (int i = 0; i < chain->cl; i++)
829  {
830  const int j = chain->ch[i];
831  if (j != 0)
832  t = type2_list[j]->shortname;
833  else
834  t = "*";
835 
836  mutt_list_insert_tail(chainhead, mutt_str_dup(t));
837  }
838  }
839 
840  mix_type2_list_free(&type2_list);
841  FREE(&coords);
842  FREE(&chain);
843 }
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:331
#define MIX_VOFFSET
Definition: remailer.c:62
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:45
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
if(!test_colorize_)
Definition: acutest.h:499
GUI selectable list of items.
Definition: mutt_menu.h:80
A Mixmaster chain.
Definition: remailer.h:62
int ch[MAX_MIXES]
Definition: remailer.h:65
Window uses all available vertical space.
Definition: mutt_window.h:35
void dialog_pop(void)
Hide a Window from the user.
Definition: mutt_window.c:750
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition: mutt_window.c:720
MixCapFlags caps
Definition: remailer.h:56
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:375
#define _(a)
Definition: message.h:28
A division of the screen.
Definition: mutt_window.h:114
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:360
Container for Accounts, Notifications.
Definition: neomutt.h:36
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
An Index Window containing a selection list.
Definition: mutt_window.h:93
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:151
struct MuttWindow * win_ibar
Definition: mutt_menu.h:93
const char * title
Title of this menu.
Definition: mutt_menu.h:82
Window has a fixed size.
Definition: mutt_window.h:44
const char * help
Quickref for the current menu.
Definition: mutt_menu.h:83
static int mutt_dlg_mixmaster_observer(struct NotifyCallback *nc)
Listen for config changes affecting the Mixmaster menu - Implements observer_t.
Definition: remailer.c:566
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:64
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:119
void * mdata
Extra data for the current menu.
Definition: mutt_menu.h:84
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:49
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:58
char * shortname
Definition: remailer.h:53
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
int(* tag)(struct Menu *menu, int sel, int act)
Tag some menu items.
Definition: mutt_menu.h:136
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:89
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
size_t cl
Definition: remailer.h:64
bool notify_observer_add(struct Notify *notify, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:153
#define MIX_CAP_MIDDLEMAN
Definition: remailer.h:43
int max
Number of entries in the menu.
Definition: mutt_menu.h:86
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:561
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:87
static void mix_type2_list_free(struct Remailer ***ttlp)
Free a Remailer List.
Definition: remailer.c:264
char * data
String.
Definition: list.h:36
WHERE bool C_StatusOnTop
Config: Display the status bar at the top.
Definition: mutt_globals.h:166
#define mutt_error(...)
Definition: logging.h:84
Create/edit a Mixmaster chain.
Definition: keymap.h:89
#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:378
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:185
static int mix_chain_add(struct MixChain *chain, const char *s, struct Remailer **type2_list)
Add a host to the chain.
Definition: remailer.c:533
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:131
int current
Current entry.
Definition: mutt_menu.h:85
struct MuttWindow * win_index
Definition: mutt_menu.h:92
char * mutt_compile_help(char *buf, size_t buflen, enum MenuType menu, const struct Mapping *items)
Create the text for the help menu.
Definition: help.c:110
static void mix_make_entry(char *buf, size_t buflen, struct Menu *menu, int num)
Format a menu item for the mixmaster chain list - Implements Menu::make_entry()
Definition: remailer.c:517
A List node for strings.
Definition: list.h:34
Window wants as much space as possible.
Definition: mutt_window.h:45
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:282
static struct Remailer ** mix_type2_list(size_t *l)
parse the type2.list as given by mixmaster -T
Definition: remailer.c:175
Index Bar containing status info about the Index.
Definition: mutt_window.h:94
void(* make_entry)(char *buf, size_t buflen, struct Menu *menu, int line)
Format a item for a menu.
Definition: mutt_menu.h:117
#define MAX_MIXES
Definition: remailer.h:38
Screen coordinates.
Definition: remailer.c:68
static const struct Mapping RemailerHelp[]
Definition: remailer.c:74
Remailer Dialog, mix_make_chain()
Definition: mutt_window.h:87
A Mixmaster remailer.
Definition: remailer.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ C_MixEntryFormat

char* C_MixEntryFormat

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

Definition at line 58 of file remailer.c.

◆ C_Mixmaster

char* C_Mixmaster

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

Definition at line 59 of file remailer.c.