NeoMutt  2020-08-07-1-gab41a1
Teaching an old dog new tricks
DOXYGEN
send.c
Go to the documentation of this file.
1 
30 #include "config.h"
31 #include <errno.h>
32 #include <locale.h>
33 #include <stdbool.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <sys/stat.h>
37 #include <time.h>
38 #include <unistd.h>
39 #include "mutt/lib.h"
40 #include "address/lib.h"
41 #include "config/lib.h"
42 #include "email/lib.h"
43 #include "core/lib.h"
44 #include "alias/lib.h"
45 #include "gui/lib.h"
46 #include "mutt.h"
47 #include "send.h"
48 #include "lib.h"
49 #include "ncrypt/lib.h"
50 #include "pattern/lib.h"
51 #include "compose.h"
52 #include "context.h"
53 #include "copy.h"
54 #include "handler.h"
55 #include "hdrline.h"
56 #include "hook.h"
57 #include "maillist.h"
58 #include "mutt_attach.h"
59 #include "mutt_body.h"
60 #include "mutt_globals.h"
61 #include "mutt_header.h"
62 #include "mutt_logging.h"
63 #include "mutt_parse.h"
64 #include "muttlib.h"
65 #include "options.h"
66 #include "protos.h"
67 #include "recvattach.h"
68 #include "rfc3676.h"
69 #include "sort.h"
70 #ifdef USE_NNTP
71 #include "nntp/lib.h"
72 #include "mx.h"
73 #endif
74 #ifdef MIXMASTER
75 #include "remailer.h"
76 #endif
77 #ifdef USE_NOTMUCH
78 #include "notmuch/lib.h"
79 #endif
80 #ifdef USE_IMAP
81 #include "imap/lib.h"
82 #endif
83 #ifdef USE_AUTOCRYPT
84 #include "autocrypt/lib.h"
85 #endif
86 
92 static void append_signature(FILE *fp, struct ConfigSubset *sub)
93 {
94  FILE *fp_tmp = NULL;
95  pid_t pid;
96 
97  const char *c_signature = cs_subset_path(sub, "signature");
98  if (c_signature && (fp_tmp = mutt_open_read(c_signature, &pid)))
99  {
100  const bool c_sig_dashes = cs_subset_bool(sub, "sig_dashes");
101  if (c_sig_dashes)
102  fputs("\n-- \n", fp);
103  mutt_file_copy_stream(fp_tmp, fp);
104  mutt_file_fclose(&fp_tmp);
105  if (pid != -1)
106  filter_wait(pid);
107  }
108 }
109 
116 static void remove_user(struct AddressList *al, bool leave_only)
117 {
118  struct Address *a = NULL, *tmp = NULL;
119  TAILQ_FOREACH_SAFE(a, al, entries, tmp)
120  {
121  if (mutt_addr_is_user(a) && (!leave_only || TAILQ_NEXT(a, entries)))
122  {
123  TAILQ_REMOVE(al, a, entries);
124  mutt_addr_free(&a);
125  }
126  }
127 }
128 
135 static void add_mailing_lists(struct AddressList *out, const struct AddressList *t,
136  const struct AddressList *c)
137 {
138  const struct AddressList *const als[] = { t, c };
139 
140  for (size_t i = 0; i < mutt_array_size(als); ++i)
141  {
142  const struct AddressList *al = als[i];
143  struct Address *a = NULL;
144  TAILQ_FOREACH(a, al, entries)
145  {
146  if (!a->group && mutt_is_mail_list(a))
147  {
149  }
150  }
151  }
152 }
153 
162 int mutt_edit_address(struct AddressList *al, const char *field, bool expand_aliases)
163 {
164  char buf[8192];
165  char *err = NULL;
166  int idna_ok = 0;
167 
168  do
169  {
170  buf[0] = '\0';
172  mutt_addrlist_write(al, buf, sizeof(buf), false);
173  if (mutt_get_field(field, buf, sizeof(buf), MUTT_ALIAS) != 0)
174  return -1;
176  mutt_addrlist_parse2(al, buf);
177  if (expand_aliases)
179  idna_ok = mutt_addrlist_to_intl(al, &err);
180  if (idna_ok != 0)
181  {
182  mutt_error(_("Bad IDN: '%s'"), err);
183  FREE(&err);
184  }
185  } while (idna_ok != 0);
186  return 0;
187 }
188 
197 static int edit_envelope(struct Envelope *en, SendFlags flags, struct ConfigSubset *sub)
198 {
199  char buf[8192];
200 
201 #ifdef USE_NNTP
202  if (OptNewsSend)
203  {
204  if (en->newsgroups)
205  mutt_str_copy(buf, en->newsgroups, sizeof(buf));
206  else
207  buf[0] = '\0';
208  if (mutt_get_field("Newsgroups: ", buf, sizeof(buf), MUTT_COMP_NO_FLAGS) != 0)
209  return -1;
210  FREE(&en->newsgroups);
211  en->newsgroups = mutt_str_dup(buf);
212 
213  if (en->followup_to)
214  mutt_str_copy(buf, en->followup_to, sizeof(buf));
215  else
216  buf[0] = '\0';
217 
218  const bool c_ask_follow_up = cs_subset_bool(sub, "ask_follow_up");
219  if (c_ask_follow_up &&
220  (mutt_get_field("Followup-To: ", buf, sizeof(buf), MUTT_COMP_NO_FLAGS) != 0))
221  {
222  return -1;
223  }
224  FREE(&en->followup_to);
225  en->followup_to = mutt_str_dup(buf);
226 
227  if (en->x_comment_to)
228  mutt_str_copy(buf, en->x_comment_to, sizeof(buf));
229  else
230  buf[0] = '\0';
231 
232  const bool c_x_comment_to = cs_subset_bool(sub, "x_comment_to");
233  const bool c_ask_x_comment_to = cs_subset_bool(sub, "ask_x_comment_to");
234  if (c_x_comment_to && c_ask_x_comment_to &&
235  (mutt_get_field("X-Comment-To: ", buf, sizeof(buf), MUTT_COMP_NO_FLAGS) != 0))
236  {
237  return -1;
238  }
239  FREE(&en->x_comment_to);
240  en->x_comment_to = mutt_str_dup(buf);
241  }
242  else
243 #endif
244  {
245  if ((mutt_edit_address(&en->to, _("To: "), true) == -1) || TAILQ_EMPTY(&en->to))
246  return -1;
247 
248  const bool c_askcc = cs_subset_bool(sub, "askcc");
249  if (c_askcc && (mutt_edit_address(&en->cc, _("Cc: "), true) == -1))
250  return -1;
251 
252  const bool c_askbcc = cs_subset_bool(sub, "askbcc");
253  if (c_askbcc && (mutt_edit_address(&en->bcc, _("Bcc: "), true) == -1))
254  return -1;
255 
256  const bool c_reply_with_xorig = cs_subset_bool(sub, "reply_with_xorig");
257  if (c_reply_with_xorig && (flags & (SEND_REPLY | SEND_LIST_REPLY | SEND_GROUP_REPLY)) &&
258  (mutt_edit_address(&en->from, "From: ", true) == -1))
259  {
260  return -1;
261  }
262  }
263 
264  if (en->subject)
265  {
266  const bool c_fast_reply = cs_subset_bool(sub, "fast_reply");
267  if (c_fast_reply)
268  return 0;
269  mutt_str_copy(buf, en->subject, sizeof(buf));
270  }
271  else
272  {
273  const char *p = NULL;
274 
275  buf[0] = '\0';
276  struct ListNode *uh = NULL;
277  STAILQ_FOREACH(uh, &UserHeader, entries)
278  {
279  size_t plen = mutt_istr_startswith(uh->data, "subject:");
280  if (plen)
281  {
282  p = mutt_str_skip_email_wsp(uh->data + plen);
283  mutt_str_copy(buf, p, sizeof(buf));
284  }
285  }
286  }
287 
288  const enum QuadOption c_abort_nosubject =
289  cs_subset_quad(sub, "abort_nosubject");
290  if ((mutt_get_field(_("Subject: "), buf, sizeof(buf), MUTT_COMP_NO_FLAGS) != 0) ||
291  ((buf[0] == '\0') &&
292  (query_quadoption(c_abort_nosubject, _("No subject, abort?")) != MUTT_NO)))
293  {
294  mutt_message(_("No subject, aborting"));
295  return -1;
296  }
297  mutt_str_replace(&en->subject, buf);
298 
299  return 0;
300 }
301 
302 #ifdef USE_NNTP
303 
310 static char *nntp_get_header(const char *s)
311 {
312  SKIPWS(s);
313  return mutt_str_dup(s);
314 }
315 #endif
316 
321 static void process_user_recips(struct Envelope *env)
322 {
323  struct ListNode *uh = NULL;
324  STAILQ_FOREACH(uh, &UserHeader, entries)
325  {
326  size_t plen;
327  if ((plen = mutt_istr_startswith(uh->data, "to:")))
328  mutt_addrlist_parse(&env->to, uh->data + plen);
329  else if ((plen = mutt_istr_startswith(uh->data, "cc:")))
330  mutt_addrlist_parse(&env->cc, uh->data + plen);
331  else if ((plen = mutt_istr_startswith(uh->data, "bcc:")))
332  mutt_addrlist_parse(&env->bcc, uh->data + plen);
333 #ifdef USE_NNTP
334  else if ((plen = mutt_istr_startswith(uh->data, "newsgroups:")))
335  env->newsgroups = nntp_get_header(uh->data + plen);
336  else if ((plen = mutt_istr_startswith(uh->data, "followup-to:")))
337  env->followup_to = nntp_get_header(uh->data + plen);
338  else if ((plen = mutt_istr_startswith(uh->data, "x-comment-to:")))
339  env->x_comment_to = nntp_get_header(uh->data + plen);
340 #endif
341  }
342 }
343 
348 static void process_user_header(struct Envelope *env)
349 {
350  struct ListNode *uh = NULL;
351  STAILQ_FOREACH(uh, &UserHeader, entries)
352  {
353  size_t plen;
354  if ((plen = mutt_istr_startswith(uh->data, "from:")))
355  {
356  /* User has specified a default From: address. Remove default address */
357  mutt_addrlist_clear(&env->from);
358  mutt_addrlist_parse(&env->from, uh->data + plen);
359  }
360  else if ((plen = mutt_istr_startswith(uh->data, "reply-to:")))
361  {
363  mutt_addrlist_parse(&env->reply_to, uh->data + plen);
364  }
365  else if ((plen = mutt_istr_startswith(uh->data, "message-id:")))
366  {
367  char *tmp = mutt_extract_message_id(uh->data + plen, NULL);
368  if (mutt_addr_valid_msgid(tmp))
369  {
370  FREE(&env->message_id);
371  env->message_id = tmp;
372  }
373  else
374  FREE(&tmp);
375  }
376  else if (!mutt_istr_startswith(uh->data, "to:") &&
377  !mutt_istr_startswith(uh->data, "cc:") &&
378  !mutt_istr_startswith(uh->data, "bcc:") &&
379 #ifdef USE_NNTP
380  !mutt_istr_startswith(uh->data, "newsgroups:") &&
381  !mutt_istr_startswith(uh->data, "followup-to:") &&
382  !mutt_istr_startswith(uh->data, "x-comment-to:") &&
383 #endif
384  !mutt_istr_startswith(uh->data, "supersedes:") &&
385  !mutt_istr_startswith(uh->data, "subject:") &&
386  !mutt_istr_startswith(uh->data, "return-path:"))
387  {
389  }
390  }
391 }
392 
400 void mutt_forward_intro(struct Mailbox *m, struct Email *e, FILE *fp, struct ConfigSubset *sub)
401 {
402  const char *c_forward_attribution_intro =
403  cs_subset_string(sub, "forward_attribution_intro");
404  if (!c_forward_attribution_intro || !fp)
405  return;
406 
407  const char *c_attribution_locale =
408  cs_subset_string(sub, "attribution_locale");
409 
410  char buf[1024];
411  setlocale(LC_TIME, NONULL(c_attribution_locale));
412  mutt_make_string(buf, sizeof(buf), 0, c_forward_attribution_intro, m, -1, e);
413  setlocale(LC_TIME, "");
414  fputs(buf, fp);
415  fputs("\n\n", fp);
416 }
417 
425 void mutt_forward_trailer(struct Mailbox *m, struct Email *e, FILE *fp,
426  struct ConfigSubset *sub)
427 {
428  const char *c_forward_attribution_trailer =
429  cs_subset_string(sub, "forward_attribution_trailer");
430  if (!c_forward_attribution_trailer || !fp)
431  return;
432 
433  const char *c_attribution_locale =
434  cs_subset_string(sub, "attribution_locale");
435 
436  char buf[1024];
437  setlocale(LC_TIME, NONULL(c_attribution_locale));
438  mutt_make_string(buf, sizeof(buf), 0, c_forward_attribution_trailer, m, -1, e);
439  setlocale(LC_TIME, "");
440  fputc('\n', fp);
441  fputs(buf, fp);
442  fputc('\n', fp);
443 }
444 
454 static int include_forward(struct Mailbox *m, struct Email *e, FILE *fp_out,
455  struct ConfigSubset *sub)
456 {
457  CopyHeaderFlags chflags = CH_DECODE;
459 
462 
463  const bool c_forward_decode = cs_subset_bool(sub, "forward_decode");
464  if ((WithCrypto != 0) && (e->security & SEC_ENCRYPT) && c_forward_decode)
465  {
466  /* make sure we have the user's passphrase before proceeding... */
468  return -1;
469  }
470 
471  mutt_forward_intro(m, e, fp_out, sub);
472 
473  if (c_forward_decode)
474  {
475  cmflags |= MUTT_CM_DECODE | MUTT_CM_CHARCONV;
476 
477  const bool c_weed = cs_subset_bool(sub, "weed");
478  if (c_weed)
479  {
480  chflags |= CH_WEED | CH_REORDER;
481  cmflags |= MUTT_CM_WEED;
482  }
483  }
484 
485  const bool c_forward_quote = cs_subset_bool(sub, "forward_quote");
486  if (c_forward_quote)
487  cmflags |= MUTT_CM_PREFIX;
488 
489  mutt_copy_message(fp_out, m, e, cmflags, chflags, 0);
490  mutt_forward_trailer(m, e, fp_out, sub);
491  return 0;
492 }
493 
504 static int inline_forward_attachments(struct Mailbox *m, struct Email *e,
505  struct Body ***plast, enum QuadOption *forwardq,
506  struct ConfigSubset *sub)
507 {
508  struct Body **last = *plast;
509  struct Body *body = NULL;
510  struct Message *msg = NULL;
511  struct AttachCtx *actx = NULL;
512  int rc = 0, i;
513 
516 
517  msg = mx_msg_open(m, e->msgno);
518  if (!msg)
519  return -1;
520 
521  actx = mutt_mem_calloc(1, sizeof(*actx));
522  actx->email = e;
523  actx->fp_root = msg->fp;
524 
525  mutt_generate_recvattach_list(actx, actx->email, actx->email->body,
526  actx->fp_root, -1, 0, 0);
527 
528  for (i = 0; i < actx->idxlen; i++)
529  {
530  body = actx->idx[i]->body;
531  if ((body->type != TYPE_MULTIPART) && !mutt_can_decode(body) &&
532  !((body->type == TYPE_APPLICATION) &&
533  (mutt_istr_equal(body->subtype, "pgp-signature") ||
534  mutt_istr_equal(body->subtype, "x-pkcs7-signature") ||
535  mutt_istr_equal(body->subtype, "pkcs7-signature"))))
536  {
537  /* Ask the quadoption only once */
538  if (*forwardq == MUTT_ABORT)
539  {
540  const enum QuadOption c_forward_attachments =
541  cs_subset_quad(sub, "forward_attachments");
542  *forwardq = query_quadoption(c_forward_attachments,
543  /* L10N: This is the prompt for $forward_attachments.
544  When inline forwarding ($mime_forward answered "no"), this prompts
545  whether to add non-decodable attachments from the original email.
546  Text/plain parts and the like will already be included in the
547  message contents, but other attachment, such as PDF files, will also
548  be added as attachments to the new mail, if this is answered yes. */
549  _("Forward attachments?"));
550  if (*forwardq != MUTT_YES)
551  {
552  if (*forwardq == -1)
553  rc = -1;
554  goto cleanup;
555  }
556  }
557  if (mutt_body_copy(actx->idx[i]->fp, last, body) == -1)
558  {
559  rc = -1;
560  goto cleanup;
561  }
562  last = &((*last)->next);
563  }
564  }
565 
566 cleanup:
567  *plast = last;
568  mx_msg_close(m, &msg);
569  mutt_actx_free(&actx);
570  return rc;
571 }
572 
580 void mutt_make_attribution(struct Mailbox *m, struct Email *e, FILE *fp_out,
581  struct ConfigSubset *sub)
582 {
583  const char *c_attribution = cs_subset_string(sub, "attribution");
584  if (!c_attribution || !fp_out)
585  return;
586 
587  const char *c_attribution_locale =
588  cs_subset_string(sub, "attribution_locale");
589 
590  char buf[1024];
591  setlocale(LC_TIME, NONULL(c_attribution_locale));
592  mutt_make_string(buf, sizeof(buf), 0, c_attribution, m, -1, e);
593  setlocale(LC_TIME, "");
594  fputs(buf, fp_out);
595  fputc('\n', fp_out);
596 }
597 
605 void mutt_make_post_indent(struct Mailbox *m, struct Email *e, FILE *fp_out,
606  struct ConfigSubset *sub)
607 {
608  const char *c_post_indent_string =
609  cs_subset_string(sub, "post_indent_string");
610  if (!c_post_indent_string || !fp_out)
611  return;
612 
613  char buf[256];
614  mutt_make_string(buf, sizeof(buf), 0, c_post_indent_string, m, -1, e);
615  fputs(buf, fp_out);
616  fputc('\n', fp_out);
617 }
618 
628 static int include_reply(struct Mailbox *m, struct Email *e, FILE *fp_out,
629  struct ConfigSubset *sub)
630 {
631  CopyMessageFlags cmflags =
633  CopyHeaderFlags chflags = CH_DECODE;
634 
635  if ((WithCrypto != 0) && (e->security & SEC_ENCRYPT))
636  {
637  /* make sure we have the user's passphrase before proceeding... */
639  return -1;
640  }
641 
644 
645  mutt_make_attribution(m, e, fp_out, sub);
646 
647  const bool c_header = cs_subset_bool(sub, "header");
648  if (!c_header)
649  cmflags |= MUTT_CM_NOHEADER;
650 
651  const bool c_weed = cs_subset_bool(sub, "weed");
652  if (c_weed)
653  {
654  chflags |= CH_WEED | CH_REORDER;
655  cmflags |= MUTT_CM_WEED;
656  }
657 
658  mutt_copy_message(fp_out, m, e, cmflags, chflags, 0);
659 
660  mutt_make_post_indent(m, e, fp_out, sub);
661 
662  return 0;
663 }
664 
672 static const struct AddressList *choose_default_to(const struct Address *from,
673  const struct Envelope *env,
674  struct ConfigSubset *sub)
675 {
676  const bool c_reply_self = cs_subset_bool(sub, "reply_self");
677  if (!c_reply_self && mutt_addr_is_user(from))
678  {
679  /* mail is from the user, assume replying to recipients */
680  return &env->to;
681  }
682  else
683  {
684  return &env->from;
685  }
686 }
687 
698 static int default_to(struct AddressList *to, struct Envelope *env,
699  SendFlags flags, int hmfupto, struct ConfigSubset *sub)
700 {
701  const struct Address *from = TAILQ_FIRST(&env->from);
702  const struct Address *reply_to = TAILQ_FIRST(&env->reply_to);
703 
704  if (flags && !TAILQ_EMPTY(&env->mail_followup_to) && (hmfupto == MUTT_YES))
705  {
706  mutt_addrlist_copy(to, &env->mail_followup_to, true);
707  return 0;
708  }
709 
710  /* Exit now if we're setting up the default Cc list for list-reply
711  * (only set if Mail-Followup-To is present and honoured). */
712  if (flags & SEND_LIST_REPLY)
713  return 0;
714 
715  const struct AddressList *default_to = choose_default_to(from, env, sub);
716 
717  if (reply_to)
718  {
719  const bool from_is_reply_to = mutt_addr_cmp(from, reply_to);
720  const bool multiple_reply_to =
721  reply_to && TAILQ_NEXT(TAILQ_FIRST(&env->reply_to), entries);
722 
723  const bool c_ignore_list_reply_to =
724  cs_subset_bool(sub, "ignore_list_reply_to");
725  const enum QuadOption c_reply_to = cs_subset_quad(sub, "reply_to");
726  if ((from_is_reply_to && !multiple_reply_to && !reply_to->personal) ||
727  (c_ignore_list_reply_to && mutt_is_mail_list(reply_to) &&
728  (mutt_addrlist_search(&env->to, reply_to) || mutt_addrlist_search(&env->cc, reply_to))))
729  {
730  /* If the Reply-To: address is a mailing list, assume that it was
731  * put there by the mailing list, and use the From: address
732  *
733  * We also take the from header if our correspondent has a reply-to
734  * header which is identical to the electronic mail address given
735  * in his From header, and the reply-to has no display-name. */
736  mutt_addrlist_copy(to, &env->from, false);
737  }
738  else if (!(from_is_reply_to && !multiple_reply_to) && (c_reply_to != MUTT_YES))
739  {
740  char prompt[256];
741  /* There are quite a few mailing lists which set the Reply-To:
742  * header field to the list address, which makes it quite impossible
743  * to send a message to only the sender of the message. This
744  * provides a way to do that. */
745  /* L10N: Asks whether the user respects the reply-to header.
746  If she says no, neomutt will reply to the from header's address instead. */
747  snprintf(prompt, sizeof(prompt), _("Reply to %s%s?"), reply_to->mailbox,
748  multiple_reply_to ? ",..." : "");
749  switch (query_quadoption(c_reply_to, prompt))
750  {
751  case MUTT_YES:
752  mutt_addrlist_copy(to, &env->reply_to, false);
753  break;
754 
755  case MUTT_NO:
756  mutt_addrlist_copy(to, default_to, false);
757  break;
758 
759  default:
760  return -1; /* abort */
761  }
762  }
763  else
764  {
765  mutt_addrlist_copy(to, &env->reply_to, false);
766  }
767  }
768  else
769  {
770  mutt_addrlist_copy(to, default_to, false);
771  }
772 
773  return 0;
774 }
775 
785 int mutt_fetch_recips(struct Envelope *out, struct Envelope *in,
786  SendFlags flags, struct ConfigSubset *sub)
787 {
788  enum QuadOption hmfupto = MUTT_ABORT;
789  const struct Address *followup_to = TAILQ_FIRST(&in->mail_followup_to);
790 
791  if ((flags & (SEND_LIST_REPLY | SEND_GROUP_REPLY | SEND_GROUP_CHAT_REPLY)) && followup_to)
792  {
793  char prompt[256];
794  snprintf(prompt, sizeof(prompt), _("Follow-up to %s%s?"), followup_to->mailbox,
795  TAILQ_NEXT(TAILQ_FIRST(&in->mail_followup_to), entries) ? ",..." : "");
796 
797  const enum QuadOption c_honor_followup_to =
798  cs_subset_quad(sub, "honor_followup_to");
799  hmfupto = query_quadoption(c_honor_followup_to, prompt);
800  if (hmfupto == MUTT_ABORT)
801  return -1;
802  }
803 
804  if (flags & SEND_LIST_REPLY)
805  {
806  add_mailing_lists(&out->to, &in->to, &in->cc);
807 
808  if (followup_to && (hmfupto == MUTT_YES) &&
809  (default_to(&out->cc, in, flags & SEND_LIST_REPLY, (hmfupto == MUTT_YES), sub) == MUTT_ABORT))
810  {
811  return -1; /* abort */
812  }
813  }
814  else if (flags & SEND_TO_SENDER)
815  {
816  mutt_addrlist_copy(&out->to, &in->from, false);
817  }
818  else
819  {
820  if (default_to(&out->to, in, flags & (SEND_GROUP_REPLY | SEND_GROUP_CHAT_REPLY),
821  (hmfupto == MUTT_YES), sub) == -1)
822  return -1; /* abort */
823 
824  if ((flags & (SEND_GROUP_REPLY | SEND_GROUP_CHAT_REPLY)) &&
825  (!followup_to || (hmfupto != MUTT_YES)))
826  {
827  /* if(!mutt_addr_is_user(in->to)) */
828  if (flags & SEND_GROUP_REPLY)
829  mutt_addrlist_copy(&out->cc, &in->to, true);
830  else
831  mutt_addrlist_copy(&out->to, &in->cc, true);
832  mutt_addrlist_copy(&out->cc, &in->cc, true);
833  }
834  }
835  return 0;
836 }
837 
843 static void add_references(struct ListHead *head, struct Envelope *env)
844 {
845  struct ListNode *np = NULL;
846 
847  struct ListHead *src = STAILQ_EMPTY(&env->references) ? &env->in_reply_to : &env->references;
848  STAILQ_FOREACH(np, src, entries)
849  {
851  }
852 }
853 
859 static void add_message_id(struct ListHead *head, struct Envelope *env)
860 {
861  if (env->message_id)
862  {
864  }
865 }
866 
872 void mutt_fix_reply_recipients(struct Envelope *env, struct ConfigSubset *sub)
873 {
874  const bool c_metoo = cs_subset_bool(sub, "metoo");
875  if (!c_metoo)
876  {
877  const bool c_reply_self = cs_subset_bool(sub, "reply_self");
878 
879  /* the order is important here. do the CC: first so that if the
880  * the user is the only recipient, it ends up on the TO: field */
881  remove_user(&env->cc, TAILQ_EMPTY(&env->to));
882  remove_user(&env->to, TAILQ_EMPTY(&env->cc) || c_reply_self);
883  }
884 
885  /* the CC field can get cluttered, especially with lists */
886  mutt_addrlist_dedupe(&env->to);
887  mutt_addrlist_dedupe(&env->cc);
888  mutt_addrlist_remove_xrefs(&env->to, &env->cc);
889 
890  if (!TAILQ_EMPTY(&env->cc) && TAILQ_EMPTY(&env->to))
891  {
892  TAILQ_SWAP(&env->to, &env->cc, Address, entries);
893  }
894 }
895 
903 void mutt_make_forward_subject(struct Envelope *env, struct Mailbox *m,
904  struct Email *e, struct ConfigSubset *sub)
905 {
906  if (!env)
907  return;
908 
909  const char *c_forward_format = cs_subset_string(sub, "forward_format");
910 
911  char buf[256];
912  /* set the default subject for the message. */
913  mutt_make_string(buf, sizeof(buf), 0, NONULL(c_forward_format), m, -1, e);
914  mutt_str_replace(&env->subject, buf);
915 }
916 
923 void mutt_make_misc_reply_headers(struct Envelope *env, struct Envelope *curenv,
924  struct ConfigSubset *sub)
925 {
926  if (!env || !curenv)
927  return;
928 
929  /* This takes precedence over a subject that might have
930  * been taken from a List-Post header. Is that correct? */
931  if (curenv->real_subj)
932  {
933  FREE(&env->subject);
934  env->subject = mutt_mem_malloc(mutt_str_len(curenv->real_subj) + 5);
935  sprintf(env->subject, "Re: %s", curenv->real_subj);
936  }
937  else if (!env->subject)
938  {
939  const char *c_empty_subject = cs_subset_string(sub, "empty_subject");
940  env->subject = mutt_str_dup(c_empty_subject);
941  }
942 }
943 
950 void mutt_add_to_reference_headers(struct Envelope *env, struct Envelope *curenv,
951  struct ConfigSubset *sub)
952 {
953  add_references(&env->references, curenv);
954  add_message_id(&env->references, curenv);
955  add_message_id(&env->in_reply_to, curenv);
956 
957 #ifdef USE_NNTP
958  const bool c_x_comment_to = cs_subset_bool(sub, "x_comment_to");
959  if (OptNewsSend && c_x_comment_to && !TAILQ_EMPTY(&curenv->from))
961 #endif
962 }
963 
970 static void make_reference_headers(struct EmailList *el, struct Envelope *env,
971  struct ConfigSubset *sub)
972 {
973  if (!el || !env || STAILQ_EMPTY(el))
974  return;
975 
976  struct EmailNode *en = STAILQ_FIRST(el);
977  bool single = !STAILQ_NEXT(en, entries);
978 
979  if (!single)
980  {
981  STAILQ_FOREACH(en, el, entries)
982  {
983  mutt_add_to_reference_headers(env, en->email->env, sub);
984  }
985  }
986  else
987  mutt_add_to_reference_headers(env, en->email->env, sub);
988 
989  /* if there's more than entry in In-Reply-To (i.e. message has multiple
990  * parents), don't generate a References: header as it's discouraged by
991  * RFC2822, sect. 3.6.4 */
992  if (!single && !STAILQ_EMPTY(&env->in_reply_to) &&
993  STAILQ_NEXT(STAILQ_FIRST(&env->in_reply_to), entries))
994  {
995  mutt_list_free(&env->references);
996  }
997 }
998 
1009 static int envelope_defaults(struct Envelope *env, struct Mailbox *m, struct EmailList *el,
1010  SendFlags flags, struct ConfigSubset *sub)
1011 {
1012  if (!el || STAILQ_EMPTY(el))
1013  return -1;
1014 
1015  struct EmailNode *en = STAILQ_FIRST(el);
1016  bool single = !STAILQ_NEXT(en, entries);
1017 
1018  struct Envelope *curenv = en->email->env;
1019  if (!curenv)
1020  return -1;
1021 
1022  if (flags & (SEND_REPLY | SEND_TO_SENDER))
1023  {
1024 #ifdef USE_NNTP
1025  if ((flags & SEND_NEWS))
1026  {
1027  /* in case followup set Newsgroups: with Followup-To: if it present */
1028  if (!env->newsgroups && !mutt_istr_equal(curenv->followup_to, "poster"))
1029  {
1030  env->newsgroups = mutt_str_dup(curenv->followup_to);
1031  }
1032  }
1033  else
1034 #endif
1035  if (!single)
1036  {
1037  STAILQ_FOREACH(en, el, entries)
1038  {
1039  if (mutt_fetch_recips(env, en->email->env, flags, sub) == -1)
1040  return -1;
1041  }
1042  }
1043  else if (mutt_fetch_recips(env, curenv, flags, sub) == -1)
1044  return -1;
1045 
1046  if ((flags & SEND_LIST_REPLY) && TAILQ_EMPTY(&env->to))
1047  {
1048  mutt_error(_("No mailing lists found"));
1049  return -1;
1050  }
1051 
1052  if (flags & SEND_REPLY)
1053  {
1054  mutt_make_misc_reply_headers(env, curenv, sub);
1055  make_reference_headers(el, env, sub);
1056  }
1057  }
1058  else if (flags & SEND_FORWARD)
1059  {
1060  mutt_make_forward_subject(env, m, en->email, sub);
1061 
1062  const bool c_forward_references = cs_subset_bool(sub, "forward_references");
1063  if (c_forward_references)
1064  make_reference_headers(el, env, sub);
1065  }
1066 
1067  return 0;
1068 }
1069 
1081 static int generate_body(FILE *fp_tmp, struct Email *e, SendFlags flags,
1082  struct Mailbox *m, struct EmailList *el, struct ConfigSubset *sub)
1083 {
1084  /* An EmailList is required for replying and forwarding */
1085  if (!el && (flags & (SEND_REPLY | SEND_FORWARD)))
1086  return -1;
1087 
1088  if (flags & SEND_REPLY)
1089  {
1090  const enum QuadOption c_include = cs_subset_quad(sub, "include");
1091  enum QuadOption ans =
1092  query_quadoption(c_include, _("Include message in reply?"));
1093  if (ans == MUTT_ABORT)
1094  return -1;
1095 
1096  if (ans == MUTT_YES)
1097  {
1098  mutt_message(_("Including quoted message..."));
1099  struct EmailNode *en = NULL;
1100  STAILQ_FOREACH(en, el, entries)
1101  {
1102  if (include_reply(m, en->email, fp_tmp, sub) == -1)
1103  {
1104  mutt_error(_("Could not include all requested messages"));
1105  return -1;
1106  }
1107  if (STAILQ_NEXT(en, entries) != NULL)
1108  {
1109  fputc('\n', fp_tmp);
1110  }
1111  }
1112  }
1113  }
1114  else if (flags & SEND_FORWARD)
1115  {
1116  const enum QuadOption c_mime_forward = cs_subset_quad(sub, "mime_forward");
1117  enum QuadOption ans =
1118  query_quadoption(c_mime_forward, _("Forward as attachment?"));
1119  if (ans == MUTT_YES)
1120  {
1121  struct Body *last = e->body;
1122 
1123  mutt_message(_("Preparing forwarded message..."));
1124 
1125  while (last && last->next)
1126  last = last->next;
1127 
1128  struct EmailNode *en = NULL;
1129  STAILQ_FOREACH(en, el, entries)
1130  {
1131  struct Body *tmp = mutt_make_message_attach(m, en->email, false, sub);
1132  if (last)
1133  {
1134  last->next = tmp;
1135  last = tmp;
1136  }
1137  else
1138  {
1139  last = tmp;
1140  e->body = tmp;
1141  }
1142  }
1143  }
1144  else if (ans != MUTT_ABORT)
1145  {
1146  enum QuadOption forwardq = MUTT_ABORT;
1147  struct Body **last = NULL;
1148  struct EmailNode *en = NULL;
1149 
1150  const bool c_forward_decode = cs_subset_bool(sub, "forward_decode");
1151  const enum QuadOption c_forward_attachments =
1152  cs_subset_quad(sub, "forward_attachments");
1153  if (c_forward_decode && (c_forward_attachments != MUTT_NO))
1154  {
1155  last = &e->body;
1156  while (*last)
1157  last = &((*last)->next);
1158  }
1159 
1160  STAILQ_FOREACH(en, el, entries)
1161  {
1162  struct Email *e_cur = en->email;
1163  include_forward(m, e_cur, fp_tmp, sub);
1164  if (c_forward_decode && (c_forward_attachments != MUTT_NO))
1165  {
1166  if (inline_forward_attachments(m, e_cur, &last, &forwardq, sub) != 0)
1167  return -1;
1168  }
1169  }
1170  }
1171  else
1172  return -1;
1173  }
1174  /* if (WithCrypto && (flags & SEND_KEY)) */
1175  else if (((WithCrypto & APPLICATION_PGP) != 0) && (flags & SEND_KEY))
1176  {
1177  struct Body *b = NULL;
1178 
1179  if (((WithCrypto & APPLICATION_PGP) != 0) && !(b = crypt_pgp_make_key_attachment()))
1180  {
1181  return -1;
1182  }
1183 
1184  b->next = e->body;
1185  e->body = b;
1186  }
1187 
1188  mutt_clear_error();
1189 
1190  return 0;
1191 }
1192 
1198 void mutt_set_followup_to(struct Envelope *env, struct ConfigSubset *sub)
1199 {
1200  /* Only generate the Mail-Followup-To if the user has requested it, and
1201  * it hasn't already been set */
1202 
1203  const bool c_followup_to = cs_subset_bool(sub, "followup_to");
1204  if (!c_followup_to)
1205  return;
1206 #ifdef USE_NNTP
1207  if (OptNewsSend)
1208  {
1209  if (!env->followup_to && env->newsgroups && (strrchr(env->newsgroups, ',')))
1210  env->followup_to = mutt_str_dup(env->newsgroups);
1211  return;
1212  }
1213 #endif
1214 
1215  if (TAILQ_EMPTY(&env->mail_followup_to))
1216  {
1217  if (mutt_is_list_recipient(false, env))
1218  {
1219  /* this message goes to known mailing lists, so create a proper
1220  * mail-followup-to header */
1221 
1222  mutt_addrlist_copy(&env->mail_followup_to, &env->to, false);
1223  mutt_addrlist_copy(&env->mail_followup_to, &env->cc, true);
1224  }
1225 
1226  /* remove ourselves from the mail-followup-to header */
1227  remove_user(&env->mail_followup_to, false);
1228 
1229  /* If we are not subscribed to any of the lists in question, re-add
1230  * ourselves to the mail-followup-to header. The mail-followup-to header
1231  * generated is a no-op with group-reply, but makes sure list-reply has the
1232  * desired effect. */
1233 
1234  if (!TAILQ_EMPTY(&env->mail_followup_to) &&
1235  !mutt_is_subscribed_list_recipient(false, env))
1236  {
1237  struct AddressList *al = NULL;
1238  if (!TAILQ_EMPTY(&env->reply_to))
1239  al = &env->reply_to;
1240  else if (!TAILQ_EMPTY(&env->from))
1241  al = &env->from;
1242 
1243  if (al)
1244  {
1245  struct Address *a = NULL;
1246  TAILQ_FOREACH_REVERSE(a, al, AddressList, entries)
1247  {
1249  }
1250  }
1251  else
1252  {
1254  }
1255  }
1256 
1258  }
1259 }
1260 
1271 static void set_reverse_name(struct AddressList *al, struct Envelope *env,
1272  struct ConfigSubset *sub)
1273 {
1274  struct Address *a = NULL;
1275  if (TAILQ_EMPTY(al))
1276  {
1277  TAILQ_FOREACH(a, &env->to, entries)
1278  {
1279  if (mutt_addr_is_user(a))
1280  {
1282  break;
1283  }
1284  }
1285  }
1286 
1287  if (TAILQ_EMPTY(al))
1288  {
1289  TAILQ_FOREACH(a, &env->cc, entries)
1290  {
1291  if (mutt_addr_is_user(a))
1292  {
1294  break;
1295  }
1296  }
1297  }
1298 
1299  if (TAILQ_EMPTY(al))
1300  {
1301  struct Address *from = TAILQ_FIRST(&env->from);
1302  if (from && mutt_addr_is_user(from))
1303  {
1305  }
1306  }
1307 
1308  if (!TAILQ_EMPTY(al))
1309  {
1310  /* when $reverse_realname is not set, clear the personal name so that it
1311  * may be set via a reply- or send-hook. */
1312 
1313  const bool c_reverse_realname = cs_subset_bool(sub, "reverse_realname");
1314  if (!c_reverse_realname)
1315  FREE(&TAILQ_FIRST(al)->personal);
1316  }
1317 }
1318 
1324 {
1325  /* Note: We let $from override $realname here.
1326  * Is this the right thing to do?
1327  */
1328 
1329  const struct Address *c_from = cs_subset_address(sub, "from");
1330  const bool c_use_domain = cs_subset_bool(sub, "use_domain");
1331  if (c_from)
1332  {
1333  return mutt_addr_copy(c_from);
1334  }
1335  else if (c_use_domain)
1336  {
1337  struct Address *addr = mutt_addr_new();
1338  mutt_str_asprintf(&addr->mailbox, "%s@%s", NONULL(Username),
1339  NONULL(mutt_fqdn(true, sub)));
1340  return addr;
1341  }
1342  else
1343  {
1344  return mutt_addr_create(NULL, Username);
1345  }
1346 }
1347 
1355 static int invoke_mta(struct Email *e, struct ConfigSubset *sub)
1356 {
1357  struct Buffer *tempfile = NULL;
1358  int rc = -1;
1359 #ifdef USE_SMTP
1360  short old_write_bcc;
1361 #endif
1362 
1363  /* Write out the message in MIME form. */
1364  tempfile = mutt_buffer_pool_get();
1365  mutt_buffer_mktemp(tempfile);
1366  FILE *fp_tmp = mutt_file_fopen(mutt_b2s(tempfile), "w");
1367  if (!fp_tmp)
1368  goto cleanup;
1369 
1370 #ifdef USE_SMTP
1371  const bool c_write_bcc = cs_subset_bool(sub, "write_bcc");
1372  const char *c_smtp_url = cs_subset_string(sub, "smtp_url");
1373  old_write_bcc = c_write_bcc;
1374  if (c_smtp_url)
1375  cs_subset_str_native_set(sub, "write_bcc", false, NULL);
1376 #endif
1377 #ifdef MIXMASTER
1379  !STAILQ_EMPTY(&e->chain),
1381 #endif
1382 #ifndef MIXMASTER
1384  false, mutt_should_hide_protected_subject(e), sub);
1385 #endif
1386 #ifdef USE_SMTP
1387  if (old_write_bcc)
1388  cs_subset_str_native_set(sub, "write_bcc", true, NULL);
1389 #endif
1390 
1391  fputc('\n', fp_tmp); /* tie off the header. */
1392 
1393  if ((mutt_write_mime_body(e->body, fp_tmp, sub) == -1))
1394  goto cleanup;
1395 
1396  if (mutt_file_fclose(&fp_tmp) != 0)
1397  {
1398  mutt_perror(mutt_b2s(tempfile));
1399  unlink(mutt_b2s(tempfile));
1400  goto cleanup;
1401  }
1402 
1403 #ifdef MIXMASTER
1404  if (!STAILQ_EMPTY(&e->chain))
1405  {
1406  rc = mix_send_message(&e->chain, mutt_b2s(tempfile));
1407  goto cleanup;
1408  }
1409 #endif
1410 
1411 #ifdef USE_NNTP
1412  if (OptNewsSend)
1413  goto sendmail;
1414 #endif
1415 
1416 #ifdef USE_SMTP
1417  if (c_smtp_url)
1418  {
1419  rc = mutt_smtp_send(&e->env->from, &e->env->to, &e->env->cc, &e->env->bcc,
1420  mutt_b2s(tempfile), (e->body->encoding == ENC_8BIT), sub);
1421  goto cleanup;
1422  }
1423 #endif
1424 
1425 sendmail:
1426  rc = mutt_invoke_sendmail(&e->env->from, &e->env->to, &e->env->cc, &e->env->bcc,
1427  mutt_b2s(tempfile), (e->body->encoding == ENC_8BIT), sub);
1428 cleanup:
1429  if (fp_tmp)
1430  {
1431  mutt_file_fclose(&fp_tmp);
1432  unlink(mutt_b2s(tempfile));
1433  }
1434  mutt_buffer_pool_release(&tempfile);
1435  return rc;
1436 }
1437 
1444 void mutt_encode_descriptions(struct Body *b, bool recurse, struct ConfigSubset *sub)
1445 {
1446  for (struct Body *t = b; t; t = t->next)
1447  {
1448  if (t->description)
1449  {
1450  const char *c_send_charset = cs_subset_string(sub, "send_charset");
1451  rfc2047_encode(&t->description, NULL, sizeof("Content-Description:"), c_send_charset);
1452  }
1453  if (recurse && t->parts)
1454  mutt_encode_descriptions(t->parts, recurse, sub);
1455  }
1456 }
1457 
1462 static void decode_descriptions(struct Body *b)
1463 {
1464  for (struct Body *t = b; t; t = t->next)
1465  {
1466  if (t->description)
1467  {
1468  rfc2047_decode(&t->description);
1469  }
1470  if (t->parts)
1471  decode_descriptions(t->parts);
1472  }
1473 }
1474 
1479 static void fix_end_of_file(const char *data)
1480 {
1481  FILE *fp = mutt_file_fopen(data, "a+");
1482  if (!fp)
1483  return;
1484  if (fseek(fp, -1, SEEK_END) >= 0)
1485  {
1486  int c = fgetc(fp);
1487  if (c != '\n')
1488  fputc('\n', fp);
1489  }
1490  mutt_file_fclose(&fp);
1491 }
1492 
1503 int mutt_resend_message(FILE *fp, struct Context *ctx, struct Email *e_cur,
1504  struct ConfigSubset *sub)
1505 {
1506  struct Email *e_new = email_new();
1507 
1508  if (mutt_prepare_template(fp, ctx->mailbox, e_new, e_cur, true) < 0)
1509  {
1510  email_free(&e_new);
1511  return -1;
1512  }
1513 
1514  if (WithCrypto)
1515  {
1516  /* mutt_prepare_template doesn't always flip on an application bit.
1517  * so fix that here */
1518  if (!(e_new->security & (APPLICATION_SMIME | APPLICATION_PGP)))
1519  {
1520  const bool c_smime_is_default = cs_subset_bool(sub, "smime_is_default");
1521  if (((WithCrypto & APPLICATION_SMIME) != 0) && c_smime_is_default)
1522  e_new->security |= APPLICATION_SMIME;
1523  else if (WithCrypto & APPLICATION_PGP)
1524  e_new->security |= APPLICATION_PGP;
1525  else
1526  e_new->security |= APPLICATION_SMIME;
1527  }
1528 
1529  const bool c_crypt_opportunistic_encrypt =
1530  cs_subset_bool(sub, "crypt_opportunistic_encrypt");
1531  if (c_crypt_opportunistic_encrypt)
1532  {
1533  e_new->security |= SEC_OPPENCRYPT;
1535  }
1536  }
1537 
1538  struct EmailList el = STAILQ_HEAD_INITIALIZER(el);
1539  emaillist_add_email(&el, e_cur);
1540  int rc = mutt_send_message(SEND_RESEND, e_new, NULL, ctx, &el, sub);
1541  emaillist_clear(&el);
1542 
1543  return rc;
1544 }
1545 
1553 static bool is_reply(struct Email *reply, struct Email *orig)
1554 {
1555  if (!reply || !reply->env || !orig || !orig->env)
1556  return false;
1557  return mutt_list_find(&orig->env->references, reply->env->message_id) ||
1558  mutt_list_find(&orig->env->in_reply_to, reply->env->message_id);
1559 }
1560 
1572 static bool search_attach_keyword(char *filename, struct ConfigSubset *sub)
1573 {
1574  const struct Regex *c_abort_noattach_regex =
1575  cs_subset_regex(sub, "abort_noattach_regex");
1576  const struct Regex *c_quote_regex = cs_subset_regex(sub, "quote_regex");
1577 
1578  /* Search for the regex in `$abort_noattach_regex` within a file */
1579  if (!c_abort_noattach_regex || !c_abort_noattach_regex->regex ||
1580  !c_quote_regex || !c_quote_regex->regex)
1581  {
1582  return false;
1583  }
1584 
1585  FILE *fp_att = mutt_file_fopen(filename, "r");
1586  if (!fp_att)
1587  return false;
1588 
1589  char *inputline = mutt_mem_malloc(1024);
1590  bool found = false;
1591  while (!feof(fp_att))
1592  {
1593  fgets(inputline, 1024, fp_att);
1594  if (!mutt_is_quote_line(inputline, NULL) &&
1595  mutt_regex_match(c_abort_noattach_regex, inputline))
1596  {
1597  found = true;
1598  break;
1599  }
1600  }
1601  FREE(&inputline);
1602  mutt_file_fclose(&fp_att);
1603  return found;
1604 }
1605 
1618 static int save_fcc(struct Email *e, struct Buffer *fcc,
1619  struct Body *clear_content, char *pgpkeylist,
1620  SendFlags flags, char **finalpath, struct ConfigSubset *sub)
1621 {
1622  int rc = 0;
1623  struct Body *save_content = NULL;
1624 
1626 
1627  /* Don't save a copy when we are in batch-mode, and the FCC
1628  * folder is on an IMAP server: This would involve possibly lots
1629  * of user interaction, which is not available in batch mode.
1630  *
1631  * Note: A patch to fix the problems with the use of IMAP servers
1632  * from non-curses mode is available from Brendan Cully. However,
1633  * I'd like to think a bit more about this before including it. */
1634 
1635 #ifdef USE_IMAP
1636  if ((flags & SEND_BATCH) && !mutt_buffer_is_empty(fcc) &&
1637  (imap_path_probe(mutt_b2s(fcc), NULL) == MUTT_IMAP))
1638  {
1639  mutt_error(
1640  _("Warning: Fcc to an IMAP mailbox is not supported in batch mode"));
1641  /* L10N: Printed after the "Fcc to an IMAP mailbox is not supported" message.
1642  To make it clearer that the message doesn't mean NeoMutt is aborting
1643  sending the mail too.
1644  %s is the full mailbox URL, including imap(s)://
1645  */
1646  mutt_error(_("Skipping Fcc to %s"), mutt_b2s(fcc));
1647  mutt_buffer_reset(fcc);
1648  return rc;
1649  }
1650 #endif
1651 
1652  if (mutt_buffer_is_empty(fcc) || mutt_str_equal("/dev/null", mutt_b2s(fcc)))
1653  return rc;
1654 
1655  struct Body *tmpbody = e->body;
1656  struct Body *save_sig = NULL;
1657  struct Body *save_parts = NULL;
1658 
1659  const bool c_fcc_before_send = cs_subset_bool(sub, "fcc_before_send");
1660  /* Before sending, we don't allow message manipulation because it
1661  * will break message signatures. This is especially complicated by
1662  * Protected Headers. */
1663  if (!c_fcc_before_send)
1664  {
1665  const bool c_fcc_clear = cs_subset_bool(sub, "fcc_clear");
1666  if ((WithCrypto != 0) &&
1667  (e->security & (SEC_ENCRYPT | SEC_SIGN | SEC_AUTOCRYPT)) && c_fcc_clear)
1668  {
1669  e->body = clear_content;
1672  }
1673 
1674  const enum QuadOption c_fcc_attach = cs_subset_quad(sub, "fcc_attach");
1675 
1676  /* check to see if the user wants copies of all attachments */
1677  bool save_atts = true;
1678  if (e->body->type == TYPE_MULTIPART)
1679  {
1680  /* In batch mode, save attachments if the quadoption is yes or ask-yes */
1681  if (flags & SEND_BATCH)
1682  {
1683  if ((c_fcc_attach == MUTT_NO) || (c_fcc_attach == MUTT_ASKNO))
1684  save_atts = false;
1685  }
1686  else if (query_quadoption(c_fcc_attach, _("Save attachments in Fcc?")) != MUTT_YES)
1687  save_atts = false;
1688  }
1689  if (!save_atts)
1690  {
1691  if ((WithCrypto != 0) && (e->security & (SEC_ENCRYPT | SEC_SIGN | SEC_AUTOCRYPT)) &&
1692  (mutt_str_equal(e->body->subtype, "encrypted") ||
1693  mutt_str_equal(e->body->subtype, "signed")))
1694  {
1695  if ((clear_content->type == TYPE_MULTIPART) &&
1696  (query_quadoption(c_fcc_attach, _("Save attachments in Fcc?")) == MUTT_NO))
1697  {
1698  if (!(e->security & SEC_ENCRYPT) && (e->security & SEC_SIGN))
1699  {
1700  /* save initial signature and attachments */
1701  save_sig = e->body->parts->next;
1702  save_parts = clear_content->parts->next;
1703  }
1704 
1705  /* this means writing only the main part */
1706  e->body = clear_content->parts;
1707 
1708  if (mutt_protect(e, pgpkeylist, false) == -1)
1709  {
1710  /* we can't do much about it at this point, so
1711  * fallback to saving the whole thing to fcc */
1712  e->body = tmpbody;
1713  save_sig = NULL;
1714  goto full_fcc;
1715  }
1716 
1717  save_content = e->body;
1718  }
1719  }
1720  else
1721  {
1722  if (query_quadoption(c_fcc_attach, _("Save attachments in Fcc?")) == MUTT_NO)
1723  e->body = e->body->parts;
1724  }
1725  }
1726  }
1727 
1728 full_fcc:
1729  if (e->body)
1730  {
1731  /* update received time so that when storing to a mbox-style folder
1732  * the From_ line contains the current time instead of when the
1733  * message was first postponed. */
1734  e->received = mutt_date_epoch();
1735  rc = mutt_write_multiple_fcc(mutt_b2s(fcc), e, NULL, false, NULL, finalpath, sub);
1736  while (rc && !(flags & SEND_BATCH))
1737  {
1738  mutt_clear_error();
1739  int choice = mutt_multi_choice(
1740  /* L10N: Called when saving to $record or Fcc failed after sending.
1741  (r)etry tries the same mailbox again.
1742  alternate (m)ailbox prompts for a different mailbox to try.
1743  (s)kip aborts saving. */
1744  _("Fcc failed. (r)etry, alternate (m)ailbox, or (s)kip?"),
1745  /* L10N: These correspond to the "Fcc failed" multi-choice prompt
1746  (r)etry, alternate (m)ailbox, or (s)kip.
1747  Any similarity to famous leaders of the FSF is coincidental. */
1748  _("rms"));
1749  switch (choice)
1750  {
1751  case 2: /* alternate (m)ailbox */
1752  /* L10N: This is the prompt to enter an "alternate (m)ailbox" when the
1753  initial Fcc fails. */
1754  rc = mutt_buffer_enter_fname(_("Fcc mailbox"), fcc, true);
1755  if ((rc == -1) || mutt_buffer_is_empty(fcc))
1756  {
1757  rc = 0;
1758  break;
1759  }
1760  /* fall through */
1761 
1762  case 1: /* (r)etry */
1763  rc = mutt_write_multiple_fcc(mutt_b2s(fcc), e, NULL, false, NULL, finalpath, sub);
1764  break;
1765 
1766  case -1: /* abort */
1767  case 3: /* (s)kip */
1768  rc = 0;
1769  break;
1770  }
1771  }
1772  }
1773 
1774  if (!c_fcc_before_send)
1775  {
1776  e->body = tmpbody;
1777 
1778  if ((WithCrypto != 0) && save_sig)
1779  {
1780  /* cleanup the second signature structures */
1781  if (save_content->parts)
1782  {
1783  mutt_body_free(&save_content->parts->next);
1784  save_content->parts = NULL;
1785  }
1786  mutt_body_free(&save_content);
1787 
1788  /* restore old signature and attachments */
1789  e->body->parts->next = save_sig;
1790  e->body->parts->parts->next = save_parts;
1791  }
1792  else if ((WithCrypto != 0) && save_content)
1793  {
1794  /* destroy the new encrypted body. */
1795  mutt_body_free(&save_content);
1796  }
1797  }
1798 
1799  return 0;
1800 }
1801 
1812 static int postpone_message(struct Email *e_post, struct Email *e_cur,
1813  const char *fcc, SendFlags flags, struct ConfigSubset *sub)
1814 {
1815  char *pgpkeylist = NULL;
1816  const char *encrypt_as = NULL;
1817  struct Body *clear_content = NULL;
1818 
1819  const char *c_postponed = cs_subset_string(sub, "postponed");
1820  if (!c_postponed)
1821  {
1822  mutt_error(_("Can't postpone. $postponed is unset"));
1823  return -1;
1824  }
1825 
1826  if (e_post->body->next)
1827  e_post->body = mutt_make_multipart(e_post->body);
1828 
1829  mutt_encode_descriptions(e_post->body, true, sub);
1830 
1831  const bool c_postpone_encrypt = cs_subset_bool(sub, "postpone_encrypt");
1832  if ((WithCrypto != 0) && c_postpone_encrypt &&
1833  (e_post->security & (SEC_ENCRYPT | SEC_AUTOCRYPT)))
1834  {
1835  if (((WithCrypto & APPLICATION_PGP) != 0) && (e_post->security & APPLICATION_PGP))
1836  {
1837  const char *c_pgp_default_key = cs_subset_string(sub, "pgp_default_key");
1838  encrypt_as = c_pgp_default_key;
1839  }
1840  else if (((WithCrypto & APPLICATION_SMIME) != 0) && (e_post->security & APPLICATION_SMIME))
1841  {
1842  const char *c_smime_default_key =
1843  cs_subset_string(sub, "smime_default_key");
1844  encrypt_as = c_smime_default_key;
1845  }
1846  if (!encrypt_as)
1847  {
1848  const char *c_postpone_encrypt_as =
1849  cs_subset_string(sub, "postpone_encrypt_as");
1850  encrypt_as = c_postpone_encrypt_as;
1851  }
1852 
1853 #ifdef USE_AUTOCRYPT
1854  if (e_post->security & SEC_AUTOCRYPT)
1855  {
1857  {
1858  e_post->body = mutt_remove_multipart(e_post->body);
1859  decode_descriptions(e_post->body);
1860  mutt_error(_("Error encrypting message. Check your crypt settings."));
1861  return -1;
1862  }
1863  encrypt_as = AutocryptDefaultKey;
1864  }
1865 #endif
1866 
1867  if (encrypt_as)
1868  {
1869  pgpkeylist = mutt_str_dup(encrypt_as);
1870  clear_content = e_post->body;
1871  if (mutt_protect(e_post, pgpkeylist, true) == -1)
1872  {
1873  FREE(&pgpkeylist);
1874  e_post->body = mutt_remove_multipart(e_post->body);
1875  decode_descriptions(e_post->body);
1876  mutt_error(_("Error encrypting message. Check your crypt settings."));
1877  return -1;
1878  }
1879 
1880  FREE(&pgpkeylist);
1881 
1882  mutt_encode_descriptions(e_post->body, false, sub);
1883  }
1884  }
1885 
1886  /* make sure the message is written to the right part of a maildir
1887  * postponed folder. */
1888  e_post->read = false;
1889  e_post->old = false;
1890 
1891  mutt_prepare_envelope(e_post->env, false, sub);
1892  mutt_env_to_intl(e_post->env, NULL, NULL); /* Handle bad IDNAs the next time. */
1893 
1894  if (mutt_write_fcc(NONULL(c_postponed), e_post,
1895  (e_cur && (flags & SEND_REPLY)) ? e_cur->env->message_id : NULL,
1896  true, fcc, NULL, sub) < 0)
1897  {
1898  if (clear_content)
1899  {
1900  mutt_body_free(&e_post->body);
1901  e_post->body = clear_content;
1902  }
1903  mutt_env_free(&e_post->body->mime_headers); /* protected headers */
1904  e_post->body = mutt_remove_multipart(e_post->body);
1905  decode_descriptions(e_post->body);
1906  mutt_unprepare_envelope(e_post->env);
1907  return -1;
1908  }
1909 
1911 
1912  if (clear_content)
1913  mutt_body_free(&clear_content);
1914 
1915  return 0;
1916 }
1917 
1924 static bool is_text_plain(const struct Body *b)
1925 {
1926  return (b->type == TYPE_TEXT) && mutt_istr_equal(b->subtype, "plain");
1927 }
1928 
1935 static bool abort_for_missing_attachments(const struct Body *b, struct ConfigSubset *sub)
1936 {
1937  const enum QuadOption c_abort_noattach =
1938  cs_subset_quad(sub, "abort_noattach");
1939 
1940  if (c_abort_noattach == MUTT_NO)
1941  return false;
1942 
1943  if (b->next)
1944  return false;
1945 
1946  bool has_keyword = false;
1947 
1948  /* search text/plain parts, whether they are main or alternative parts */
1949  if (is_text_plain(b))
1950  {
1951  has_keyword |= search_attach_keyword(b->filename, sub);
1952  }
1953  else
1954  {
1955  for (b = b->parts; b; b = b->next)
1956  {
1957  if (is_text_plain(b))
1958  {
1959  has_keyword |= search_attach_keyword(b->filename, sub);
1960  }
1961  }
1962  }
1963 
1964  if (!has_keyword)
1965  return false;
1966 
1967  if (c_abort_noattach == MUTT_YES)
1968  {
1969  mutt_error(_("Message contains text matching \"$abort_noattach_regex\". "
1970  "Not sending."));
1971  return true;
1972  }
1973 
1974  return query_quadoption(c_abort_noattach,
1975  _("No attachments, cancel sending?")) != MUTT_NO;
1976 }
1977 
1990 int mutt_send_message(SendFlags flags, struct Email *e_templ, const char *tempfile,
1991  struct Context *ctx, struct EmailList *el, struct ConfigSubset *sub)
1992 {
1993  char buf[1024];
1994  struct Buffer fcc = mutt_buffer_make(0); /* where to copy this message */
1995  FILE *fp_tmp = NULL;
1996  struct Body *pbody = NULL;
1997  int i;
1998  bool free_clear_content = false;
1999 
2000  struct Body *clear_content = NULL;
2001  char *pgpkeylist = NULL;
2002  /* save current value of "pgp_sign_as" and "smime_default_key" */
2003  char *pgp_sign_as = NULL;
2004  char *smime_sign_as = NULL;
2005  const char *tag = NULL;
2006  char *err = NULL;
2007  char *ctype = NULL;
2008  char *finalpath = NULL;
2009  struct EmailNode *en = NULL;
2010  struct Email *e_cur = NULL;
2011  struct Mailbox *mailbox = ctx ? ctx->mailbox : NULL;
2012 
2013  if (el)
2014  en = STAILQ_FIRST(el);
2015  if (en)
2016  e_cur = STAILQ_NEXT(en, entries) ? NULL : en->email;
2017 
2018  int rc = -1;
2019 
2020 #ifdef USE_NNTP
2021  if (flags & SEND_NEWS)
2022  OptNewsSend = true;
2023  else
2024  OptNewsSend = false;
2025 #endif
2026 
2027  const enum QuadOption c_recall = cs_subset_quad(sub, "recall");
2028 
2029  if (!flags && !e_templ && (c_recall != MUTT_NO) && mutt_num_postponed(mailbox, true))
2030  {
2031  /* If the user is composing a new message, check to see if there
2032  * are any postponed messages first. */
2033  enum QuadOption ans =
2034  query_quadoption(c_recall, _("Recall postponed message?"));
2035  if (ans == MUTT_ABORT)
2036  return rc;
2037 
2038  if (ans == MUTT_YES)
2039  flags |= SEND_POSTPONED;
2040  }
2041 
2042  /* Allocate the buffer due to the long lifetime, but
2043  * pre-resize it to ensure there are no NULL data field issues */
2044  mutt_buffer_alloc(&fcc, 1024);
2045 
2046  if (flags & SEND_POSTPONED)
2047  {
2049  {
2050  const char *c_pgp_sign_as = cs_subset_string(sub, "pgp_sign_as");
2051  pgp_sign_as = mutt_str_dup(c_pgp_sign_as);
2052  }
2054  {
2055  const char *c_smime_sign_as = cs_subset_string(sub, "smime_sign_as");
2056  smime_sign_as = mutt_str_dup(c_smime_sign_as);
2057  }
2058  }
2059 
2060  /* Delay expansion of aliases until absolutely necessary--shouldn't
2061  * be necessary unless we are prompting the user or about to execute a
2062  * send-hook. */
2063 
2064  if (!e_templ)
2065  {
2066  e_templ = email_new();
2067 
2068  if (flags == SEND_POSTPONED)
2069  {
2070  rc = mutt_get_postponed(ctx, e_templ, &e_cur, &fcc);
2071  if (rc < 0)
2072  {
2073  flags = SEND_POSTPONED;
2074  goto cleanup;
2075  }
2076  flags = rc;
2077 #ifdef USE_NNTP
2078  /* If postponed message is a news article, it have
2079  * a "Newsgroups:" header line, then set appropriate flag. */
2080  if (e_templ->env->newsgroups)
2081  {
2082  flags |= SEND_NEWS;
2083  OptNewsSend = true;
2084  }
2085  else
2086  {
2087  flags &= ~SEND_NEWS;
2088  OptNewsSend = false;
2089  }
2090 #endif
2091  }
2092 
2093  if (flags & (SEND_POSTPONED | SEND_RESEND))
2094  {
2095  fp_tmp = mutt_file_fopen(e_templ->body->filename, "a+");
2096  if (!fp_tmp)
2097  {
2098  mutt_perror(e_templ->body->filename);
2099  goto cleanup;
2100  }
2101  }
2102 
2103  if (!e_templ->env)
2104  e_templ->env = mutt_env_new();
2105  }
2106 
2107  /* Parse and use an eventual list-post header */
2108  if ((flags & SEND_LIST_REPLY) && e_cur && e_cur->env && e_cur->env->list_post)
2109  {
2110  /* Use any list-post header as a template */
2111  mutt_parse_mailto(e_templ->env, NULL, e_cur->env->list_post);
2112  /* We don't let them set the sender's address. */
2113  mutt_addrlist_clear(&e_templ->env->from);
2114  }
2115 
2116  if (!(flags & (SEND_KEY | SEND_POSTPONED | SEND_RESEND)))
2117  {
2118  /* When SEND_DRAFT_FILE is set, the caller has already
2119  * created the "parent" body structure. */
2120  if (!(flags & SEND_DRAFT_FILE))
2121  {
2122  pbody = mutt_body_new();
2123  pbody->next = e_templ->body; /* don't kill command-line attachments */
2124  e_templ->body = pbody;
2125 
2126  const char *c_content_type = cs_subset_string(sub, "content_type");
2127  ctype = mutt_str_dup(c_content_type);
2128  if (!ctype)
2129  ctype = mutt_str_dup("text/plain");
2130  mutt_parse_content_type(ctype, e_templ->body);
2131  FREE(&ctype);
2132  e_templ->body->unlink = true;
2133  e_templ->body->use_disp = false;
2134  e_templ->body->disposition = DISP_INLINE;
2135 
2136  if (tempfile)
2137  {
2138  fp_tmp = mutt_file_fopen(tempfile, "a+");
2139  e_templ->body->filename = mutt_str_dup(tempfile);
2140  }
2141  else
2142  {
2143  mutt_mktemp(buf, sizeof(buf));
2144  fp_tmp = mutt_file_fopen(buf, "w+");
2145  e_templ->body->filename = mutt_str_dup(buf);
2146  }
2147  }
2148  else
2149  fp_tmp = mutt_file_fopen(e_templ->body->filename, "a+");
2150 
2151  if (!fp_tmp)
2152  {
2153  mutt_debug(LL_DEBUG1, "can't create tempfile %s (errno=%d)\n",
2154  e_templ->body->filename, errno);
2155  mutt_perror(e_templ->body->filename);
2156  goto cleanup;
2157  }
2158  }
2159 
2160  const bool c_reverse_name = cs_subset_bool(sub, "reverse_name");
2161  /* this is handled here so that the user can match ~f in send-hook */
2162  if (e_cur && c_reverse_name && !(flags & (SEND_POSTPONED | SEND_RESEND)))
2163  {
2164  /* We shouldn't have to worry about alias expansion here since we are
2165  * either replying to a real or postponed message, therefore no aliases
2166  * should exist since the user has not had the opportunity to add
2167  * addresses to the list. We just have to ensure the postponed messages
2168  * have their aliases expanded. */
2169 
2170  if (!TAILQ_EMPTY(&e_templ->env->from))
2171  {
2172  mutt_debug(LL_DEBUG5, "e_templ->env->from before set_reverse_name: %s\n",
2173  TAILQ_FIRST(&e_templ->env->from)->mailbox);
2174  mutt_addrlist_clear(&e_templ->env->from);
2175  }
2176  set_reverse_name(&e_templ->env->from, e_cur->env, sub);
2177  }
2178 
2179  const bool c_reply_with_xorig = cs_subset_bool(sub, "reply_with_xorig");
2180  if (e_cur && c_reply_with_xorig && !(flags & (SEND_POSTPONED | SEND_RESEND | SEND_FORWARD)))
2181  {
2182  /* We shouldn't have to worry about freeing 'e_templ->env->from' before
2183  * setting it here since this code will only execute when doing some
2184  * sort of reply. The pointer will only be set when using the -H command
2185  * line option.
2186  *
2187  * If there is already a from address recorded in 'e_templ->env->from',
2188  * then it theoretically comes from `$reverse_name` handling, and we don't use
2189  * the 'X-Orig-To header'. */
2190  if (!TAILQ_EMPTY(&e_cur->env->x_original_to) && TAILQ_EMPTY(&e_templ->env->from))
2191  {
2192  mutt_addrlist_copy(&e_templ->env->from, &e_cur->env->x_original_to, false);
2193  mutt_debug(LL_DEBUG5, "e_templ->env->from extracted from X-Original-To: header: %s\n",
2194  TAILQ_FIRST(&e_templ->env->from)->mailbox);
2195  }
2196  }
2197 
2198  const bool c_resume_draft_files = cs_subset_bool(sub, "resume_draft_files");
2199  const char *c_editor = cs_subset_string(sub, "editor");
2200  if (!(flags & (SEND_POSTPONED | SEND_RESEND)) &&
2201  !((flags & SEND_DRAFT_FILE) && c_resume_draft_files))
2202  {
2203  if ((flags & (SEND_REPLY | SEND_FORWARD | SEND_TO_SENDER)) && mailbox &&
2204  (envelope_defaults(e_templ->env, mailbox, el, flags, sub) == -1))
2205  {
2206  goto cleanup;
2207  }
2208 
2209  const bool c_hdrs = cs_subset_bool(sub, "hdrs");
2210  if (c_hdrs)
2211  process_user_recips(e_templ->env);
2212 
2213  /* Expand aliases and remove duplicates/crossrefs */
2214  mutt_expand_aliases_env(e_templ->env);
2215 
2216  if (flags & SEND_REPLY)
2217  mutt_fix_reply_recipients(e_templ->env, sub);
2218 
2219 #ifdef USE_NNTP
2220  if ((flags & SEND_NEWS) && (mailbox && mailbox->type == MUTT_NNTP) &&
2221  !e_templ->env->newsgroups)
2222  {
2223  e_templ->env->newsgroups =
2224  mutt_str_dup(((struct NntpMboxData *) mailbox->mdata)->group);
2225  }
2226 #endif
2227 
2228  const bool c_autoedit = cs_subset_bool(sub, "autoedit");
2229  const bool c_edit_headers = cs_subset_bool(sub, "edit_headers");
2230  const bool c_fast_reply = cs_subset_bool(sub, "fast_reply");
2231  if (!(flags & SEND_BATCH) && !(c_autoedit && c_edit_headers) &&
2232  !((flags & SEND_REPLY) && c_fast_reply))
2233  {
2234  if (edit_envelope(e_templ->env, flags, sub) == -1)
2235  goto cleanup;
2236  }
2237 
2238  /* the from address must be set here regardless of whether or not
2239  * $use_from is set so that the '~P' (from you) operator in send-hook
2240  * patterns will work. if $use_from is unset, the from address is killed
2241  * after send-hooks are evaluated */
2242 
2243  const bool killfrom = TAILQ_EMPTY(&e_templ->env->from);
2244  if (killfrom)
2245  {
2246  mutt_addrlist_append(&e_templ->env->from, mutt_default_from(sub));
2247  }
2248 
2249  if ((flags & SEND_REPLY) && e_cur)
2250  {
2251  /* change setting based upon message we are replying to */
2252  mutt_message_hook(mailbox, e_cur, MUTT_REPLY_HOOK);
2253 
2254  /* set the replied flag for the message we are generating so that the
2255  * user can use ~Q in a send-hook to know when reply-hook's are also
2256  * being used. */
2257  e_templ->replied = true;
2258  }
2259 
2260  /* change settings based upon recipients */
2261 
2262  mutt_message_hook(NULL, e_templ, MUTT_SEND_HOOK);
2263 
2264  /* Unset the replied flag from the message we are composing since it is
2265  * no longer required. This is done here because the FCC'd copy of
2266  * this message was erroneously get the 'R'eplied flag when stored in
2267  * a maildir-style mailbox. */
2268  e_templ->replied = false;
2269 
2270  /* $use_from and/or $from might have changed in a send-hook */
2271  if (killfrom)
2272  {
2273  mutt_addrlist_clear(&e_templ->env->from);
2274 
2275  const bool c_use_from = cs_subset_bool(sub, "use_from");
2276  if (c_use_from && !(flags & (SEND_POSTPONED | SEND_RESEND)))
2277  mutt_addrlist_append(&e_templ->env->from, mutt_default_from(sub));
2278  }
2279 
2280  if (c_hdrs)
2281  process_user_header(e_templ->env);
2282 
2283  if (flags & SEND_BATCH)
2284  {
2285  if (mutt_file_copy_stream(stdin, fp_tmp) < 1)
2286  {
2287  mutt_error(_("Refusing to send an empty email"));
2288  mutt_message(_("Try: echo | neomutt -s 'subject' user@example.com"));
2289  goto cleanup;
2290  }
2291  }
2292 
2293  const bool c_sig_on_top = cs_subset_bool(sub, "sig_on_top");
2294  if (c_sig_on_top && !(flags & (SEND_KEY | SEND_BATCH)) && c_editor)
2295  {
2296  append_signature(fp_tmp, sub);
2297  }
2298 
2299  /* include replies/forwarded messages, unless we are given a template */
2300  if (!tempfile && (mailbox || !(flags & (SEND_REPLY | SEND_FORWARD))) &&
2301  (generate_body(fp_tmp, e_templ, flags, mailbox, el, sub) == -1))
2302  {
2303  goto cleanup;
2304  }
2305 
2306  if (!c_sig_on_top && !(flags & (SEND_KEY | SEND_BATCH)) && c_editor)
2307  {
2308  append_signature(fp_tmp, sub);
2309  }
2310  }
2311 
2312  /* Only set format=flowed for new messages. postponed/resent/draftfiles
2313  * should respect the original email.
2314  *
2315  * This is set here so that send-hook can be used to turn the option on. */
2316  if (!(flags & (SEND_KEY | SEND_POSTPONED | SEND_RESEND | SEND_DRAFT_FILE)))
2317  {
2318  const bool c_text_flowed = cs_subset_bool(sub, "text_flowed");
2319  if (c_text_flowed && is_text_plain(e_templ->body))
2320  {
2321  mutt_param_set(&e_templ->body->parameter, "format", "flowed");
2322  }
2323  }
2324 
2325  /* This hook is even called for postponed messages, and can, e.g., be used
2326  * for setting the editor, the sendmail path, or the envelope sender. */
2327  mutt_message_hook(NULL, e_templ, MUTT_SEND2_HOOK);
2328 
2329  /* wait until now to set the real name portion of our return address so
2330  * that $realname can be set in a send-hook */
2331  {
2332  struct Address *from = TAILQ_FIRST(&e_templ->env->from);
2333  if (from && !from->personal && !(flags & (SEND_RESEND | SEND_POSTPONED)))
2334  {
2335  const char *c_realname = cs_subset_string(sub, "realname");
2336  from->personal = mutt_str_dup(c_realname);
2337  }
2338  }
2339 
2340  if (!(((WithCrypto & APPLICATION_PGP) != 0) && (flags & SEND_KEY)))
2341  mutt_file_fclose(&fp_tmp);
2342 
2343  if (!(flags & SEND_BATCH))
2344  {
2345  struct stat st;
2346  time_t mtime = mutt_file_decrease_mtime(e_templ->body->filename, NULL);
2347  if (mtime == (time_t) -1)
2348  {
2349  mutt_perror(e_templ->body->filename);
2350  goto cleanup;
2351  }
2352 
2353  mutt_update_encoding(e_templ->body, sub);
2354 
2355  const bool c_edit_headers = cs_subset_bool(sub, "edit_headers");
2356  const bool c_autoedit = cs_subset_bool(sub, "autoedit");
2357  const enum QuadOption c_forward_edit = cs_subset_quad(sub, "forward_edit");
2358 
2359  /* Select whether or not the user's editor should be called now. We
2360  * don't want to do this when:
2361  * 1) we are sending a key/cert
2362  * 2) we are forwarding a message and the user doesn't want to edit it.
2363  * This is controlled by the quadoption $forward_edit. However, if
2364  * both $edit_headers and $autoedit are set, we want to ignore the
2365  * setting of $forward_edit because the user probably needs to add the
2366  * recipients. */
2367  if (!(flags & SEND_KEY) &&
2368  (((flags & SEND_FORWARD) == 0) || (c_edit_headers && c_autoedit) ||
2369  (query_quadoption(c_forward_edit, _("Edit forwarded message?")) == MUTT_YES)))
2370  {
2371  /* If the this isn't a text message, look for a mailcap edit command */
2372  if (mutt_needs_mailcap(e_templ->body))
2373  {
2374  if (!mutt_edit_attachment(e_templ->body))
2375  goto cleanup;
2376  }
2377  else if (c_edit_headers)
2378  {
2379  mutt_env_to_local(e_templ->env);
2380  mutt_edit_headers(c_editor, e_templ->body->filename, e_templ, &fcc);
2381  mutt_env_to_intl(e_templ->env, NULL, NULL);
2382  }
2383  else
2384  {
2385  mutt_edit_file(c_editor, e_templ->body->filename);
2386  if (stat(e_templ->body->filename, &st) == 0)
2387  {
2388  if (mtime != st.st_mtime)
2389  fix_end_of_file(e_templ->body->filename);
2390  }
2391  else
2392  mutt_perror(e_templ->body->filename);
2393  }
2394 
2395  mutt_message_hook(NULL, e_templ, MUTT_SEND2_HOOK);
2396  }
2397 
2398  if (!(flags & (SEND_POSTPONED | SEND_FORWARD | SEND_KEY | SEND_RESEND | SEND_DRAFT_FILE)))
2399  {
2400  if (stat(e_templ->body->filename, &st) == 0)
2401  {
2402  const enum QuadOption c_abort_unmodified =
2403  cs_subset_quad(sub, "abort_unmodified");
2404 
2405  /* if the file was not modified, bail out now */
2406  if ((mtime == st.st_mtime) && !e_templ->body->next &&
2407  (query_quadoption(c_abort_unmodified,
2408  _("Abort unmodified message?")) == MUTT_YES))
2409  {
2410  mutt_message(_("Aborted unmodified message"));
2411  goto cleanup;
2412  }
2413  }
2414  else
2415  mutt_perror(e_templ->body->filename);
2416  }
2417  }
2418 
2419  /* Set the message security unless:
2420  * 1) crypto support is not enabled (WithCrypto==0)
2421  * 2) pgp: header field was present during message editing with $edit_headers (e_templ->security != 0)
2422  * 3) we are resending a message
2423  * 4) we are recalling a postponed message (don't override the user's saved settings)
2424  * 5) we are in batch mode
2425  *
2426  * This is done after allowing the user to edit the message so that security
2427  * settings can be configured with send2-hook and $edit_headers. */
2428  if ((WithCrypto != 0) && (e_templ->security == 0) &&
2429  !(flags & (SEND_BATCH | SEND_POSTPONED | SEND_RESEND)))
2430  {
2431  bool c_autocrypt = false;
2432  bool c_autocrypt_reply = false;
2433 
2434 #ifdef USE_AUTOCRYPT
2435  c_autocrypt = cs_subset_bool(sub, "autocrypt");
2436  c_autocrypt_reply = cs_subset_bool(sub, "autocrypt_reply");
2437 #endif
2438 
2439  if (c_autocrypt && c_autocrypt_reply && e_cur && (e_cur->security & SEC_AUTOCRYPT))
2440  {
2442  }
2443  else
2444  {
2445  const bool c_crypt_autosign = cs_subset_bool(sub, "crypt_autosign");
2446  const bool c_crypt_autoencrypt = cs_subset_bool(sub, "crypt_autoencrypt");
2447  const bool c_crypt_replyencrypt =
2448  cs_subset_bool(sub, "crypt_replyencrypt");
2449  const bool c_crypt_replysign = cs_subset_bool(sub, "crypt_replysign");
2450  const bool c_crypt_replysignencrypted =
2451  cs_subset_bool(sub, "crypt_replysignencrypted");
2452 
2453  if (c_crypt_autosign)
2454  e_templ->security |= SEC_SIGN;
2455  if (c_crypt_autoencrypt)
2456  e_templ->security |= SEC_ENCRYPT;
2457  if (c_crypt_replyencrypt && e_cur && (e_cur->security & SEC_ENCRYPT))
2458  e_templ->security |= SEC_ENCRYPT;
2459  if (c_crypt_replysign && e_cur && (e_cur->security & SEC_SIGN))
2460  e_templ->security |= SEC_SIGN;
2461  if (c_crypt_replysignencrypted && e_cur && (e_cur->security & SEC_ENCRYPT))
2462  e_templ->security |= SEC_SIGN;
2463 
2464  const bool c_crypt_opportunistic_encrypt =
2465  cs_subset_bool(sub, "crypt_opportunistic_encrypt");
2466 
2467  if (((WithCrypto & APPLICATION_PGP) != 0) &&
2468  ((e_templ->security & (SEC_ENCRYPT | SEC_SIGN)) || c_crypt_opportunistic_encrypt))
2469  {
2470  const bool c_pgp_autoinline = cs_subset_bool(sub, "pgp_autoinline");
2471  const bool c_pgp_replyinline = cs_subset_bool(sub, "pgp_replyinline");
2472 
2473  if (c_pgp_autoinline)
2474  e_templ->security |= SEC_INLINE;
2475  if (c_pgp_replyinline && e_cur && (e_cur->security & SEC_INLINE))
2476  e_templ->security |= SEC_INLINE;
2477  }
2478  }
2479 
2480  const bool c_crypt_opportunistic_encrypt =
2481  cs_subset_bool(sub, "crypt_opportunistic_encrypt");
2482 
2483  if (e_templ->security || c_crypt_opportunistic_encrypt)
2484  {
2485  const bool c_crypt_autopgp = cs_subset_bool(sub, "crypt_autopgp");
2486  const bool c_crypt_autosmime = cs_subset_bool(sub, "crypt_autosmime");
2487 
2488  /* When replying / forwarding, use the original message's
2489  * crypto system. According to the documentation,
2490  * smime_is_default should be disregarded here.
2491  *
2492  * Problem: At least with forwarding, this doesn't really
2493  * make much sense. Should we have an option to completely
2494  * disable individual mechanisms at run-time? */
2495  if (e_cur)
2496  {
2497  if (((WithCrypto & APPLICATION_PGP) != 0) && c_crypt_autopgp &&
2498  (e_cur->security & APPLICATION_PGP))
2499  {
2500  e_templ->security |= APPLICATION_PGP;
2501  }
2502  else if (((WithCrypto & APPLICATION_SMIME) != 0) && c_crypt_autosmime &&
2503  (e_cur->security & APPLICATION_SMIME))
2504  {
2505  e_templ->security |= APPLICATION_SMIME;
2506  }
2507  }
2508 
2509  const bool c_smime_is_default = cs_subset_bool(sub, "smime_is_default");
2510 
2511  /* No crypto mechanism selected? Use availability + smime_is_default
2512  * for the decision. */
2513  if (!(e_templ->security & (APPLICATION_SMIME | APPLICATION_PGP)))
2514  {
2515  if (((WithCrypto & APPLICATION_SMIME) != 0) && c_crypt_autosmime && c_smime_is_default)
2516  {
2517  e_templ->security |= APPLICATION_SMIME;
2518  }
2519  else if (((WithCrypto & APPLICATION_PGP) != 0) && c_crypt_autopgp)
2520  {
2521  e_templ->security |= APPLICATION_PGP;
2522  }
2523  else if (((WithCrypto & APPLICATION_SMIME) != 0) && c_crypt_autosmime)
2524  {
2525  e_templ->security |= APPLICATION_SMIME;
2526  }
2527  }
2528  }
2529 
2530  /* opportunistic encrypt relies on SMIME or PGP already being selected */
2531  if (c_crypt_opportunistic_encrypt)
2532  {
2533  /* If something has already enabled encryption, e.g. `$crypt_autoencrypt`
2534  * or `$crypt_replyencrypt`, then don't enable opportunistic encrypt for
2535  * the message. */
2536  if (!(e_templ->security & (SEC_ENCRYPT | SEC_AUTOCRYPT)))
2537  {
2538  e_templ->security |= SEC_OPPENCRYPT;
2539  crypt_opportunistic_encrypt(e_templ);
2540  }
2541  }
2542 
2543  /* No permissible mechanisms found. Don't sign or encrypt. */
2544  if (!(e_templ->security & (APPLICATION_SMIME | APPLICATION_PGP)))
2545  e_templ->security = SEC_NO_FLAGS;
2546  }
2547 
2548  /* Deal with the corner case where the crypto module backend is not available.
2549  * This can happen if configured without PGP/SMIME and with GPGME, but
2550  * $crypt_use_gpgme is unset. */
2551  if (e_templ->security && !crypt_has_module_backend(e_templ->security))
2552  {
2553  mutt_error(_(
2554  "No crypto backend configured. Disabling message security setting."));
2555  e_templ->security = SEC_NO_FLAGS;
2556  }
2557 
2558  /* specify a default fcc. if we are in batchmode, only save a copy of
2559  * the message if the value of $copy is yes or ask-yes */
2560 
2561  const enum QuadOption c_copy = cs_subset_quad(sub, "copy");
2562 
2563  if (mutt_buffer_is_empty(&fcc) && !(flags & SEND_POSTPONED_FCC) &&
2564  (!(flags & SEND_BATCH) || (c_copy & 0x1)))
2565  {
2566  /* set the default FCC */
2567  const bool killfrom = TAILQ_EMPTY(&e_templ->env->from);
2568  if (killfrom)
2569  {
2570  mutt_addrlist_append(&e_templ->env->from, mutt_default_from(sub));
2571  }
2572  mutt_select_fcc(&fcc, e_templ);
2573  if (killfrom)
2574  {
2575  mutt_addrlist_clear(&e_templ->env->from);
2576  }
2577  }
2578 
2579  mutt_rfc3676_space_stuff(e_templ);
2580 
2581  mutt_update_encoding(e_templ->body, sub);
2582 
2583  if (!(flags & SEND_BATCH))
2584  {
2585  main_loop:
2586 
2588  i = mutt_compose_menu(e_templ, &fcc, e_cur,
2590  if (i == -1)
2591  {
2592 /* abort */
2593 #ifdef USE_NNTP
2594  if (flags & SEND_NEWS)
2595  mutt_message(_("Article not posted"));
2596  else
2597 #endif
2598  mutt_message(_("Mail not sent"));
2599  goto cleanup;
2600  }
2601  else if (i == 1)
2602  {
2603  if (postpone_message(e_templ, e_cur, mutt_b2s(&fcc), flags, sub) != 0)
2604  goto main_loop;
2605  mutt_message(_("Message postponed"));
2606  rc = 1;
2607  goto cleanup;
2608  }
2609  }
2610 
2611 #ifdef USE_NNTP
2612  if (!(flags & SEND_NEWS))
2613 #endif
2614  if ((mutt_addrlist_count_recips(&e_templ->env->to) == 0) &&
2615  (mutt_addrlist_count_recips(&e_templ->env->cc) == 0) &&
2616  (mutt_addrlist_count_recips(&e_templ->env->bcc) == 0))
2617  {
2618  if (flags & SEND_BATCH)
2619  {
2620  puts(_("No recipients specified"));
2621  goto cleanup;
2622  }
2623 
2624  mutt_error(_("No recipients specified"));
2625  goto main_loop;
2626  }
2627 
2628  if (mutt_env_to_intl(e_templ->env, &tag, &err))
2629  {
2630  mutt_error(_("Bad IDN in '%s': '%s'"), tag, err);
2631  FREE(&err);
2632  if (flags & SEND_BATCH)
2633  goto cleanup;
2634  goto main_loop;
2635  }
2636 
2637  const enum QuadOption c_abort_nosubject =
2638  cs_subset_quad(sub, "abort_nosubject");
2639 
2640  if (!e_templ->env->subject && !(flags & SEND_BATCH) &&
2641  (query_quadoption(c_abort_nosubject, _("No subject, abort sending?")) != MUTT_NO))
2642  {
2643  /* if the abort is automatic, print an error message */
2644  if (c_abort_nosubject == MUTT_YES)
2645  mutt_error(_("No subject specified"));
2646  goto main_loop;
2647  }
2648 #ifdef USE_NNTP
2649  if ((flags & SEND_NEWS) && !e_templ->env->subject)
2650  {
2651  mutt_error(_("No subject specified"));
2652  goto main_loop;
2653  }
2654 
2655  if ((flags & SEND_NEWS) && !e_templ->env->newsgroups)
2656  {
2657  mutt_error(_("No newsgroup specified"));
2658  goto main_loop;
2659  }
2660 #endif
2661 
2662  if (!(flags & SEND_BATCH) && abort_for_missing_attachments(e_templ->body, sub))
2663  {
2664  goto main_loop;
2665  }
2666 
2667  if (e_templ->body->next)
2668  e_templ->body = mutt_make_multipart(e_templ->body);
2669 
2670  /* Ok, we need to do it this way instead of handling all fcc stuff in
2671  * one place in order to avoid going to main_loop with encoded "env"
2672  * in case of error. Ugh. */
2673 
2674  mutt_encode_descriptions(e_templ->body, true, sub);
2675 
2676  /* Make sure that clear_content and free_clear_content are
2677  * properly initialized -- we may visit this particular place in
2678  * the code multiple times, including after a failed call to
2679  * mutt_protect(). */
2680 
2681  clear_content = NULL;
2682  free_clear_content = false;
2683 
2684  if (WithCrypto)
2685  {
2686  if (e_templ->security & (SEC_ENCRYPT | SEC_SIGN | SEC_AUTOCRYPT))
2687  {
2688  /* save the decrypted attachments */
2689  clear_content = e_templ->body;
2690 
2691  if ((crypt_get_keys(e_templ, &pgpkeylist, 0) == -1) ||
2692  (mutt_protect(e_templ, pgpkeylist, false) == -1))
2693  {
2694  e_templ->body = mutt_remove_multipart(e_templ->body);
2695 
2696  FREE(&pgpkeylist);
2697 
2698  decode_descriptions(e_templ->body);
2699  goto main_loop;
2700  }
2701  mutt_encode_descriptions(e_templ->body, false, sub);
2702  }
2703 
2704  /* at this point, e_templ->body is one of the following three things:
2705  * - multipart/signed. In this case, clear_content is a child
2706  * - multipart/encrypted. In this case, clear_content exists independently
2707  * - application/pgp. In this case, clear_content exists independently
2708  * - something else. In this case, it's the same as clear_content */
2709 
2710  /* This is ugly -- lack of "reporting back" from mutt_protect(). */
2711 
2712  if (clear_content && (e_templ->body != clear_content) &&
2713  (e_templ->body->parts != clear_content))
2714  free_clear_content = true;
2715  }
2716 
2717  if (!OptNoCurses)
2718  mutt_message(_("Sending message..."));
2719 
2720  mutt_prepare_envelope(e_templ->env, true, sub);
2721 
2722  const bool c_fcc_before_send = cs_subset_bool(sub, "fcc_before_send");
2723  if (c_fcc_before_send)
2724  save_fcc(e_templ, &fcc, clear_content, pgpkeylist, flags, &finalpath, sub);
2725 
2726  i = invoke_mta(e_templ, sub);
2727  if (i < 0)
2728  {
2729  if (!(flags & SEND_BATCH))
2730  {
2731  if (!WithCrypto)
2732  ; // do nothing
2733  else if ((e_templ->security & (SEC_ENCRYPT | SEC_AUTOCRYPT)) ||
2734  ((e_templ->security & SEC_SIGN) && (e_templ->body->type == TYPE_APPLICATION)))
2735  {
2736  if (e_templ->body != clear_content)
2737  {
2738  mutt_body_free(&e_templ->body); /* destroy PGP data */
2739  e_templ->body = clear_content; /* restore clear text. */
2740  }
2741  }
2742  else if ((e_templ->security & SEC_SIGN) && (e_templ->body->type == TYPE_MULTIPART))
2743  {
2744  mutt_body_free(&e_templ->body->parts->next); /* destroy sig */
2745  e_templ->body = mutt_remove_multipart(e_templ->body);
2746  }
2747 
2748  FREE(&pgpkeylist);
2749  mutt_env_free(&e_templ->body->mime_headers); /* protected headers */
2750  e_templ->body = mutt_remove_multipart(e_templ->body);
2751  decode_descriptions(e_templ->body);
2752  mutt_unprepare_envelope(e_templ->env);
2753  FREE(&finalpath);
2754  goto main_loop;
2755  }
2756  else
2757  {
2758  puts(_("Could not send the message"));
2759  goto cleanup;
2760  }
2761  }
2762 
2763  if (!c_fcc_before_send)
2764  save_fcc(e_templ, &fcc, clear_content, pgpkeylist, flags, &finalpath, sub);
2765 
2766  if (!OptNoCurses)
2767  {
2768  mutt_message((i != 0) ? _("Sending in background") :
2769  (flags & SEND_NEWS) ? _("Article posted") : /* USE_NNTP */
2770  _("Mail sent"));
2771 #ifdef USE_NOTMUCH
2772  const bool c_nm_record = cs_subset_bool(sub, "nm_record");
2773  if (c_nm_record)
2774  nm_record_message(mailbox, finalpath, e_cur);
2775 #endif
2776  mutt_sleep(0);
2777  }
2778 
2779  if (WithCrypto)
2780  FREE(&pgpkeylist);
2781 
2782  if ((WithCrypto != 0) && free_clear_content)
2783  mutt_body_free(&clear_content);
2784 
2785  /* set 'replied' flag only if the user didn't change/remove
2786  * In-Reply-To: and References: headers during edit */
2787  if (flags & SEND_REPLY)
2788  {
2789  if (!(flags & SEND_POSTPONED) && mailbox)
2790  {
2791  STAILQ_FOREACH(en, el, entries)
2792  {
2793  mutt_set_flag(mailbox, en->email, MUTT_REPLIED, is_reply(en->email, e_templ));
2794  }
2795  }
2796  }
2797 
2798  rc = 0;
2799 
2800 cleanup:
2801  mutt_buffer_dealloc(&fcc);
2802 
2803  if (flags & SEND_POSTPONED)
2804  {
2805  if (WithCrypto & APPLICATION_PGP)
2806  {
2807  cs_subset_str_string_set(sub, "pgp_sign_as", pgp_sign_as, NULL);
2808  }
2810  {
2811  cs_subset_str_string_set(sub, "smime_sign_as", smime_sign_as, NULL);
2812  }
2813  }
2814 
2815  mutt_file_fclose(&fp_tmp);
2816  if (!(flags & SEND_NO_FREE_HEADER))
2817  email_free(&e_templ);
2818 
2819  FREE(&finalpath);
2820  return rc;
2821 }
void mutt_make_attribution(struct Mailbox *m, struct Email *e, FILE *fp_out, struct ConfigSubset *sub)
Add "on DATE, PERSON wrote" header.
Definition: send.c:580
#define MUTT_SEND_HOOK
send-hook: when composing a new email
Definition: hook.h:47
int nm_record_message(struct Mailbox *m, char *path, struct Email *e)
Add a message to the Notmuch database.
Definition: notmuch.c:2021
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:876
Convenience wrapper for the gui headers.
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:416
The "current" mailbox.
Definition: context.h:38
#define mutt_buffer_mktemp(buf)
Definition: muttlib.h:77
void mutt_actx_free(struct AttachCtx **ptr)
Free an Attachment Context.
Definition: attach.c:140
char * filename
when sending a message, this is the file to which this structure refers
Definition: body.h:46
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
#define NONULL(x)
Definition: string2.h:37
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct Envelope * mime_headers
Memory hole protected headers.
Definition: body.h:63
Miscellaneous email parsing routines.
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:67
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:68
Representation of the email&#39;s header.
#define WithCrypto
Definition: lib.h:123
void mutt_expand_aliases(struct AddressList *al)
Expand aliases in a List of Addresses.
Definition: alias.c:294
#define SEND_POSTPONED_FCC
Used by mutt_get_postponed() to signal that the x-mutt-fcc header field was present.
Definition: send.h:49
#define SEND_TO_SENDER
Compose new email to sender.
Definition: send.h:52
IMAP network mailbox.
The envelope/body of an email.
Definition: email.h:37
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define TAILQ_FIRST(head)
Definition: queue.h:716
#define mutt_perror(...)
Definition: logging.h:85
GUI editor for an email&#39;s headers.
static void fix_end_of_file(const char *data)
Ensure a file ends with a linefeed.
Definition: send.c:1479
#define MUTT_ALIAS
Do alias "completion" by calling up the alias-menu.
Definition: mutt.h:57
void mutt_update_encoding(struct Body *a, struct ConfigSubset *sub)
Update the encoding type.
Definition: sendlib.c:903
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe()
Definition: imap.c:2378
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 Body * body
List of MIME parts.
Definition: email.h:91
&#39;NNTP&#39; (Usenet) Mailbox type
Definition: mailbox.h:52
static int include_forward(struct Mailbox *m, struct Email *e, FILE *fp_out, struct ConfigSubset *sub)
Write out a forwarded message.
Definition: send.c:454
Structs that make up an email.
String processing routines to generate the mail index.
void mutt_generate_recvattach_list(struct AttachCtx *actx, struct Email *e, struct Body *parts, FILE *fp, int parent_type, int level, bool decrypted)
Create a list of attachments.
Definition: recvattach.c:1359
The "currently-open" mailbox.
struct AddressList reply_to
Email&#39;s &#39;reply-to&#39;.
Definition: envelope.h:62
Autocrypt end-to-end encryption.
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:84
int mutt_addrlist_parse(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:458
User aborted the question (with Ctrl-G)
Definition: quad.h:38
#define mutt_message(...)
Definition: logging.h:83
int emaillist_add_email(struct EmailList *el, struct Email *e)
Add an Email to a list.
Definition: email.c:148
struct Email * email
Used by recvattach for updating.
Definition: attach.h:51
static void add_references(struct ListHead *head, struct Envelope *env)
Add the email&#39;s references to a list.
Definition: send.c:843
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:40
int mutt_addrlist_to_local(struct AddressList *al)
Convert an Address list from Punycode.
Definition: address.c:1386
struct AddressList bcc
Email&#39;s &#39;Bcc&#39; list.
Definition: envelope.h:60
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1468
#define SEND_DRAFT_FILE
Used by the -H flag.
Definition: send.h:51
static int postpone_message(struct Email *e_post, struct Email *e_cur, const char *fcc, SendFlags flags, struct ConfigSubset *sub)
Save an Email for another day.
Definition: send.c:1812
int mutt_write_mime_body(struct Body *a, FILE *fp, struct ConfigSubset *sub)
Write a MIME part.
Definition: body.c:314
static char * nntp_get_header(const char *s)
Get the trimmed header.
Definition: send.c:310
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:85
void mutt_expand_aliases_env(struct Envelope *env)
Expand aliases in all the fields of an Envelope.
Definition: alias.c:308
static size_t plen
Length of cached packet.
Definition: pgppacket.c:39
static void process_user_header(struct Envelope *env)
Process the user headers.
Definition: send.c:348
bool mutt_is_mail_list(const struct Address *addr)
Is this the email address of a mailing list? - Implements addr_predicate_t.
Definition: maillist.c:45
bool mutt_should_hide_protected_subject(struct Email *e)
Should NeoMutt hide the protected subject?
Definition: crypt.c:1073
#define SEND_FORWARD
Forward email.
Definition: send.h:44
int mutt_write_fcc(const char *path, struct Email *e, const char *msgid, bool post, const char *fcc, char **finalpath, struct ConfigSubset *sub)
Write email to FCC mailbox.
Definition: sendlib.c:1507
NeoMutt Logging.
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:737
regex_t * regex
compiled expression
Definition: regex3.h:91
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
static int invoke_mta(struct Email *e, struct ConfigSubset *sub)
Send an email.
Definition: send.c:1355
int mutt_edit_attachment(struct Body *a)
Edit an attachment.
Definition: mutt_attach.c:258
FILE * fp_root
Used by recvattach for updating.
Definition: attach.h:52
#define MUTT_CM_WEED
Weed message/rfc822 attachment headers.
Definition: copy.h:40
String manipulation buffer.
Definition: buffer.h:33
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:728
void mutt_parse_mime_message(struct Mailbox *m, struct Email *e)
Parse a MIME email.
Definition: mutt_parse.c:48
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:375
int mutt_copy_message(FILE *fp_out, struct Mailbox *m, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Copy a message from a Mailbox.
Definition: copy.c:830
struct ListHead userhdrs
user defined headers
Definition: envelope.h:83
#define _(a)
Definition: message.h:28
struct Address * mutt_addr_new(void)
Create a new Address.
Definition: address.c:385
char * real_subj
Offset of the real subject.
Definition: envelope.h:67
static void add_message_id(struct ListHead *head, struct Envelope *env)
Add the email&#39;s message ID to a list.
Definition: send.c:859
static void append_signature(FILE *fp, struct ConfigSubset *sub)
Append a signature to an email.
Definition: send.c:92
struct Body * next
next attachment in the list
Definition: body.h:53
short idxlen
Number of attachmentes.
Definition: attach.h:55
An email address.
Definition: address.h:34
8-bit text
Definition: mime.h:50
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:48
char * mailbox
Mailbox and host address.
Definition: address.h:37
#define SEC_AUTOCRYPT
(Autocrypt) Message will be, or was Autocrypt encrypt+signed
Definition: lib.h:94
#define MUTT_MESSAGE_HOOK
message-hook: run before displaying a message
Definition: hook.h:52
uint16_t CopyMessageFlags
Flags for mutt_copy_message(), e.g. MUTT_CM_NOHEADER.
Definition: copy.h:31
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address config item by name.
Definition: helpers.c:47
struct Address * mutt_addr_copy(const struct Address *addr)
Copy the real address.
Definition: address.c:716
int crypt_get_keys(struct Email *e, char **keylist, bool oppenc_mode)
Check we have all the keys we need.
Definition: crypt.c:943
int mutt_addrlist_parse2(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:616
uint16_t SendFlags
Flags for mutt_send_message(), e.g. SEND_REPLY.
Definition: send.h:37
int mutt_env_to_intl(struct Envelope *env, const char **tag, char **err)
Convert an Envelope&#39;s Address fields to Punycode format.
Definition: envelope.c:309
int cs_subset_str_string_set(const struct ConfigSubset *sub, const char *name, const char *value, struct Buffer *err)
Set a config item by string.
Definition: subset.c:395
#define MUTT_CM_NO_FLAGS
No flags are set.
Definition: copy.h:34
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:440
struct Address * mutt_addr_create(const char *personal, const char *mailbox)
Create and populate a new Address.
Definition: address.c:398
#define SEND_POSTPONED
Recall a postponed email.
Definition: send.h:45
int mutt_is_subscribed_list_recipient(bool all_addr, struct Envelope *e)
Matches subscribed mailing lists.
Definition: exec.c:383
char * AutocryptDefaultKey
Autocrypt default key id (used for postponing messages)
Definition: config.c:43
void mutt_buffer_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:598
#define MUTT_CM_REPLYING
Replying the message.
Definition: copy.h:43
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:91
Messages that have been replied to.
Definition: mutt.h:95
The body of an email.
Definition: body.h:34
unsigned int disposition
content-disposition, ContentDisposition
Definition: body.h:67
Convenience wrapper for the config headers.
Prepare and send an email.
Email Address Handling.
#define SEC_INLINE
Email has an inline signature.
Definition: lib.h:92
static int default_to(struct AddressList *to, struct Envelope *env, SendFlags flags, int hmfupto, struct ConfigSubset *sub)
Generate default email addresses.
Definition: send.c:698
WHERE char * Username
User&#39;s login name.
Definition: mutt_globals.h:52
struct Body * mutt_body_new(void)
Create a new Body.
Definition: body.c:43
Some miscellaneous functions.
const struct Regex * cs_subset_regex(const struct ConfigSubset *sub, const char *name)
Get a regex config item by name.
Definition: helpers.c:175
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition: subset.c:292
#define mutt_array_size(x)
Definition: memory.h:33
static int generate_body(FILE *fp_tmp, struct Email *e, SendFlags flags, struct Mailbox *m, struct EmailList *el, struct ConfigSubset *sub)
Create a new email body.
Definition: send.c:1081
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
Definition: mx.c:1206
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:134
void mutt_addrlist_dedupe(struct AddressList *al)
Remove duplicate addresses.
Definition: address.c:1405
bool read
Email is read.
Definition: email.h:51
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1446
static void make_reference_headers(struct EmailList *el, struct Envelope *env, struct ConfigSubset *sub)
Generate reference headers for an email.
Definition: send.c:970
struct ListHead in_reply_to
in-reply-to header content
Definition: envelope.h:82
char * message_id
Message ID.
Definition: envelope.h:69
struct Mailbox * mailbox
Definition: context.h:50
void mutt_prepare_envelope(struct Envelope *env, bool final, struct ConfigSubset *sub)
Prepare an email header.
Definition: sendlib.c:1237
Parse and execute user-defined hooks.
static const struct AddressList * choose_default_to(const struct Address *from, const struct Envelope *env, struct ConfigSubset *sub)
Pick the best &#39;to:&#39; value.
Definition: send.c:672
bool mutt_parse_mailto(struct Envelope *e, char **body, const char *src)
Parse a mailto:// url.
Definition: parse.c:1591
Many unsorted constants and some structs.
API for mailboxes.
bool old
Email is seen, but unread.
Definition: email.h:50
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
Definition: queue.h:738
void rfc2047_decode(char **pd)
Decode any RFC2047-encoded header fields.
Definition: rfc2047.c:639
#define MUTT_COMP_NO_FLAGS
No flags are set.
Definition: mutt.h:56
struct AddressList from
Email&#39;s &#39;From&#39; list.
Definition: envelope.h:57
static void process_user_recips(struct Envelope *env)
Process the user headers.
Definition: send.c:321
#define CH_WEED
Weed the headers?
Definition: copy.h:52
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
struct Envelope * env
Envelope information.
Definition: email.h:90
Convenience wrapper for the core headers.
int mutt_body_copy(FILE *fp, struct Body **tgt, struct Body *src)
Create a send-mode duplicate from a receive-mode body.
Definition: mutt_body.c:48
static void decode_descriptions(struct Body *b)
rfc2047 decode them in case of an error
Definition: send.c:1462
struct ListNode * mutt_list_find(const struct ListHead *h, const char *data)
Find a string in a List.
Definition: list.c:102
#define SKIPWS(ch)
Definition: string2.h:46
struct AddressList cc
Email&#39;s &#39;Cc&#39; list.
Definition: envelope.h:59
A normal Email, write full header + MIME headers.
Definition: header.h:40
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
#define SEND_LIST_REPLY
Reply to mailing list.
Definition: send.h:43
static bool is_reply(struct Email *reply, struct Email *orig)
Is one email a reply to another?
Definition: send.c:1553
Email Aliases.
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
unsigned int encoding
content-transfer-encoding, ContentEncoding
Definition: body.h:66
static bool is_text_plain(const struct Body *b)
is a Body a text/plain MIME part?
Definition: send.c:1924
void * mdata
Driver specific data.
Definition: mailbox.h:136
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition: envelope.c:42
Usenet network mailbox type; talk to an NNTP server.
struct Body * mutt_make_multipart(struct Body *b)
Create a multipart email.
Definition: multipart.c:99
#define SEND_KEY
Mail a PGP public key.
Definition: send.h:47
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:888
int mutt_autocrypt_set_sign_as_default_key(struct Email *e)
Set the Autocrypt default key for signing.
Definition: autocrypt.c:685
char * subtype
content-type subtype
Definition: body.h:37
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:834
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:64
static int inline_forward_attachments(struct Mailbox *m, struct Email *e, struct Body ***plast, enum QuadOption *forwardq, struct ConfigSubset *sub)
Add attachments to an email, inline.
Definition: send.c:504
#define mutt_b2s(buf)
Definition: buffer.h:41
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:98
#define MUTT_CM_PREFIX
Quote the header and body.
Definition: copy.h:36
int mutt_write_multiple_fcc(const char *path, struct Email *e, const char *msgid, bool post, char *fcc, char **finalpath, struct ConfigSubset *sub)
Handle FCC with multiple, comma separated entries.
Definition: sendlib.c:1459
int mutt_multi_choice(const char *prompt, const char *letters)
Offer the user a multiple choice question.
Definition: curs_lib.c:933
Prototypes for many functions.
char * x_comment_to
List of &#39;X-comment-to&#39; fields.
Definition: envelope.h:78
#define SEND_RESEND
Reply using the current email as a template.
Definition: send.h:48
struct ListHead chain
Mixmaster chain.
Definition: email.h:100
Representation of the body of an email.
A set of inherited config items.
Definition: subset.h:46
void mutt_unprepare_envelope(struct Envelope *env)
Undo the encodings of mutt_prepare_envelope()
Definition: sendlib.c:1276
Notmuch virtual mailbox type.
#define mutt_mktemp(buf, buflen)
Definition: muttlib.h:74
struct Body * mutt_remove_multipart(struct Body *b)
Extract the multipart body if it exists.
Definition: multipart.c:125
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:97
A local copy of an email.
Definition: mx.h:83
A mailbox.
Definition: mailbox.h:81
int mutt_is_list_recipient(bool all_addr, struct Envelope *e)
Matches known mailing lists.
Definition: exec.c:396
struct Address * mutt_default_from(struct ConfigSubset *sub)
Get a default &#39;from&#39; Address.
Definition: send.c:1323
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:39
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
void mutt_set_followup_to(struct Envelope *env, struct ConfigSubset *sub)
Set followup-to field.
Definition: send.c:1198
char * mutt_extract_message_id(const char *s, size_t *len)
Find a message-id.
Definition: parse.c:361
void mutt_fix_reply_recipients(struct Envelope *env, struct ConfigSubset *sub)
Remove duplicate recipients.
Definition: send.c:872
#define MUTT_CM_DECODE
Decode the message body into text/plain.
Definition: copy.h:37
struct Body * mutt_make_message_attach(struct Mailbox *m, struct Email *e, bool attach_msg, struct ConfigSubset *sub)
Create a message attachment.
Definition: sendlib.c:935
void mutt_select_fcc(struct Buffer *path, struct Email *e)
Select the FCC path for an email.
Definition: hook.c:692
#define CH_REORDER
Re-order output of headers (specified by &#39;hdr_order&#39;)
Definition: copy.h:58
#define SEC_AUTOCRYPT_OVERRIDE
(Autocrypt) Indicates manual set/unset of encryption
Definition: lib.h:95
Type: &#39;text/*&#39;.
Definition: mime.h:38
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:96
#define MUTT_CM_CHARCONV
Perform character set conversions.
Definition: copy.h:41
bool mutt_can_decode(struct Body *a)
Will decoding the attachment produce any output.
Definition: handler.c:1803
Match patterns to emails.
char * data
Pointer to data.
Definition: buffer.h:35
static void set_reverse_name(struct AddressList *al, struct Envelope *env, struct ConfigSubset *sub)
Try to set the &#39;from&#39; field from the recipients.
Definition: send.c:1271
bool mutt_addr_cmp(const struct Address *a, const struct Address *b)
Compare two e-mail addresses.
Definition: address.c:864
#define CH_DECODE
Do RFC2047 header decoding.
Definition: copy.h:53
void mutt_forward_intro(struct Mailbox *m, struct Email *e, FILE *fp, struct ConfigSubset *sub)
Add the "start of forwarded message" text.
Definition: send.c:400
int mutt_protect(struct Email *e, char *keylist, bool postpone)
Encrypt and/or sign a message.
Definition: crypt.c:159
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
static int save_fcc(struct Email *e, struct Buffer *fcc, struct Body *clear_content, char *pgpkeylist, SendFlags flags, char **finalpath, struct ConfigSubset *sub)
Save an Email to a &#39;sent mail&#39; folder.
Definition: send.c:1618
RFC3676 Format Flowed routines.
FILE * fp
Used in the recvattach menu.
Definition: attach.h:37
void mutt_addrlist_prepend(struct AddressList *al, struct Address *a)
Prepend an Address to an AddressList.
Definition: address.c:1499
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:219
API for encryption/signing of emails.
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
static int include_reply(struct Mailbox *m, struct Email *e, FILE *fp_out, struct ConfigSubset *sub)
Generate the reply text for an email.
Definition: send.c:628
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
Definition: string.c:748
#define SEND_NEWS
Reply to a news article.
Definition: send.h:54
Handling of email attachments.
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:177
int mutt_fetch_recips(struct Envelope *out, struct Envelope *in, SendFlags flags, struct ConfigSubset *sub)
Generate recpients for a reply email.
Definition: send.c:785
struct ListNode * mutt_list_insert_head(struct ListHead *h, char *s)
Insert a string at the beginning of a List.
Definition: list.c:45
int mix_send_message(struct ListHead *chain, const char *tempfile)
Send an email via Mixmaster.
Definition: remailer.c:845
int mutt_smtp_send(const struct AddressList *from, const struct AddressList *to, const struct AddressList *cc, const struct AddressList *bcc, const char *msgfile, bool eightbit, struct ConfigSubset *sub)
Send a message using SMTP.
Definition: smtp.c:759
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
bool mutt_addrlist_search(const struct AddressList *haystack, const struct Address *needle)
Search for an e-mail address in a list.
Definition: address.c:881
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:132
void mutt_update_num_postponed(void)
Force the update of the number of postponed messages.
Definition: postpone.c:202
#define STAILQ_NEXT(elm, field)
Definition: queue.h:397
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib...
Definition: email.h:39
#define SEND_REPLY
Reply to sender.
Definition: send.h:41
NNTP-specific Mailbox data -.
Definition: lib.h:138
Handle mailing lists.
#define SEC_OPPENCRYPT
Opportunistic encrypt mode.
Definition: lib.h:93
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
Definition: helpers.c:153
#define SEND_NO_FREE_HEADER
Used by the -E flag.
Definition: send.h:50
void rfc2047_encode(char **pd, const char *specials, int col, const char *charsets)
RFC-2047-encode a string.
Definition: rfc2047.c:615
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
char * list_post
This stores a mailto URL, or nothing.
Definition: envelope.h:65
int mutt_resend_message(FILE *fp, struct Context *ctx, struct Email *e_cur, struct ConfigSubset *sub)
Resend an email.
Definition: send.c:1503
#define SEC_SIGN
Email is signed.
Definition: lib.h:86
int mutt_addrlist_count_recips(const struct AddressList *al)
Count the number of Addresses with valid recipients.
Definition: address.c:844
bool crypt_has_module_backend(SecurityFlags type)
Is there a crypto backend for a given type?
Definition: cryptglue.c:167
char * personal
Real name of address.
Definition: address.h:36
int mutt_num_postponed(struct Mailbox *m, bool force)
Return the number of postponed messages.
Definition: postpone.c:89
enum QuadOption query_quadoption(enum QuadOption opt, const char *prompt)
Ask the user a quad-question.
Definition: curs_lib.c:517
void mutt_parse_content_type(const char *s, struct Body *ct)
Parse a content type.
Definition: parse.c:425
void mutt_env_to_local(struct Envelope *env)
Convert an Envelope&#39;s Address fields to local format.
Definition: envelope.c:271
void mutt_edit_headers(const char *editor, const char *body, struct Email *e, struct Buffer *fcc)
Let the user edit the message header and body.
Definition: mutt_header.c:167
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:636
void crypt_opportunistic_encrypt(struct Email *e)
Can all recipients be determined.
Definition: crypt.c:1021
struct Body * crypt_pgp_make_key_attachment(void)
Wrapper for CryptModuleSpecs::pgp_make_key_attachment()
Definition: cryptglue.c:303
const char * mutt_fqdn(bool may_hide_host, const struct ConfigSubset *sub)
Get the Fully-Qualified Domain Name.
Definition: sendlib.c:1181
#define SEND_GROUP_REPLY
Reply to all.
Definition: send.h:42
char * data
String.
Definition: list.h:36
char * subject
Email&#39;s subject.
Definition: envelope.h:66
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
Duplicate the structure of an entire email.
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:323
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1304
static int edit_envelope(struct Envelope *en, SendFlags flags, struct ConfigSubset *sub)
Edit Envelope fields.
Definition: send.c:197
Routines for managing attachments.
Log at debug level 1.
Definition: logging.h:40
bool group
Group mailbox?
Definition: address.h:38
char * newsgroups
List of newsgroups.
Definition: envelope.h:75
#define MUTT_SEND2_HOOK
send2-hook: when changing fields in the compose menu
Definition: hook.h:56
void emaillist_clear(struct EmailList *el)
Drop a private list of Emails.
Definition: email.c:127
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:721
bool use_disp
Content-Disposition uses filename= ?
Definition: body.h:68
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
Definition: file.c:271
Ask the user, defaulting to &#39;No&#39;.
Definition: quad.h:41
static void add_mailing_lists(struct AddressList *out, const struct AddressList *t, const struct AddressList *c)
Search Address lists for mailing lists.
Definition: send.c:135
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:451
struct Email * email
Email in the list.
Definition: email.h:125
uint32_t CopyHeaderFlags
Flags for mutt_copy_header(), e.g. CH_UPDATE.
Definition: copy.h:49
Cached regular expression.
Definition: regex3.h:88
#define mutt_error(...)
Definition: logging.h:84
bool mutt_needs_mailcap(struct Body *m)
Does this type need a mailcap entry do display.
Definition: muttlib.c:405
bool mutt_addr_valid_msgid(const char *msgid)
Is this a valid Message ID?
Definition: address.c:764
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
Definition: body.h:69
bool replied
Email has been replied to.
Definition: email.h:54
void mutt_rfc3676_space_stuff(struct Email *e)
Perform RFC3676 space stuffing on an Email.
Definition: rfc3676.c:479
char * followup_to
List of &#39;followup-to&#39; fields.
Definition: envelope.h:77
bool mutt_regex_match(const struct Regex *regex, const char *str)
Shorthand to mutt_regex_capture()
Definition: regex.c:609
FILE * fp
pointer to the message data
Definition: mx.h:85
time_t mutt_file_decrease_mtime(const char *fp, struct stat *st)
Decrease a file&#39;s modification time by 1 second.
Definition: file.c:963
#define MUTT_REPLY_HOOK
reply-hook: when replying to an email
Definition: hook.h:55
int mutt_invoke_sendmail(struct AddressList *from, struct AddressList *to, struct AddressList *cc, struct AddressList *bcc, const char *msg, bool eightbit, struct ConfigSubset *sub)
Run sendmail.
Definition: sendmail.c:315
void mutt_addrlist_remove_xrefs(const struct AddressList *a, struct AddressList *b)
Remove cross-references.
Definition: address.c:1441
#define FREE(x)
Definition: memory.h:40
bool mutt_addr_is_user(const struct Address *addr)
Does the address belong to the user.
Definition: alias.c:544
static bool abort_for_missing_attachments(const struct Body *b, struct ConfigSubset *sub)
Should we abort sending because of missing attachments?
Definition: send.c:1935
int mutt_send_message(SendFlags flags, struct Email *e_templ, const char *tempfile, struct Context *ctx, struct EmailList *el, struct ConfigSubset *sub)
Send an email.
Definition: send.c:1990
#define MUTT_COMPOSE_NOFREEHEADER
Definition: compose.h:35
#define STAILQ_EMPTY(head)
Definition: queue.h:345
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
struct AddressList to
Email&#39;s &#39;To&#39; list.
Definition: envelope.h:58
List of Emails.
Definition: email.h:123
static bool search_attach_keyword(char *filename, struct ConfigSubset *sub)
Search an email for &#39;attachment&#39; keywords.
Definition: send.c:1572
struct Email * email_new(void)
Create a new Email.
Definition: email.c:72
#define TAILQ_NEXT(elm, field)
Definition: queue.h:825
int mutt_is_quote_line(char *line, regmatch_t *pmatch)
Is a line of message text a quote?
Definition: pager.c:964
void mutt_make_misc_reply_headers(struct Envelope *env, struct Envelope *curenv, struct ConfigSubset *sub)
Set subject for a reply.
Definition: send.c:923
Hundreds of global variables to back the user variables.
Handling of global boolean variables.
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
void mutt_message_hook(struct Mailbox *m, struct Email *e, HookFlags type)
Perform a message hook.
Definition: hook.c:573
#define TAILQ_EMPTY(head)
Definition: queue.h:714
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:1100
#define SEND_GROUP_CHAT_REPLY
Reply to all recipients preserving To/Cc.
Definition: send.h:53
#define MUTT_CM_NOHEADER
Don&#39;t copy the message header.
Definition: copy.h:35
WHERE bool OptNewsSend
(pseudo) used to change behavior when posting
Definition: options.h:46
void mutt_forward_trailer(struct Mailbox *m, struct Email *e, FILE *fp, struct ConfigSubset *sub)
Add a "end of forwarded message" text.
Definition: send.c:425
Log at debug level 5.
Definition: logging.h:44
Convenience wrapper for the library headers.
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:588
static void remove_user(struct AddressList *al, bool leave_only)
Remove any address which matches the current user.
Definition: send.c:116
struct ListHead references
message references (in reverse order)
Definition: envelope.h:81
A List node for strings.
Definition: list.h:34
#define TAILQ_SWAP(head1, head2, type, field)
Definition: queue.h:852
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:43
FILE * mutt_open_read(const char *path, pid_t *thepid)
Run a command to read from.
Definition: muttlib.c:1304
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:217
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
Decide how to display email content.
Content is inline.
Definition: mime.h:62
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:53
struct AddressList x_original_to
Email&#39;s &#39;X-Orig-to&#39;.
Definition: envelope.h:64
#define STAILQ_FIRST(head)
Definition: queue.h:347
A set of attachments.
Definition: attach.h:49
void mutt_add_to_reference_headers(struct Envelope *env, struct Envelope *curenv, struct ConfigSubset *sub)
Generate references for a reply email.
Definition: send.c:950
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:54
void mutt_make_post_indent(struct Mailbox *m, struct Email *e, FILE *fp_out, struct ConfigSubset *sub)
Add suffix to replied email text.
Definition: send.c:605
void mutt_edit_file(const char *editor, const char *file)
Let the user edit a file.
Definition: curs_lib.c:355
void mutt_encode_descriptions(struct Body *b, bool recurse, struct ConfigSubset *sub)
rfc2047 encode the content-descriptions
Definition: send.c:1444
size_t mutt_addrlist_write(const struct AddressList *al, char *buf, size_t buflen, bool display)
Write an Address to a buffer.
Definition: address.c:1150
static int envelope_defaults(struct Envelope *env, struct Mailbox *m, struct EmailList *el, SendFlags flags, struct ConfigSubset *sub)
Fill in some defaults for a new email.
Definition: send.c:1009
#define mutt_buffer_enter_fname(prompt, fname, mailbox)
Definition: curs_lib.h:88
struct Message * mx_msg_open(struct Mailbox *m, int msgno)
return a stream pointer for a message
Definition: mx.c:1158
int mutt_get_postponed(struct Context *ctx, struct Email *hdr, struct Email **cur, struct Buffer *fcc)
Recall a postponed message.
Definition: postpone.c:315
Type: &#39;application/*&#39;.
Definition: mime.h:33
int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *e_new, struct Email *e, bool resend)
Prepare a message template.
Definition: postpone.c:655
QuadOption
Possible values for a quad-option.
Definition: quad.h:36
int mutt_edit_address(struct AddressList *al, const char *field, bool expand_aliases)
Edit an email address.
Definition: send.c:162
int mutt_compose_menu(struct Email *e, struct Buffer *fcc, struct Email *e_cur, int flags)
Allow the user to edit the message envelope.
Definition: compose.c:1318
int mutt_rfc822_write_header(FILE *fp, struct Envelope *env, struct Body *attach, enum MuttWriteHeaderMode mode, bool privacy, bool hide_protected_subject, struct ConfigSubset *sub)
Write out one RFC822 header line.
Definition: header.c:573
void mutt_param_set(struct ParameterList *pl, const char *attribute, const char *value)
Set a Parameter.
Definition: parameter.c:110
Support of Mixmaster anonymous remailer.
time_t received
Time when the message was placed in the mailbox.
Definition: email.h:83
#define SEND_BATCH
Send email in batch mode (without user interaction)
Definition: send.h:46
The header of an Email.
Definition: envelope.h:54
void mutt_make_forward_subject(struct Envelope *env, struct Mailbox *m, struct Email *e, struct ConfigSubset *sub)
Create a subject for a forwarded email.
Definition: send.c:903
#define mutt_make_string(BUF, BUFLEN, COLS, S, M, INPGR, E)
Definition: hdrline.h:58
int msgno
Number displayed to the user.
Definition: email.h:87
void mutt_addrlist_append(struct AddressList *al, struct Address *a)
Append an Address to an AddressList.
Definition: address.c:1488
void mutt_buffer_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:265
const char * mutt_get_name(const struct Address *a)
Pick the best name to display from an address.
Definition: sort.c:157
struct Body * body
Attachment.
Definition: attach.h:36