NeoMutt  2025-01-09-117-gace867
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
sendmail.h File Reference

Send email using sendmail. More...

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

Go to the source code of this file.

Functions

int mutt_invoke_sendmail (struct Mailbox *m, struct AddressList *from, struct AddressList *to, struct AddressList *cc, struct AddressList *bcc, const char *msg, bool eightbit, struct ConfigSubset *sub)
 Run sendmail.
 

Detailed Description

Send email using sendmail.

Authors
  • Richard Russon

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 sendmail.h.

Function Documentation

◆ mutt_invoke_sendmail()

int mutt_invoke_sendmail ( struct Mailbox m,
struct AddressList *  from,
struct AddressList *  to,
struct AddressList *  cc,
struct AddressList *  bcc,
const char *  msg,
bool  eightbit,
struct ConfigSubset sub 
)

Run sendmail.

Parameters
mMailbox
fromThe sender
toRecipients
ccRecipients
bccRecipients
msgFile containing message
eightbitMessage contains 8bit chars
subConfig Subset
Return values
0Success
-1Failure
See also
$inews

Definition at line 300 of file sendmail.c.

304{
305 char *ps = NULL, *path = NULL, *s = NULL, *childout = NULL;
306 struct SendmailArgArray args = ARRAY_HEAD_INITIALIZER;
307 struct SendmailArgArray extra_args = ARRAY_HEAD_INITIALIZER;
308 int i;
309
310 if (OptNewsSend)
311 {
312 struct Buffer *cmd = buf_pool_get();
313
314 const struct Expando *c_inews = cs_subset_expando(sub, "inews");
316 cmd->dsize, NeoMutt->env, cmd);
317 if (buf_is_empty(cmd))
318 {
319 i = nntp_post(m, msg);
320 unlink(msg);
321 buf_pool_release(&cmd);
322 return i;
323 }
324
325 s = buf_strdup(cmd);
326 buf_pool_release(&cmd);
327 }
328 else
329 {
330 const char *const c_sendmail = cs_subset_string(sub, "sendmail");
331 s = mutt_str_dup(c_sendmail);
332 }
333
334 if (!s)
335 {
336 mutt_error(_("$sendmail must be set in order to send mail"));
337 return -1;
338 }
339
340 ps = s;
341 i = 0;
342 while ((ps = strtok(ps, " ")))
343 {
344 if (i)
345 {
346 if (mutt_str_equal(ps, "--"))
347 break;
348 ARRAY_ADD(&args, ps);
349 }
350 else
351 {
352 path = mutt_str_dup(ps);
353 ps = strrchr(ps, '/');
354 if (ps)
355 ps++;
356 else
357 ps = path;
358 ARRAY_ADD(&args, ps);
359 }
360 ps = NULL;
361 i++;
362 }
363
364 if (!OptNewsSend)
365 {
366 /* If $sendmail contained a "--", we save the recipients to append to
367 * args after other possible options added below. */
368 if (ps)
369 {
370 ps = NULL;
371 while ((ps = strtok(ps, " ")))
372 {
373 ARRAY_ADD(&extra_args, ps);
374 ps = NULL;
375 }
376 }
377
378 const bool c_use_8bit_mime = cs_subset_bool(sub, "use_8bit_mime");
379 if (eightbit && c_use_8bit_mime)
380 ARRAY_ADD(&args, "-B8BITMIME");
381
382 const bool c_use_envelope_from = cs_subset_bool(sub, "use_envelope_from");
383 if (c_use_envelope_from)
384 {
385 const struct Address *c_envelope_from_address = cs_subset_address(sub, "envelope_from_address");
386 if (c_envelope_from_address)
387 {
388 ARRAY_ADD(&args, "-f");
389 add_args_one(&args, c_envelope_from_address);
390 }
391 else if (!TAILQ_EMPTY(from) && !TAILQ_NEXT(TAILQ_FIRST(from), entries))
392 {
393 ARRAY_ADD(&args, "-f");
394 add_args(&args, from);
395 }
396 }
397
398 const char *const c_dsn_notify = cs_subset_string(sub, "dsn_notify");
399 if (c_dsn_notify)
400 {
401 ARRAY_ADD(&args, "-N");
402 ARRAY_ADD(&args, c_dsn_notify);
403 }
404
405 const char *const c_dsn_return = cs_subset_string(sub, "dsn_return");
406 if (c_dsn_return)
407 {
408 ARRAY_ADD(&args, "-R");
409 ARRAY_ADD(&args, c_dsn_return);
410 }
411 ARRAY_ADD(&args, "--");
412 const char **e = NULL;
413 ARRAY_FOREACH(e, &extra_args)
414 {
415 ARRAY_ADD(&args, *e);
416 }
417 add_args(&args, to);
418 add_args(&args, cc);
419 add_args(&args, bcc);
420 }
421
422 ARRAY_ADD(&args, NULL);
423
424 const short c_sendmail_wait = cs_subset_number(sub, "sendmail_wait");
425 i = send_msg(path, &args, msg, OptNoCurses ? NULL : &childout, c_sendmail_wait);
426
427 /* Some user's $sendmail command uses gpg for password decryption,
428 * and is set up to prompt using ncurses pinentry. If we
429 * mutt_endwin() it leaves other users staring at a blank screen.
430 * So instead, just force a hard redraw on the next refresh. */
431 if (!OptNoCurses)
432 {
434 }
435
436 if (i != (EX_OK & 0xff))
437 {
438 if (i != S_BKG)
439 {
440 const char *e = mutt_str_sysexit(i);
441 mutt_error(_("Error sending message, child exited %d (%s)"), i, NONULL(e));
442 if (childout)
443 {
444 struct stat st = { 0 };
445
446 if ((stat(childout, &st) == 0) && (st.st_size > 0))
447 {
448 struct PagerData pdata = { 0 };
449 struct PagerView pview = { &pdata };
450
451 pdata.fname = childout;
452
453 pview.banner = _("Output of the delivery process");
455 pview.mode = PAGER_MODE_OTHER;
456
457 mutt_do_pager(&pview, NULL);
458 }
459 }
460 }
461 }
462 else if (childout)
463 {
464 unlink(childout);
465 }
466
467 FREE(&childout);
468 FREE(&path);
469 FREE(&s);
470 ARRAY_FREE(&args);
471 ARRAY_FREE(&extra_args);
472
473 if (i == (EX_OK & 0xff))
474 i = 0;
475 else if (i == S_BKG)
476 i = 1;
477 else
478 i = -1;
479 return i;
480}
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address config item by name.
Definition: config_type.c:286
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:156
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:214
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:204
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:58
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:291
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:571
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:291
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:143
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
Definition: config_type.c:361
void mutt_need_hard_redraw(void)
Force a hard refresh.
Definition: curs_lib.c:101
int mutt_do_pager(struct PagerView *pview, struct Email *e)
Display some page-able text to the user (help or attachment)
Definition: do_pager.c:122
int expando_filter(const struct Expando *exp, const struct ExpandoRenderCallback *erc, void *data, MuttFormatFlags flags, int max_cols, char **env_list, struct Buffer *buf)
Render an Expando and run the result through a filter.
Definition: filter.c:139
const struct ExpandoRenderCallback NntpRenderCallbacks[]
Callbacks for Newsrc Expandos.
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:66
bool OptNewsSend
(pseudo) used to change behavior when posting
Definition: globals.c:65
#define mutt_error(...)
Definition: logging2.h:93
#define FREE(x)
Definition: memory.h:55
#define _(a)
Definition: message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:254
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:661
const char * mutt_str_sysexit(int err_num)
Return a string matching an error code.
Definition: string.c:170
int nntp_post(struct Mailbox *m, const char *msg)
Post article.
Definition: nntp.c:1946
#define MUTT_PAGER_NO_FLAGS
No flags are set.
Definition: lib.h:60
@ PAGER_MODE_OTHER
Pager is invoked via 3rd path. Non-email content is likely to be shown.
Definition: lib.h:140
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
#define TAILQ_FIRST(head)
Definition: queue.h:780
#define TAILQ_NEXT(elm, field)
Definition: queue.h:889
#define TAILQ_EMPTY(head)
Definition: queue.h:778
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: render.h:33
static void add_args_one(struct SendmailArgArray *args, const struct Address *addr)
Add an Address to a dynamic array.
Definition: sendmail.c:259
static void add_args(struct SendmailArgArray *args, struct AddressList *al)
Add a list of Addresses to a dynamic array.
Definition: sendmail.c:273
#define EX_OK
Definition: sendmail.c:57
static int send_msg(const char *path, struct SendmailArgArray *args, const char *msg, char **tempfile, int wait_time)
Invoke sendmail in a subshell.
Definition: sendmail.c:91
#define NONULL(x)
Definition: string2.h:37
#define S_BKG
Definition: string2.h:41
An email address.
Definition: address.h:36
String manipulation buffer.
Definition: buffer.h:36
size_t dsize
Length of data.
Definition: buffer.h:39
Parsed Expando trees.
Definition: expando.h:41
Container for Accounts, Notifications.
Definition: neomutt.h:43
char ** env
Private copy of the environment variables.
Definition: neomutt.h:55
Data to be displayed by PagerView.
Definition: lib.h:159
const char * fname
Name of the file to read.
Definition: lib.h:163
Paged view into some data.
Definition: lib.h:170
struct PagerData * pdata
Data that pager displays. NOTNULL.
Definition: lib.h:171
enum PagerMode mode
Pager mode.
Definition: lib.h:172
PagerFlags flags
Additional settings to tweak pager's function.
Definition: lib.h:173
const char * banner
Title to display in status bar.
Definition: lib.h:174
+ Here is the call graph for this function:
+ Here is the caller graph for this function: