NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
DOXYGEN
sendmail.h File Reference
#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

Definition at line 287 of file sendmail.c.

291 {
292  char *ps = NULL, *path = NULL, *s = NULL, *childout = NULL;
293  struct SendmailArgs args = ARRAY_HEAD_INITIALIZER;
294  struct SendmailArgs extra_args = ARRAY_HEAD_INITIALIZER;
295  int i;
296 
297 #ifdef USE_NNTP
298  if (OptNewsSend)
299  {
300  char cmd[1024];
301 
302  const char *c_inews = cs_subset_string(sub, "inews");
303  mutt_expando_format(cmd, sizeof(cmd), 0, sizeof(cmd), NONULL(c_inews),
305  if (*cmd == '\0')
306  {
307  i = nntp_post(m, msg);
308  unlink(msg);
309  return i;
310  }
311 
312  s = mutt_str_dup(cmd);
313  }
314  else
315 #endif
316  {
317  const char *c_sendmail = cs_subset_string(sub, "sendmail");
318  s = mutt_str_dup(c_sendmail);
319  }
320 
321  /* ensure that $sendmail is set to avoid a crash. http://dev.mutt.org/trac/ticket/3548 */
322  if (!s)
323  {
324  mutt_error(_("$sendmail must be set in order to send mail"));
325  return -1;
326  }
327 
328  ps = s;
329  i = 0;
330  while ((ps = strtok(ps, " ")))
331  {
332  if (i)
333  {
334  if (mutt_str_equal(ps, "--"))
335  break;
336  ARRAY_ADD(&args, ps);
337  }
338  else
339  {
340  path = mutt_str_dup(ps);
341  ps = strrchr(ps, '/');
342  if (ps)
343  ps++;
344  else
345  ps = path;
346  ARRAY_ADD(&args, ps);
347  }
348  ps = NULL;
349  i++;
350  }
351 
352 #ifdef USE_NNTP
353  if (!OptNewsSend)
354  {
355 #endif
356  /* If $sendmail contained a "--", we save the recipients to append to
357  * args after other possible options added below. */
358  if (ps)
359  {
360  ps = NULL;
361  while ((ps = strtok(ps, " ")))
362  {
363  ARRAY_ADD(&extra_args, ps);
364  }
365  }
366 
367  const bool c_use_8bit_mime = cs_subset_bool(sub, "use_8bit_mime");
368  if (eightbit && c_use_8bit_mime)
369  ARRAY_ADD(&args, "-B8BITMIME");
370 
371  const bool c_use_envelope_from = cs_subset_bool(sub, "use_envelope_from");
372  if (c_use_envelope_from)
373  {
374  const struct Address *c_envelope_from_address =
375  cs_subset_address(sub, "envelope_from_address");
376  if (c_envelope_from_address)
377  {
378  ARRAY_ADD(&args, "-f");
379  add_args_one(&args, c_envelope_from_address);
380  }
381  else if (!TAILQ_EMPTY(from) && !TAILQ_NEXT(TAILQ_FIRST(from), entries))
382  {
383  ARRAY_ADD(&args, "-f");
384  add_args(&args, from);
385  }
386  }
387 
388  const char *c_dsn_notify = cs_subset_string(sub, "dsn_notify");
389  if (c_dsn_notify)
390  {
391  ARRAY_ADD(&args, "-N");
392  ARRAY_ADD(&args, c_dsn_notify);
393  }
394 
395  const char *c_dsn_return = cs_subset_string(sub, "dsn_return");
396  if (c_dsn_return)
397  {
398  ARRAY_ADD(&args, "-R");
399  ARRAY_ADD(&args, c_dsn_return);
400  }
401  ARRAY_ADD(&args, "--");
402  const char **e = NULL;
403  ARRAY_FOREACH(e, &extra_args)
404  {
405  ARRAY_ADD(&args, *e);
406  }
407  add_args(&args, to);
408  add_args(&args, cc);
409  add_args(&args, bcc);
410 #ifdef USE_NNTP
411  }
412 #endif
413 
414  ARRAY_ADD(&args, NULL);
415 
416  /* Some user's $sendmail command uses gpg for password decryption,
417  * and is set up to prompt using ncurses pinentry. If we
418  * mutt_endwin() it leaves other users staring at a blank screen.
419  * So instead, just force a hard redraw on the next refresh. */
420  if (!OptNoCurses)
422 
423  const short c_sendmail_wait = cs_subset_number(sub, "sendmail_wait");
424  i = send_msg(path, &args, msg, OptNoCurses ? NULL : &childout, c_sendmail_wait);
425  if (i != (EX_OK & 0xff))
426  {
427  if (i != S_BKG)
428  {
429  const char *e = mutt_str_sysexit(i);
430  mutt_error(_("Error sending message, child exited %d (%s)"), i, NONULL(e));
431  if (childout)
432  {
433  struct stat st;
434 
435  if ((stat(childout, &st) == 0) && (st.st_size > 0))
436  {
437  mutt_do_pager(_("Output of the delivery process"), childout,
438  MUTT_PAGER_NO_FLAGS, NULL);
439  }
440  }
441  }
442  }
443  else if (childout)
444  unlink(childout);
445 
446  FREE(&childout);
447  FREE(&path);
448  FREE(&s);
449  ARRAY_FREE(&args);
450  ARRAY_FREE(&extra_args);
451 
452  if (i == (EX_OK & 0xff))
453  i = 0;
454  else if (i == S_BKG)
455  i = 1;
456  else
457  i = -1;
458  return i;
459 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:
S_BKG
#define S_BKG
Definition: string2.h:42
_
#define _(a)
Definition: message.h:28
NONULL
#define NONULL(x)
Definition: string2.h:37
ARRAY_ADD
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:152
cs_subset_bool
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:69
TAILQ_EMPTY
#define TAILQ_EMPTY(head)
Definition: queue.h:714
mutt_str_dup
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
FREE
#define FREE(x)
Definition: memory.h:40
send_msg
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:85
OptNoCurses
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:48
MUTT_FORMAT_NO_FLAGS
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
mutt_str_equal
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
TAILQ_FIRST
#define TAILQ_FIRST(head)
Definition: queue.h:716
cs_subset_address
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address config item by name.
Definition: helpers.c:48
mutt_need_hard_redraw
void mutt_need_hard_redraw(void)
Force a hard refresh.
Definition: curs_lib.c:130
ARRAY_FOREACH
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
cs_subset_number
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:111
mutt_do_pager
int mutt_do_pager(const char *banner, const char *tempfile, PagerFlags do_color, struct Pager *info)
Display some page-able text to the user.
Definition: curs_lib.c:691
ARRAY_HEAD_INITIALIZER
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:54
MUTT_PAGER_NO_FLAGS
#define MUTT_PAGER_NO_FLAGS
No flags are set.
Definition: lib.h:42
ARRAY_FREE
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:198
EX_OK
#define EX_OK
Definition: sendmail.c:56
cs_subset_string
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:241
TAILQ_NEXT
#define TAILQ_NEXT(elm, field)
Definition: queue.h:825
mutt_expando_format
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:774
nntp_post
int nntp_post(struct Mailbox *m, const char *msg)
Post article.
Definition: nntp.c:1866
add_args
static void add_args(struct SendmailArgs *args, struct AddressList *al)
Add a list of Addresses to a dynamic array.
Definition: sendmail.c:262
mutt_str_sysexit
const char * mutt_str_sysexit(int err_num)
Return a string matching an error code.
Definition: string.c:112
OptNewsSend
WHERE bool OptNewsSend
(pseudo) used to change behavior when posting
Definition: options.h:46
nntp_format_str
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:920
add_args_one
static void add_args_one(struct SendmailArgs *args, const struct Address *addr)
Add an Address to a dynamic array.
Definition: sendmail.c:248
Address
An email address.
Definition: address.h:34
mutt_error
#define mutt_error(...)
Definition: logging.h:84