NeoMutt  2024-02-01-23-g345d7b
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
copy.c
Go to the documentation of this file.
1
32#include "config.h"
33#include <ctype.h>
34#include <inttypes.h> // IWYU pragma: keep
35#include <locale.h>
36#include <stdbool.h>
37#include <string.h>
38#include "mutt/lib.h"
39#include "address/lib.h"
40#include "config/lib.h"
41#include "email/lib.h"
42#include "core/lib.h"
43#include "gui/lib.h"
44#include "mutt.h"
45#include "copy.h"
46#include "index/lib.h"
47#include "ncrypt/lib.h"
48#include "pager/lib.h"
49#include "send/lib.h"
50#include "format_flags.h"
51#include "globals.h"
52#include "handler.h"
53#include "hdrline.h"
54#include "mx.h"
55#ifdef USE_NOTMUCH
56#include "notmuch/lib.h"
57#include "muttlib.h"
58#endif
59#ifdef ENABLE_NLS
60#include <libintl.h>
61#endif
62
63static int address_header_decode(char **h);
64static int copy_delete_attach(struct Body *b, FILE *fp_in, FILE *fp_out,
65 const char *quoted_date);
66
67ARRAY_HEAD(HeaderArray, char *);
68
78static void add_one_header(struct HeaderArray *headers, size_t pos, char *value)
79{
80 char **old = ARRAY_GET(headers, pos);
81 if (old && *old)
82 {
83 char *new_value = NULL;
84 mutt_str_asprintf(&new_value, "%s%s", *old, value);
85 FREE(old);
86 FREE(&value);
87 value = new_value;
88 }
89 ARRAY_SET(headers, pos, value);
90}
91
108int mutt_copy_hdr(FILE *fp_in, FILE *fp_out, LOFF_T off_start, LOFF_T off_end,
109 CopyHeaderFlags chflags, const char *prefix, int wraplen)
110{
111 bool from = false;
112 bool this_is_from = false;
113 bool ignore = false;
114 char buf[1024] = { 0 }; /* should be long enough to get most fields in one pass */
115 char *nl = NULL;
116 struct HeaderArray headers = ARRAY_HEAD_INITIALIZER;
117 int hdr_count;
118 int x;
119 char *this_one = NULL;
120 size_t this_one_len = 0;
121
122 if (off_start < 0)
123 return -1;
124
125 if (ftello(fp_in) != off_start)
126 if (!mutt_file_seek(fp_in, off_start, SEEK_SET))
127 return -1;
128
129 buf[0] = '\n';
130 buf[1] = '\0';
131
132 if ((chflags & (CH_REORDER | CH_WEED | CH_MIME | CH_DECODE | CH_PREFIX | CH_WEED_DELIVERED)) == 0)
133 {
134 /* Without these flags to complicate things
135 * we can do a more efficient line to line copying */
136 while (ftello(fp_in) < off_end)
137 {
138 nl = strchr(buf, '\n');
139
140 if (!fgets(buf, sizeof(buf), fp_in))
141 break;
142
143 /* Is it the beginning of a header? */
144 if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
145 {
146 ignore = true;
147 if (!from && mutt_str_startswith(buf, "From "))
148 {
149 if ((chflags & CH_FROM) == 0)
150 continue;
151 from = true;
152 }
153 else if ((chflags & CH_NOQFROM) && mutt_istr_startswith(buf, ">From "))
154 {
155 continue;
156 }
157 else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
158 {
159 break; /* end of header */
160 }
161
162 if ((chflags & (CH_UPDATE | CH_XMIT | CH_NOSTATUS)) &&
163 (mutt_istr_startswith(buf, "Status:") || mutt_istr_startswith(buf, "X-Status:")))
164 {
165 continue;
166 }
167 if ((chflags & (CH_UPDATE_LEN | CH_XMIT | CH_NOLEN)) &&
168 (mutt_istr_startswith(buf, "Content-Length:") ||
169 mutt_istr_startswith(buf, "Lines:")))
170 {
171 continue;
172 }
173 if ((chflags & CH_UPDATE_REFS) && mutt_istr_startswith(buf, "References:"))
174 {
175 continue;
176 }
177 if ((chflags & CH_UPDATE_IRT) && mutt_istr_startswith(buf, "In-Reply-To:"))
178 {
179 continue;
180 }
181 if (chflags & CH_UPDATE_LABEL && mutt_istr_startswith(buf, "X-Label:"))
182 continue;
183 if ((chflags & CH_UPDATE_SUBJECT) && mutt_istr_startswith(buf, "Subject:"))
184 {
185 continue;
186 }
187
188 ignore = false;
189 }
190
191 if (!ignore && (fputs(buf, fp_out) == EOF))
192 return -1;
193 }
194 return 0;
195 }
196
197 hdr_count = 1;
198 x = 0;
199
200 /* We are going to read and collect the headers in an array
201 * so we are able to do re-ordering.
202 * First count the number of entries in the array */
203 if (chflags & CH_REORDER)
204 {
205 struct ListNode *np = NULL;
206 STAILQ_FOREACH(np, &HeaderOrderList, entries)
207 {
208 mutt_debug(LL_DEBUG3, "Reorder list: %s\n", np->data);
209 hdr_count++;
210 }
211 }
212
213 mutt_debug(LL_DEBUG1, "WEED is %sset\n", (chflags & CH_WEED) ? "" : "not ");
214
215 ARRAY_RESERVE(&headers, hdr_count);
216
217 /* Read all the headers into the array */
218 while (ftello(fp_in) < off_end)
219 {
220 nl = strchr(buf, '\n');
221
222 /* Read a line */
223 if (!fgets(buf, sizeof(buf), fp_in))
224 break;
225
226 /* Is it the beginning of a header? */
227 if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
228 {
229 /* Do we have anything pending? */
230 if (this_one)
231 {
232 if (chflags & CH_DECODE)
233 {
234 if (address_header_decode(&this_one) == 0)
235 rfc2047_decode(&this_one);
236 this_one_len = mutt_str_len(this_one);
237
238 /* Convert CRLF line endings to LF */
239 if ((this_one_len > 2) && (this_one[this_one_len - 2] == '\r') &&
240 (this_one[this_one_len - 1] == '\n'))
241 {
242 this_one[this_one_len - 2] = '\n';
243 this_one[this_one_len - 1] = '\0';
244 }
245 }
246
247 add_one_header(&headers, x, this_one);
248 this_one = NULL;
249 }
250
251 ignore = true;
252 this_is_from = false;
253 if (!from && mutt_str_startswith(buf, "From "))
254 {
255 if ((chflags & CH_FROM) == 0)
256 continue;
257 this_is_from = true;
258 from = true;
259 }
260 else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
261 {
262 break; /* end of header */
263 }
264
265 /* note: CH_FROM takes precedence over header weeding. */
266 if (!((chflags & CH_FROM) && (chflags & CH_FORCE_FROM) && this_is_from) &&
267 (chflags & CH_WEED) && mutt_matches_ignore(buf))
268 {
269 continue;
270 }
271 if ((chflags & CH_WEED_DELIVERED) && mutt_istr_startswith(buf, "Delivered-To:"))
272 {
273 continue;
274 }
275 if ((chflags & (CH_UPDATE | CH_XMIT | CH_NOSTATUS)) &&
276 (mutt_istr_startswith(buf, "Status:") || mutt_istr_startswith(buf, "X-Status:")))
277 {
278 continue;
279 }
280 if ((chflags & (CH_UPDATE_LEN | CH_XMIT | CH_NOLEN)) &&
281 (mutt_istr_startswith(buf, "Content-Length:") || mutt_istr_startswith(buf, "Lines:")))
282 {
283 continue;
284 }
285 if ((chflags & CH_MIME))
286 {
287 if (mutt_istr_startswith(buf, "mime-version:"))
288 {
289 continue;
290 }
291 size_t plen = mutt_istr_startswith(buf, "content-");
292 if ((plen != 0) && (mutt_istr_startswith(buf + plen, "transfer-encoding:") ||
293 mutt_istr_startswith(buf + plen, "type:")))
294 {
295 continue;
296 }
297 }
298 if ((chflags & CH_UPDATE_REFS) && mutt_istr_startswith(buf, "References:"))
299 {
300 continue;
301 }
302 if ((chflags & CH_UPDATE_IRT) && mutt_istr_startswith(buf, "In-Reply-To:"))
303 {
304 continue;
305 }
306 if ((chflags & CH_UPDATE_LABEL) && mutt_istr_startswith(buf, "X-Label:"))
307 continue;
308 if ((chflags & CH_UPDATE_SUBJECT) && mutt_istr_startswith(buf, "Subject:"))
309 {
310 continue;
311 }
312
313 /* Find x -- the array entry where this header is to be saved */
314 if (chflags & CH_REORDER)
315 {
316 struct ListNode *np = NULL;
317 x = 0;
318 int match = -1;
319 size_t match_len = 0;
320
321 STAILQ_FOREACH(np, &HeaderOrderList, entries)
322 {
323 size_t hdr_order_len = mutt_str_len(np->data);
324 if (mutt_istrn_equal(buf, np->data, hdr_order_len))
325 {
326 if ((match == -1) || (hdr_order_len > match_len))
327 {
328 match = x;
329 match_len = hdr_order_len;
330 }
331 mutt_debug(LL_DEBUG2, "Reorder: %s matches %s", np->data, buf);
332 }
333 x++;
334 }
335 if (match != -1)
336 x = match;
337 }
338
339 ignore = false;
340 } /* If beginning of header */
341
342 if (!ignore)
343 {
344 mutt_debug(LL_DEBUG2, "Reorder: x = %d; hdr_count = %d\n", x, hdr_count);
345 if (this_one)
346 {
347 size_t blen = mutt_str_len(buf);
348
349 mutt_mem_realloc(&this_one, this_one_len + blen + 1);
350 mutt_strn_copy(this_one + this_one_len, buf, blen, blen + 1);
351 this_one_len += blen;
352 }
353 else
354 {
355 this_one = mutt_str_dup(buf);
356 this_one_len = mutt_str_len(this_one);
357 }
358 }
359 } /* while (ftello (fp_in) < off_end) */
360
361 /* Do we have anything pending? -- XXX, same code as in above in the loop. */
362 if (this_one)
363 {
364 if (chflags & CH_DECODE)
365 {
366 if (address_header_decode(&this_one) == 0)
367 rfc2047_decode(&this_one);
368 this_one_len = mutt_str_len(this_one);
369 }
370
371 add_one_header(&headers, x, this_one);
372 this_one = NULL;
373 }
374
375 /* Now output the headers in order */
376 bool error = false;
377 char **hp = NULL;
378 const short c_wrap = cs_subset_number(NeoMutt->sub, "wrap");
379
380 ARRAY_FOREACH(hp, &headers)
381 {
382 if (!error && hp && *hp)
383 {
384 /* We couldn't do the prefixing when reading because RFC2047
385 * decoding may have concatenated lines. */
386 if (chflags & (CH_DECODE | CH_PREFIX))
387 {
388 const char *pre = (chflags & CH_PREFIX) ? prefix : NULL;
389 wraplen = mutt_window_wrap_cols(wraplen, c_wrap);
390
391 if (mutt_write_one_header(fp_out, 0, *hp, pre, wraplen, chflags, NeoMutt->sub) == -1)
392 {
393 error = true;
394 }
395 }
396 else
397 {
398 if (fputs(*hp, fp_out) == EOF)
399 {
400 error = true;
401 }
402 }
403 }
404
405 FREE(hp);
406 }
407 ARRAY_FREE(&headers);
408
409 if (error)
410 return -1;
411 return 0;
412}
413
425int mutt_copy_header(FILE *fp_in, struct Email *e, FILE *fp_out,
426 CopyHeaderFlags chflags, const char *prefix, int wraplen)
427{
428 char *temp_hdr = NULL;
429
430 if (e->env)
431 {
432 chflags |= ((e->env->changed & MUTT_ENV_CHANGED_IRT) ? CH_UPDATE_IRT : 0) |
436 }
437
438 if (mutt_copy_hdr(fp_in, fp_out, e->offset, e->body->offset, chflags, prefix, wraplen) == -1)
439 return -1;
440
441 if (chflags & CH_TXTPLAIN)
442 {
443 char chsbuf[128] = { 0 };
444 char buf[128] = { 0 };
445 fputs("MIME-Version: 1.0\n", fp_out);
446 fputs("Content-Transfer-Encoding: 8bit\n", fp_out);
447 fputs("Content-Type: text/plain; charset=", fp_out);
448 const char *const c_charset = cc_charset();
449 mutt_ch_canonical_charset(chsbuf, sizeof(chsbuf), c_charset ? c_charset : "us-ascii");
450 mutt_addr_cat(buf, sizeof(buf), chsbuf, MimeSpecials);
451 fputs(buf, fp_out);
452 fputc('\n', fp_out);
453 }
454
455 if ((chflags & CH_UPDATE_IRT) && !STAILQ_EMPTY(&e->env->in_reply_to))
456 {
457 fputs("In-Reply-To:", fp_out);
458 struct ListNode *np = NULL;
459 STAILQ_FOREACH(np, &e->env->in_reply_to, entries)
460 {
461 fputc(' ', fp_out);
462 fputs(np->data, fp_out);
463 }
464 fputc('\n', fp_out);
465 }
466
467 if ((chflags & CH_UPDATE_REFS) && !STAILQ_EMPTY(&e->env->references))
468 {
469 fputs("References:", fp_out);
470 mutt_write_references(&e->env->references, fp_out, 0);
471 fputc('\n', fp_out);
472 }
473
474 if ((chflags & CH_UPDATE) && ((chflags & CH_NOSTATUS) == 0))
475 {
476 if (e->old || e->read)
477 {
478 fputs("Status: ", fp_out);
479 if (e->read)
480 fputs("RO", fp_out);
481 else if (e->old)
482 fputc('O', fp_out);
483 fputc('\n', fp_out);
484 }
485
486 if (e->flagged || e->replied)
487 {
488 fputs("X-Status: ", fp_out);
489 if (e->replied)
490 fputc('A', fp_out);
491 if (e->flagged)
492 fputc('F', fp_out);
493 fputc('\n', fp_out);
494 }
495 }
496
497 if (chflags & CH_UPDATE_LEN && ((chflags & CH_NOLEN) == 0))
498 {
499 fprintf(fp_out, "Content-Length: " OFF_T_FMT "\n", e->body->length);
500 if ((e->lines != 0) || (e->body->length == 0))
501 fprintf(fp_out, "Lines: %d\n", e->lines);
502 }
503
504 const bool c_weed = cs_subset_bool(NeoMutt->sub, "weed");
505#ifdef USE_NOTMUCH
506 if (chflags & CH_VIRTUAL)
507 {
508 /* Add some fake headers based on notmuch data */
509 char *folder = nm_email_get_folder(e);
510 if (folder && !(c_weed && mutt_matches_ignore("folder")))
511 {
512 char buf[1024] = { 0 };
513 mutt_str_copy(buf, folder, sizeof(buf));
514 mutt_pretty_mailbox(buf, sizeof(buf));
515
516 fputs("Folder: ", fp_out);
517 fputs(buf, fp_out);
518 fputc('\n', fp_out);
519 }
520 }
521#endif
522
523 struct Buffer *tags = buf_pool_get();
524 driver_tags_get(&e->tags, tags);
525 if (!buf_is_empty(tags) && !(c_weed && mutt_matches_ignore("tags")))
526 {
527 fputs("Tags: ", fp_out);
528 fputs(buf_string(tags), fp_out);
529 fputc('\n', fp_out);
530 }
531 buf_pool_release(&tags);
532
533 const struct Slist *const c_send_charset = cs_subset_slist(NeoMutt->sub, "send_charset");
534 const short c_wrap = cs_subset_number(NeoMutt->sub, "wrap");
535 if ((chflags & CH_UPDATE_LABEL) && e->env->x_label)
536 {
537 temp_hdr = e->env->x_label;
538 /* env->x_label isn't currently stored with direct references elsewhere.
539 * Mailbox->label_hash strdups the keys. But to be safe, encode a copy */
540 if (!(chflags & CH_DECODE))
541 {
542 temp_hdr = mutt_str_dup(temp_hdr);
543 rfc2047_encode(&temp_hdr, NULL, sizeof("X-Label:"), c_send_charset);
544 }
545 if (mutt_write_one_header(fp_out, "X-Label", temp_hdr, (chflags & CH_PREFIX) ? prefix : 0,
546 mutt_window_wrap_cols(wraplen, c_wrap), chflags,
547 NeoMutt->sub) == -1)
548 {
549 return -1;
550 }
551 if (!(chflags & CH_DECODE))
552 FREE(&temp_hdr);
553 }
554
555 if ((chflags & CH_UPDATE_SUBJECT) && e->env->subject)
556 {
557 temp_hdr = e->env->subject;
558 /* env->subject is directly referenced in Mailbox->subj_hash, so we
559 * have to be careful not to encode (and thus free) that memory. */
560 if (!(chflags & CH_DECODE))
561 {
562 temp_hdr = mutt_str_dup(temp_hdr);
563 rfc2047_encode(&temp_hdr, NULL, sizeof("Subject:"), c_send_charset);
564 }
565 if (mutt_write_one_header(fp_out, "Subject", temp_hdr, (chflags & CH_PREFIX) ? prefix : 0,
566 mutt_window_wrap_cols(wraplen, c_wrap), chflags,
567 NeoMutt->sub) == -1)
568 {
569 return -1;
570 }
571 if (!(chflags & CH_DECODE))
572 FREE(&temp_hdr);
573 }
574
575 if ((chflags & CH_NONEWLINE) == 0)
576 {
577 if (chflags & CH_PREFIX)
578 fputs(prefix, fp_out);
579 fputc('\n', fp_out); /* add header terminator */
580 }
581
582 if (ferror(fp_out) || feof(fp_out))
583 return -1;
584
585 return 0;
586}
587
599static int count_delete_lines(FILE *fp, struct Body *b, LOFF_T *length, size_t datelen)
600{
601 int dellines = 0;
602
603 if (b->deleted)
604 {
605 if (!mutt_file_seek(fp, b->offset, SEEK_SET))
606 {
607 return -1;
608 }
609 for (long l = b->length; l; l--)
610 {
611 const int ch = getc(fp);
612 if (ch == EOF)
613 break;
614 if (ch == '\n')
615 dellines++;
616 }
617 /* 3 and 89 come from the added header of three lines in
618 * copy_delete_attach(). 89 is the size of the header(including
619 * the newlines, tabs, and a single digit length), not including
620 * the date length. */
621 dellines -= 3;
622 *length -= b->length - (89 + datelen);
623 /* Count the number of digits exceeding the first one to write the size */
624 for (long l = 10; b->length >= l; l *= 10)
625 (*length)++;
626 }
627 else
628 {
629 for (b = b->parts; b; b = b->next)
630 {
631 const int del = count_delete_lines(fp, b, length, datelen);
632 if (del == -1)
633 {
634 return -1;
635 }
636 dellines += del;
637 }
638 }
639 return dellines;
640}
641
653int mutt_copy_message_fp(FILE *fp_out, FILE *fp_in, struct Email *e,
654 CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
655{
656 struct Body *body = e->body;
657 struct Buffer *prefix = buf_pool_get();
658 LOFF_T new_offset = -1;
659 int rc = 0;
660
661 if (cmflags & MUTT_CM_PREFIX)
662 {
663 const bool c_text_flowed = cs_subset_bool(NeoMutt->sub, "text_flowed");
664 if (c_text_flowed)
665 {
666 buf_strcpy(prefix, ">");
667 }
668 else
669 {
670 const char *const c_attribution_locale = cs_subset_string(NeoMutt->sub, "attribution_locale");
671 const char *const c_indent_string = cs_subset_string(NeoMutt->sub, "indent_string");
672 struct Mailbox *m_cur = get_current_mailbox();
673 setlocale(LC_TIME, NONULL(c_attribution_locale));
674 mutt_make_string(prefix, wraplen, NONULL(c_indent_string), m_cur, -1, e,
676 setlocale(LC_TIME, "");
677 }
678 }
679
680 if ((cmflags & MUTT_CM_NOHEADER) == 0)
681 {
682 if (cmflags & MUTT_CM_PREFIX)
683 {
684 chflags |= CH_PREFIX;
685 }
686 else if (e->attach_del && (chflags & CH_UPDATE_LEN))
687 {
688 int new_lines;
689 int rc_attach_del = -1;
690 LOFF_T new_length = body->length;
691 struct Buffer *quoted_date = NULL;
692
693 quoted_date = buf_pool_get();
694 buf_addch(quoted_date, '"');
695 mutt_date_make_date(quoted_date, cs_subset_bool(NeoMutt->sub, "local_date_header"));
696 buf_addch(quoted_date, '"');
697
698 /* Count the number of lines and bytes to be deleted */
699 if (!mutt_file_seek(fp_in, body->offset, SEEK_SET))
700 {
701 goto attach_del_cleanup;
702 }
703 const int del = count_delete_lines(fp_in, body, &new_length, buf_len(quoted_date));
704 if (del == -1)
705 {
706 goto attach_del_cleanup;
707 }
708 new_lines = e->lines - del;
709
710 /* Copy the headers */
711 if (mutt_copy_header(fp_in, e, fp_out, chflags | CH_NOLEN | CH_NONEWLINE, NULL, wraplen))
712 goto attach_del_cleanup;
713 fprintf(fp_out, "Content-Length: " OFF_T_FMT "\n", new_length);
714 if (new_lines <= 0)
715 new_lines = 0;
716 else
717 fprintf(fp_out, "Lines: %d\n", new_lines);
718
719 putc('\n', fp_out);
720 if (ferror(fp_out) || feof(fp_out))
721 goto attach_del_cleanup;
722 new_offset = ftello(fp_out);
723
724 /* Copy the body */
725 if (!mutt_file_seek(fp_in, body->offset, SEEK_SET))
726 goto attach_del_cleanup;
727 if (copy_delete_attach(body, fp_in, fp_out, buf_string(quoted_date)))
728 goto attach_del_cleanup;
729
730 buf_pool_release(&quoted_date);
731
732 LOFF_T fail = ((ftello(fp_out) - new_offset) - new_length);
733 if (fail)
734 {
735 mutt_error(ngettext("The length calculation was wrong by %ld byte",
736 "The length calculation was wrong by %ld bytes", fail),
737 (long) fail);
738 new_length += fail;
739 }
740
741 /* Update original message if we are sync'ing a mailfolder */
742 if (cmflags & MUTT_CM_UPDATE)
743 {
744 e->attach_del = false;
745 e->lines = new_lines;
746 body->offset = new_offset;
747
748 body->length = new_length;
749 mutt_body_free(&body->parts);
750 }
751
752 rc_attach_del = 0;
753
754 attach_del_cleanup:
755 buf_pool_release(&quoted_date);
756 rc = rc_attach_del;
757 goto done;
758 }
759
760 if (mutt_copy_header(fp_in, e, fp_out, chflags,
761 (chflags & CH_PREFIX) ? buf_string(prefix) : NULL, wraplen) == -1)
762 {
763 rc = -1;
764 goto done;
765 }
766
767 new_offset = ftello(fp_out);
768 }
769
770 if (cmflags & MUTT_CM_DECODE)
771 {
772 /* now make a text/plain version of the message */
773 struct State state = { 0 };
774 state.fp_in = fp_in;
775 state.fp_out = fp_out;
776 if (cmflags & MUTT_CM_PREFIX)
777 state.prefix = buf_string(prefix);
778 if (cmflags & MUTT_CM_DISPLAY)
779 {
780 state.flags |= STATE_DISPLAY;
781 state.wraplen = wraplen;
782 const char *const c_pager = pager_get_pager(NeoMutt->sub);
783 if (!c_pager)
784 state.flags |= STATE_PAGER;
785 }
786 if (cmflags & MUTT_CM_PRINTING)
787 state.flags |= STATE_PRINTING;
788 if (cmflags & MUTT_CM_WEED)
789 state.flags |= STATE_WEED;
790 if (cmflags & MUTT_CM_CHARCONV)
791 state.flags |= STATE_CHARCONV;
792 if (cmflags & MUTT_CM_REPLYING)
793 state.flags |= STATE_REPLYING;
794
795 if ((WithCrypto != 0) && cmflags & MUTT_CM_VERIFY)
796 state.flags |= STATE_VERIFY;
797
798 rc = mutt_body_handler(body, &state);
799 }
800 else if ((WithCrypto != 0) && (cmflags & MUTT_CM_DECODE_CRYPT) && (e->security & SEC_ENCRYPT))
801 {
802 struct Body *cur = NULL;
803 FILE *fp = NULL;
804
805 if (((WithCrypto & APPLICATION_PGP) != 0) && (cmflags & MUTT_CM_DECODE_PGP) &&
807 {
808 if (crypt_pgp_decrypt_mime(fp_in, &fp, e->body, &cur))
809 {
810 rc = 1;
811 goto done;
812 }
813 fputs("MIME-Version: 1.0\n", fp_out);
814 }
815
816 if (((WithCrypto & APPLICATION_SMIME) != 0) && (cmflags & MUTT_CM_DECODE_SMIME) &&
818 {
819 if (crypt_smime_decrypt_mime(fp_in, &fp, e->body, &cur))
820 {
821 rc = 1;
822 goto done;
823 }
824 }
825
826 if (!cur)
827 {
828 mutt_error(_("No decryption engine available for message"));
829 rc = 1;
830 goto done;
831 }
832
833 mutt_write_mime_header(cur, fp_out, NeoMutt->sub);
834 fputc('\n', fp_out);
835
836 if (!mutt_file_seek(fp, cur->offset, SEEK_SET))
837 {
838 rc = 1;
839 goto done;
840 }
841
842 if (mutt_file_copy_bytes(fp, fp_out, cur->length) == -1)
843 {
844 mutt_file_fclose(&fp);
845 mutt_body_free(&cur);
846 rc = 1;
847 goto done;
848 }
849 mutt_body_free(&cur);
850 mutt_file_fclose(&fp);
851 }
852 else
853 {
854 if (!mutt_file_seek(fp_in, body->offset, SEEK_SET))
855 {
856 rc = 1;
857 goto done;
858 }
859 if (cmflags & MUTT_CM_PREFIX)
860 {
861 int c;
862 size_t bytes = body->length;
863
864 fputs(buf_string(prefix), fp_out);
865
866 while (((c = fgetc(fp_in)) != EOF) && bytes--)
867 {
868 fputc(c, fp_out);
869 if (c == '\n')
870 {
871 fputs(buf_string(prefix), fp_out);
872 }
873 }
874 }
875 else if (mutt_file_copy_bytes(fp_in, fp_out, body->length) == -1)
876 {
877 rc = 1;
878 goto done;
879 }
880 }
881
882 if ((cmflags & MUTT_CM_UPDATE) && ((cmflags & MUTT_CM_NOHEADER) == 0) &&
883 (new_offset != -1))
884 {
885 body->offset = new_offset;
886 mutt_body_free(&body->parts);
887 }
888
889done:
890 buf_pool_release(&prefix);
891 return rc;
892}
893
908int mutt_copy_message(FILE *fp_out, struct Email *e, struct Message *msg,
909 CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
910{
911 if (!msg || !e->body)
912 {
913 return -1;
914 }
915 if (fp_out == msg->fp)
916 {
917 mutt_debug(LL_DEBUG1, "trying to read/write from/to the same FILE*!\n");
918 return -1;
919 }
920
921 int rc = mutt_copy_message_fp(fp_out, msg->fp, e, cmflags, chflags, wraplen);
922 if ((rc == 0) && (ferror(fp_out) || feof(fp_out)))
923 {
924 mutt_debug(LL_DEBUG1, "failed to detect EOF!\n");
925 rc = -1;
926 }
927 return rc;
928}
929
941static int append_message(struct Mailbox *dest, FILE *fp_in, struct Mailbox *src,
942 struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags)
943{
944 char buf[256] = { 0 };
945 struct Message *msg = NULL;
946 int rc;
947
948 if (!mutt_file_seek(fp_in, e->offset, SEEK_SET))
949 return -1;
950 if (!fgets(buf, sizeof(buf), fp_in))
951 return -1;
952
953 msg = mx_msg_open_new(dest, e, is_from(buf, NULL, 0, NULL) ? MUTT_MSG_NO_FLAGS : MUTT_ADD_FROM);
954 if (!msg)
955 return -1;
956 if ((dest->type == MUTT_MBOX) || (dest->type == MUTT_MMDF))
957 chflags |= CH_FROM | CH_FORCE_FROM;
958 chflags |= ((dest->type == MUTT_MAILDIR) ? CH_NOSTATUS : CH_UPDATE);
959 rc = mutt_copy_message_fp(msg->fp, fp_in, e, cmflags, chflags, 0);
960 if (mx_msg_commit(dest, msg) != 0)
961 rc = -1;
962
963#ifdef USE_NOTMUCH
964 if (msg->committed_path && (dest->type == MUTT_MAILDIR) && (src->type == MUTT_NOTMUCH))
965 nm_update_filename(src, NULL, msg->committed_path, e);
966#endif
967
968 mx_msg_close(dest, &msg);
969 return rc;
970}
971
983int mutt_append_message(struct Mailbox *m_dst, struct Mailbox *m_src,
984 struct Email *e, struct Message *msg,
985 CopyMessageFlags cmflags, CopyHeaderFlags chflags)
986{
987 if (!e)
988 return -1;
989
990 const bool own_msg = !msg;
991 if (own_msg && !(msg = mx_msg_open(m_src, e)))
992 {
993 return -1;
994 }
995
996 int rc = append_message(m_dst, msg->fp, m_src, e, cmflags, chflags);
997 if (own_msg)
998 {
999 mx_msg_close(m_src, &msg);
1000 }
1001 return rc;
1002}
1003
1017static int copy_delete_attach(struct Body *b, FILE *fp_in, FILE *fp_out, const char *quoted_date)
1018{
1019 struct Body *part = NULL;
1020
1021 for (part = b->parts; part; part = part->next)
1022 {
1023 if (part->deleted || part->parts)
1024 {
1025 /* Copy till start of this part */
1026 if (mutt_file_copy_bytes(fp_in, fp_out, part->hdr_offset - ftello(fp_in)))
1027 {
1028 return -1;
1029 }
1030
1031 if (part->deleted)
1032 {
1033 /* If this is modified, count_delete_lines() needs to be changed too */
1034 fprintf(fp_out,
1035 "Content-Type: message/external-body; access-type=x-mutt-deleted;\n"
1036 "\texpiration=%s; length=" OFF_T_FMT "\n"
1037 "\n",
1038 quoted_date, part->length);
1039 if (ferror(fp_out))
1040 {
1041 return -1;
1042 }
1043
1044 /* Copy the original mime headers */
1045 if (mutt_file_copy_bytes(fp_in, fp_out, part->offset - ftello(fp_in)))
1046 {
1047 return -1;
1048 }
1049
1050 /* Skip the deleted body */
1051 if (!mutt_file_seek(fp_in, part->offset + part->length, SEEK_SET))
1052 {
1053 return -1;
1054 }
1055 }
1056 else
1057 {
1058 if (copy_delete_attach(part, fp_in, fp_out, quoted_date))
1059 {
1060 return -1;
1061 }
1062 }
1063 }
1064 }
1065
1066 /* Copy the last parts */
1067 if (mutt_file_copy_bytes(fp_in, fp_out, b->offset + b->length - ftello(fp_in)))
1068 return -1;
1069
1070 return 0;
1071}
1072
1079static int address_header_decode(char **h)
1080{
1081 char *s = *h;
1082 size_t l;
1083 bool rp = false;
1084
1085 switch (tolower((unsigned char) *s))
1086 {
1087 case 'b':
1088 {
1089 if (!(l = mutt_istr_startswith(s, "bcc:")))
1090 return 0;
1091 break;
1092 }
1093 case 'c':
1094 {
1095 if (!(l = mutt_istr_startswith(s, "cc:")))
1096 return 0;
1097 break;
1098 }
1099 case 'f':
1100 {
1101 if (!(l = mutt_istr_startswith(s, "from:")))
1102 return 0;
1103 break;
1104 }
1105 case 'm':
1106 {
1107 if (!(l = mutt_istr_startswith(s, "mail-followup-to:")))
1108 return 0;
1109 break;
1110 }
1111 case 'r':
1112 {
1113 if ((l = mutt_istr_startswith(s, "return-path:")))
1114 {
1115 rp = true;
1116 break;
1117 }
1118 else if ((l = mutt_istr_startswith(s, "reply-to:")))
1119 {
1120 break;
1121 }
1122 return 0;
1123 }
1124 case 's':
1125 {
1126 if (!(l = mutt_istr_startswith(s, "sender:")))
1127 return 0;
1128 break;
1129 }
1130 case 't':
1131 {
1132 if (!(l = mutt_istr_startswith(s, "to:")))
1133 return 0;
1134 break;
1135 }
1136 default:
1137 return 0;
1138 }
1139
1140 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
1141 mutt_addrlist_parse(&al, s + l);
1142 if (TAILQ_EMPTY(&al))
1143 return 0;
1144
1147 struct Address *a = NULL;
1148 TAILQ_FOREACH(a, &al, entries)
1149 {
1150 if (a->personal)
1151 {
1153 }
1154 }
1155
1156 /* angle brackets for return path are mandated by RFC5322,
1157 * so leave Return-Path as-is */
1158 if (rp)
1159 {
1160 *h = mutt_str_dup(s);
1161 }
1162 else
1163 {
1164 struct Buffer buf = { 0 };
1165 (*h)[l - 1] = '\0';
1166 mutt_addrlist_write_wrap(&al, &buf, *h);
1167 buf_addch(&buf, '\n');
1168 *h = buf.data;
1169 }
1170
1172
1173 FREE(&s);
1174 return 1;
1175}
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1464
void mutt_addr_cat(char *buf, size_t buflen, const char *value, const char *specials)
Copy a string and wrap it in quotes if it contains special characters.
Definition: address.c:708
size_t mutt_addrlist_write_wrap(const struct AddressList *al, struct Buffer *buf, const char *header)
Write an AddressList to a buffer, perform line wrapping.
Definition: address.c:1193
int mutt_addrlist_to_local(struct AddressList *al)
Convert an Address list from Punycode.
Definition: address.c:1382
int mutt_addrlist_parse(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:480
Email Address Handling.
#define ARRAY_SET(head, idx, elem)
Set an element in the array.
Definition: array.h:123
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:189
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
#define ARRAY_HEAD(name, type)
Define a named struct for arrays of elements of a certain type.
Definition: array.h:47
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:204
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:109
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:58
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:508
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:308
void buf_dequote_comment(struct Buffer *buf)
Un-escape characters in an email address comment.
Definition: buffer.c:451
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:258
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:412
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:97
void mutt_pretty_mailbox(char *buf, size_t buflen)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:478
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition: helpers.c:243
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:144
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
Convenience wrapper for the config headers.
const char * cc_charset(void)
Get the cached value of $charset.
Definition: config_cache.c:116
static int append_message(struct Mailbox *dest, FILE *fp_in, struct Mailbox *src, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags)
Appends a copy of the given message to a mailbox.
Definition: copy.c:941
static int address_header_decode(char **h)
Parse an email's headers.
Definition: copy.c:1079
int mutt_copy_header(FILE *fp_in, struct Email *e, FILE *fp_out, CopyHeaderFlags chflags, const char *prefix, int wraplen)
Copy Email header.
Definition: copy.c:425
int mutt_append_message(struct Mailbox *m_dst, struct Mailbox *m_src, struct Email *e, struct Message *msg, CopyMessageFlags cmflags, CopyHeaderFlags chflags)
Append a message.
Definition: copy.c:983
int mutt_copy_hdr(FILE *fp_in, FILE *fp_out, LOFF_T off_start, LOFF_T off_end, CopyHeaderFlags chflags, const char *prefix, int wraplen)
Copy header from one file to another.
Definition: copy.c:108
int mutt_copy_message(FILE *fp_out, struct Email *e, struct Message *msg, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Copy a message from a Mailbox.
Definition: copy.c:908
static int count_delete_lines(FILE *fp, struct Body *b, LOFF_T *length, size_t datelen)
Count lines to be deleted in this email body.
Definition: copy.c:599
static void add_one_header(struct HeaderArray *headers, size_t pos, char *value)
Add a header to a Headers array.
Definition: copy.c:78
int mutt_copy_message_fp(FILE *fp_out, FILE *fp_in, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Make a copy of a message from a FILE pointer.
Definition: copy.c:653
static int copy_delete_attach(struct Body *b, FILE *fp_in, FILE *fp_out, const char *quoted_date)
Copy a message, deleting marked attachments.
Definition: copy.c:1017
Duplicate the structure of an entire email.
#define CH_DECODE
Do RFC2047 header decoding.
Definition: copy.h:56
#define MUTT_CM_WEED
Weed message/rfc822 attachment headers.
Definition: copy.h:43
#define MUTT_CM_REPLYING
Replying the message.
Definition: copy.h:46
#define MUTT_CM_PREFIX
Quote the header and body.
Definition: copy.h:39
#define CH_XMIT
Transmitting this message? (Ignore Lines: and Content-Length:)
Definition: copy.h:57
#define MUTT_CM_UPDATE
Update structs on sync.
Definition: copy.h:42
#define MUTT_CM_VERIFY
Do signature verification.
Definition: copy.h:49
#define CH_PREFIX
Quote header using $indent_string string?
Definition: copy.h:59
#define CH_UPDATE
Update the status and x-status fields?
Definition: copy.h:54
#define CH_NOSTATUS
Suppress the status and x-status fields.
Definition: copy.h:60
#define CH_FROM
Retain the "From " message separator?
Definition: copy.h:58
#define MUTT_CM_DECODE_PGP
Used for decoding PGP messages.
Definition: copy.h:47
#define MUTT_CM_DECODE
Decode the message body into text/plain.
Definition: copy.h:40
#define CH_NONEWLINE
Don't output terminating newline after the header.
Definition: copy.h:62
#define CH_WEED_DELIVERED
Weed eventual Delivered-To headers.
Definition: copy.h:67
#define CH_UPDATE_LABEL
Update X-Label: from email->env->x_label?
Definition: copy.h:73
#define CH_WEED
Weed the headers?
Definition: copy.h:55
#define CH_REORDER
Re-order output of headers (specified by 'hdr_order')
Definition: copy.h:61
#define MUTT_CM_CHARCONV
Perform character set conversions.
Definition: copy.h:44
#define MUTT_CM_DECODE_SMIME
Used for decoding S/MIME messages.
Definition: copy.h:48
#define CH_MIME
Ignore MIME fields.
Definition: copy.h:63
#define CH_UPDATE_REFS
Update References:
Definition: copy.h:71
#define CH_NOQFROM
Ignore ">From " line.
Definition: copy.h:69
uint32_t CopyHeaderFlags
Flags for mutt_copy_header(), e.g. CH_UPDATE.
Definition: copy.h:52
#define CH_UPDATE_LEN
Update Lines: and Content-Length:
Definition: copy.h:64
#define CH_UPDATE_IRT
Update In-Reply-To:
Definition: copy.h:70
#define MUTT_CM_PRINTING
Printing the message - display light.
Definition: copy.h:45
#define CH_FORCE_FROM
Give CH_FROM precedence over CH_WEED?
Definition: copy.h:68
#define MUTT_CM_DECODE_CRYPT
Definition: copy.h:50
#define MUTT_CM_NOHEADER
Don't copy the message header.
Definition: copy.h:38
#define CH_TXTPLAIN
Generate text/plain MIME headers.
Definition: copy.h:65
uint16_t CopyMessageFlags
Flags for mutt_copy_message(), e.g. MUTT_CM_NOHEADER.
Definition: copy.h:36
#define CH_VIRTUAL
Write virtual header lines too.
Definition: copy.h:75
#define CH_UPDATE_SUBJECT
Update Subject: protected header update.
Definition: copy.h:74
#define CH_NOLEN
Don't write Content-Length: and Lines:
Definition: copy.h:66
#define MUTT_CM_DISPLAY
Output is displayed to the user.
Definition: copy.h:41
Convenience wrapper for the core headers.
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition: mailbox.h:51
@ MUTT_MMDF
'mmdf' Mailbox type
Definition: mailbox.h:46
@ MUTT_MBOX
'mbox' Mailbox type
Definition: mailbox.h:45
@ MUTT_MAILDIR
'Maildir' Mailbox type
Definition: mailbox.h:48
int crypt_pgp_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition: cryptglue.c:210
int crypt_smime_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition: cryptglue.c:432
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:58
Structs that make up an email.
bool mutt_matches_ignore(const char *s)
Does the string match the ignore list.
Definition: parse.c:320
#define MUTT_ENV_CHANGED_SUBJECT
Protected header update.
Definition: envelope.h:37
#define MUTT_ENV_CHANGED_XLABEL
X-Label edited.
Definition: envelope.h:36
#define MUTT_ENV_CHANGED_IRT
In-Reply-To changed to link/break threads.
Definition: envelope.h:34
#define MUTT_ENV_CHANGED_REFS
References changed to break thread.
Definition: envelope.h:35
int mutt_file_copy_bytes(FILE *fp_in, FILE *fp_out, size_t size)
Copy some content from one file to another.
Definition: file.c:252
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
Definition: file.c:771
#define mutt_file_fclose(FP)
Definition: file.h:148
Flags to control mutt_expando_format()
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
bool is_from(const char *s, char *path, size_t pathlen, time_t *tp)
Is a string a 'From' header line?
Definition: from.c:49
struct ListHead HeaderOrderList
List of header fields in the order they should be displayed.
Definition: globals.c:50
Global variables.
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
Convenience wrapper for the gui headers.
int mutt_body_handler(struct Body *b, struct State *state)
Handler for the Body of an email.
Definition: handler.c:1631
Decide how to display email content.
void mutt_make_string(struct Buffer *buf, int cols, const char *s, struct Mailbox *m, int inpgr, struct Email *e, MuttFormatFlags flags, const char *progress)
Create formatted strings using mailbox expandos.
Definition: hdrline.c:1438
String processing routines to generate the mail index.
int mutt_write_mime_header(struct Body *b, FILE *fp, struct ConfigSubset *sub)
Create a MIME header.
Definition: header.c:756
void mutt_write_references(const struct ListHead *r, FILE *fp, size_t trim)
Add the message references to a list.
Definition: header.c:519
int mutt_write_one_header(FILE *fp, const char *tag, const char *value, const char *pfx, int wraplen, CopyHeaderFlags chflags, struct ConfigSubset *sub)
Write one header line to a file.
Definition: header.c:423
GUI manage the main index (list of emails)
struct Mailbox * get_current_mailbox(void)
Get the current Mailbox.
Definition: index.c:715
@ LL_DEBUG3
Log at debug level 3.
Definition: logging2.h:45
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
int nm_update_filename(struct Mailbox *m, const char *old_file, const char *new_file, struct Email *e)
Change the filename.
Definition: notmuch.c:1757
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define FREE(x)
Definition: memory.h:45
const char MimeSpecials[]
Characters that need special treatment in MIME.
Definition: mime.c:67
@ TYPE_MULTIPART
Type: 'multipart/*'.
Definition: mime.h:37
@ TYPE_APPLICATION
Type: 'application/*'.
Definition: mime.h:33
void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name)
Canonicalise the charset of a string.
Definition: charset.c:374
void mutt_date_make_date(struct Buffer *buf, bool local)
Write a date in RFC822 format to a buffer.
Definition: date.c:396
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
#define STATE_PAGER
Output will be displayed in the Pager.
Definition: state.h:42
#define STATE_WEED
Weed headers even when not in display mode.
Definition: state.h:36
#define STATE_DISPLAY
Output is displayed to the user.
Definition: state.h:33
#define STATE_REPLYING
Are we replying?
Definition: state.h:39
#define STATE_VERIFY
Perform signature verification.
Definition: state.h:34
#define STATE_CHARCONV
Do character set conversions.
Definition: state.h:37
#define STATE_PRINTING
Are we printing? - STATE_DISPLAY "light".
Definition: state.h:38
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:852
char * mutt_strn_copy(char *dest, const char *src, size_t len, size_t dsize)
Copy a sub-string into a buffer.
Definition: string.c:409
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:230
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:545
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:630
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:242
bool mutt_istrn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings ignoring case (to a maximum), safely.
Definition: string.c:502
Many unsorted constants and some structs.
int mutt_window_wrap_cols(int width, short wrap)
Calculate the wrap column for a given screen width.
Definition: mutt_window.c:372
Some miscellaneous functions.
int mx_msg_close(struct Mailbox *m, struct Message **ptr)
Close a message.
Definition: mx.c:1178
struct Message * mx_msg_open(struct Mailbox *m, struct Email *e)
Return a stream pointer for a message.
Definition: mx.c:1132
struct Message * mx_msg_open_new(struct Mailbox *m, const struct Email *e, MsgOpenFlags flags)
Open a new message.
Definition: mx.c:1038
int mx_msg_commit(struct Mailbox *m, struct Message *msg)
Commit a message to a folder - Wrapper for MxOps::msg_commit()
Definition: mx.c:1157
API for mailboxes.
#define MUTT_ADD_FROM
add a From_ line
Definition: mx.h:40
#define MUTT_MSG_NO_FLAGS
No flags are set.
Definition: mx.h:39
API for encryption/signing of emails.
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:90
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:91
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:78
#define WithCrypto
Definition: lib.h:116
Notmuch virtual mailbox type.
char * nm_email_get_folder(struct Email *e)
Get the folder for a Email.
Definition: notmuch.c:1469
const char * pager_get_pager(struct ConfigSubset *sub)
Get the value of $pager.
Definition: config.c:105
GUI display a file/email/help in a viewport with paging.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define STAILQ_EMPTY(head)
Definition: queue.h:348
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:637
#define TAILQ_EMPTY(head)
Definition: queue.h:721
void rfc2047_encode(char **pd, const char *specials, int col, const struct Slist *charsets)
RFC-2047-encode a string.
Definition: rfc2047.c:628
void rfc2047_decode(char **pd)
Decode any RFC2047-encoded header fields.
Definition: rfc2047.c:661
void rfc2047_decode_addrlist(struct AddressList *al)
Decode any RFC2047 headers in an Address list.
Definition: rfc2047.c:799
Convenience wrapper for the send headers.
#define NONULL(x)
Definition: string2.h:37
An email address.
Definition: address.h:36
struct Buffer * personal
Real name of address.
Definition: address.h:37
The body of an email.
Definition: body.h:36
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:72
LOFF_T offset
offset where the actual data begins
Definition: body.h:52
bool deleted
Attachment marked for deletion.
Definition: body.h:87
LOFF_T length
length (in bytes) of attachment
Definition: body.h:53
struct Body * next
next attachment in the list
Definition: body.h:71
long hdr_offset
Offset in stream where the headers begin.
Definition: body.h:80
unsigned int type
content-type primary type, ContentType
Definition: body.h:40
String manipulation buffer.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:37
The envelope/body of an email.
Definition: email.h:39
bool read
Email is read.
Definition: email.h:50
struct Envelope * env
Envelope information.
Definition: email.h:68
int lines
How many lines in the body of this message?
Definition: email.h:62
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
Definition: email.h:43
struct Body * body
List of MIME parts.
Definition: email.h:69
bool old
Email is seen, but unread.
Definition: email.h:49
LOFF_T offset
Where in the stream does this message begin?
Definition: email.h:71
bool attach_del
Has an attachment marked for deletion.
Definition: email.h:102
bool flagged
Marked important?
Definition: email.h:47
bool replied
Email has been replied to.
Definition: email.h:51
struct TagList tags
For drivers that support server tagging.
Definition: email.h:72
char *const subject
Email's subject.
Definition: envelope.h:70
unsigned char changed
Changed fields, e.g. MUTT_ENV_CHANGED_SUBJECT.
Definition: envelope.h:90
struct ListHead references
message references (in reverse order)
Definition: envelope.h:83
struct ListHead in_reply_to
in-reply-to header content
Definition: envelope.h:84
char * x_label
X-Label.
Definition: envelope.h:76
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
A mailbox.
Definition: mailbox.h:79
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
A local copy of an email.
Definition: message.h:34
FILE * fp
pointer to the message data
Definition: message.h:35
char * committed_path
the final path generated by mx_msg_commit()
Definition: message.h:37
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
String list.
Definition: slist.h:37
Keep track when processing files.
Definition: state.h:48
int wraplen
Width to wrap lines to (when flags & STATE_DISPLAY)
Definition: state.h:53
StateFlags flags
Flags, e.g. STATE_DISPLAY.
Definition: state.h:52
FILE * fp_out
File to write to.
Definition: state.h:50
FILE * fp_in
File to read from.
Definition: state.h:49
const char * prefix
String to add to the beginning of each output line.
Definition: state.h:51
void driver_tags_get(struct TagList *tl, struct Buffer *tags)
Get tags all tags separated by space.
Definition: tags.c:164