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;
| (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)
{
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);
}
}
{
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*/
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);
else if (WithCrypto
&& (flags & M_CM_DECODE_CRYPT) && (hdr->security & ENCRYPT))
{
- BODY *cur;
+ BODY *cur = NULL;
FILE *fp;
if ((WithCrypto & APPLICATION_PGP)
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
{
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)
static int address_header_decode (char **h)
{
char *s = *h;
- int l;
+ int l, rp = 0;
ADDRESS *a = NULL;
if (ascii_strncasecmp (s, "return-path:", 12) == 0)
{
l = 12;
+ rp = 1;
break;
}
else if (ascii_strncasecmp (s, "reply-to:", 9) == 0)
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);
+
+ /* 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;
}