NeoMutt  2023-05-17-33-gce4425
Teaching an old dog new tricks
DOXYGEN
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. More...
 

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, nntp_format_str()

Definition at line 298 of file sendmail.c.

302{
303 char *ps = NULL, *path = NULL, *s = NULL, *childout = NULL;
304 struct SendmailArgs args = ARRAY_HEAD_INITIALIZER;
305 struct SendmailArgs extra_args = ARRAY_HEAD_INITIALIZER;
306 int i;
307
308#ifdef USE_NNTP
309 if (OptNewsSend)
310 {
311 char cmd[1024] = { 0 };
312
313 const char *const c_inews = cs_subset_string(sub, "inews");
314 mutt_expando_format(cmd, sizeof(cmd), 0, sizeof(cmd), NONULL(c_inews),
316 if (*cmd == '\0')
317 {
318 i = nntp_post(m, msg);
319 unlink(msg);
320 return i;
321 }
322
323 s = mutt_str_dup(cmd);
324 }
325 else
326#endif
327 {
328 const char *const c_sendmail = cs_subset_string(sub, "sendmail");
329 s = mutt_str_dup(c_sendmail);
330 }
331
332 /* ensure that $sendmail is set to avoid a crash. http://dev.mutt.org/trac/ticket/3548 */
333 if (!s)
334 {
335 mutt_error(_("$sendmail must be set in order to send mail"));
336 return -1;
337 }
338
339 ps = s;
340 i = 0;
341 while ((ps = strtok(ps, " ")))
342 {
343 if (i)
344 {
345 if (mutt_str_equal(ps, "--"))
346 break;
347 ARRAY_ADD(&args, ps);
348 }
349 else
350 {
351 path = mutt_str_dup(ps);
352 ps = strrchr(ps, '/');
353 if (ps)
354 ps++;
355 else
356 ps = path;
357 ARRAY_ADD(&args, ps);
358 }
359 ps = NULL;
360 i++;
361 }
362
363#ifdef USE_NNTP
364 if (!OptNewsSend)
365 {
366#endif
367 /* If $sendmail contained a "--", we save the recipients to append to
368 * args after other possible options added below. */
369 if (ps)
370 {
371 ps = NULL;
372 while ((ps = strtok(ps, " ")))
373 {
374 ARRAY_ADD(&extra_args, ps);
375 ps = NULL;
376 }
377 }
378
379 const bool c_use_8bit_mime = cs_subset_bool(sub, "use_8bit_mime");
380 if (eightbit && c_use_8bit_mime)
381 ARRAY_ADD(&args, "-B8BITMIME");
382
383 const bool c_use_envelope_from = cs_subset_bool(sub, "use_envelope_from");
384 if (c_use_envelope_from)
385 {
386 const struct Address *c_envelope_from_address = cs_subset_address(sub, "envelope_from_address");
387 if (c_envelope_from_address)
388 {
389 ARRAY_ADD(&args, "-f");
390 add_args_one(&args, c_envelope_from_address);
391 }
392 else if (!TAILQ_EMPTY(from) && !TAILQ_NEXT(TAILQ_FIRST(from), entries))
393 {
394 ARRAY_ADD(&args, "-f");
395 add_args(&args, from);
396 }
397 }
398
399 const char *const c_dsn_notify = cs_subset_string(sub, "dsn_notify");
400 if (c_dsn_notify)
401 {
402 ARRAY_ADD(&args, "-N");
403 ARRAY_ADD(&args, c_dsn_notify);
404 }
405
406 const char *const c_dsn_return = cs_subset_string(sub, "dsn_return");
407 if (c_dsn_return)
408 {
409 ARRAY_ADD(&args, "-R");
410 ARRAY_ADD(&args, c_dsn_return);
411 }
412 ARRAY_ADD(&args, "--");
413 const char **e = NULL;
414 ARRAY_FOREACH(e, &extra_args)
415 {
416 ARRAY_ADD(&args, *e);
417 }
418 add_args(&args, to);
419 add_args(&args, cc);
420 add_args(&args, bcc);
421#ifdef USE_NNTP
422 }
423#endif
424
425 ARRAY_ADD(&args, NULL);
426
427 const short c_sendmail_wait = cs_subset_number(sub, "sendmail_wait");
428 i = send_msg(path, &args, msg, OptNoCurses ? NULL : &childout, c_sendmail_wait);
429
430 /* Some user's $sendmail command uses gpg for password decryption,
431 * and is set up to prompt using ncurses pinentry. If we
432 * mutt_endwin() it leaves other users staring at a blank screen.
433 * So instead, just force a hard redraw on the next refresh. */
434 if (!OptNoCurses)
435 {
437 }
438
439 if (i != (EX_OK & 0xff))
440 {
441 if (i != S_BKG)
442 {
443 const char *e = mutt_str_sysexit(i);
444 mutt_error(_("Error sending message, child exited %d (%s)"), i, NONULL(e));
445 if (childout)
446 {
447 struct stat st = { 0 };
448
449 if ((stat(childout, &st) == 0) && (st.st_size > 0))
450 {
451 struct PagerData pdata = { 0 };
452 struct PagerView pview = { &pdata };
453
454 pdata.fname = childout;
455
456 pview.banner = _("Output of the delivery process");
458 pview.mode = PAGER_MODE_OTHER;
459
460 mutt_do_pager(&pview, NULL);
461 }
462 }
463 }
464 }
465 else if (childout)
466 {
467 unlink(childout);
468 }
469
470 FREE(&childout);
471 FREE(&path);
472 FREE(&s);
473 ARRAY_FREE(&args);
474 ARRAY_FREE(&extra_args);
475
476 if (i == (EX_OK & 0xff))
477 i = 0;
478 else if (i == S_BKG)
479 i = 1;
480 else
481 i = -1;
482 return i;
483}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:155
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:211
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:203
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:57
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address config item by name.
Definition: helpers.c:49
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
void mutt_need_hard_redraw(void)
Force a hard refresh.
Definition: curs_lib.c:163
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:123
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:82
bool OptNewsSend
(pseudo) used to change behavior when posting
Definition: globals.c:80
const char * nntp_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)
Expand the newsrc filename - Implements format_t -.
Definition: newsrc.c:927
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string -.
Definition: muttlib.c:742
#define mutt_error(...)
Definition: logging2.h:87
#define FREE(x)
Definition: memory.h:43
#define _(a)
Definition: message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:798
const char * mutt_str_sysexit(int err_num)
Return a string matching an error code.
Definition: string.c:167
int nntp_post(struct Mailbox *m, const char *msg)
Post article.
Definition: nntp.c:1912
#define MUTT_PAGER_NO_FLAGS
No flags are set.
Definition: lib.h:59
@ PAGER_MODE_OTHER
Pager is invoked via 3rd path. Non-email content is likely to be shown.
Definition: lib.h:140
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define TAILQ_NEXT(elm, field)
Definition: queue.h:832
#define TAILQ_EMPTY(head)
Definition: queue.h:721
static void add_args_one(struct SendmailArgs *args, const struct Address *addr)
Add an Address to a dynamic array.
Definition: sendmail.c:257
static int send_msg(const char *path, struct SendmailArgs *args, const char *msg, char **tempfile, int wait_time)
Invoke sendmail in a subshell.
Definition: sendmail.c:92
static void add_args(struct SendmailArgs *args, struct AddressList *al)
Add a list of Addresses to a dynamic array.
Definition: sendmail.c:271
#define EX_OK
Definition: sendmail.c:56
#define NONULL(x)
Definition: string2.h:37
#define S_BKG
Definition: string2.h:41
An email address.
Definition: address.h:36
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: