2 * Copyright (C) 1996-2000,2002,2014 Michael R. Elkins <me@mutt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #include "mutt_crypt.h"
30 #include "mutt_idna.h"
31 #include "mutt_curses.h"
36 #include <unistd.h> /* needed for SEEK_SET under SunOS 4.1.4 */
38 static int address_header_decode (char **str);
39 static int copy_delete_attach (BODY *b, FILE *fpin, FILE *fpout, char *date);
41 /* Ok, the only reason for not merging this with mutt_copy_header()
42 * below is to avoid creating a HEADER structure in message_handler().
43 * Also, this one will wrap headers much more aggressively than the other one.
46 mutt_copy_hdr (FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, int flags,
52 char buf[LONG_STRING]; /* should be long enough to get most fields in one pass */
58 char *this_one = NULL;
59 size_t this_one_len = 0;
62 if (ftello (in) != off_start)
63 fseeko (in, off_start, 0);
68 if ((flags & (CH_REORDER | CH_WEED | CH_MIME | CH_DECODE | CH_PREFIX | CH_WEED_DELIVERED)) == 0)
70 /* Without these flags to complicate things
71 * we can do a more efficient line to line copying
73 while (ftello (in) < off_end)
75 nl = strchr (buf, '\n');
77 if ((fgets (buf, sizeof (buf), in)) == NULL)
80 /* Is it the beginning of a header? */
81 if (nl && buf[0] != ' ' && buf[0] != '\t')
84 if (!from && mutt_strncmp ("From ", buf, 5) == 0)
86 if ((flags & CH_FROM) == 0)
90 else if (flags & (CH_NOQFROM) &&
91 ascii_strncasecmp (">From ", buf, 6) == 0)
94 else if (buf[0] == '\n' || (buf[0] == '\r' && buf[1] == '\n'))
95 break; /* end of header */
97 if ((flags & (CH_UPDATE | CH_XMIT | CH_NOSTATUS)) &&
98 (ascii_strncasecmp ("Status:", buf, 7) == 0 ||
99 ascii_strncasecmp ("X-Status:", buf, 9) == 0))
101 if ((flags & (CH_UPDATE_LEN | CH_XMIT | CH_NOLEN)) &&
102 (ascii_strncasecmp ("Content-Length:", buf, 15) == 0 ||
103 ascii_strncasecmp ("Lines:", buf, 6) == 0))
105 if ((flags & CH_UPDATE_REFS) &&
106 ascii_strncasecmp ("References:", buf, 11) == 0)
108 if ((flags & CH_UPDATE_IRT) &&
109 ascii_strncasecmp ("In-Reply-To:", buf, 12) == 0)
111 if ((flags & CH_UPDATE_LABEL) &&
112 ascii_strncasecmp ("X-Label:", buf, 8) == 0)
114 if ((flags & CH_UPDATE_SUBJECT) &&
115 ascii_strncasecmp ("Subject:", buf, 8) == 0)
121 if (!ignore && fputs (buf, out) == EOF)
131 /* We are going to read and collect the headers in an array
132 * so we are able to do re-ordering.
133 * First count the number of entries in the array
135 if (flags & CH_REORDER)
137 for (t = HeaderOrderList; t; t = t->next)
139 dprint(3, (debugfile, "Reorder list: %s\n", t->data));
144 dprint (1, (debugfile, "WEED is %s\n", (flags & CH_WEED) ? "Set" : "Not"));
146 headers = safe_calloc (hdr_count, sizeof (char *));
148 /* Read all the headers into the array */
149 while (ftello (in) < off_end)
151 nl = strchr (buf, '\n');
154 if ((fgets (buf, sizeof (buf), in)) == NULL)
157 /* Is it the beginning of a header? */
158 if (nl && buf[0] != ' ' && buf[0] != '\t')
160 /* Do we have anything pending? */
163 if (flags & CH_DECODE)
165 if (!address_header_decode (&this_one))
166 rfc2047_decode (&this_one);
167 this_one_len = mutt_strlen (this_one);
171 headers[x] = this_one;
174 int hlen = mutt_strlen (headers[x]);
176 safe_realloc (&headers[x], hlen + this_one_len + sizeof (char));
177 strcat (headers[x] + hlen, this_one); /* __STRCAT_CHECKED__ */
186 if (!from && mutt_strncmp ("From ", buf, 5) == 0)
188 if ((flags & CH_FROM) == 0)
190 this_is_from = from = 1;
192 else if (buf[0] == '\n' || (buf[0] == '\r' && buf[1] == '\n'))
193 break; /* end of header */
195 /* note: CH_FROM takes precedence over header weeding. */
196 if (!((flags & CH_FROM) && (flags & CH_FORCE_FROM) && this_is_from) &&
198 mutt_matches_ignore (buf, Ignore) &&
199 !mutt_matches_ignore (buf, UnIgnore))
201 if ((flags & CH_WEED_DELIVERED) &&
202 ascii_strncasecmp ("Delivered-To:", buf, 13) == 0)
204 if ((flags & (CH_UPDATE | CH_XMIT | CH_NOSTATUS)) &&
205 (ascii_strncasecmp ("Status:", buf, 7) == 0 ||
206 ascii_strncasecmp ("X-Status:", buf, 9) == 0))
208 if ((flags & (CH_UPDATE_LEN | CH_XMIT | CH_NOLEN)) &&
209 (ascii_strncasecmp ("Content-Length:", buf, 15) == 0 ||
210 ascii_strncasecmp ("Lines:", buf, 6) == 0))
212 if ((flags & CH_MIME) &&
213 ((ascii_strncasecmp ("content-", buf, 8) == 0 &&
214 (ascii_strncasecmp ("transfer-encoding:", buf + 8, 18) == 0 ||
215 ascii_strncasecmp ("type:", buf + 8, 5) == 0)) ||
216 ascii_strncasecmp ("mime-version:", buf, 13) == 0))
218 if ((flags & CH_UPDATE_REFS) &&
219 ascii_strncasecmp ("References:", buf, 11) == 0)
221 if ((flags & CH_UPDATE_IRT) &&
222 ascii_strncasecmp ("In-Reply-To:", buf, 12) == 0)
224 if ((flags & CH_UPDATE_LABEL) &&
225 ascii_strncasecmp ("X-Label:", buf, 8) == 0)
227 if ((flags & CH_UPDATE_SUBJECT) &&
228 ascii_strncasecmp ("Subject:", buf, 8) == 0)
231 /* Find x -- the array entry where this header is to be saved */
232 if (flags & CH_REORDER)
234 for (t = HeaderOrderList, x = 0 ; (t) ; t = t->next, x++)
236 if (!ascii_strncasecmp (buf, t->data, mutt_strlen (t->data)))
238 dprint(2, (debugfile, "Reorder: %s matches %s\n", t->data, buf));
245 } /* If beginning of header */
249 dprint (2, (debugfile, "Reorder: x = %d; hdr_count = %d\n", x, hdr_count));
252 this_one = safe_strdup (buf);
253 this_one_len = mutt_strlen (this_one);
257 int blen = mutt_strlen (buf);
259 safe_realloc (&this_one, this_one_len + blen + sizeof (char));
260 strcat (this_one + this_one_len, buf); /* __STRCAT_CHECKED__ */
261 this_one_len += blen;
264 } /* while (ftello (in) < off_end) */
266 /* Do we have anything pending? -- XXX, same code as in above in the loop. */
269 if (flags & CH_DECODE)
271 if (!address_header_decode (&this_one))
272 rfc2047_decode (&this_one);
273 this_one_len = mutt_strlen (this_one);
277 headers[x] = this_one;
280 int hlen = mutt_strlen (headers[x]);
282 safe_realloc (&headers[x], hlen + this_one_len + sizeof (char));
283 strcat (headers[x] + hlen, this_one); /* __STRCAT_CHECKED__ */
290 /* Now output the headers in order */
291 for (x = 0; x < hdr_count; x++)
295 /* We couldn't do the prefixing when reading because RFC 2047
296 * decoding may have concatenated lines.
299 if (flags & (CH_DECODE|CH_PREFIX))
301 if (mutt_write_one_header (out, 0, headers[x],
302 flags & CH_PREFIX ? prefix : 0,
303 mutt_window_wrap_cols (MuttIndexWindow, Wrap), flags) == -1)
311 if (fputs (headers[x], out) == EOF)
320 /* Free in a separate loop to be sure that all headers are freed
321 * in case of error. */
322 for (x = 0; x < hdr_count; x++)
332 CH_DECODE RFC2047 header decoding
333 CH_FROM retain the "From " message separator
334 CH_FORCE_FROM give CH_FROM precedence over CH_WEED
335 CH_MIME ignore MIME fields
336 CH_NOLEN don't write Content-Length: and Lines:
337 CH_NONEWLINE don't output a newline after the header
338 CH_NOSTATUS ignore the Status: and X-Status:
339 CH_PREFIX quote header with $indent_str
340 CH_REORDER output header in order specified by `hdr_order'
341 CH_TXTPLAIN generate text/plain MIME headers [hack alert.]
342 CH_UPDATE write new Status: and X-Status:
343 CH_UPDATE_LEN write new Content-Length: and Lines:
344 CH_XMIT ignore Lines: and Content-Length:
345 CH_WEED do header weeding
346 CH_NOQFROM ignore ">From " line
347 CH_UPDATE_IRT update the In-Reply-To: header
348 CH_UPDATE_REFS update the References: header
349 CH_UPDATE_LABEL update the X-Label: header
352 string to use if CH_PREFIX is set
356 mutt_copy_header (FILE *in, HEADER *h, FILE *out, int flags, const char *prefix)
358 char buffer[SHORT_STRING];
359 char *temp_hdr = NULL;
362 flags |= ((h->env->changed & MUTT_ENV_CHANGED_IRT) ? CH_UPDATE_IRT : 0)
363 | ((h->env->changed & MUTT_ENV_CHANGED_REFS) ? CH_UPDATE_REFS : 0)
364 | ((h->env->changed & MUTT_ENV_CHANGED_XLABEL) ? CH_UPDATE_LABEL : 0)
365 | ((h->env->changed & MUTT_ENV_CHANGED_SUBJECT) ? CH_UPDATE_SUBJECT : 0);
367 if (mutt_copy_hdr (in, out, h->offset, h->content->offset, flags, prefix) == -1)
370 if (flags & CH_TXTPLAIN)
372 char chsbuf[SHORT_STRING];
373 fputs ("MIME-Version: 1.0\n", out);
374 fputs ("Content-Transfer-Encoding: 8bit\n", out);
375 fputs ("Content-Type: text/plain; charset=", out);
376 mutt_canonical_charset (chsbuf, sizeof (chsbuf), Charset ? Charset : "us-ascii");
377 rfc822_cat(buffer, sizeof(buffer), chsbuf, MimeSpecials);
382 if ((flags & CH_UPDATE_IRT) && h->env->in_reply_to)
384 LIST *listp = h->env->in_reply_to;
385 fputs ("In-Reply-To:", out);
386 for (; listp; listp = listp->next)
389 fputs (listp->data, out);
394 if ((flags & CH_UPDATE_REFS) && h->env->references)
396 fputs ("References:", out);
397 mutt_write_references (h->env->references, out, 0);
401 if ((flags & CH_UPDATE) && (flags & CH_NOSTATUS) == 0)
403 if (h->old || h->read)
405 fputs ("Status: ", out);
413 if (h->flagged || h->replied)
415 fputs ("X-Status: ", out);
424 if (flags & CH_UPDATE_LEN &&
425 (flags & CH_NOLEN) == 0)
427 fprintf (out, "Content-Length: " OFF_T_FMT "\n", h->content->length);
428 if (h->lines != 0 || h->content->length == 0)
429 fprintf (out, "Lines: %d\n", h->lines);
432 if ((flags & CH_UPDATE_LABEL) && h->env->x_label)
434 temp_hdr = h->env->x_label;
435 /* env->x_label isn't currently stored with direct references
436 * elsewhere. Context->label_hash strdups the keys. But to be
437 * safe, encode a copy */
438 if (!(flags & CH_DECODE))
440 temp_hdr = safe_strdup (temp_hdr);
441 rfc2047_encode_string (&temp_hdr);
443 if (mutt_write_one_header (out, "X-Label", temp_hdr,
444 flags & CH_PREFIX ? prefix : 0,
445 mutt_window_wrap_cols (MuttIndexWindow, Wrap),
448 if (!(flags & CH_DECODE))
452 if ((flags & CH_UPDATE_SUBJECT) && h->env->subject)
454 temp_hdr = h->env->subject;
455 /* env->subject is directly referenced in Context->subj_hash, so we
456 * have to be careful not to encode (and thus free) that memory. */
457 if (!(flags & CH_DECODE))
459 temp_hdr = safe_strdup (temp_hdr);
460 rfc2047_encode_string (&temp_hdr);
462 if (mutt_write_one_header (out, "Subject", temp_hdr,
463 flags & CH_PREFIX ? prefix : 0,
464 mutt_window_wrap_cols (MuttIndexWindow, Wrap),
467 if (!(flags & CH_DECODE))
471 if ((flags & CH_NONEWLINE) == 0)
473 if (flags & CH_PREFIX)
475 fputc ('\n', out); /* add header terminator */
478 if (ferror (out) || feof (out))
484 /* Count the number of lines and bytes to be deleted in this body*/
485 static int count_delete_lines (FILE *fp, BODY *b, LOFF_T *length, size_t datelen)
493 fseeko (fp, b->offset, SEEK_SET);
494 for (l = b->length ; l ; l --)
503 *length -= b->length - (84 + datelen);
504 /* Count the number of digits exceeding the first one to write the size */
505 for (l = 10 ; b->length >= l ; l *= 10)
510 for (b = b->parts ; b ; b = b->next)
511 dellines += count_delete_lines (fp, b, length, datelen);
516 /* make a copy of a message
518 * fpout where to write output
519 * fpin where to get input
520 * hdr header of message being copied
521 * body structure of message being copied
523 * MUTT_CM_NOHEADER don't copy header
524 * MUTT_CM_PREFIX quote header and body
525 * MUTT_CM_DECODE decode message body to text/plain
526 * MUTT_CM_DISPLAY displaying output to the user
527 * MUTT_CM_PRINTING printing the message
528 * MUTT_CM_UPDATE update structures in memory after syncing
529 * MUTT_CM_DECODE_PGP used for decoding PGP messages
530 * MUTT_CM_CHARCONV perform character set conversion
531 * chflags flags to mutt_copy_header()
535 _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body,
536 int flags, int chflags)
538 char prefix[SHORT_STRING];
540 LOFF_T new_offset = -1;
543 if (flags & MUTT_CM_PREFIX)
545 if (option (OPTTEXTFLOWED))
546 strfcpy (prefix, ">", sizeof (prefix));
548 _mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix), Context, hdr, 0);
551 if ((flags & MUTT_CM_NOHEADER) == 0)
553 if (flags & MUTT_CM_PREFIX)
554 chflags |= CH_PREFIX;
556 else if (hdr->attach_del && (chflags & CH_UPDATE_LEN))
559 LOFF_T new_length = body->length;
560 char date[SHORT_STRING];
562 mutt_make_date (date, sizeof (date));
563 date[5] = date[mutt_strlen (date) - 1] = '\"';
565 /* Count the number of lines and bytes to be deleted */
566 fseeko (fpin, body->offset, SEEK_SET);
567 new_lines = hdr->lines -
568 count_delete_lines (fpin, body, &new_length, mutt_strlen (date));
570 /* Copy the headers */
571 if (mutt_copy_header (fpin, hdr, fpout,
572 chflags | CH_NOLEN | CH_NONEWLINE, NULL))
574 fprintf (fpout, "Content-Length: " OFF_T_FMT "\n", new_length);
578 fprintf (fpout, "Lines: %d\n", new_lines);
581 if (ferror (fpout) || feof (fpout))
583 new_offset = ftello (fpout);
586 fseeko (fpin, body->offset, SEEK_SET);
587 if (copy_delete_attach (body, fpin, fpout, date))
592 LOFF_T fail = ((ftello (fpout) - new_offset) - new_length);
596 mutt_error ("The length calculation was wrong by %ld bytes", fail);
603 /* Update original message if we are sync'ing a mailfolder */
604 if (flags & MUTT_CM_UPDATE)
607 hdr->lines = new_lines;
608 body->offset = new_offset;
610 /* update the total size of the mailbox to reflect this deletion */
611 Context->size -= body->length - new_length;
613 * if the message is visible, update the visible size of the mailbox
616 if (Context->v2r[hdr->msgno] != -1)
617 Context->vsize -= body->length - new_length;
619 body->length = new_length;
620 mutt_free_body (&body->parts);
626 if (mutt_copy_header (fpin, hdr, fpout, chflags,
627 (chflags & CH_PREFIX) ? prefix : NULL) == -1)
630 new_offset = ftello (fpout);
633 if (flags & MUTT_CM_DECODE)
635 /* now make a text/plain version of the message */
636 memset (&s, 0, sizeof (STATE));
639 if (flags & MUTT_CM_PREFIX)
641 if (flags & MUTT_CM_DISPLAY)
642 s.flags |= MUTT_DISPLAY;
643 if (flags & MUTT_CM_PRINTING)
644 s.flags |= MUTT_PRINTING;
645 if (flags & MUTT_CM_WEED)
646 s.flags |= MUTT_WEED;
647 if (flags & MUTT_CM_CHARCONV)
648 s.flags |= MUTT_CHARCONV;
649 if (flags & MUTT_CM_REPLYING)
650 s.flags |= MUTT_REPLYING;
652 if (WithCrypto && flags & MUTT_CM_VERIFY)
653 s.flags |= MUTT_VERIFY;
655 rc = mutt_body_handler (body, &s);
658 && (flags & MUTT_CM_DECODE_CRYPT) && (hdr->security & ENCRYPT))
663 if ((WithCrypto & APPLICATION_PGP)
664 && (flags & MUTT_CM_DECODE_PGP) && (hdr->security & APPLICATION_PGP) &&
665 hdr->content->type == TYPEMULTIPART)
667 if (crypt_pgp_decrypt_mime (fpin, &fp, hdr->content, &cur))
669 fputs ("MIME-Version: 1.0\n", fpout);
672 if ((WithCrypto & APPLICATION_SMIME)
673 && (flags & MUTT_CM_DECODE_SMIME) && (hdr->security & APPLICATION_SMIME)
674 && hdr->content->type == TYPEAPPLICATION)
676 if (crypt_smime_decrypt_mime (fpin, &fp, hdr->content, &cur))
682 mutt_error (_("No decryption engine available for message"));
686 mutt_write_mime_header (cur, fpout);
689 fseeko (fp, cur->offset, 0);
690 if (mutt_copy_bytes (fp, fpout, cur->length) == -1)
693 mutt_free_body (&cur);
696 mutt_free_body (&cur);
701 fseeko (fpin, body->offset, 0);
702 if (flags & MUTT_CM_PREFIX)
705 size_t bytes = body->length;
707 fputs(prefix, fpout);
709 while ((c = fgetc(fpin)) != EOF && bytes--)
714 fputs(prefix, fpout);
718 else if (mutt_copy_bytes (fpin, fpout, body->length) == -1)
722 if ((flags & MUTT_CM_UPDATE) && (flags & MUTT_CM_NOHEADER) == 0
725 body->offset = new_offset;
726 mutt_free_body (&body->parts);
732 /* should be made to return -1 on fatal errors, and 1 on non-fatal errors
733 * like partial decode, where it is worth displaying as much as possible */
735 mutt_copy_message (FILE *fpout, CONTEXT *src, HEADER *hdr, int flags,
741 if ((msg = mx_open_message (src, hdr->msgno)) == NULL)
743 if ((r = _mutt_copy_message (fpout, msg->fp, hdr, hdr->content, flags, chflags)) == 0
744 && (ferror (fpout) || feof (fpout)))
746 dprint (1, (debugfile, "_mutt_copy_message failed to detect EOF!\n"));
749 mx_close_message (src, &msg);
753 /* appends a copy of the given message to a mailbox
755 * dest destination mailbox
756 * fpin where to get input
758 * hdr message being copied
759 * body structure of message being copied
760 * flags mutt_copy_message() flags
761 * chflags mutt_copy_header() flags
765 _mutt_append_message (CONTEXT *dest, FILE *fpin, CONTEXT *src, HEADER *hdr,
766 BODY *body, int flags, int chflags)
772 fseeko (fpin, hdr->offset, 0);
773 if (fgets (buf, sizeof (buf), fpin) == NULL)
776 if ((msg = mx_open_new_message (dest, hdr, is_from (buf, NULL, 0, NULL) ? 0 : MUTT_ADD_FROM)) == NULL)
778 if (dest->magic == MUTT_MBOX || dest->magic == MUTT_MMDF)
779 chflags |= CH_FROM | CH_FORCE_FROM;
780 chflags |= (dest->magic == MUTT_MAILDIR ? CH_NOSTATUS : CH_UPDATE);
781 r = _mutt_copy_message (msg->fp, fpin, hdr, body, flags, chflags);
782 if (mx_commit_message (msg, dest) != 0)
785 mx_close_message (dest, &msg);
790 mutt_append_message (CONTEXT *dest, CONTEXT *src, HEADER *hdr, int cmflags,
796 if ((msg = mx_open_message (src, hdr->msgno)) == NULL)
798 r = _mutt_append_message (dest, msg->fp, src, hdr, hdr->content, cmflags, chflags);
799 mx_close_message (src, &msg);
804 * This function copies a message body, while deleting _in_the_copy_
805 * any attachments which are marked for deletion.
806 * Nothing is changed in the original message -- this is left to the caller.
808 * The function will return 0 on success and -1 on failure.
810 static int copy_delete_attach (BODY *b, FILE *fpin, FILE *fpout, char *date)
814 for (part = b->parts ; part ; part = part->next)
816 if (part->deleted || part->parts)
818 /* Copy till start of this part */
819 if (mutt_copy_bytes (fpin, fpout, part->hdr_offset - ftello (fpin)))
825 "Content-Type: message/external-body; access-type=x-mutt-deleted;\n"
826 "\texpiration=%s; length=" OFF_T_FMT "\n"
827 "\n", date + 5, part->length);
831 /* Copy the original mime headers */
832 if (mutt_copy_bytes (fpin, fpout, part->offset - ftello (fpin)))
835 /* Skip the deleted body */
836 fseeko (fpin, part->offset + part->length, SEEK_SET);
840 if (copy_delete_attach (part, fpin, fpout, date))
846 /* Copy the last parts */
847 if (mutt_copy_bytes (fpin, fpout, b->offset + b->length - ftello (fpin)))
854 * This function is the equivalent of mutt_write_address_list(),
855 * but writes to a buffer instead of writing to a stream.
856 * mutt_write_address_list could be re-used if we wouldn't store
857 * all the decoded headers in a huge array, first.
862 static void format_address_header (char **h, ADDRESS *a)
864 char buf[HUGE_STRING];
868 int l, linelen, buflen, count, cbuflen, c2buflen, plen;
870 linelen = mutt_strlen (*h);
872 buflen = linelen + 3;
874 safe_realloc (h, buflen);
875 for (count = 0; a; a = a->next, count++)
877 ADDRESS *tmp = a->next;
879 *buf = *cbuf = *c2buf = '\0';
880 l = rfc822_write_address (buf, sizeof (buf), a, 0);
883 if (count && linelen + l > 74)
885 strcpy (cbuf, "\n\t"); /* __STRCPY_CHECKED__ */
892 strcpy (cbuf, " "); /* __STRCPY_CHECKED__ */
897 if (!a->group && a->next && a->next->mailbox)
901 strcpy (c2buf, ","); /* __STRCPY_CHECKED__ */
904 cbuflen = mutt_strlen (cbuf);
905 c2buflen = mutt_strlen (c2buf);
906 buflen += l + cbuflen + c2buflen;
907 safe_realloc (h, buflen);
909 strcat (p + plen, cbuf); /* __STRCAT_CHECKED__ */
911 strcat (p + plen, buf); /* __STRCAT_CHECKED__ */
913 strcat (p + plen, c2buf); /* __STRCAT_CHECKED__ */
917 /* Space for this was allocated in the beginning of this function. */
918 strcat (p + plen, "\n"); /* __STRCAT_CHECKED__ */
921 static int address_header_decode (char **h)
929 switch (tolower ((unsigned char) *s))
933 if (ascii_strncasecmp (s, "return-path:", 12) == 0)
939 else if (ascii_strncasecmp (s, "reply-to:", 9) == 0)
948 if (ascii_strncasecmp (s, "from:", 5))
955 if (ascii_strncasecmp (s, "cc:", 3))
963 if (ascii_strncasecmp (s, "bcc:", 4))
970 if (ascii_strncasecmp (s, "sender:", 7))
977 if (ascii_strncasecmp (s, "to:", 3))
984 if (ascii_strncasecmp (s, "mail-followup-to:", 17))
992 if ((a = rfc822_parse_adrlist (a, s + l)) == NULL)
995 mutt_addrlist_to_local (a);
996 rfc2047_decode_adrlist (a);
997 for (cur = a; cur; cur = cur->next)
999 rfc822_dequote_comment (cur->personal);
1001 /* angle brackets for return path are mandated by RfC5322,
1002 * so leave Return-Path as-is */
1004 *h = safe_strdup (s);
1007 *h = safe_calloc (1, l + 2);
1008 strfcpy (*h, s, l + 1);
1009 format_address_header (h, a);
1012 rfc822_free_address (&a);