X-Git-Url: https://git.llucax.com/software/mutt-debian.git/blobdiff_plain/14c29200cb58d3c4a0830265f2433849781858d0..e0765f8ab8243c097213733be0d4be2a31448b89:/copy.c?ds=inline diff --git a/copy.c b/copy.c index 4cb91d0..62f2727 100644 --- a/copy.c +++ b/copy.c @@ -287,7 +287,7 @@ mutt_copy_hdr (FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, int flags, if (flags & (CH_DECODE|CH_PREFIX)) { if (mutt_write_one_header (out, 0, headers[x], - flags & CH_PREFIX ? prefix : 0, mutt_term_width (Wrap)) == -1) + flags & CH_PREFIX ? prefix : 0, mutt_term_width (Wrap), flags) == -1) { error = TRUE; break; @@ -348,7 +348,7 @@ mutt_copy_header (FILE *in, HEADER *h, FILE *out, int flags, const char *prefix) | (h->env->refs_changed ? CH_UPDATE_REFS : 0); if (mutt_copy_hdr (in, out, h->offset, h->content->offset, flags, prefix) == -1) - return (-1); + return -1; if (flags & CH_TXTPLAIN) { @@ -360,99 +360,47 @@ mutt_copy_header (FILE *in, HEADER *h, FILE *out, int flags, const char *prefix) rfc822_cat(buffer, sizeof(buffer), chsbuf, MimeSpecials); fputs(buffer, out); fputc('\n', out); - - if (ferror (out) != 0 || feof (out) != 0) - return -1; - } - if (flags & CH_UPDATE) + if ((flags & CH_UPDATE_IRT) && h->env->in_reply_to) { - if ((flags & CH_NOSTATUS) == 0) + LIST *listp = h->env->in_reply_to; + fputs ("In-Reply-To:", out); + for (; listp; listp = listp->next) { - if (h->env->irt_changed && h->env->in_reply_to) - { - LIST *listp = h->env->in_reply_to; - - if (fputs ("In-Reply-To: ", out) == EOF) - return (-1); - - for (; listp; listp = listp->next) - if ((fputs (listp->data, out) == EOF) || (fputc (' ', out) == EOF)) - return (-1); - - if (fputc ('\n', out) == EOF) - return (-1); - } - - if (h->env->refs_changed && h->env->references) - { - LIST *listp = h->env->references, *refs = NULL, *t; - - if (fputs ("References: ", out) == EOF) - return (-1); - - /* Mutt stores references in reverse order, thus we create - * a reordered refs list that we can put in the headers */ - for (; listp; listp = listp->next, refs = t) - { - t = (LIST *)safe_malloc (sizeof (LIST)); - t->data = listp->data; - t->next = refs; - } - - for (; refs; refs = refs->next) - if ((fputs (refs->data, out) == EOF) || (fputc (' ', out) == EOF)) - return (-1); - - /* clearing refs from memory */ - for (t = refs; refs; refs = t->next, t = refs) - FREE (&refs); - - if (fputc ('\n', out) == EOF) - return (-1); - } - - if (h->old || h->read) - { - if (fputs ("Status: ", out) == EOF) - return (-1); - - if (h->read) - { - if (fputs ("RO", out) == EOF) - return (-1); - } - else if (h->old) - { - if (fputc ('O', out) == EOF) - return (-1); - } - - if (fputc ('\n', out) == EOF) - return (-1); - } + fputc (' ', out); + fputs (listp->data, out); + } + fputc ('\n', out); + } - if (h->flagged || h->replied) - { - if (fputs ("X-Status: ", out) == EOF) - return (-1); + if ((flags & CH_UPDATE_REFS) && h->env->references) + { + fputs ("References:", out); + mutt_write_references (h->env->references, out, 0); + fputc ('\n', out); + } - if (h->replied) - { - if (fputc ('A', out) == EOF) - return (-1); - } + if ((flags & CH_UPDATE) && (flags & CH_NOSTATUS) == 0) + { + if (h->old || h->read) + { + fputs ("Status: ", out); + if (h->read) + fputs ("RO", out); + else if (h->old) + fputc ('O', out); + fputc ('\n', out); + } - if (h->flagged) - { - if (fputc ('F', out) == EOF) - return (-1); - } - - if (fputc ('\n', out) == EOF) - return (-1); - } + if (h->flagged || h->replied) + { + fputs ("X-Status: ", out); + if (h->replied) + fputc ('A', out); + if (h->flagged) + fputc ('F', out); + fputc ('\n', out); } } @@ -468,14 +416,13 @@ mutt_copy_header (FILE *in, HEADER *h, FILE *out, int flags, const char *prefix) { if (flags & CH_PREFIX) fputs(prefix, out); - if (fputc ('\n', out) == EOF) /* add header terminator */ - return (-1); + fputc ('\n', out); /* add header terminator */ } if (ferror (out) || feof (out)) return -1; - return (0); + return 0; } /* Count the number of lines and bytes to be deleted in this body*/ @@ -572,7 +519,9 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, if (new_lines <= 0) new_lines = 0; else - fprintf (fpout, "Lines: %d\n\n", new_lines); + fprintf (fpout, "Lines: %d\n", new_lines); + + putc ('\n', fpout); if (ferror (fpout) || feof (fpout)) return -1; new_offset = ftello (fpout); @@ -652,7 +601,7 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, else if (WithCrypto && (flags & M_CM_DECODE_CRYPT) && (hdr->security & ENCRYPT)) { - BODY *cur; + BODY *cur = NULL; FILE *fp; if ((WithCrypto & APPLICATION_PGP) @@ -672,18 +621,24 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, return (-1); } + if (!cur) + { + mutt_error (_("No decryption engine available for message")); + return -1; + } + mutt_write_mime_header (cur, fpout); fputc ('\n', fpout); fseeko (fp, cur->offset, 0); if (mutt_copy_bytes (fp, fpout, cur->length) == -1) { - fclose (fp); + safe_fclose (&fp); mutt_free_body (&cur); return (-1); } mutt_free_body (&cur); - fclose (fp); + safe_fclose (&fp); } else { @@ -718,6 +673,8 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, return rc; } +/* should be made to return -1 on fatal errors, and 1 on non-fatal errors + * like partial decode, where it is worth displaying as much as possible */ int mutt_copy_message (FILE *fpout, CONTEXT *src, HEADER *hdr, int flags, int chflags) @@ -908,9 +865,10 @@ static void format_address_header (char **h, ADDRESS *a) static int address_header_decode (char **h) { char *s = *h; - int l; + int l, rp = 0; ADDRESS *a = NULL; + ADDRESS *cur = NULL; switch (tolower ((unsigned char) *s)) { @@ -919,6 +877,7 @@ static int address_header_decode (char **h) if (ascii_strncasecmp (s, "return-path:", 12) == 0) { l = 12; + rp = 1; break; } else if (ascii_strncasecmp (s, "reply-to:", 9) == 0) @@ -979,15 +938,23 @@ static int address_header_decode (char **h) mutt_addrlist_to_local (a); rfc2047_decode_adrlist (a); - - *h = safe_calloc (1, l + 2); - - strfcpy (*h, s, l + 1); - - format_address_header (h, a); + for (cur = a; cur; cur = cur->next) + if (cur->personal) + rfc822_dequote_comment (cur->personal); + + /* angle brackets for return path are mandated by RfC5322, + * so leave Return-Path as-is */ + if (rp) + *h = safe_strdup (s); + else + { + *h = safe_calloc (1, l + 2); + strfcpy (*h, s, l + 1); + format_address_header (h, a); + } rfc822_free_address (&a); - + FREE (&s); return 1; }