- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
- */
+ *
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * It's licensed under the GNU General Public License,
+ * please see the file GPL in the top level source directory.
+ */
-mutt_copy_hdr (FILE *in, FILE *out, long off_start, long off_end, int flags,
- const char *prefix)
+mutt_copy_hdr (FILE * in, FILE * out, long off_start, long off_end, int flags,
+ const char *prefix)
- if (nl && buf[0] != ' ' && buf[0] != '\t')
- {
- ignore = 1;
- if (!from && mutt_strncmp ("From ", buf, 5) == 0)
- {
- if ((flags & CH_FROM) == 0)
- continue;
- from = 1;
- }
- else if (flags & (CH_NOQFROM) &&
- ascii_strncasecmp (">From ", buf, 6) == 0)
- continue;
-
- else if (buf[0] == '\n' || (buf[0] == '\r' && buf[1] == '\n'))
- break; /* end of header */
-
- if ((flags & (CH_UPDATE | CH_XMIT | CH_NOSTATUS)) &&
- (ascii_strncasecmp ("Status:", buf, 7) == 0 ||
- ascii_strncasecmp ("X-Status:", buf, 9) == 0))
- continue;
- if ((flags & (CH_UPDATE_LEN | CH_XMIT | CH_NOLEN)) &&
- (ascii_strncasecmp ("Content-Length:", buf, 15) == 0 ||
- ascii_strncasecmp ("Lines:", buf, 6) == 0))
- continue;
- if ((flags & CH_UPDATE_REFS) &&
- ascii_strncasecmp ("References:", buf, 11) == 0)
- continue;
- if ((flags & CH_UPDATE_IRT) &&
- ascii_strncasecmp ("In-Reply-To:", buf, 12) == 0)
- continue;
- ignore = 0;
+ if (nl && buf[0] != ' ' && buf[0] != '\t') {
+ ignore = 1;
+ if (!from && str_ncmp ("From ", buf, 5) == 0) {
+ if ((flags & CH_FROM) == 0)
+ continue;
+ from = 1;
+ }
+ else if (flags & (CH_NOQFROM) &&
+ ascii_strncasecmp (">From ", buf, 6) == 0)
+ continue;
+
+ else if (buf[0] == '\n' || (buf[0] == '\r' && buf[1] == '\n'))
+ break; /* end of header */
+
+ if ((flags & (CH_UPDATE | CH_XMIT | CH_NOSTATUS)) &&
+ (ascii_strncasecmp ("Status:", buf, 7) == 0 ||
+ ascii_strncasecmp ("X-Status:", buf, 9) == 0))
+ continue;
+ if ((flags & (CH_UPDATE_LEN | CH_XMIT | CH_NOLEN)) &&
+ (ascii_strncasecmp ("Content-Length:", buf, 15) == 0 ||
+ ascii_strncasecmp ("Lines:", buf, 6) == 0))
+ continue;
+ if ((flags & CH_UPDATE_REFS) &&
+ ascii_strncasecmp ("References:", buf, 11) == 0)
+ continue;
+ if ((flags & CH_UPDATE_IRT) &&
+ ascii_strncasecmp ("In-Reply-To:", buf, 12) == 0)
+ continue;
+ ignore = 0;
- if (flags & CH_REORDER)
- {
- for (t = HeaderOrderList; t; t = t->next)
- {
- dprint(1, (debugfile, "Reorder list: %s\n", t->data));
+ if (flags & CH_REORDER) {
+ for (t = HeaderOrderList; t; t = t->next) {
+ debug_print (1, ("Reorder list: %s\n", t->data));
- if (nl && buf[0] != ' ' && buf[0] != '\t')
- {
+ if (nl && buf[0] != ' ' && buf[0] != '\t') {
+
+ /* set curline to 1 for To:/Cc:/Bcc: and 0 otherwise */
+ curline = (flags & CH_WEED) && (ascii_strncmp ("To:", buf, 3) == 0 ||
+ ascii_strncmp ("Cc:", buf, 3) == 0 ||
+ ascii_strncmp ("Bcc:", buf, 4) == 0);
+
- if (this_one)
- {
- if (flags & CH_DECODE)
- {
- if (!address_header_decode (&this_one))
- rfc2047_decode (&this_one);
- }
-
- if (!headers[x])
- headers[x] = this_one;
- else
- {
- safe_realloc (&headers[x], mutt_strlen (headers[x]) +
- mutt_strlen (this_one) + sizeof (char));
- strcat (headers[x], this_one); /* __STRCAT_CHECKED__ */
- FREE (&this_one);
- }
-
- this_one = NULL;
+ if (this_one) {
+ if (flags & CH_DECODE) {
+ if (!address_header_decode (&this_one))
+ rfc2047_decode (&this_one);
+ }
+
+ if (!headers[x])
+ headers[x] = this_one;
+ else {
+ mem_realloc (&headers[x], str_len (headers[x]) +
+ str_len (this_one) + sizeof (char));
+ strcat (headers[x], this_one); /* __STRCAT_CHECKED__ */
+ mem_free (&this_one);
+ }
+
+ this_one = NULL;
- if (!from && mutt_strncmp ("From ", buf, 5) == 0)
- {
- if ((flags & CH_FROM) == 0)
- continue;
- this_is_from = from = 1;
+ if (!from && str_ncmp ("From ", buf, 5) == 0) {
+ if ((flags & CH_FROM) == 0)
+ continue;
+ this_is_from = from = 1;
- (ascii_strncasecmp ("Status:", buf, 7) == 0 ||
- ascii_strncasecmp ("X-Status:", buf, 9) == 0))
- continue;
+ (ascii_strncasecmp ("Status:", buf, 7) == 0 ||
+ ascii_strncasecmp ("X-Status:", buf, 9) == 0))
+ continue;
- (ascii_strncasecmp ("Content-Length:", buf, 15) == 0 ||
- ascii_strncasecmp ("Lines:", buf, 6) == 0))
- continue;
+ (ascii_strncasecmp ("Content-Length:", buf, 15) == 0 ||
+ ascii_strncasecmp ("Lines:", buf, 6) == 0))
+ continue;
- ((ascii_strncasecmp ("content-", buf, 8) == 0 &&
- (ascii_strncasecmp ("transfer-encoding:", buf + 8, 18) == 0 ||
- ascii_strncasecmp ("type:", buf + 8, 5) == 0)) ||
- ascii_strncasecmp ("mime-version:", buf, 13) == 0))
- continue;
+ ((ascii_strncasecmp ("content-", buf, 8) == 0 &&
+ (ascii_strncasecmp ("transfer-encoding:", buf + 8, 18) == 0 ||
+ ascii_strncasecmp ("type:", buf + 8, 5) == 0)) ||
+ ascii_strncasecmp ("mime-version:", buf, 13) == 0))
+ continue;
- if (flags & CH_REORDER)
- {
- for (t = HeaderOrderList, x = 0 ; (t) ; t = t->next, x++)
- {
- if (!ascii_strncasecmp (buf, t->data, mutt_strlen (t->data)))
- {
- dprint(2, (debugfile, "Reorder: %s matches %s\n", t->data, buf));
- break;
- }
- }
+ if (flags & CH_REORDER) {
+ for (t = HeaderOrderList, x = 0; (t); t = t->next, x++) {
+ if (!ascii_strncasecmp (buf, t->data, str_len (t->data))) {
+ debug_print (2, ("Reorder: %s matches %s\n", t->data, buf));
+ break;
+ }
+ }
- this_one = safe_strdup (buf);
- else
- {
- safe_realloc (&this_one,
- mutt_strlen (this_one) + mutt_strlen (buf) + sizeof (char));
- strcat (this_one, buf); /* __STRCAT_CHECKED__ */
+ this_one = str_dup (buf);
+ /* we do want to see all lines if this header doesn't feature
+ * abbreviations (curline is 0), $max_display_recips is 0 and
+ * while the number hasn't reached $max_display_recips yet */
+ else if (curline == 0 || MaxDispRecips == 0 || ++curline <= MaxDispRecips) {
+ mem_realloc (&this_one,
+ str_len (this_one) + str_len (buf) +
+ sizeof (char));
+ strcat (this_one, buf); /* __STRCAT_CHECKED__ */
+ /* only for the first line which doesn't exeeds
+ * $max_display_recips: abbreviate it */
+ } else if (curline == MaxDispRecips+1) {
+ mem_realloc (&this_one, str_len (this_one) + 5);
+ strcat (this_one, " ...");
- else
- {
- safe_realloc (&headers[x], mutt_strlen (headers[x]) +
- mutt_strlen (this_one) + sizeof (char));
- strcat (headers[x], this_one); /* __STRCAT_CHECKED__ */
- FREE (&this_one);
+ else {
+ mem_realloc (&headers[x], str_len (headers[x]) +
+ str_len (this_one) + sizeof (char));
+ strcat (headers[x], this_one); /* __STRCAT_CHECKED__ */
+ mem_free (&this_one);
- if (flags & CH_PREFIX)
- {
- char *ch = headers[x];
- int print_prefix = 1;
-
- while (*ch)
- {
- if (print_prefix)
- {
- if (fputs (prefix, out) == EOF)
- {
- error = TRUE;
- break;
- }
- print_prefix = 0;
- }
-
- if (*ch == '\n' && ch[1])
- print_prefix = 1;
-
- if (putc (*ch++, out) == EOF)
- {
- error = TRUE;
- break;
- }
- }
- if (error)
- break;
+ if (flags & CH_PREFIX) {
+ char *ch = headers[x];
+ int print_prefix = 1;
+
+ while (*ch) {
+ if (print_prefix) {
+ if (fputs (prefix, out) == EOF) {
+ error = TRUE;
+ break;
+ }
+ print_prefix = 0;
+ }
+
+ if (*ch == '\n' && ch[1])
+ print_prefix = 1;
+
+ if (putc (*ch++, out) == EOF) {
+ error = TRUE;
+ break;
+ }
+ }
+ if (error)
+ break;
- flags |= (h->irt_changed ? CH_UPDATE_IRT : 0)
- | (h->refs_changed ? CH_UPDATE_REFS : 0);
-
- if (mutt_copy_hdr (in, out, h->offset, h->content->offset, flags, prefix) == -1)
+ if (h->env)
+ flags |= (h->env->irt_changed ? CH_UPDATE_IRT : 0) |
+ (h->env->refs_changed ? CH_UPDATE_REFS : 0);
+
+ if (mutt_copy_hdr (in, out, h->offset, h->content->offset, flags, prefix) ==
+ -1)
- mutt_canonical_charset (chsbuf, sizeof (chsbuf), Charset ? Charset : "us-ascii");
- rfc822_cat(buffer, sizeof(buffer), chsbuf, MimeSpecials);
- fputs(buffer, out);
- fputc('\n', out);
-
+ mutt_canonical_charset (chsbuf, sizeof (chsbuf),
+ Charset ? Charset : "us-ascii");
+ rfc822_cat (buffer, sizeof (buffer), chsbuf, MimeSpecials);
+ fputs (buffer, out);
+ fputc ('\n', out);
+
- if (flags & CH_UPDATE)
- {
- if ((flags & CH_NOSTATUS) == 0)
- {
- if (h->irt_changed && h->new_env->in_reply_to)
- {
- LIST *listp = h->new_env->in_reply_to;
+ if (flags & CH_UPDATE) {
+ if ((flags & CH_NOSTATUS) == 0) {
+ if (h->env->irt_changed && h->env->in_reply_to) {
+ LIST *listp = h->env->in_reply_to;
- if (h->refs_changed && h->new_env->references)
- {
- LIST *listp = h->new_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->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 *) mem_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)
+ mem_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);
+ 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);
- if (h->flagged || h->replied)
- {
- if (fputs ("X-Status: ", out) == EOF)
- return (-1);
-
- if (h->replied)
- {
- if (fputc ('A', out) == EOF)
- return (-1);
- }
-
- if (h->flagged)
- {
- if (fputc ('F', out) == EOF)
- return (-1);
- }
-
- if (fputc ('\n', out) == EOF)
- return (-1);
+ if (h->flagged || h->replied) {
+ if (fputs ("X-Status: ", out) == EOF)
+ return (-1);
+
+ if (h->replied) {
+ if (fputc ('A', out) == EOF)
+ return (-1);
+ }
+
+ if (h->flagged) {
+ if (fputc ('F', out) == EOF)
+ return (-1);
+ }
+
+ if (fputc ('\n', out) == EOF)
+ return (-1);
- if (flags & CH_UPDATE_LEN &&
- (flags & CH_NOLEN) == 0)
- {
- fprintf (out, "Content-Length: %ld\n", h->content->length);
+ if (flags & CH_UPDATE_LEN && (flags & CH_NOLEN) == 0) {
+ fprintf (out, "Content-Length: " OFF_T_FMT "\n", h->content->length);
-_mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body,
- int flags, int chflags)
+_mutt_copy_message (FILE * fpout, FILE * fpin, HEADER * hdr, BODY * body,
+ int flags, int chflags)
- chflags | CH_NOLEN | CH_NONEWLINE, NULL))
- return -1;
- fprintf (fpout, "Content-Length: %ld\n", new_length);
+ chflags | CH_NOLEN | CH_NONEWLINE, NULL))
+ return -1;
+ fprintf (fpout, "Content-Length: " OFF_T_FMT "\n", new_length);
/* Copy the body */
fseek (fpin, body->offset, SEEK_SET);
if (copy_delete_attach (body, fpin, fpout, date))
/* Copy the body */
fseek (fpin, body->offset, SEEK_SET);
if (copy_delete_attach (body, fpin, fpout, date))
- /* Update original message if we are sync'ing a mailfolder */
- if (flags & M_CM_UPDATE)
- {
- hdr->attach_del = 0;
- hdr->lines = new_lines;
- body->offset = new_offset;
-
- /* update the total size of the mailbox to reflect this deletion */
- Context->size -= body->length - new_length;
- /*
- * if the message is visible, update the visible size of the mailbox
- * as well.
- */
- if (Context->v2r[hdr->msgno] != -1)
- Context->vsize -= body->length - new_length;
-
- body->length = new_length;
- mutt_free_body (&body->parts);
+ /* Update original message if we are sync'ing a mailfolder */
+ if (flags & M_CM_UPDATE) {
+ hdr->attach_del = 0;
+ hdr->lines = new_lines;
+ body->offset = new_offset;
+
+ /* update the total size of the mailbox to reflect this deletion */
+ Context->size -= body->length - new_length;
+ /*
+ * if the message is visible, update the visible size of the mailbox
+ * as well.
+ */
+ if (Context->v2r[hdr->msgno] != -1)
+ Context->vsize -= body->length - new_length;
+
+ body->length = new_length;
+ mutt_free_body (&body->parts);
}
mutt_write_mime_header (cur, fpout);
fputc ('\n', fpout);
fseek (fp, cur->offset, 0);
}
mutt_write_mime_header (cur, fpout);
fputc ('\n', fpout);
fseek (fp, cur->offset, 0);
- if ((r = _mutt_copy_message (fpout, msg->fp, hdr, hdr->content, flags, chflags)) == 0
- && (ferror (fpout) || feof (fpout)))
- {
- dprint (1, (debugfile, "_mutt_copy_message failed to detect EOF!\n"));
+ if ((r =
+ _mutt_copy_message (fpout, msg->fp, hdr, hdr->content, flags,
+ chflags)) == 0 && (ferror (fpout)
+ || feof (fpout))) {
+ debug_print (1, ("_mutt_copy_message failed to detect EOF!\n"));
-_mutt_append_message (CONTEXT *dest, FILE *fpin, CONTEXT *src, HEADER *hdr,
- BODY *body, int flags, int chflags)
-{
+_mutt_append_message (CONTEXT * dest, FILE * fpin, CONTEXT * src,
+ HEADER * hdr, BODY * body, int flags, int chflags) {
+ char buf[STRING];
- if ((msg = mx_open_new_message (dest, hdr, (src->magic == M_MBOX || src->magic == M_MMDF) ? 0 : M_ADD_FROM)) == NULL)
- return -1;
+ fseek(fpin, hdr->offset, 0);
+ if (fgets (buf, sizeof (buf), fpin) == NULL)
+ return (-1);
+ if ((msg = mx_open_new_message (dest, hdr, is_from (buf, NULL, 0, NULL) ? 0 : M_ADD_FROM)) == NULL)
+ return (-1);
- r = _mutt_append_message (dest, msg->fp, src, hdr, hdr->content, cmflags, chflags);
+ r =
+ _mutt_append_message (dest, msg->fp, src, hdr, hdr->content, cmflags,
+ chflags);
- return -1;
-
- if (part->deleted)
- {
- fprintf (fpout,
- "Content-Type: message/external-body; access-type=x-mutt-deleted;\n"
- "\texpiration=%s; length=%ld\n"
- "\n", date + 5, part->length);
- if (ferror (fpout))
- return -1;
-
- /* Copy the original mime headers */
- if (mutt_copy_bytes (fpin, fpout, part->offset - ftell (fpin)))
- return -1;
-
- /* Skip the deleted body */
- fseek (fpin, part->offset + part->length, SEEK_SET);
+ return -1;
+
+ if (part->deleted) {
+ fprintf (fpout,
+ "Content-Type: message/external-body; access-type=x-mutt-deleted;\n"
+ "\texpiration=%s; length=" OFF_T_FMT "\n"
+ "\n", date + 5, part->length);
+ if (ferror (fpout))
+ return -1;
+
+ /* Copy the original mime headers */
+ if (mutt_copy_bytes (fpin, fpout, part->offset - ftell (fpin)))
+ return -1;
+
+ /* Skip the deleted body */
+ fseek (fpin, part->offset + part->length, SEEK_SET);
- linelen = mutt_strlen (*h);
- buflen = linelen + 3;
-
-
- safe_realloc (h, buflen);
- for (count = 0; a; a = a->next, count++)
- {
+
+ linelen = str_len (*h);
+ buflen = linelen + 3;
+
+
+ mem_realloc (h, buflen);
+ for (count = 0; a; a = a->next, count++) {
a->next = NULL;
*buf = *cbuf = *c2buf = '\0';
rfc822_write_address (buf, sizeof (buf), a, 0);
a->next = tmp;
a->next = NULL;
*buf = *cbuf = *c2buf = '\0';
rfc822_write_address (buf, sizeof (buf), a, 0);
a->next = tmp;
-
- buflen += l + mutt_strlen (cbuf) + mutt_strlen (c2buf);
- safe_realloc (h, buflen);
- strcat (*h, cbuf); /* __STRCAT_CHECKED__ */
- strcat (*h, buf); /* __STRCAT_CHECKED__ */
- strcat (*h, c2buf); /* __STRCAT_CHECKED__ */
+
+ buflen += l + str_len (cbuf) + str_len (c2buf);
+ mem_realloc (h, buflen);
+ strcat (*h, cbuf); /* __STRCAT_CHECKED__ */
+ strcat (*h, buf); /* __STRCAT_CHECKED__ */
+ strcat (*h, c2buf); /* __STRCAT_CHECKED__ */