dprint (2, (debugfile, "Getting mailbox UIDVALIDITY\n"));
pc += 3;
pc = imap_next_word (pc);
- sscanf (pc, "%lu", &(idata->uid_validity));
+ idata->uid_validity = strtol (pc, NULL, 10);
status->uidvalidity = idata->uid_validity;
}
else if (ascii_strncasecmp ("OK [UIDNEXT", pc, 11) == 0)
dprint (2, (debugfile, "Getting mailbox UIDNEXT\n"));
pc += 3;
pc = imap_next_word (pc);
- sscanf (pc, "%u", &status->uidnext);
+ idata->uidnext = strtol (pc, NULL, 10);
+ status->uidnext = idata->uidnext;
}
else
{
const char *want_headers = "DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL";
#if USE_HCACHE
- void *hc = NULL;
- unsigned long *uid_validity = NULL;
+ void *hc = NULL;
+ uint32_t *uid_validity = NULL;
+ uint32_t *uidnext = NULL;
+ int evalhc = 0;
char uid_buf[64];
#endif /* USE_HCACHE */
if (!msgbegin)
hc = mutt_hcache_open (HeaderCache, ctx->path);
- if (hc) {
+ if (hc)
+ {
+ uid_validity = mutt_hcache_fetch_raw (hc, "/UIDVALIDITY", imap_hcache_keylen);
+ uidnext = mutt_hcache_fetch_raw (hc, "/UIDNEXT", imap_hcache_keylen);
+ if (uid_validity && uidnext && *uid_validity == idata->uid_validity)
+ evalhc = 1;
+ FREE (&uid_validity);
+ }
+ if (evalhc)
+ {
snprintf (buf, sizeof (buf),
- "FETCH %d:%d (UID FLAGS)", msgbegin + 1, msgend + 1);
- fetchlast = msgend + 1;
+ "UID FETCH %d:%d (UID FLAGS)", 1, *uidnext - 1);
+ FREE (&uidnext);
imap_cmd_start (idata, buf);
if (rc != IMAP_CMD_CONTINUE)
break;
- if ((mfhrc = msg_fetch_header (idata->ctx, &h, idata->buf, NULL)) == -1)
+ if ((mfhrc = msg_fetch_header (ctx, &h, idata->buf, NULL)) == -1)
continue;
else if (mfhrc < 0)
break;
- /* make sure we don't get remnants from older larger message headers */
- fputs ("\n\n", fp);
-
sprintf(uid_buf, "/%u", h.data->uid); /* XXX --tg 21:41 04-07-11 */
- uid_validity = (unsigned long *) mutt_hcache_fetch (hc, uid_buf, &imap_hcache_keylen);
+ uid_validity = (uint32_t*)mutt_hcache_fetch (hc, uid_buf, &imap_hcache_keylen);
if (uid_validity != NULL && *uid_validity == idata->uid_validity)
{
FREE(&uid_validity);
}
- while ((rc != IMAP_CMD_OK) && ((mfhrc == -1) ||
- ((msgno + 1) >= fetchlast)));
-
+ while (rc != IMAP_CMD_OK && mfhrc == -1);
+ if (rc == IMAP_CMD_OK)
+ break;
if ((mfhrc < -1) || ((rc != IMAP_CMD_CONTINUE) && (rc != IMAP_CMD_OK)))
{
imap_free_header_data ((void**) &h.data);
for (msgno = msgbegin; msgno <= msgend ; msgno++)
{
- if (ReadInc && (!msgno || ((msgno+1) % ReadInc == 0)))
- mutt_message (_("Fetching message headers... [%d/%d]"), msgno + 1,
- msgend + 1);
-
if (ctx->hdrs[msgno])
+ {
+ msgbegin++;
continue;
+ }
+
+ if (ReadInc && (msgno == msgbegin || ((msgno+1) % ReadInc == 0)))
+ mutt_message (_("Fetching message headers... [%d/%d]"), msgno + 1,
+ msgend + 1);
if (msgno + 1 > fetchlast)
{
if (rc != IMAP_CMD_CONTINUE)
break;
- if ((mfhrc = msg_fetch_header (idata->ctx, &h, idata->buf, fp)) == -1)
+ if ((mfhrc = msg_fetch_header (ctx, &h, idata->buf, fp)) == -1)
continue;
else if (mfhrc < 0)
break;
}
}
+ if (maxuid && (status = imap_mboxcache_get (idata, idata->mailbox)))
+ status->uidnext = maxuid + 1;
+
#if USE_HCACHE
+ mutt_hcache_store_raw (hc, "/UIDVALIDITY", &idata->uid_validity,
+ sizeof (idata->uid_validity), imap_hcache_keylen);
+ mutt_hcache_store_raw (hc, "/UIDNEXT", &idata->uidnext,
+ sizeof (idata->uidnext), imap_hcache_keylen);
mutt_hcache_close (hc);
#endif /* USE_HCACHE */
mx_update_context (ctx, ctx->msgcount - oldmsgcount);
}
- if (maxuid && (status = imap_mboxcache_get (idata, idata->mailbox)))
- status->uidnext = maxuid + 1;
-
return msgend;
}