if (m->magic == MUTT_NOTMUCH)
chflags |= CH_VIRTUAL;
#endif
- res = mutt_copy_message(fp_out, m, e, cmflags, chflags);
+ res = mutt_copy_message(fp_out, m, e, cmflags, chflags, MuttIndexWindow->cols);
if (((mutt_file_fclose(&fp_out) != 0) && (errno != EPIPE)) || (res < 0))
{
if (decode)
mutt_parse_mime_message(m, e);
- mutt_copy_message(fp, m, e, cmflags, chflags);
+ mutt_copy_message(fp, m, e, cmflags, chflags, 0);
}
/**
* @param off_end Offset to finish at
* @param chflags Flags, see #CopyHeaderFlags
* @param prefix Prefix for quoting headers
+ * @param wraplen Width to wrap at (when chflags & CH_DISPLAY)
* @retval 0 Success
* @retval -1 Failure
*
* wrap headers much more aggressively than the other one.
*/
int mutt_copy_hdr(FILE *fp_in, FILE *fp_out, LOFF_T off_start, LOFF_T off_end,
- CopyHeaderFlags chflags, const char *prefix)
+ CopyHeaderFlags chflags, const char *prefix, int wraplen)
{
bool from = false;
bool this_is_from = false;
if (chflags & (CH_DECODE | CH_PREFIX))
{
const char *pre = (chflags & CH_PREFIX) ? prefix : NULL;
- const int wraplen = mutt_window_wrap_cols(MuttIndexWindow->cols, C_Wrap);
+ wraplen = mutt_window_wrap_cols(wraplen, C_Wrap);
if (mutt_write_one_header(fp_out, 0, headers[x], pre, wraplen, chflags) == -1)
{
* @param fp_out FILE pointer to write to
* @param chflags See #CopyHeaderFlags
* @param prefix Prefix for quoting headers (if #CH_PREFIX is set)
+ * @param wraplen Width to wrap at (when chflags & CH_DISPLAY)
* @retval 0 Success
* @retval -1 Failure
*/
int mutt_copy_header(FILE *fp_in, struct Email *e, FILE *fp_out,
- CopyHeaderFlags chflags, const char *prefix)
+ CopyHeaderFlags chflags, const char *prefix, int wraplen)
{
char *temp_hdr = NULL;
((e->env->changed & MUTT_ENV_CHANGED_SUBJECT) ? CH_UPDATE_SUBJECT : 0);
}
- if (mutt_copy_hdr(fp_in, fp_out, e->offset, e->content->offset, chflags, prefix) == -1)
+ if (mutt_copy_hdr(fp_in, fp_out, e->offset, e->content->offset, chflags,
+ prefix, wraplen) == -1)
return -1;
if (chflags & CH_TXTPLAIN)
temp_hdr = mutt_str_strdup(temp_hdr);
rfc2047_encode(&temp_hdr, NULL, sizeof("X-Label:"), C_SendCharset);
}
- if (mutt_write_one_header(
- fp_out, "X-Label", temp_hdr, (chflags & CH_PREFIX) ? prefix : 0,
- mutt_window_wrap_cols(MuttIndexWindow->cols, C_Wrap), chflags) == -1)
+ if (mutt_write_one_header(fp_out, "X-Label", temp_hdr, (chflags & CH_PREFIX) ? prefix : 0,
+ mutt_window_wrap_cols(wraplen, C_Wrap), chflags) == -1)
{
return -1;
}
temp_hdr = mutt_str_strdup(temp_hdr);
rfc2047_encode(&temp_hdr, NULL, sizeof("Subject:"), C_SendCharset);
}
- if (mutt_write_one_header(
- fp_out, "Subject", temp_hdr, (chflags & CH_PREFIX) ? prefix : 0,
- mutt_window_wrap_cols(MuttIndexWindow->cols, C_Wrap), chflags) == -1)
+ if (mutt_write_one_header(fp_out, "Subject", temp_hdr, (chflags & CH_PREFIX) ? prefix : 0,
+ mutt_window_wrap_cols(wraplen, C_Wrap), chflags) == -1)
{
return -1;
}
/**
* mutt_copy_message_fp - make a copy of a message from a FILE pointer
- * @param fp_out Where to write output
- * @param fp_in Where to get input
+ * @param fp_out Where to write output
+ * @param fp_in Where to get input
* @param e Email being copied
* @param cmflags Flags, see #CopyMessageFlags
* @param chflags Flags, see #CopyHeaderFlags
+ * @param wraplen Width to wrap at (when chflags & CH_DISPLAY)
* @retval 0 Success
* @retval -1 Failure
*/
int mutt_copy_message_fp(FILE *fp_out, FILE *fp_in, struct Email *e,
- CopyMessageFlags cmflags, CopyHeaderFlags chflags)
+ CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
{
struct Body *body = e->content;
char prefix[128];
new_lines = e->lines - count_delete_lines(fp_in, body, &new_length, dlen);
/* Copy the headers */
- if (mutt_copy_header(fp_in, e, fp_out, chflags | CH_NOLEN | CH_NONEWLINE, NULL))
+ if (mutt_copy_header(fp_in, e, fp_out, chflags | CH_NOLEN | CH_NONEWLINE, NULL, wraplen))
return -1;
fprintf(fp_out, "Content-Length: " OFF_T_FMT "\n", new_length);
if (new_lines <= 0)
}
if (mutt_copy_header(fp_in, e, fp_out, chflags,
- (chflags & CH_PREFIX) ? prefix : NULL) == -1)
+ (chflags & CH_PREFIX) ? prefix : NULL, wraplen) == -1)
{
return -1;
}
if (cmflags & MUTT_CM_PREFIX)
s.prefix = prefix;
if (cmflags & MUTT_CM_DISPLAY)
+ {
s.flags |= MUTT_DISPLAY;
+ s.wraplen = wraplen;
+ }
if (cmflags & MUTT_CM_PRINTING)
s.flags |= MUTT_PRINTING;
if (cmflags & MUTT_CM_WEED)
* @param e Email
* @param cmflags Flags, see #CopyMessageFlags
* @param chflags Flags, see #CopyHeaderFlags
+ * @param wraplen Width to wrap at (when chflags & CH_DISPLAY)
* @retval 0 Success
* @retval -1 Failure
*
* like partial decode, where it is worth displaying as much as possible
*/
int mutt_copy_message(FILE *fp_out, struct Mailbox *m, struct Email *e,
- CopyMessageFlags cmflags, CopyHeaderFlags chflags)
+ CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
{
struct Message *msg = mx_msg_open(m, e->msgno);
if (!msg)
return -1;
if (!e->content)
return -1;
- int rc = mutt_copy_message_fp(fp_out, msg->fp, e, cmflags, chflags);
+ int rc = mutt_copy_message_fp(fp_out, msg->fp, e, cmflags, chflags, wraplen);
if ((rc == 0) && (ferror(fp_out) || feof(fp_out)))
{
mutt_debug(LL_DEBUG1, "failed to detect EOF!\n");
if ((dest->magic == MUTT_MBOX) || (dest->magic == MUTT_MMDF))
chflags |= CH_FROM | CH_FORCE_FROM;
chflags |= ((dest->magic == MUTT_MAILDIR) ? CH_NOSTATUS : CH_UPDATE);
- rc = mutt_copy_message_fp(msg->fp, fp_in, e, cmflags, chflags);
+ rc = mutt_copy_message_fp(msg->fp, fp_in, e, cmflags, chflags, 0);
if (mx_msg_commit(dest, msg) != 0)
rc = -1;
#define CH_UPDATE_SUBJECT (1 << 20) ///< Update Subject: protected header update
#define CH_VIRTUAL (1 << 21) ///< Write virtual header lines too
-int mutt_copy_hdr(FILE *fp_in, FILE *fp_out, LOFF_T off_start, LOFF_T off_end, CopyHeaderFlags chflags, const char *prefix);
+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);
-int mutt_copy_header(FILE *fp_in, struct Email *e, FILE *fp_out, CopyHeaderFlags chflags, const char *prefix);
+int mutt_copy_header(FILE *fp_in, struct Email *e, FILE *fp_out, CopyHeaderFlags chflags, const char *prefix, int wraplen);
-int mutt_copy_message_fp(FILE *fp_out, FILE *fp_in, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags);
-int mutt_copy_message (FILE *fp_out, struct Mailbox *m, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags);
+int mutt_copy_message_fp(FILE *fp_out, FILE *fp_in, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen);
+int mutt_copy_message (FILE *fp_out, struct Mailbox *m, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen);
int mutt_append_message(struct Mailbox *dest, struct Mailbox *src, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags);
goto bail;
}
- rc = mutt_copy_hdr(fp, msg->fp, 0, sb.st_size, CH_NOLEN | cf, NULL);
+ rc = mutt_copy_hdr(fp, msg->fp, 0, sb.st_size, CH_NOLEN | cf, NULL, 0);
if (rc == 0)
{
fputc('\n', msg->fp);
if (s->flags & MUTT_DISPLAY)
chflags |= CH_DISPLAY;
- mutt_copy_hdr(s->fp_in, s->fp_out, off_start, b->parts->offset, chflags, s->prefix);
+ mutt_copy_hdr(s->fp_in, s->fp_out, off_start, b->parts->offset, chflags, s->prefix, 0);
if (s->prefix)
state_puts(s->prefix, s);
if (C_Weed)
chflags |= CH_WEED | CH_REORDER;
- mutt_copy_hdr(s->fp_in, s->fp_out, ftello(s->fp_in), b->parts->offset, chflags, NULL);
+ mutt_copy_hdr(s->fp_in, s->fp_out, ftello(s->fp_in), b->parts->offset,
+ chflags, NULL, 0);
}
}
else if (expiration && (expire < mutt_date_epoch()))
if (C_Weed)
chflags |= CH_WEED | CH_REORDER;
- mutt_copy_hdr(s->fp_in, s->fp_out, ftello(s->fp_in), b->parts->offset, chflags, NULL);
+ mutt_copy_hdr(s->fp_in, s->fp_out, ftello(s->fp_in), b->parts->offset,
+ chflags, NULL, 0);
}
}
else
if (C_Weed)
chflags |= CH_WEED | CH_REORDER;
- mutt_copy_hdr(s->fp_in, s->fp_out, ftello(s->fp_in), b->parts->offset, chflags, NULL);
+ mutt_copy_hdr(s->fp_in, s->fp_out, ftello(s->fp_in), b->parts->offset,
+ chflags, NULL, 0);
}
}
if (!dest)
return -1;
- int rc = mutt_copy_message(dest->fp, m, e, MUTT_CM_UPDATE, CH_UPDATE | CH_UPDATE_LEN);
+ int rc = mutt_copy_message(dest->fp, m, e, MUTT_CM_UPDATE, CH_UPDATE | CH_UPDATE_LEN, 0);
if (rc == 0)
{
char oldpath[PATH_MAX];
new_offset[i - first].hdr = ftello(fp) + offset;
if (mutt_copy_message(fp, m, m->emails[i], MUTT_CM_UPDATE,
- CH_FROM | CH_UPDATE | CH_UPDATE_LEN) != 0)
+ CH_FROM | CH_UPDATE | CH_UPDATE_LEN, 0) != 0)
{
mutt_perror(tempfile);
unlink(tempfile);
if ((ctx->mailbox->magic == MUTT_MBOX) || (ctx->mailbox->magic == MUTT_MMDF))
chflags = CH_FROM | CH_UPDATE_LEN;
chflags |= ((ctx->mailbox->magic == MUTT_MAILDIR) ? CH_NOSTATUS : CH_UPDATE);
- if ((mutt_copy_message_fp(msg->fp, fp, e_new, MUTT_CM_NO_FLAGS, chflags) == 0) &&
+ if ((mutt_copy_message_fp(msg->fp, fp, e_new, MUTT_CM_NO_FLAGS, chflags, 0) == 0) &&
(mx_msg_commit(ctx->mailbox, msg) == 0))
{
rc = 0;
if (((WithCrypto & APPLICATION_PGP) != 0) && (e->security & APPLICATION_PGP))
{
- mutt_copy_message(fp_out, m, e, MUTT_CM_DECODE | MUTT_CM_CHARCONV, CH_NO_FLAGS);
+ mutt_copy_message(fp_out, m, e, MUTT_CM_DECODE | MUTT_CM_CHARCONV, CH_NO_FLAGS, 0);
fflush(fp_out);
mutt_endwin();
if (e->security & SEC_ENCRYPT)
{
mutt_copy_message(fp_out, m, e, MUTT_CM_NOHEADER | MUTT_CM_DECODE_CRYPT | MUTT_CM_DECODE_SMIME,
- CH_NO_FLAGS);
+ CH_NO_FLAGS, 0);
}
else
- mutt_copy_message(fp_out, m, e, MUTT_CM_NO_FLAGS, CH_NO_FLAGS);
+ mutt_copy_message(fp_out, m, e, MUTT_CM_NO_FLAGS, CH_NO_FLAGS, 0);
fflush(fp_out);
char *mbox = NULL;
{
if (a->mime_headers->subject)
{
- if ((s->flags & MUTT_DISPLAY) && C_Weed && mutt_matches_ignore("subject"))
+ const bool display = (s->flags & MUTT_DISPLAY);
+
+ if (display && C_Weed && mutt_matches_ignore("subject"))
return 0;
state_mark_protected_header(s);
- mutt_write_one_header(s->fp_out, "Subject", a->mime_headers->subject, s->prefix,
- mutt_window_wrap_cols(MuttIndexWindow->cols, C_Wrap),
- (s->flags & MUTT_DISPLAY) ? CH_DISPLAY : CH_NO_FLAGS);
+ int wraplen = display ? mutt_window_wrap_cols(s->wraplen, C_Wrap) : 0;
+
+ mutt_write_one_header(s->fp_out, "Subject", a->mime_headers->subject,
+ s->prefix, wraplen, display ? CH_DISPLAY : CH_NO_FLAGS);
state_puts("\n", s);
}
}
if (e->security & SEC_ENCRYPT)
{
mutt_copy_message(fp_out, m, e, MUTT_CM_DECODE_CRYPT & MUTT_CM_DECODE_SMIME,
- CH_MIME | CH_WEED | CH_NONEWLINE);
+ CH_MIME | CH_WEED | CH_NONEWLINE, 0);
}
else
- mutt_copy_message(fp_out, m, e, MUTT_CM_NO_FLAGS, CH_NO_FLAGS);
+ mutt_copy_message(fp_out, m, e, MUTT_CM_NO_FLAGS, CH_NO_FLAGS, 0);
fflush(fp_out);
mutt_file_fclose(&fp_out);
#endif
if (pat->op != MUTT_PAT_BODY)
- mutt_copy_header(msg->fp, e, s.fp_out, CH_FROM | CH_DECODE, NULL);
+ mutt_copy_header(msg->fp, e, s.fp_out, CH_FROM | CH_DECODE, NULL, 0);
if (pat->op != MUTT_PAT_HEADER)
{
chflags |= CH_PREFIX;
}
- mutt_copy_header(fp_in, e, fp_out, chflags, quote ? prefix2 : NULL);
+ mutt_copy_header(fp_in, e, fp_out, chflags, quote ? prefix2 : NULL, 0);
}
/**
if (cur)
{
mutt_forward_intro(Context->mailbox, cur->email, fp_tmp);
- mutt_copy_message_fp(fp_tmp, fp, cur->email, cmflags, chflags);
+ mutt_copy_message_fp(fp_tmp, fp, cur->email, cmflags, chflags, 0);
mutt_forward_trailer(Context->mailbox, cur->email, fp_tmp);
}
else
{
mutt_forward_intro(Context->mailbox, actx->idx[i]->content->email, fp_tmp);
mutt_copy_message_fp(fp_tmp, actx->idx[i]->fp,
- actx->idx[i]->content->email, cmflags, chflags);
+ actx->idx[i]->content->email, cmflags, chflags, 0);
mutt_forward_trailer(Context->mailbox, actx->idx[i]->content->email, fp_tmp);
}
}
cmflags |= MUTT_CM_WEED;
}
- mutt_copy_message_fp(fp_tmp, fp, e, cmflags, chflags);
+ mutt_copy_message_fp(fp_tmp, fp, e, cmflags, chflags, 0);
mutt_make_post_indent(Context->mailbox, e, fp_tmp);
}
if (C_ForwardQuote)
cmflags |= MUTT_CM_PREFIX;
- /* wrapping headers for forwarding is considered a display
- * rather than send action */
- chflags |= CH_DISPLAY;
-
- mutt_copy_message(fp_out, m, e, cmflags, chflags);
+ mutt_copy_message(fp_out, m, e, cmflags, chflags, 0);
mutt_forward_trailer(m, e, fp_out);
return 0;
}
cmflags |= MUTT_CM_WEED;
}
- mutt_copy_message(fp_out, m, e, cmflags, chflags);
+ mutt_copy_message(fp_out, m, e, cmflags, chflags, 0);
mutt_make_post_indent(m, e, fp_out);
transform_to_7bit(a->parts, fp_in);
mutt_copy_hdr(fp_in, fp_out, a->offset, a->offset + a->length,
- CH_MIME | CH_NONEWLINE | CH_XMIT, NULL);
+ CH_MIME | CH_NONEWLINE | CH_XMIT, NULL, 0);
fputs("MIME-Version: 1.0\n", fp_out);
mutt_write_mime_header(a->parts, fp_out);
}
}
- mutt_copy_message(fp, m, e, cmflags, chflags);
+ mutt_copy_message(fp, m, e, cmflags, chflags, 0);
fflush(fp);
rewind(fp);
else
wraplen = C_WrapHeaders;
}
- else if ((wraplen <= 0) || (wraplen > MuttIndexWindow->cols))
- wraplen = MuttIndexWindow->cols;
+ else if (wraplen <= 0)
+ wraplen = 78;
if (tag)
{
FREE(&msgid_str);
fputs("Resent-To: ", fp_tmp);
mutt_write_addrlist(to, fp_tmp, 11, 0);
- mutt_copy_header(fp, e, fp_tmp, chflags, NULL);
+ mutt_copy_header(fp, e, fp_tmp, chflags, NULL, 0);
fputc('\n', fp_tmp);
mutt_file_copy_bytes(fp, fp_tmp, e->content->length);
if (mutt_file_fclose(&fp_tmp) != 0)
*/
struct State
{
- FILE *fp_in; ///< File to read from
- FILE *fp_out; ///< File to write to
- char *prefix; ///< String to add to the beginning of each output line
- StateFlags flags; ///< Flags, e.g. #MUTT_DISPLAY
+ FILE *fp_in; ///< File to read from
+ FILE *fp_out; ///< File to write to
+ char *prefix; ///< String to add to the beginning of each output line
+ StateFlags flags; ///< Flags, e.g. #MUTT_DISPLAY
+ int wraplen; ///< Width to wrap lines to (when flags & #MUTT_DISPLAY)
};
#define state_set_prefix(state) ((state)->flags |= MUTT_PENDINGPREFIX)