/*
* Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
* Copyright (C) 1999-2009 Brendan Cully <brendan@kublai.com>
/*
* Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
* Copyright (C) 1999-2009 Brendan Cully <brendan@kublai.com>
* 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 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.
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- snprintf (hdrreq, sizeof (hdrreq), "BODY.PEEK[HEADER.FIELDS (%s%s%s)]",
- want_headers, ImapHeaders ? " " : "", ImapHeaders ? ImapHeaders : "");
- }
+ safe_asprintf (&hdrreq, "BODY.PEEK[HEADER.FIELDS (%s%s%s)]",
+ want_headers, ImapHeaders ? " " : "", NONULL (ImapHeaders));
+ }
- snprintf (hdrreq, sizeof (hdrreq), "RFC822.HEADER.LINES (%s%s%s)",
- want_headers, ImapHeaders ? " " : "", ImapHeaders ? ImapHeaders : "");
+ safe_asprintf (&hdrreq, "RFC822.HEADER.LINES (%s%s%s)",
+ want_headers, ImapHeaders ? " " : "", NONULL (ImapHeaders));
}
else
{ /* Unable to fetch headers for lower versions */
mutt_error _("Unable to fetch headers from this IMAP server version.");
mutt_sleep (2); /* pause a moment to let the user see the error */
}
else
{ /* Unable to fetch headers for lower versions */
mutt_error _("Unable to fetch headers from this IMAP server version.");
mutt_sleep (2); /* pause a moment to let the user see the error */
if (!(fp = safe_fopen (tempfile, "w+")))
{
mutt_error (_("Could not create temporary file %s"), tempfile);
mutt_sleep (2);
if (!(fp = safe_fopen (tempfile, "w+")))
{
mutt_error (_("Could not create temporary file %s"), tempfile);
mutt_sleep (2);
snprintf (buf, sizeof (buf),
"UID FETCH 1:%u (UID FLAGS)", uidnext - 1);
snprintf (buf, sizeof (buf),
"UID FETCH 1:%u (UID FLAGS)", uidnext - 1);
rc = IMAP_CMD_CONTINUE;
for (msgno = msgbegin; rc == IMAP_CMD_CONTINUE; msgno++)
{
mutt_progress_update (&progress, msgno + 1, -1);
rc = IMAP_CMD_CONTINUE;
for (msgno = msgbegin; rc == IMAP_CMD_CONTINUE; msgno++)
{
mutt_progress_update (&progress, msgno + 1, -1);
memset (&h, 0, sizeof (h));
h.data = safe_calloc (1, sizeof (IMAP_HEADER_DATA));
do
memset (&h, 0, sizeof (h));
h.data = safe_calloc (1, sizeof (IMAP_HEADER_DATA));
do
idx = h.sid - 1;
ctx->hdrs[idx] = imap_hcache_get (idata, h.data->uid);
if (ctx->hdrs[idx])
{
ctx->hdrs[idx]->index = idx;
idx = h.sid - 1;
ctx->hdrs[idx] = imap_hcache_get (idata, h.data->uid);
if (ctx->hdrs[idx])
{
ctx->hdrs[idx]->index = idx;
- fetchlast = msgend + 1;
-
- snprintf (buf, sizeof (buf),
- "FETCH %d:%d (UID FLAGS INTERNALDATE RFC822.SIZE %s)", msgno + 1,
- fetchlast, hdrreq);
- imap_cmd_start (idata, buf);
+ fetchlast = msgend + 1;
+ safe_asprintf (&cmd, "FETCH %d:%d (UID FLAGS INTERNALDATE RFC822.SIZE %s)",
+ msgno + 1, fetchlast, hdrreq);
+ imap_cmd_start (idata, cmd);
+ FREE (&cmd);
+ /* May receive FLAGS updates in a separate untagged response (#2935) */
+ if (idx < ctx->msgcount)
+ {
+ dprint (2, (debugfile, "imap_read_headers: message %d is not new\n",
+ h.sid));
+ continue;
+ }
if (!(msg->fp = msg_cache_put (idata, h)))
{
cache->uid = HEADER_DATA(h)->uid;
if (!(msg->fp = msg_cache_put (idata, h)))
{
cache->uid = HEADER_DATA(h)->uid;
cache->path = safe_strdup (path);
if (!(msg->fp = safe_fopen (path, "w+")))
{
cache->path = safe_strdup (path);
if (!(msg->fp = safe_fopen (path, "w+")))
{
snprintf (buf, sizeof (buf), "UID FETCH %u %s", HEADER_DATA(h)->uid,
(mutt_bit_isset (idata->capabilities, IMAP4REV1) ?
(option (OPTIMAPPEEK) ? "BODY.PEEK[]" : "BODY[]") :
snprintf (buf, sizeof (buf), "UID FETCH %u %s", HEADER_DATA(h)->uid,
(mutt_bit_isset (idata->capabilities, IMAP4REV1) ?
(option (OPTIMAPPEEK) ? "BODY.PEEK[]" : "BODY[]") :
imap_fix_path (idata, mx.mbox, mailbox, sizeof (mailbox));
if (!*mailbox)
strfcpy (mailbox, "INBOX", sizeof (mailbox));
imap_fix_path (idata, mx.mbox, mailbox, sizeof (mailbox));
if (!*mailbox)
strfcpy (mailbox, "INBOX", sizeof (mailbox));
M_PROGRESS_SIZE, NetInc, len);
imap_munge_mbox_name (mbox, sizeof (mbox), mailbox);
M_PROGRESS_SIZE, NetInc, len);
imap_munge_mbox_name (mbox, sizeof (mbox), mailbox);
- snprintf (buf, sizeof (buf), "APPEND %s (%s%s%s%s%s) {%lu}", mbox,
+ imap_make_date (internaldate, msg->received);
+ snprintf (buf, sizeof (buf), "APPEND %s (%s%s%s%s%s) \"%s\" {%lu}", mbox,
msg->flags.read ? "\\Seen" : "",
msg->flags.read && (msg->flags.replied || msg->flags.flagged) ? " " : "",
msg->flags.replied ? "\\Answered" : "",
msg->flags.replied && msg->flags.flagged ? " " : "",
msg->flags.flagged ? "\\Flagged" : "",
msg->flags.read ? "\\Seen" : "",
msg->flags.read && (msg->flags.replied || msg->flags.flagged) ? " " : "",
msg->flags.replied ? "\\Answered" : "",
msg->flags.replied && msg->flags.flagged ? " " : "",
msg->flags.flagged ? "\\Flagged" : "",
if (len)
flush_buffer(buf, &len, idata->conn);
mutt_socket_write (idata->conn, "\r\n");
if (len)
flush_buffer(buf, &len, idata->conn);
mutt_socket_write (idata->conn, "\r\n");
imap_fix_path (idata, mx.mbox, mbox, sizeof (mbox));
if (!*mbox)
strfcpy (mbox, "INBOX", sizeof (mbox));
imap_fix_path (idata, mx.mbox, mbox, sizeof (mbox));
if (!*mbox)
strfcpy (mbox, "INBOX", sizeof (mbox));
if ((rc = imap_exec (idata, cmd.data, IMAP_CMD_QUEUE)) < 0)
{
dprint (1, (debugfile, "could not queue copy\n"));
if ((rc = imap_exec (idata, cmd.data, IMAP_CMD_QUEUE)) < 0)
{
dprint (1, (debugfile, "could not queue copy\n"));
dprint (2, (debugfile, "imap_fetch_message: parsing FLAGS\n"));
if ((s = msg_parse_flags (&newh, s)) == NULL)
return NULL;
dprint (2, (debugfile, "imap_fetch_message: parsing FLAGS\n"));
if ((s = msg_parse_flags (&newh, s)) == NULL)
return NULL;
/* YAUH (yet another ugly hack): temporarily set context to
* read-write even if it's read-only, so *server* updates of
* flags can be processed by mutt_set_flag. ctx->changed must
* be restored afterwards */
readonly = ctx->readonly;
ctx->readonly = 0;
/* YAUH (yet another ugly hack): temporarily set context to
* read-write even if it's read-only, so *server* updates of
* flags can be processed by mutt_set_flag. ctx->changed must
* be restored afterwards */
readonly = ctx->readonly;
ctx->readonly = 0;
mutt_set_flag (ctx, h, M_NEW, !(hd->read || hd->old));
mutt_set_flag (ctx, h, M_OLD, hd->old);
mutt_set_flag (ctx, h, M_READ, hd->read);
mutt_set_flag (ctx, h, M_NEW, !(hd->read || hd->old));
mutt_set_flag (ctx, h, M_OLD, hd->old);
mutt_set_flag (ctx, h, M_READ, hd->read);
* read header lines and call it again. Silly. */
if ((rc = msg_parse_fetch (h, buf)) != -2 || !fp)
return rc;
* read header lines and call it again. Silly. */
if ((rc = msg_parse_fetch (h, buf)) != -2 || !fp)
return rc;
if (imap_get_literal_count (buf, &bytes) == 0)
{
imap_read_literal (fp, idata, bytes, NULL);
if (imap_get_literal_count (buf, &bytes) == 0)
{
imap_read_literal (fp, idata, bytes, NULL);
/* subtract headers from message size - unfortunately only the subset of
* headers we've requested. */
h->content_length -= bytes;
/* subtract headers from message size - unfortunately only the subset of
* headers we've requested. */
h->content_length -= bytes;