NeoMutt  2020-04-24
Teaching an old dog new tricks
DOXYGEN
postpone.c
Go to the documentation of this file.
1 
30 #include "config.h"
31 #include <stdbool.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <sys/stat.h>
35 #include <time.h>
36 #include <unistd.h>
37 #include "mutt/lib.h"
38 #include "config/lib.h"
39 #include "email/lib.h"
40 #include "core/lib.h"
41 #include "gui/lib.h"
42 #include "mutt.h"
43 #include "context.h"
44 #include "format_flags.h"
45 #include "globals.h"
46 #include "handler.h"
47 #include "hdrline.h"
48 #include "keymap.h"
49 #include "mutt_logging.h"
50 #include "mutt_menu.h"
51 #include "mutt_thread.h"
52 #include "muttlib.h"
53 #include "mx.h"
54 #include "opcodes.h"
55 #include "options.h"
56 #include "protos.h"
57 #include "rfc3676.h"
58 #include "send.h"
59 #include "sendlib.h"
60 #include "sort.h"
61 #include "state.h"
62 #include "ncrypt/lib.h"
63 #ifdef USE_IMAP
64 #include "imap/lib.h"
65 #endif
66 
67 static const struct Mapping PostponeHelp[] = {
68  { N_("Exit"), OP_EXIT },
69  { N_("Del"), OP_DELETE },
70  { N_("Undel"), OP_UNDELETE },
71  { N_("Help"), OP_HELP },
72  { NULL, 0 },
73 };
74 
75 static short PostCount = 0;
76 static bool UpdateNumPostponed = false;
77 
86 int mutt_num_postponed(struct Mailbox *m, bool force)
87 {
88  struct stat st;
89 
90  static time_t LastModify = 0;
91  static char *OldPostponed = NULL;
92 
94  {
95  UpdateNumPostponed = false;
96  force = true;
97  }
98 
99  if (mutt_str_strcmp(C_Postponed, OldPostponed) != 0)
100  {
101  FREE(&OldPostponed);
102  OldPostponed = mutt_str_strdup(C_Postponed);
103  LastModify = 0;
104  force = true;
105  }
106 
107  if (!C_Postponed)
108  return 0;
109 
110  // We currently are in the C_Postponed mailbox so just pick the current status
111  if (m && (mutt_str_strcmp(C_Postponed, m->realpath) == 0))
112  {
113  PostCount = m->msg_count - m->msg_deleted;
114  return PostCount;
115  }
116 
117 #ifdef USE_IMAP
118  /* LastModify is useless for IMAP */
119  if (imap_path_probe(C_Postponed, NULL) == MUTT_IMAP)
120  {
121  if (force)
122  {
123  short newpc;
124 
125  newpc = imap_path_status(C_Postponed, false);
126  if (newpc >= 0)
127  {
128  PostCount = newpc;
129  mutt_debug(LL_DEBUG3, "%d postponed IMAP messages found\n", PostCount);
130  }
131  else
132  mutt_debug(LL_DEBUG3, "using old IMAP postponed count\n");
133  }
134  return PostCount;
135  }
136 #endif
137 
138  if (stat(C_Postponed, &st) == -1)
139  {
140  PostCount = 0;
141  LastModify = 0;
142  return 0;
143  }
144 
145  if (S_ISDIR(st.st_mode))
146  {
147  /* if we have a maildir mailbox, we need to stat the "new" dir */
148  struct Buffer *buf = mutt_buffer_pool_get();
149 
150  mutt_buffer_printf(buf, "%s/new", C_Postponed);
151  if ((access(mutt_b2s(buf), F_OK) == 0) && (stat(mutt_b2s(buf), &st) == -1))
152  {
153  PostCount = 0;
154  LastModify = 0;
156  return 0;
157  }
159  }
160 
161  if (LastModify < st.st_mtime)
162  {
163 #ifdef USE_NNTP
164  int optnews = OptNews;
165 #endif
166  LastModify = st.st_mtime;
167 
168  if (access(C_Postponed, R_OK | F_OK) != 0)
169  return PostCount = 0;
170 #ifdef USE_NNTP
171  if (optnews)
172  OptNews = false;
173 #endif
174  struct Mailbox *m_post = mx_path_resolve(C_Postponed);
175  struct Context *ctx = mx_mbox_open(m_post, MUTT_NOSORT | MUTT_QUIET);
176  if (ctx)
177  {
178  PostCount = ctx->mailbox->msg_count;
179  }
180  else
181  {
182  mailbox_free(&m_post);
183  PostCount = 0;
184  }
185  mx_fastclose_mailbox(m_post);
186  ctx_free(&ctx);
187 #ifdef USE_NNTP
188  if (optnews)
189  OptNews = true;
190 #endif
191  }
192 
193  return PostCount;
194 }
195 
200 {
201  UpdateNumPostponed = true;
202 }
203 
207 static void post_make_entry(char *buf, size_t buflen, struct Menu *menu, int line)
208 {
209  struct Context *ctx = menu->data;
210 
211  mutt_make_string_flags(buf, buflen, menu->win_index->state.cols,
212  NONULL(C_IndexFormat), ctx, ctx->mailbox,
213  ctx->mailbox->emails[line], MUTT_FORMAT_ARROWCURSOR);
214 }
215 
221 static struct Email *select_msg(struct Context *ctx)
222 {
223  int r = -1;
224  bool done = false;
225  char helpstr[1024];
226 
227  struct MuttWindow *dlg =
230 #ifdef USE_DEBUG_WINDOW
231  dlg->name = "postpone";
232 #endif
233  dlg->type = WT_DIALOG;
234  struct MuttWindow *index =
237  index->type = WT_INDEX;
238  struct MuttWindow *ibar = mutt_window_new(
240  ibar->type = WT_INDEX_BAR;
241 
242  if (C_StatusOnTop)
243  {
244  mutt_window_add_child(dlg, ibar);
245  mutt_window_add_child(dlg, index);
246  }
247  else
248  {
249  mutt_window_add_child(dlg, index);
250  mutt_window_add_child(dlg, ibar);
251  }
252 
253  dialog_push(dlg);
254 
255  struct Menu *menu = mutt_menu_new(MENU_POSTPONE);
256 
257  menu->pagelen = index->state.rows;
258  menu->win_index = index;
259  menu->win_ibar = ibar;
260 
261  menu->make_entry = post_make_entry;
262  menu->max = ctx->mailbox->msg_count;
263  menu->title = _("Postponed Messages");
264  menu->data = ctx;
265  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_POSTPONE, PostponeHelp);
267 
268  /* The postponed mailbox is setup to have sorting disabled, but the global
269  * C_Sort variable may indicate something different. Sorting has to be
270  * disabled while the postpone menu is being displayed. */
271  const short orig_sort = C_Sort;
272  C_Sort = SORT_ORDER;
273 
274  while (!done)
275  {
276  const int op = mutt_menu_loop(menu);
277  switch (op)
278  {
279  case OP_DELETE:
280  case OP_UNDELETE:
281  /* should deleted draft messages be saved in the trash folder? */
282  mutt_set_flag(ctx->mailbox, ctx->mailbox->emails[menu->current],
283  MUTT_DELETE, (op == OP_DELETE));
285  if (C_Resolve && (menu->current < menu->max - 1))
286  {
287  menu->oldcurrent = menu->current;
288  menu->current++;
289  if (menu->current >= menu->top + menu->pagelen)
290  {
291  menu->top = menu->current;
292  menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
293  }
294  else
295  menu->redraw |= REDRAW_MOTION_RESYNC;
296  }
297  else
298  menu->redraw |= REDRAW_CURRENT;
299  break;
300 
301  case OP_GENERIC_SELECT_ENTRY:
302  r = menu->current;
303  done = true;
304  break;
305 
306  case OP_EXIT:
307  done = true;
308  break;
309  }
310  }
311 
312  C_Sort = orig_sort;
313  mutt_menu_pop_current(menu);
314  mutt_menu_free(&menu);
315  dialog_pop();
316  mutt_window_free(&dlg);
317 
318  return (r > -1) ? ctx->mailbox->emails[r] : NULL;
319 }
320 
331 int mutt_get_postponed(struct Context *ctx, struct Email *hdr,
332  struct Email **cur, struct Buffer *fcc)
333 {
334  if (!C_Postponed)
335  return -1;
336 
337  struct Email *e = NULL;
338  int rc = SEND_POSTPONED;
339  const char *p = NULL;
340  struct Context *ctx_post = NULL;
341 
342  struct Mailbox *m = mx_path_resolve(C_Postponed);
343  if (ctx && (ctx->mailbox == m))
344  ctx_post = ctx;
345  else
346  ctx_post = mx_mbox_open(m, MUTT_NOSORT);
347 
348  if (!ctx_post)
349  {
350  PostCount = 0;
351  mutt_error(_("No postponed messages"));
352  mailbox_free(&m);
353  return -1;
354  }
355 
356  /* TODO:
357  * mx_mbox_open() for IMAP leaves IMAP_REOPEN_ALLOW set. For the
358  * index this is papered-over because it calls mx_check_mailbox()
359  * every event loop(which resets that flag).
360  *
361  * For a stable-branch fix, I'm doing the same here, to prevent
362  * context changes from occuring behind the scenes and causing
363  * segvs, but probably the flag needs to be reset after downloading
364  * headers in imap_open_mailbox().
365  */
366  mx_mbox_check(ctx_post->mailbox, NULL);
367 
368  if (ctx_post->mailbox->msg_count == 0)
369  {
370  PostCount = 0;
371  if (ctx_post == ctx)
372  ctx_post = NULL;
373  else
374  mx_mbox_close(&ctx_post);
375  mutt_error(_("No postponed messages"));
376  return -1;
377  }
378 
379  if (ctx_post->mailbox->msg_count == 1)
380  {
381  /* only one message, so just use that one. */
382  e = ctx_post->mailbox->emails[0];
383  }
384  else if (!(e = select_msg(ctx_post)))
385  {
386  if (ctx_post == ctx)
387  ctx_post = NULL;
388  else
389  mx_mbox_close(&ctx_post);
390  return -1;
391  }
392 
393  if (mutt_prepare_template(NULL, ctx_post->mailbox, hdr, e, false) < 0)
394  {
395  if (ctx_post != ctx)
396  {
397  mx_fastclose_mailbox(ctx_post->mailbox);
398  FREE(&ctx_post);
399  }
400  return -1;
401  }
402 
403  /* finished with this message, so delete it. */
404  mutt_set_flag(ctx_post->mailbox, e, MUTT_DELETE, true);
405  mutt_set_flag(ctx_post->mailbox, e, MUTT_PURGE, true);
406 
407  /* update the count for the status display */
408  PostCount = ctx_post->mailbox->msg_count - ctx_post->mailbox->msg_deleted;
409 
410  /* avoid the "purge deleted messages" prompt */
411  int opt_delete = C_Delete;
412  C_Delete = MUTT_YES;
413  if (ctx_post == ctx)
414  ctx_post = NULL;
415  else
416  mx_mbox_close(&ctx_post);
417  C_Delete = opt_delete;
418 
419  struct ListNode *np = NULL, *tmp = NULL;
420  STAILQ_FOREACH_SAFE(np, &hdr->env->userhdrs, entries, tmp)
421  {
422  size_t plen = mutt_str_startswith(np->data, "X-Mutt-References:", CASE_IGNORE);
423  if (plen)
424  {
425  /* if a mailbox is currently open, look to see if the original message
426  * the user attempted to reply to is in this mailbox */
427  p = mutt_str_skip_email_wsp(np->data + plen);
428  if (!ctx->mailbox->id_hash)
430  *cur = mutt_hash_find(ctx->mailbox->id_hash, p);
431 
432  if (*cur)
433  rc |= SEND_REPLY;
434  }
435  else if ((plen = mutt_str_startswith(np->data, "X-Mutt-Fcc:", CASE_IGNORE)))
436  {
437  p = mutt_str_skip_email_wsp(np->data + plen);
438  mutt_buffer_strcpy(fcc, p);
440 
441  /* note that x-mutt-fcc was present. we do this because we want to add a
442  * default fcc if the header was missing, but preserve the request of the
443  * user to not make a copy if the header field is present, but empty.
444  * see http://dev.mutt.org/trac/ticket/3653 */
445  rc |= SEND_POSTPONED_FCC;
446  }
447  else if (((WithCrypto & APPLICATION_PGP) != 0) &&
448  /* this is generated by old neomutt versions */
449  (mutt_str_startswith(np->data, "Pgp:", CASE_MATCH) ||
450  /* this is the new way */
451  mutt_str_startswith(np->data, "X-Mutt-PGP:", CASE_MATCH)))
452  {
453  hdr->security = mutt_parse_crypt_hdr(strchr(np->data, ':') + 1, true, APPLICATION_PGP);
454  hdr->security |= APPLICATION_PGP;
455  }
456  else if (((WithCrypto & APPLICATION_SMIME) != 0) &&
457  mutt_str_startswith(np->data, "X-Mutt-SMIME:", CASE_MATCH))
458  {
459  hdr->security = mutt_parse_crypt_hdr(strchr(np->data, ':') + 1, true, APPLICATION_SMIME);
460  hdr->security |= APPLICATION_SMIME;
461  }
462 #ifdef MIXMASTER
463  else if (mutt_str_startswith(np->data, "X-Mutt-Mix:", CASE_MATCH))
464  {
465  mutt_list_free(&hdr->chain);
466 
467  char *t = strtok(np->data + 11, " \t\n");
468  while (t)
469  {
471  t = strtok(NULL, " \t\n");
472  }
473  }
474 #endif
475  else
476  {
477  // skip header removal
478  continue;
479  }
480 
481  // remove the header
482  STAILQ_REMOVE(&hdr->env->userhdrs, np, ListNode, entries);
483  FREE(&np->data);
484  FREE(&np);
485  }
486 
489 
490  return rc;
491 }
492 
500 SecurityFlags mutt_parse_crypt_hdr(const char *p, bool set_empty_signas, SecurityFlags crypt_app)
501 {
502  char smime_cryptalg[1024] = { 0 };
503  char sign_as[1024] = { 0 };
504  char *q = NULL;
505  SecurityFlags flags = SEC_NO_FLAGS;
506 
507  if (!WithCrypto)
508  return SEC_NO_FLAGS;
509 
511  for (; p[0] != '\0'; p++)
512  {
513  switch (p[0])
514  {
515  case 'c':
516  case 'C':
517  q = smime_cryptalg;
518 
519  if (p[1] == '<')
520  {
521  for (p += 2; (p[0] != '\0') && (p[0] != '>') &&
522  (q < (smime_cryptalg + sizeof(smime_cryptalg) - 1));
523  *q++ = *p++)
524  {
525  }
526 
527  if (p[0] != '>')
528  {
529  mutt_error(_("Illegal S/MIME header"));
530  return SEC_NO_FLAGS;
531  }
532  }
533 
534  *q = '\0';
535  break;
536 
537  case 'e':
538  case 'E':
539  flags |= SEC_ENCRYPT;
540  break;
541 
542  case 'i':
543  case 'I':
544  flags |= SEC_INLINE;
545  break;
546 
547  /* This used to be the micalg parameter.
548  *
549  * It's no longer needed, so we just skip the parameter in order
550  * to be able to recall old messages. */
551  case 'm':
552  case 'M':
553  if (p[1] != '<')
554  break;
555 
556  for (p += 2; (p[0] != '\0') && (p[0] != '>'); p++)
557  ;
558  if (p[0] != '>')
559  {
560  mutt_error(_("Illegal crypto header"));
561  return SEC_NO_FLAGS;
562  }
563  break;
564 
565  case 'o':
566  case 'O':
567  flags |= SEC_OPPENCRYPT;
568  break;
569 
570  case 'a':
571  case 'A':
572 #ifdef USE_AUTOCRYPT
573  flags |= SEC_AUTOCRYPT;
574 #endif
575  break;
576 
577  case 'z':
578  case 'Z':
579 #ifdef USE_AUTOCRYPT
580  flags |= SEC_AUTOCRYPT_OVERRIDE;
581 #endif
582  break;
583 
584  case 's':
585  case 'S':
586  flags |= SEC_SIGN;
587  q = sign_as;
588 
589  if (p[1] == '<')
590  {
591  for (p += 2;
592  (p[0] != '\0') && (*p != '>') && (q < (sign_as + sizeof(sign_as) - 1));
593  *q++ = *p++)
594  {
595  }
596 
597  if (p[0] != '>')
598  {
599  mutt_error(_("Illegal crypto header"));
600  return SEC_NO_FLAGS;
601  }
602  }
603 
604  q[0] = '\0';
605  break;
606 
607  default:
608  mutt_error(_("Illegal crypto header"));
609  return SEC_NO_FLAGS;
610  }
611  }
612 
613  /* the cryptalg field must not be empty */
614  if (((WithCrypto & APPLICATION_SMIME) != 0) && *smime_cryptalg)
615  {
616  struct Buffer errmsg = mutt_buffer_make(0);
617  int rc = cs_subset_str_string_set(NeoMutt->sub, "smime_encrypt_with",
618  smime_cryptalg, &errmsg);
619 
620  if ((CSR_RESULT(rc) != CSR_SUCCESS) && !mutt_buffer_is_empty(&errmsg))
621  mutt_error("%s", mutt_b2s(&errmsg));
622 
623  mutt_buffer_dealloc(&errmsg);
624  }
625 
626  /* Set {Smime,Pgp}SignAs, if desired. */
627 
628  if (((WithCrypto & APPLICATION_PGP) != 0) && (crypt_app == APPLICATION_PGP) &&
629  (flags & SEC_SIGN) && (set_empty_signas || *sign_as))
630  {
631  mutt_str_replace(&C_PgpSignAs, sign_as);
632  }
633 
634  if (((WithCrypto & APPLICATION_SMIME) != 0) && (crypt_app == APPLICATION_SMIME) &&
635  (flags & SEC_SIGN) && (set_empty_signas || *sign_as))
636  {
637  mutt_str_replace(&C_SmimeSignAs, sign_as);
638  }
639 
640  return flags;
641 }
642 
655 int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *e_new,
656  struct Email *e, bool resend)
657 {
658  struct Message *msg = NULL;
659  struct Body *b = NULL;
660  FILE *fp_body = NULL;
661  int rc = -1;
662  struct State s = { 0 };
663  SecurityFlags sec_type;
664  struct Envelope *protected_headers = NULL;
665 
666  if (!fp && !(msg = mx_msg_open(m, e->msgno)))
667  return -1;
668 
669  if (!fp)
670  fp = msg->fp;
671 
672  fp_body = fp;
673 
674  /* parse the message header and MIME structure */
675 
676  fseeko(fp, e->offset, SEEK_SET);
677  e_new->offset = e->offset;
678  /* enable header weeding for resent messages */
679  e_new->env = mutt_rfc822_read_header(fp, e_new, true, resend);
680  e_new->content->length = e->content->length;
681  mutt_parse_part(fp, e_new->content);
682 
683  /* If resending a message, don't keep message_id or mail_followup_to.
684  * Otherwise, we are resuming a postponed message, and want to keep those
685  * headers if they exist. */
686  if (resend)
687  {
688  FREE(&e_new->env->message_id);
689  FREE(&e_new->env->mail_followup_to);
690  }
691 
692  /* decrypt pgp/mime encoded messages */
693 
694  if (((WithCrypto & APPLICATION_PGP) != 0) &&
695  (sec_type = mutt_is_multipart_encrypted(e_new->content)))
696  {
697  e_new->security |= sec_type;
698  if (!crypt_valid_passphrase(sec_type))
699  goto bail;
700 
701  mutt_message(_("Decrypting message..."));
702  if ((crypt_pgp_decrypt_mime(fp, &fp_body, e_new->content, &b) == -1) || !b)
703  {
704  goto bail;
705  }
706 
707  mutt_body_free(&e_new->content);
708  e_new->content = b;
709 
710  if (b->mime_headers)
711  {
712  protected_headers = b->mime_headers;
713  b->mime_headers = NULL;
714  }
715 
717  }
718 
719  /* remove a potential multipart/signed layer - useful when
720  * resending messages */
721  if ((WithCrypto != 0) && mutt_is_multipart_signed(e_new->content))
722  {
723  e_new->security |= SEC_SIGN;
724  if (((WithCrypto & APPLICATION_PGP) != 0) &&
726  mutt_param_get(&e_new->content->parameter, "protocol"),
727  "application/pgp-signature") == 0))
728  {
729  e_new->security |= APPLICATION_PGP;
730  }
731  else if (WithCrypto & APPLICATION_SMIME)
732  e_new->security |= APPLICATION_SMIME;
733 
734  /* destroy the signature */
735  mutt_body_free(&e_new->content->parts->next);
736  e_new->content = mutt_remove_multipart(e_new->content);
737 
738  if (e_new->content->mime_headers)
739  {
740  mutt_env_free(&protected_headers);
741  protected_headers = e_new->content->mime_headers;
742  e_new->content->mime_headers = NULL;
743  }
744  }
745 
746  /* We don't need no primary multipart.
747  * Note: We _do_ preserve messages!
748  *
749  * XXX - we don't handle multipart/alternative in any
750  * smart way when sending messages. However, one may
751  * consider this a feature. */
752  if (e_new->content->type == TYPE_MULTIPART)
753  e_new->content = mutt_remove_multipart(e_new->content);
754 
755  s.fp_in = fp_body;
756 
757  struct Buffer *file = mutt_buffer_pool_get();
758 
759  /* create temporary files for all attachments */
760  for (b = e_new->content; b; b = b->next)
761  {
762  /* what follows is roughly a receive-mode variant of
763  * mutt_get_tmp_attachment () from muttlib.c */
764 
765  mutt_buffer_reset(file);
766  if (b->filename)
767  {
768  mutt_buffer_strcpy(file, b->filename);
770  }
771  else
772  {
773  /* avoid Content-Disposition: header with temporary filename */
774  b->use_disp = false;
775  }
776 
777  /* set up state flags */
778 
779  s.flags = 0;
780 
781  if (b->type == TYPE_TEXT)
782  {
783  if (mutt_str_strcasecmp("yes",
784  mutt_param_get(&b->parameter, "x-mutt-noconv")) == 0)
785  {
786  b->noconv = true;
787  }
788  else
789  {
790  s.flags |= MUTT_CHARCONV;
791  b->noconv = false;
792  }
793 
794  mutt_param_delete(&b->parameter, "x-mutt-noconv");
795  }
796 
797  mutt_adv_mktemp(file);
798  s.fp_out = mutt_file_fopen(mutt_b2s(file), "w");
799  if (!s.fp_out)
800  goto bail;
801 
802  if (((WithCrypto & APPLICATION_PGP) != 0) &&
803  ((sec_type = mutt_is_application_pgp(b)) & (SEC_ENCRYPT | SEC_SIGN)))
804  {
805  if (sec_type & SEC_ENCRYPT)
806  {
807  if (!crypt_valid_passphrase(APPLICATION_PGP))
808  goto bail;
809  mutt_message(_("Decrypting message..."));
810  }
811 
812  if (mutt_body_handler(b, &s) < 0)
813  {
814  mutt_error(_("Decryption failed"));
815  goto bail;
816  }
817 
818  if ((b == e_new->content) && !protected_headers)
819  {
820  protected_headers = b->mime_headers;
821  b->mime_headers = NULL;
822  }
823 
824  e_new->security |= sec_type;
825  b->type = TYPE_TEXT;
826  mutt_str_replace(&b->subtype, "plain");
827  mutt_param_delete(&b->parameter, "x-action");
828  }
829  else if (((WithCrypto & APPLICATION_SMIME) != 0) &&
830  ((sec_type = mutt_is_application_smime(b)) & (SEC_ENCRYPT | SEC_SIGN)))
831  {
832  if (sec_type & SEC_ENCRYPT)
833  {
834  if (!crypt_valid_passphrase(APPLICATION_SMIME))
835  goto bail;
836  crypt_smime_getkeys(e_new->env);
837  mutt_message(_("Decrypting message..."));
838  }
839 
840  if (mutt_body_handler(b, &s) < 0)
841  {
842  mutt_error(_("Decryption failed"));
843  goto bail;
844  }
845 
846  e_new->security |= sec_type;
847  b->type = TYPE_TEXT;
848  mutt_str_replace(&b->subtype, "plain");
849  }
850  else
851  mutt_decode_attachment(b, &s);
852 
853  if (mutt_file_fclose(&s.fp_out) != 0)
854  goto bail;
855 
856  mutt_str_replace(&b->filename, mutt_b2s(file));
857  b->unlink = true;
858 
860 
861  mutt_body_free(&b->parts);
862  if (b->email)
863  b->email->content = NULL; /* avoid dangling pointer */
864  }
865 
866  if (C_CryptProtectedHeadersRead && protected_headers && protected_headers->subject &&
867  (mutt_str_strcmp(e_new->env->subject, protected_headers->subject) != 0))
868  {
869  mutt_str_replace(&e_new->env->subject, protected_headers->subject);
870  }
871  mutt_env_free(&protected_headers);
872 
873  /* Fix encryption flags. */
874 
875  /* No inline if multipart. */
876  if ((WithCrypto != 0) && (e_new->security & SEC_INLINE) && e_new->content->next)
877  e_new->security &= ~SEC_INLINE;
878 
879  /* Do we even support multiple mechanisms? */
880  e_new->security &= WithCrypto | ~(APPLICATION_PGP | APPLICATION_SMIME);
881 
882  /* Theoretically, both could be set. Take the one the user wants to set by default. */
883  if ((e_new->security & APPLICATION_PGP) && (e_new->security & APPLICATION_SMIME))
884  {
885  if (C_SmimeIsDefault)
886  e_new->security &= ~APPLICATION_PGP;
887  else
888  e_new->security &= ~APPLICATION_SMIME;
889  }
890 
892 
893  rc = 0;
894 
895 bail:
896 
897  /* that's it. */
899  if (fp_body != fp)
900  mutt_file_fclose(&fp_body);
901  if (msg)
902  mx_msg_close(m, &msg);
903 
904  if (rc == -1)
905  {
906  mutt_env_free(&e_new->env);
907  mutt_body_free(&e_new->content);
908  }
909 
910  return rc;
911 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
Convenience wrapper for the gui headers.
The "current" mailbox.
Definition: context.h:37
void mutt_decode_attachment(struct Body *b, struct State *s)
Decode an email&#39;s attachment.
Definition: handler.c:1803
WHERE bool C_StatusOnTop
Config: Display the status bar at the top.
Definition: globals.h:252
void mutt_stamp_attachment(struct Body *a)
Timestamp an Attachment.
Definition: sendlib.c:1443
char * filename
when sending a message, this is the file to which this structure refers
Definition: body.h:46
Manage keymappings.
#define NONULL(x)
Definition: string2.h:37
struct Envelope * mime_headers
Memory hole protected headers.
Definition: body.h:63
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:399
int msg_count
Total number of messages.
Definition: mailbox.h:91
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
struct Body * mutt_remove_multipart(struct Body *b)
Extract the multipart body if it exists.
Definition: sendlib.c:1772
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:70
#define WithCrypto
Definition: lib.h:163
#define SEND_POSTPONED_FCC
Used by mutt_get_postponed() to signal that the x-mutt-fcc header field was present.
Definition: send.h:97
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
int imap_path_status(const char *path, bool queue)
Refresh the number of total and new messages.
Definition: imap.c:1319
static struct Email * select_msg(struct Context *ctx)
Create a Menu to select a postponed message.
Definition: postpone.c:221
GUI selectable list of items.
Definition: mutt_menu.h:82
#define CSR_RESULT(x)
Definition: set.h:52
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe()
Definition: imap.c:2524
struct AddressList mail_followup_to
Email&#39;s &#39;mail-followup-to&#39;.
Definition: envelope.h:63
int mx_mbox_check(struct Mailbox *m, int *index_hint)
Check for new mail - Wrapper for MxOps::mbox_check()
Definition: mx.c:1104
int msg_deleted
Number of deleted messages.
Definition: mailbox.h:96
#define MUTT_CHARCONV
Do character set conversions.
Definition: state.h:36
int mx_mbox_close(struct Context **ptr)
Save changes and close mailbox.
Definition: mx.c:593
Structs that make up an email.
String processing routines to generate the mail index.
The "currently-open" mailbox.
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:124
Dialog (nested Windows) displayed to the user.
Definition: mutt_window.h:70
#define mutt_message(...)
Definition: logging.h:83
Window uses all available vertical space.
Definition: mutt_window.h:35
int oldcurrent
For driver use only.
Definition: mutt_menu.h:108
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:40
void dialog_pop(void)
Hide a Window from the user.
Definition: mutt_window.c:628
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:125
static size_t plen
Length of cached packet.
Definition: pgppacket.c:39
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
NeoMutt Logging.
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition: mutt_window.c:605
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: format_flags.h:35
struct Body * content
List of MIME parts.
Definition: email.h:90
bool noconv
Don&#39;t do character set conversion.
Definition: body.h:73
void * mutt_hash_find(const struct Hash *table, const char *strkey)
Find the HashElem data in a Hash table element using a key.
Definition: hash.c:378
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
WHERE unsigned char C_Delete
Config: Really delete messages, when the mailbox is closed.
Definition: globals.h:181
String manipulation buffer.
Definition: buffer.h:33
struct ListHead userhdrs
user defined headers
Definition: envelope.h:83
#define _(a)
Definition: message.h:28
struct Body * next
next attachment in the list
Definition: body.h:53
struct Context * mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition: mx.c:255
FILE * fp_out
File to write to.
Definition: state.h:47
Messages to be purged (bypass trash)
Definition: mutt.h:98
A division of the screen.
Definition: mutt_window.h:88
#define SEC_AUTOCRYPT
(Autocrypt) Message will be, or was Autocrypt encrypt+signed
Definition: lib.h:134
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition: lib.h:123
Match case when comparing strings.
Definition: string2.h:67
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Flags to control mutt_expando_format()
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
All user-callable functions.
#define SEND_POSTPONED
Recall a postponed email.
Definition: send.h:92
Container for Accounts, Notifications.
Definition: neomutt.h:35
FILE * fp_in
File to read from.
Definition: state.h:46
void mutt_buffer_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:688
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:123
The body of an email.
Definition: body.h:34
Convenience wrapper for the config headers.
static void post_make_entry(char *buf, size_t buflen, struct Menu *menu, int line)
Format a menu item for the email list - Implements Menu::make_entry()
Definition: postpone.c:207
An Index Window containing a selection list.
Definition: mutt_window.h:74
Prepare and send an email.
Hundreds of global variables to back the user variables.
#define SEC_INLINE
Email has an inline signature.
Definition: lib.h:132
Assorted sorting methods.
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:74
Some miscellaneous functions.
WHERE bool C_SmimeIsDefault
Config: Use SMIME rather than PGP by default.
Definition: globals.h:273
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
Definition: state.h:49
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
Definition: mx.c:1171
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:146
char * message_id
Message ID.
Definition: envelope.h:69
struct Mailbox * mailbox
Definition: context.h:51
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition: crypt.c:459
Many unsorted constants and some structs.
API for mailboxes.
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:60
void mutt_make_string_flags(char *buf, size_t buflen, int cols, const char *s, struct Context *ctx, struct Mailbox *m, struct Email *e, MuttFormatFlags flags)
Create formatted strings using mailbox expandos.
Definition: hdrline.c:1505
struct MuttWindow * win_ibar
Definition: mutt_menu.h:95
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:55
const char * title
Title of this menu.
Definition: mutt_menu.h:84
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:89
Convenience wrapper for the core headers.
void mx_fastclose_mailbox(struct Mailbox *m)
free up memory associated with the Mailbox
Definition: mx.c:414
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
struct Menu * menu
Needed for pattern compilation.
Definition: context.h:47
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition: crypt.c:418
void mutt_rfc3676_space_unstuff(struct Email *e)
Remove RFC3676 space stuffing.
Definition: rfc3676.c:481
WHERE short C_Sort
Config: Sort method for the index.
Definition: sort.h:58
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:359
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:36
Window has a fixed size.
Definition: mutt_window.h:44
const char * help
Quickref for the current menu.
Definition: mutt_menu.h:85
char * subtype
content-type subtype
Definition: body.h:37
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:65
#define REDRAW_MOTION_RESYNC
Redraw any changing the menu selection.
Definition: mutt_menu.h:44
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:58
void mutt_param_delete(struct ParameterList *pl, const char *attribute)
Delete a matching Parameter.
Definition: parameter.c:142
#define mutt_b2s(buf)
Definition: buffer.h:41
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:138
Prototypes for many functions.
SecurityFlags mutt_is_application_pgp(struct Body *m)
Does the message use PGP?
Definition: crypt.c:565
struct ListHead chain
Mixmaster chain.
Definition: email.h:99
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:93
WHERE bool C_CryptOpportunisticEncrypt
Config: Enable encryption when the recipient&#39;s key is available.
Definition: globals.h:268
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:137
#define REDRAW_STATUS
Redraw the status bar.
Definition: mutt_menu.h:46
A local copy of an email.
Definition: mx.h:83
struct MuttWindow * mutt_window_new(enum MuttWindowOrientation orient, enum MuttWindowSize size, int rows, int cols)
Create a new Window.
Definition: mutt_window.c:56
Create/manipulate threading in emails.
LOFF_T length
length (in bytes) of attachment
Definition: body.h:45
WHERE char * C_IndexFormat
Config: printf-like format string for the index menu (emails)
Definition: globals.h:114
Messages to be deleted.
Definition: mutt.h:96
A mailbox.
Definition: mailbox.h:81
#define MUTT_NOSORT
Do not sort the mailbox after opening it.
Definition: mx.h:53
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:49
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:57
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:107
#define SEC_AUTOCRYPT_OVERRIDE
(Autocrypt) Indicates manual set/unset of encryption
Definition: lib.h:135
Type: &#39;text/*&#39;.
Definition: mime.h:38
WHERE bool C_Resolve
Config: Move to the next email whenever a command modifies an email.
Definition: globals.h:243
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:96
void crypt_smime_getkeys(struct Envelope *env)
Wrapper for CryptModuleSpecs::smime_getkeys()
Definition: cryptglue.c:460
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
static short PostCount
Definition: postpone.c:75
RFC3676 Format Flowed routines.
GUI present the user with a selectable list.
API for encryption/signing of emails.
Ignore case when comparing strings.
Definition: string2.h:68
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
Definition: string.c:802
SecurityFlags mutt_is_application_smime(struct Body *m)
Does the message use S/MIME?
Definition: crypt.c:624
#define MUTT_QUIET
Do not print any messages.
Definition: mx.h:56
void mutt_update_num_postponed(void)
Force the update of the number of postponed messages.
Definition: postpone.c:199
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:91
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib...
Definition: email.h:39
WHERE bool C_CryptProtectedHeadersRead
Config: Display protected headers (Memory Hole) in the pager.
Definition: globals.h:270
#define SEND_REPLY
Reply to sender.
Definition: send.h:88
struct Hash * mutt_make_id_hash(struct Mailbox *m)
Create a Hash Table for message-ids.
Definition: mutt_thread.c:1456
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:455
#define SEC_OPPENCRYPT
Opportunistic encrypt mode.
Definition: lib.h:133
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
unsigned int type
content-type primary type
Definition: body.h:65
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:473
LOFF_T offset
Where in the stream does this message begin?
Definition: email.h:83
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
#define SEC_SIGN
Email is signed.
Definition: lib.h:126
Keep track when processing files.
int mutt_num_postponed(struct Mailbox *m, bool force)
Return the number of postponed messages.
Definition: postpone.c:86
void mutt_parse_part(FILE *fp, struct Body *b)
Parse a MIME part.
Definition: parse.c:1407
SecurityFlags mutt_parse_crypt_hdr(const char *p, bool set_empty_signas, SecurityFlags crypt_app)
Parse a crypto header string.
Definition: postpone.c:500
void crypt_opportunistic_encrypt(struct Email *e)
Can all recipients be determined.
Definition: crypt.c:1036
int crypt_pgp_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition: cryptglue.c:212
char * data
String.
Definition: list.h:35
char * subject
Email&#39;s subject.
Definition: envelope.h:66
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
bool use_disp
Content-Disposition uses filename= ?
Definition: body.h:68
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:42
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define mutt_error(...)
Definition: logging.h:84
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
Definition: body.h:69
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:654
FILE * fp
pointer to the message data
Definition: mx.h:85
void mutt_adv_mktemp(struct Buffer *buf)
Create a temporary file.
Definition: muttlib.c:94
#define FREE(x)
Definition: memory.h:40
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
Definition: mx.c:1655
void * data
Extra data for the current menu.
Definition: mutt_menu.h:86
static bool UpdateNumPostponed
Definition: postpone.c:76
Mapping between user-readable string and a constant.
Definition: mapping.h:29
Keep track when processing files.
Definition: state.h:44
int mutt_body_handler(struct Body *b, struct State *s)
Handler for the Body of an email.
Definition: handler.c:1550
char * d_filename
filename to be used for the content-disposition header.
Definition: body.h:47
void ctx_free(struct Context **ptr)
Free a Context.
Definition: context.c:48
Handling of global boolean variables.
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
Miscellaneous functions for sending an email.
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:38
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
int const char * file
Definition: acutest.h:617
int const char int line
Definition: acutest.h:617
int current
Current entry.
Definition: mutt_menu.h:87
WHERE char * C_Postponed
Config: Folder to store postponed messages.
Definition: globals.h:135
WHERE char * C_PgpSignAs
Config: Use this alternative key for signing messages.
Definition: globals.h:161
struct MuttWindow * win_index
Definition: mutt_menu.h:94
Convenience wrapper for the library headers.
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:588
char * mutt_compile_help(char *buf, size_t buflen, enum MenuType menu, const struct Mapping *items)
Create the text for the help menu.
Definition: help.c:116
WHERE char * C_SmimeSignAs
Config: Use this alternative key for signing messages.
Definition: globals.h:165
A List node for strings.
Definition: list.h:33
Window wants as much space as possible.
Definition: mutt_window.h:45
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
Decide how to display email content.
struct Envelope * mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed)
parses an RFC822 header
Definition: parse.c:1137
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:53
#define N_(a)
Definition: message.h:32
struct Email * email
header information for message/rfc822
Definition: body.h:55
Index Bar containing status info about the Index.
Definition: mutt_window.h:75
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:103
void(* make_entry)(char *buf, size_t buflen, struct Menu *menu, int line)
Format a item for a menu.
Definition: mutt_menu.h:119
WHERE bool OptNews
(pseudo) used to change reader mode
Definition: options.h:46
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:641
Select a postponed email.
Definition: keymap.h:79
struct Message * mx_msg_open(struct Mailbox *m, int msgno)
return a stream pointer for a message
Definition: mx.c:1123
int mutt_get_postponed(struct Context *ctx, struct Email *hdr, struct Email **cur, struct Buffer *fcc)
Recall a postponed message.
Definition: postpone.c:331
Log at debug level 3.
Definition: logging.h:42
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
struct Hash * id_hash
Hash table by msg id.
Definition: mailbox.h:127
#define REDRAW_CURRENT
Redraw the current line of the menu.
Definition: mutt_menu.h:45
The header of an Email.
Definition: envelope.h:54
int msgno
Number displayed to the user.
Definition: email.h:86