NeoMutt  2024-04-16-36-g75b6fb
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
mixmaster.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stdbool.h>
32#include <stdio.h>
33#include <unistd.h>
34#include "mutt/lib.h"
35#include "address/lib.h"
36#include "config/lib.h"
37#include "email/lib.h"
38#include "core/lib.h"
39#include "gui/lib.h"
40#include "send/lib.h"
41#include "globals.h"
42#include "protos.h"
43
51{
52 bool need_hostname = false;
53
54 if (!TAILQ_EMPTY(&e->env->cc) || !TAILQ_EMPTY(&e->env->bcc))
55 {
56 mutt_error(_("Mixmaster doesn't accept Cc or Bcc headers"));
57 return -1;
58 }
59
60 /* When using mixmaster, we MUST qualify any addresses since
61 * the message will be delivered through remote systems.
62 *
63 * use_domain won't be respected at this point, hidden_host will.
64 */
65
66 struct Address *a = NULL;
67 TAILQ_FOREACH(a, &e->env->to, entries)
68 {
69 if (!a->group && !buf_find_char(a->mailbox, '@'))
70 {
71 need_hostname = true;
72 break;
73 }
74 }
75
76 if (need_hostname)
77 {
78 const char *fqdn = mutt_fqdn(true, NeoMutt->sub);
79 if (!fqdn)
80 {
81 mutt_error(_("Please set the hostname variable to a proper value when using mixmaster"));
82 return -1;
83 }
84
85 /* Cc and Bcc are empty at this point. */
86 mutt_addrlist_qualify(&e->env->to, fqdn);
89 }
90
91 return 0;
92}
93
101int mix_send_message(struct ListHead *chain, const char *tempfile)
102{
103 int i = 0;
104 struct Buffer *cmd = buf_pool_get();
105 struct Buffer *cd_quoted = buf_pool_get();
106
107 const char *const c_mixmaster = cs_subset_string(NeoMutt->sub, "mixmaster");
108 buf_printf(cmd, "cat %s | %s -m ", tempfile, c_mixmaster);
109
110 struct ListNode *np = NULL;
111 STAILQ_FOREACH(np, chain, entries)
112 {
113 buf_addstr(cmd, (i != 0) ? "," : " -l ");
114 buf_quote_filename(cd_quoted, (char *) np->data, true);
115 buf_addstr(cmd, buf_string(cd_quoted));
116 i = 1;
117 }
118
119 mutt_endwin();
120
121 i = mutt_system(cmd->data);
122 if (i != 0)
123 {
124 fprintf(stderr, _("Error sending message, child exited %d\n"), i);
125 if (!OptNoCurses)
126 {
128 mutt_error(_("Error sending message"));
129 }
130 }
131
132 buf_pool_release(&cmd);
133 buf_pool_release(&cd_quoted);
134 unlink(tempfile);
135 return i;
136}
void mutt_addrlist_qualify(struct AddressList *al, const char *host)
Expand local names in an Address list using a hostname.
Definition: address.c:680
Email Address Handling.
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
const char * buf_find_char(const struct Buffer *buf, const char c)
Return a pointer to a char found in the buffer.
Definition: buffer.c:654
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
Definition: curs_lib.c:173
void mutt_endwin(void)
Shutdown curses.
Definition: curs_lib.c:151
Structs that make up an email.
void buf_quote_filename(struct Buffer *buf, const char *filename, bool add_outer)
Quote a filename to survive the shell's quoting rules.
Definition: file.c:930
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:72
#define mutt_error(...)
Definition: logging2.h:92
Convenience wrapper for the gui headers.
int mix_send_message(struct ListHead *chain, const char *tempfile)
Send an email via Mixmaster.
Definition: mixmaster.c:101
int mix_check_message(struct Email *e)
Safety-check the message before passing it to mixmaster.
Definition: mixmaster.c:50
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
Prototypes for many functions.
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:51
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define TAILQ_EMPTY(head)
Definition: queue.h:721
Convenience wrapper for the send headers.
const char * mutt_fqdn(bool may_hide_host, const struct ConfigSubset *sub)
Get the Fully-Qualified Domain Name.
Definition: sendlib.c:706
An email address.
Definition: address.h:36
bool group
Group mailbox?
Definition: address.h:39
struct Buffer * mailbox
Mailbox and host address.
Definition: address.h:38
String manipulation buffer.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:37
The envelope/body of an email.
Definition: email.h:39
struct Envelope * env
Envelope information.
Definition: email.h:68
struct AddressList to
Email's 'To' list.
Definition: envelope.h:60
struct AddressList reply_to
Email's 'reply-to'.
Definition: envelope.h:64
struct AddressList mail_followup_to
Email's 'mail-followup-to'.
Definition: envelope.h:65
struct AddressList cc
Email's 'Cc' list.
Definition: envelope.h:61
struct AddressList bcc
Email's 'Bcc' list.
Definition: envelope.h:62
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45