#include "mutt/mutt.h"
/**
- * struct ParameterList - List of parameters.
+ * struct ParameterList - List of parameters
*/
TAILQ_HEAD(ParameterList, Parameter);
WHERE bool Help; ///< Config: Display a help line with common key bindings
#ifdef USE_IMAP
WHERE bool ImapCheckSubscribed; ///< Config: (imap) When opening a mailbox, ask the server for a list of subscribed folders
-WHERE bool ImapCondStore;
+WHERE bool ImapCondStore; ///< Config: (imap) Enable the CONDSTORE extension
WHERE bool ImapListSubscribed; ///< Config: (imap) When browsing a mailbox, only display subscribed folders
WHERE bool ImapPassive; ///< Config: (imap) Reuse an existing IMAP connection to check for new mail
WHERE bool ImapPeek; ///< Config: (imap) Don't mark messages as read when fetching them from the server
-WHERE bool ImapQResync;
+WHERE bool ImapQResync; ///< Config: (imap) Enable the QRESYNC extension
#endif
#ifdef USE_SSL
#ifndef USE_SSL_GNUTLS
idata->reopen |= IMAP_EXPUNGE_PENDING;
}
-/* cmd_parse_vanished: handles VANISHED (RFC 7162), which is like
- * expunge, but passes a seqset of UIDs. An optional (EARLIER) argument
- * specifies not to decrement subsequent MSNs. */
+/**
+ * cmd_parse_vanished - Parse vanished command
+ * @param idata Server data
+ * @param s String containing MSN of message to expunge
+ *
+ * Handle VANISHED (RFC7162), which is like expunge, but passes a seqset of UIDs.
+ * An optional (EARLIER) argument specifies not to decrement subsequent MSNs.
+ */
static void cmd_parse_vanished(struct ImapData *idata, char *s)
{
- int earlier = 0, rc;
- char *end_of_seqset;
- struct SeqsetIterator *iter;
- unsigned int uid, exp_msn, cur;
- struct Header *h;
+ bool earlier = false;
+ int rc;
+ unsigned int uid = 0;
mutt_debug(2, "Handling VANISHED\n");
{
/* The RFC says we should not decrement msns with the VANISHED EARLIER tag.
* My experimentation says that's crap. */
- /* earlier = 1; */
- earlier = 1;
+ earlier = true;
s = imap_next_word(s);
}
- end_of_seqset = s;
+ char *end_of_seqset = s;
while (*end_of_seqset)
{
if (!strchr("0123456789:,", *end_of_seqset))
end_of_seqset++;
}
- iter = mutt_seqset_iterator_new(s);
+ struct SeqsetIterator *iter = mutt_seqset_iterator_new(s);
if (!iter)
{
mutt_debug(2, "VANISHED: empty seqset [%s]?\n", s);
while ((rc = mutt_seqset_iterator_next(iter, &uid)) == 0)
{
- h = (struct Header *) mutt_hash_int_find(idata->uid_hash, uid);
+ struct Header *h = mutt_hash_int_find(idata->uid_hash, uid);
if (!h)
continue;
- exp_msn = HEADER_DATA(h)->msn;
+ unsigned int exp_msn = HEADER_DATA(h)->msn;
/* imap_expunge_mailbox() will rewrite h->index.
* It needs to resort using SORT_ORDER anyway, so setting to INT_MAX
h->index = INT_MAX;
HEADER_DATA(h)->msn = 0;
- if (exp_msn < 1 || exp_msn > idata->max_msn)
+ if ((exp_msn < 1) || (exp_msn > idata->max_msn))
{
mutt_debug(1, "VANISHED: msn for UID %u is incorrect.\n", uid);
continue;
if (!earlier)
{
/* decrement seqno of those above. */
- for (cur = exp_msn; cur < idata->max_msn; cur++)
+ for (unsigned int cur = exp_msn; cur < idata->max_msn; cur++)
{
h = idata->msn_index[cur];
if (h)
SKIPWS(s);
if (*s != '(')
{
- mutt_debug(1, "cmd_parse_fetch: bogus MODSEQ response: %s\n", s);
+ mutt_debug(1, "bogus MODSEQ response: %s\n", s);
return;
}
s++;
s++;
else
{
- mutt_debug(1, "cmd_parse_fetch: Unterminated MODSEQ response: %s\n", s);
+ mutt_debug(1, "Unterminated MODSEQ response: %s\n", s);
return;
}
}
else if (mutt_str_strncasecmp("FETCH", s, 5) == 0)
cmd_parse_fetch(idata, pn);
}
- else if ((idata->state >= IMAP_SELECTED) && mutt_str_strncasecmp("VANISHED", s, 8) == 0)
+ else if ((idata->state >= IMAP_SELECTED) && (mutt_str_strncasecmp("VANISHED", s, 8) == 0))
cmd_parse_vanished(idata, pn);
else if (mutt_str_strncasecmp("CAPABILITY", s, 10) == 0)
cmd_parse_capability(idata, s);
/* check_status: curs_main uses imap_check_mailbox to detect
* whether the index needs updating */
idata->check_status = IMAP_NEWMAIL_PENDING;
- imap_read_headers(idata, idata->max_msn + 1, count, 0);
+ imap_read_headers(idata, idata->max_msn + 1, count, false);
}
else if (idata->reopen & IMAP_EXPUNGE_PENDING)
{
}
FREE(&mx.mbox);
- if (imap_mboxcache_get(idata, mailbox, 0))
+ if (imap_mboxcache_get(idata, mailbox, false))
{
mutt_debug(3, "found %s in cache\n", mailbox);
return 0;
imap_exec(idata, buf, 0);
queued = 0;
- status = imap_mboxcache_get(idata, mbox, 0);
+ status = imap_mboxcache_get(idata, mbox, false);
if (status)
return status->messages;
struct ImapStatus *imap_mboxcache_get(struct ImapData *idata, const char *mbox, bool create)
{
struct ImapStatus *status = NULL;
-#ifdef USE_HCACHE
- header_cache_t *hc = NULL;
- void *uidvalidity = NULL;
- void *uidnext = NULL;
- unsigned long long *modseq = NULL;
-#endif
-
struct ListNode *np = NULL;
STAILQ_FOREACH(np, &idata->mboxcache, entries)
{
struct ImapStatus *scache = mutt_mem_calloc(1, sizeof(struct ImapStatus));
scache->name = (char *) mbox;
mutt_list_insert_tail(&idata->mboxcache, (char *) scache);
- status = imap_mboxcache_get(idata, mbox, 0);
+ status = imap_mboxcache_get(idata, mbox, false);
status->name = mutt_str_strdup(mbox);
}
#ifdef USE_HCACHE
- hc = imap_hcache_open(idata, mbox);
+ header_cache_t *hc = imap_hcache_open(idata, mbox);
if (hc)
{
- uidvalidity = mutt_hcache_fetch_raw(hc, "/UIDVALIDITY", 12);
- uidnext = mutt_hcache_fetch_raw(hc, "/UIDNEXT", 8);
- modseq = mutt_hcache_fetch_raw(hc, "/MODSEQ", 7);
+ void *uidvalidity = mutt_hcache_fetch_raw(hc, "/UIDVALIDITY", 12);
+ void *uidnext = mutt_hcache_fetch_raw(hc, "/UIDNEXT", 8);
+ unsigned long long *modseq = mutt_hcache_fetch_raw(hc, "/MODSEQ", 7);
if (uidvalidity)
{
if (!status)
mutt_hcache_free(hc, &uidnext);
mutt_hcache_free(hc, (void **) &modseq);
mutt_hcache_close(hc);
- return imap_mboxcache_get(idata, mbox, 1);
+ return imap_mboxcache_get(idata, mbox, true);
}
status->uidvalidity = *(unsigned int *) uidvalidity;
status->uidnext = uidnext ? *(unsigned int *) uidnext : 0;
status->modseq = modseq ? *modseq : 0;
- mutt_debug(3, "mboxcache: hcache uidvalidity %u, uidnext %u, modseq %llu\n",
- status->uidvalidity, status->uidnext, status->modseq);
+ mutt_debug(3, "hcache uidvalidity %u, uidnext %u, modseq %llu\n",
+ status->uidvalidity, status->uidnext, status->modseq);
}
mutt_hcache_free(hc, &uidvalidity);
mutt_hcache_free(hc, &uidnext);
if (ImapCheckSubscribed)
imap_exec(idata, "LSUB \"\" \"*\"", IMAP_CMD_QUEUE);
-#if USE_HCACHE
+#ifdef USE_HCACHE
if (mutt_bit_isset(idata->capabilities, CONDSTORE) && ImapCondStore)
condstore = " (CONDSTORE)";
else
imap_cmd_start(idata, bufout);
- status = imap_mboxcache_get(idata, idata->mailbox, 1);
+ status = imap_mboxcache_get(idata, idata->mailbox, true);
do
{
ctx->v2r = mutt_mem_calloc(count, sizeof(int));
ctx->msgcount = 0;
- if (count && (imap_read_headers(idata, 1, count, 1) < 0))
+ if (count && (imap_read_headers(idata, 1, count, true) < 0))
{
mutt_error(_("Error opening mailbox"));
goto fail;
* | imap/auth_cram.c | @subpage imap_auth_cram |
* | imap/auth_gss.c | @subpage imap_auth_gss |
* | imap/auth_login.c | @subpage imap_auth_login |
+ * | imap/auth_oauth.c | @subpage imap_auth_oauth |
* | imap/auth_plain.c | @subpage imap_auth_plain |
* | imap/auth_sasl.c | @subpage imap_auth_sasl |
* | imap/browse.c | @subpage imap_browse |
#endif
};
+/**
+ * struct SeqsetIterator - UID Sequence Set Iterator
+ */
struct SeqsetIterator
{
char *full_seqset;
char *eostr;
int in_range;
int down;
- unsigned int range_cur, range_end;
- char *substr_cur, *substr_end;
+ unsigned int range_cur;
+ unsigned int range_end;
+ char *substr_cur;
+ char *substr_end;
};
/* -- private IMAP functions -- */
/* message.c */
void imap_free_header_data(struct ImapHeaderData **data);
-int imap_read_headers (struct ImapData* idata, unsigned int msn_begin, unsigned int msn_end,
- int initial_download);
+int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned int msn_end, bool initial_download);
char *imap_set_flags(struct ImapData *idata, struct Header *h, char *s, int *server_changes);
int imap_cache_del(struct ImapData *idata, struct Header *h);
int imap_cache_clean(struct ImapData *idata);
struct Header *imap_hcache_get(struct ImapData *idata, unsigned int uid);
int imap_hcache_put(struct ImapData *idata, struct Header *h);
int imap_hcache_del(struct ImapData *idata, unsigned int uid);
-int imap_hcache_store_uid_seqset (struct ImapData *idata);
-int imap_hcache_clear_uid_seqset (struct ImapData *idata);
-char *imap_hcache_get_uid_seqset (struct ImapData *idata);
+int imap_hcache_store_uid_seqset(struct ImapData *idata);
+int imap_hcache_clear_uid_seqset(struct ImapData *idata);
+char *imap_hcache_get_uid_seqset(struct ImapData *idata);
#endif
int imap_continue(const char *msg, const char *resp);
void imap_unquote_string(char *s);
void imap_munge_mbox_name(struct ImapData *idata, char *dest, size_t dlen, const char *src);
void imap_unmunge_mbox_name(struct ImapData *idata, char *s);
-struct SeqsetIterator *mutt_seqset_iterator_new (const char *seqset);
-int mutt_seqset_iterator_next (struct SeqsetIterator *iter, unsigned int *next);
-void mutt_seqset_iterator_free (struct SeqsetIterator **p_iter);
+struct SeqsetIterator *mutt_seqset_iterator_new(const char *seqset);
+int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next);
+void mutt_seqset_iterator_free(struct SeqsetIterator **p_iter);
int imap_account_match(const struct Account *a1, const struct Account *a2);
void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen);
return -1;
}
else if ((mutt_str_strncasecmp("BODY", s, 4) == 0) ||
- (mutt_str_strncasecmp("RFC822.struct Header", s, 13) == 0))
+ (mutt_str_strncasecmp("RFC822.HEADER", s, 13) == 0))
{
/* handle above, in msg_fetch_header */
return -2;
SKIPWS(s);
if (*s != '(')
{
- mutt_debug(1, "msg_parse_flags: bogus MODSEQ response: %s\n", s);
+ mutt_debug(1, "bogus MODSEQ response: %s\n", s);
return -1;
}
s++;
s++;
else
{
- mutt_debug(1, "msg_parse_flags: Unterminated MODSEQ response: %s\n", s);
+ mutt_debug(1, "Unterminated MODSEQ response: %s\n", s);
return -1;
}
}
*len = 0;
}
-/* If the user hits ctrl-c during an initial header download for a mailbox,
+/**
+ * query_abort_header_download - Ask the user whether to abort the download
+ * @param idata Server data
+ * @retval true Abort the download
+ *
+ * If the user hits ctrl-c during an initial header download for a mailbox,
* prompt whether to completely abort the download and close the mailbox.
*/
-static int query_abort_header_download(struct ImapData *idata)
+static bool query_abort_header_download(struct ImapData *idata)
{
- int abort = 0;
+ bool abort = false;
mutt_flushinp();
- /* L10N: This prompt is made if the user hits Ctrl-C when opening
- * an IMAP mailbox */
+ /* L10N: This prompt is made if the user hits Ctrl-C when opening an IMAP mailbox */
if (mutt_yesorno(_("Abort download and close mailbox?"), MUTT_YES) == MUTT_YES)
{
- abort = 1;
+ abort = true;
imap_close_connection(idata);
}
SigInt = 0;
idata->msn_index_size = new_size;
}
-/* This function is run after imap_alloc_msn_index, so we skip the
+/**
+ * imap_alloc_uid_hash - Create a Hash Table for the UIDs
+ * @param idata Server data
+ * @param msn_count Number of MSNs in use
+ *
+ * This function is run after imap_alloc_msn_index, so we skip the
* malicious msn_count size check.
*/
static void imap_alloc_uid_hash(struct ImapData *idata, unsigned int msn_count)
}
/**
- * generate_seqset - Generate a sequence set
+ * imap_fetch_msn_seqset - Generate a sequence set
* @param b Buffer for the result
* @param idata Server data
* @param msn_begin First Message Sequence number
{
int chunks = 0;
int state = 0; /* 1: single msn, 2: range of msn */
- unsigned int range_begin, range_end;
+ unsigned int range_begin = 0;
+ unsigned int range_end = 0;
- for (unsigned int msn = msn_begin; msn <= msn_end + 1; msn++)
+ for (unsigned int msn = msn_begin; msn <= (msn_end + 1); msn++)
{
- if (msn <= msn_end && !idata->msn_index[msn - 1])
+ if ((msn <= msn_end) && !idata->msn_index[msn - 1])
{
switch (state)
{
}
/* Too big. Just query the whole range then. */
- if (chunks == 150 || mutt_str_strlen(b->data) > 500)
+ if ((chunks == 150) || (mutt_str_strlen(b->data) > 500))
{
b->dptr = b->data;
mutt_buffer_printf(b, "%u:%u", msn_begin, msn_end);
mutt_set_flag(ctx, h, flag_name, new_hd_flag);
}
-#if USE_HCACHE
-/* Retrieve data from the header cache.
+#ifdef USE_HCACHE
+/**
+ * read_headers_normal_eval_cache - Retrieve data from the header cache
+ * @param idata Server data
+ * @param msn_end Last Message Sequence number
+ * @param uidnext UID of next email
+ * @param store_flag_updates if true, save flags to the header cache
+ * @param eval_condstore if true, use CONDSTORE to fetch flags
+ * @retval 0 Success
+ * @retval -1 Error
*
* Without CONDSTORE or QRESYNC, we need to query all the current
* UIDs and update their flag state and current MSN.
* their MSN. The current flag state will be queried in
* read_headers_condstore_qresync_updates().
*/
-static int read_headers_normal_eval_cache(struct ImapData *idata, unsigned int msn_end,
- unsigned int uidnext,
- int store_flag_updates, int eval_condstore)
+static int read_headers_normal_eval_cache(struct ImapData *idata,
+ unsigned int msn_end, unsigned int uidnext,
+ bool store_flag_updates, bool eval_condstore)
{
- struct Context *ctx;
- int idx, msgno, rc, mfhrc = 0;
struct Progress progress;
- struct ImapHeader h;
char buf[LONG_STRING];
- ctx = idata->ctx;
- idx = ctx->msgcount;
+ struct Context *ctx = idata->ctx;
+ int idx = ctx->msgcount;
/* L10N:
Comparing the cached data with the IMAP server's data */
imap_cmd_start(idata, buf);
- rc = IMAP_CMD_CONTINUE;
- for (msgno = 1; rc == IMAP_CMD_CONTINUE; msgno++)
+ int rc = IMAP_CMD_CONTINUE;
+ int mfhrc = 0;
+ struct ImapHeader h;
+ for (int msgno = 1; rc == IMAP_CMD_CONTINUE; msgno++)
{
if (SigInt && query_abort_header_download(idata))
return -1;
if (rc != IMAP_CMD_CONTINUE)
break;
- if ((mfhrc = msg_fetch_header(ctx, &h, idata->buf, NULL)) < 0)
+ mfhrc = msg_fetch_header(ctx, &h, idata->buf, NULL);
+ if (mfhrc < 0)
continue;
if (!h.data->uid)
{
- mutt_debug(2, "imap_read_headers: skipping hcache FETCH "
- "response for message number %d missing a UID\n",
- h.data->msn);
+ mutt_debug(2, "skipping hcache FETCH response for message number %d missing a UID\n",
+ h.data->msn);
continue;
}
- if (h.data->msn < 1 || h.data->msn > msn_end)
+ if ((h.data->msn < 1) || (h.data->msn > msn_end))
{
- mutt_debug(1, "imap_read_headers: skipping hcache FETCH "
- "response for unknown message number %d\n",
- h.data->msn);
+ mutt_debug(1, "skipping hcache FETCH response for unknown message number %d\n",
+ h.data->msn);
continue;
}
if (idata->msn_index[h.data->msn - 1])
{
- mutt_debug(2, "imap_read_headers: skipping hcache FETCH "
- "for duplicate message %d\n",
- h.data->msn);
+ mutt_debug(2, "skipping hcache FETCH for duplicate message %d\n", h.data->msn);
continue;
}
ctx->hdrs[idx]->index = idx;
/* messages which have not been expunged are ACTIVE (borrowed from mh
* folders) */
- ctx->hdrs[idx]->active = 1;
- ctx->hdrs[idx]->changed = 0;
+ ctx->hdrs[idx]->active = true;
+ ctx->hdrs[idx]->changed = false;
if (!eval_condstore)
{
ctx->hdrs[idx]->read = h.data->read;
}
/* ctx->hdrs[msgno]->received is restored from mutt_hcache_restore */
- ctx->hdrs[idx]->data = (void *) (h.data);
+ ctx->hdrs[idx]->data = h.data;
STAILQ_INIT(&ctx->hdrs[idx]->tags);
driver_tags_replace(&ctx->hdrs[idx]->tags, mutt_str_strdup(h.data->flags_remote));
return 0;
}
-/* Retrieve data from the header cache.
+/**
+ * read_headers_qresync_eval_cache - Retrieve data from the header cache
+ * @param idata Server data
+ * @param uid_seqset Sequence Set of UIDs
+ * @retval >=0 Success
+ * @retval -1 Error
*
- * For QRESYNC, we grab the UIDs in order by MSN from the header
- * cache.
+ * For QRESYNC, we grab the UIDs in order by MSN from the header cache.
*
- * In read_headers_condstore_qresync_updates(). We will update change
- * flags using CHANGEDSINCE and find out what UIDs have been expunged
- * using VANISHED.
+ * In read_headers_condstore_qresync_updates(). We will update change flags
+ * using CHANGEDSINCE and find out what UIDs have been expunged using VANISHED.
*/
static int read_headers_qresync_eval_cache(struct ImapData *idata, char *uid_seqset)
{
- struct Context *ctx;
int rc;
- unsigned int uid, msn;
- struct SeqsetIterator *iter;
- struct Header *h;
- struct ImapHeaderData *ihd;
+ unsigned int uid = 0;
mutt_debug(2, "Reading uid seqset from header cache\n");
- ctx = idata->ctx;
- msn = 1;
+ struct Context *ctx = idata->ctx;
+ unsigned int msn = 1;
- iter = mutt_seqset_iterator_new(uid_seqset);
+ struct SeqsetIterator *iter = mutt_seqset_iterator_new(uid_seqset);
if (!iter)
return -1;
if (msn > idata->msn_index_size)
alloc_msn_index(idata, msn);
- h = imap_hcache_get(idata, uid);
+ struct Header *h = imap_hcache_get(idata, uid);
if (h)
{
idata->max_msn = MAX(idata->max_msn, msn);
if (ctx->msgcount >= ctx->hdrmax)
mx_alloc_memory(ctx);
- ihd = mutt_mem_calloc(1, sizeof(struct ImapHeaderData));
+ struct ImapHeaderData *ihd = mutt_mem_calloc(1, sizeof(struct ImapHeaderData));
h->data = ihd;
h->index = ctx->msgcount;
- h->active = 1;
- h->changed = 0;
+ h->active = true;
+ h->changed = false;
ihd->read = h->read;
ihd->old = h->old;
ihd->deleted = h->deleted;
return rc;
}
-/*
- * Retrieve updates from the server.
+/**
+ * read_headers_condstore_qresync_updates - Retrieve updates from the server
+ * @param idata Server data
+ * @param msn_end Last Message Sequence number
+ * @param uidnext UID of next email
+ * @param hc_modseq Timestamp of last Header Cache update
+ * @param eval_qresync If true, use QRESYNC
+ * @retval 0 Success
+ * @retval -1 Error
*
* CONDSTORE and QRESYNC use FETCH extensions to grab updates.
*/
-static int read_headers_condstore_qresync_updates(struct ImapData *idata, unsigned int msn_end,
- unsigned int uidnext,
- unsigned long long hc_modseq, int eval_qresync)
+static int read_headers_condstore_qresync_updates(struct ImapData *idata,
+ unsigned int msn_end, unsigned int uidnext,
+ unsigned long long hc_modseq, bool eval_qresync)
{
- struct Context *ctx;
struct Progress progress;
- int msgno, rc;
char buf[LONG_STRING];
- unsigned int header_msn;
- char *fetch_buf;
+ unsigned int header_msn = 0;
- ctx = idata->ctx;
+ struct Context *ctx = idata->ctx;
- /* L10N:
- Fetching IMAP flag changes, using the CONDSTORE extension */
+ /* L10N: Fetching IMAP flag changes, using the CONDSTORE extension */
mutt_progress_init(&progress, _("Fetching flag updates..."),
MUTT_PROGRESS_MSG, ReadInc, msn_end);
imap_cmd_start(idata, buf);
- rc = IMAP_CMD_CONTINUE;
- for (msgno = 1; rc == IMAP_CMD_CONTINUE; msgno++)
+ int rc = IMAP_CMD_CONTINUE;
+ for (int msgno = 1; rc == IMAP_CMD_CONTINUE; msgno++)
{
if (SigInt && query_abort_header_download(idata))
return -1;
/* so we just need to grab the header and persist it back into
* the header cache */
- fetch_buf = idata->buf;
+ char *fetch_buf = idata->buf;
if (fetch_buf[0] != '*')
continue;
fetch_buf = imap_next_word(fetch_buf);
- if (!isdigit((unsigned char) *fetch_buf) || mutt_str_atoui(fetch_buf, &header_msn) < 0)
+ if (!isdigit((unsigned char) *fetch_buf) || (mutt_str_atoui(fetch_buf, &header_msn) < 0))
continue;
- if (header_msn < 1 || header_msn > msn_end || !idata->msn_index[header_msn - 1])
+ if ((header_msn < 1) || (header_msn > msn_end) || !idata->msn_index[header_msn - 1])
{
- mutt_debug(1, "imap_read_headers: skipping CONDSTORE flag "
- "update for unknown message number %u\n",
- header_msn);
+ mutt_debug(1, "skipping CONDSTORE flag update for unknown message number %u\n", header_msn);
continue;
}
/* The IMAP flag setting as part of cmd_parse_fetch() ends up
* flipping these on. */
idata->check_status &= ~IMAP_FLAGS_PENDING;
- ctx->changed = 0;
+ ctx->changed = false;
/* VANISHED handling: we need to empty out the messages */
if (idata->reopen & IMAP_EXPUNGE_PENDING)
}
#endif /* USE_HCACHE */
-/* Retrieve new messages from the server
+/**
+ * read_headers_fetch_new - Retrieve new messages from the server
+ * @param[in] idata Server data
+ * @param[in] msn_begin First Message Sequence number
+ * @param[in] msn_end Last Message Sequence number
+ * @param[in] evalhc if true, check the Header Cache
+ * @param[out] maxuid Highest UID seen
+ * @param[in] initial_download true, if this is the first opening of the mailbox
+ * @retval 0 Success
+ * @retval -1 Error
*/
static int read_headers_fetch_new(struct ImapData *idata, unsigned int msn_begin,
- unsigned int msn_end, int evalhc,
- unsigned int *maxuid, int initial_download)
+ unsigned int msn_end, bool evalhc,
+ unsigned int *maxuid, bool initial_download)
{
- struct Context *ctx;
- int idx, msgno, rc, mfhrc = 0, retval = -1;
+ int rc, mfhrc = 0, retval = -1;
unsigned int fetch_msn_end = 0;
struct Progress progress;
char *hdrreq = NULL;
char tempfile[_POSIX_PATH_MAX];
FILE *fp = NULL;
struct ImapHeader h;
- struct Buffer *b;
static const char *const want_headers =
"DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE "
"CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL "
"X-ORIGINAL-TO";
- ctx = idata->ctx;
- idx = ctx->msgcount;
+ struct Context *ctx = idata->ctx;
+ int idx = ctx->msgcount;
if (mutt_bit_isset(idata->capabilities, IMAP4REV1))
{
- safe_asprintf(&hdrreq, "BODY.PEEK[struct Header.FIELDS (%s%s%s)]",
- want_headers, ImapHeaders ? " " : "", NONULL(ImapHeaders));
+ safe_asprintf(&hdrreq, "BODY.PEEK[HEADER.FIELDS (%s%s%s)]", want_headers,
+ ImapHeaders ? " " : "", NONULL(ImapHeaders));
}
else if (mutt_bit_isset(idata->capabilities, IMAP4))
{
- safe_asprintf(&hdrreq, "RFC822.struct Header.LINES (%s%s%s)", want_headers,
+ 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 */
goto bail;
}
/* instead of downloading all headers and then parsing them, we parse them
* as they come in. */
mutt_mktemp(tempfile, sizeof(tempfile));
- if (!(fp = mutt_file_fopen(tempfile, "w+")))
+ fp = mutt_file_fopen(tempfile, "w+");
+ if (!fp)
{
mutt_error(_("Could not create temporary file %s"), tempfile);
- mutt_sleep(2);
goto bail;
}
unlink(tempfile);
mutt_progress_init(&progress, _("Fetching message headers..."),
MUTT_PROGRESS_MSG, ReadInc, msn_end);
- while (msn_begin <= msn_end && fetch_msn_end < msn_end)
+ while ((msn_begin <= msn_end) && (fetch_msn_end < msn_end))
{
- b = mutt_buffer_new();
+ struct Buffer *b = mutt_buffer_new();
if (evalhc)
{
/* In case there are holes in the header cache. */
mutt_buffer_free(&b);
rc = IMAP_CMD_CONTINUE;
- for (msgno = msn_begin; rc == IMAP_CMD_CONTINUE; msgno++)
+ for (int msgno = msn_begin; rc == IMAP_CMD_CONTINUE; msgno++)
{
if (initial_download && SigInt && query_abort_header_download(idata))
goto bail;
/* make sure we don't get remnants from older larger message headers */
fputs("\n\n", fp);
- if (h.data->msn < 1 || h.data->msn > fetch_msn_end)
+ if ((h.data->msn < 1) || (h.data->msn > fetch_msn_end))
{
mutt_debug(1, "skipping FETCH response for unknown message number %d\n",
h.data->msn);
/* messages which have not been expunged are ACTIVE (borrowed from mh
* folders) */
ctx->hdrs[idx]->active = true;
- ctx->hdrs[idx]->changed = 0;
+ ctx->hdrs[idx]->changed = false;
ctx->hdrs[idx]->read = h.data->read;
ctx->hdrs[idx]->old = h.data->old;
ctx->hdrs[idx]->deleted = h.data->deleted;
/**
* imap_read_headers - Read headers from the server
- * @param idata Server data
- * @param msn_begin First Message Sequence Number
- * @param msn_end Last Message Sequence Number
+ * @param idata Server data
+ * @param msn_begin First Message Sequence Number
+ * @param msn_end Last Message Sequence Number
+ * @param initial_download true, if this is the first opening of the mailbox
* @retval num Last MSN
* @retval -1 Failure
*
* comes in while downloading headers (in theory).
*/
int imap_read_headers(struct ImapData *idata, unsigned int msn_begin,
- unsigned int msn_end, int initial_download)
+ unsigned int msn_end, bool initial_download)
{
struct ImapStatus *status = NULL;
int oldmsgcount;
void *uid_validity = NULL;
void *puidnext = NULL;
unsigned int uidnext = 0;
- int has_condstore = 0;
- int has_qresync = 0;
- int eval_condstore = 0;
- int eval_qresync = 0;
+ bool has_condstore = false;
+ bool has_qresync = false;
+ bool eval_condstore = false;
+ bool eval_qresync = false;
unsigned long long *pmodseq = NULL;
unsigned long long hc_modseq = 0;
char *uid_seqset = NULL;
if (idata->modseq)
{
if (mutt_bit_isset(idata->capabilities, CONDSTORE) && ImapCondStore)
- has_condstore = 1;
+ has_condstore = true;
/* If mutt_bit_isset(QRESYNC) and option(OPTIMAPQRESYNC) then Mutt
* sends ENABLE QRESYNC. If we receive an ENABLED response back, then
* idata->qresync is set.
*/
if (idata->qresync)
- has_qresync = 1;
+ has_qresync = true;
}
- if (uid_validity && uidnext && *(unsigned int *) uid_validity == idata->uid_validity)
+ if (uid_validity && uidnext && (*(unsigned int *) uid_validity == idata->uid_validity))
{
evalhc = true;
pmodseq = mutt_hcache_fetch_raw(idata->hcache, "/MODSEQ", 7);
{
uid_seqset = imap_hcache_get_uid_seqset(idata);
if (uid_seqset)
- eval_qresync = 1;
+ eval_qresync = true;
}
if (!eval_qresync && has_condstore)
- eval_condstore = 1;
+ eval_condstore = true;
}
}
mutt_hcache_free(idata->hcache, &uid_validity);
}
if ((eval_condstore || eval_qresync) && (hc_modseq != idata->modseq))
+ {
if (read_headers_condstore_qresync_updates(idata, msn_end, uidnext,
hc_modseq, eval_qresync) < 0)
+ {
goto bail;
+ }
+ }
/* Look for the first empty MSN and start there */
while (msn_begin <= msn_end)
if (maxuid && (status = imap_mboxcache_get(idata, idata->mailbox, 0)) &&
(status->uidnext < maxuid + 1))
+ {
status->uidnext = maxuid + 1;
+ }
-#if USE_HCACHE
+#ifdef USE_HCACHE
mutt_hcache_store_raw(idata->hcache, "/UIDVALIDITY", 12, &idata->uid_validity,
sizeof(idata->uid_validity));
if (maxuid && idata->uidnext < maxuid + 1)
idata->uidnext = maxuid + 1;
}
if (idata->uidnext > 1)
+ {
mutt_hcache_store_raw(idata->hcache, "/UIDNEXT", 8, &idata->uidnext,
sizeof(idata->uidnext));
+ }
/* We currently only sync CONDSTORE and QRESYNC on the initial download.
* To do it more often, we'll need to deal with flag updates combined with
if (initial_download)
{
if (has_condstore || has_qresync)
+ {
mutt_hcache_store_raw(idata->hcache, "/MODSEQ", 7, &idata->modseq,
sizeof(idata->modseq));
+ }
else
mutt_hcache_delete(idata->hcache, "/MODSEQ", 7);
retval = msn_end;
bail:
-#if USE_HCACHE
+#ifdef USE_HCACHE
imap_hcache_close(idata);
FREE(&uid_seqset);
#endif /* USE_HCACHE */
}
#ifdef USE_HCACHE
-/* Generates a seqseq of the UIDs in msn_index to persist in the header cache.
+/**
+ * imap_msn_index_to_uid_seqset - Convert MSN index of UIDs to Seqset
+ * @param b Buffer for the result
+ * @param idata Server data
*
+ * Generates a seqseq of the UIDs in msn_index to persist in the header cache.
* Empty spots are stored as 0.
*/
static void imap_msn_index_to_uid_seqset(struct Buffer *b, struct ImapData *idata)
{
- int first = 1, state = 0, match = 0;
- struct Header *cur_header;
- unsigned int msn, cur_uid = 0, last_uid = 0;
+ int first = 1, state = 0;
+ bool match = false;
+ unsigned int cur_uid = 0, last_uid = 0;
unsigned int range_begin = 0, range_end = 0;
- for (msn = 1; msn <= idata->max_msn + 1; msn++)
+ for (unsigned int msn = 1; msn <= idata->max_msn + 1; msn++)
{
- match = 0;
+ match = false;
if (msn <= idata->max_msn)
{
- cur_header = idata->msn_index[msn - 1];
+ struct Header *cur_header = idata->msn_index[msn - 1];
cur_uid = cur_header ? HEADER_DATA(cur_header)->uid : 0;
- if (!state || (cur_uid && (cur_uid - 1 == last_uid)))
- match = 1;
+ if (!state || (cur_uid && ((cur_uid - 1) == last_uid)))
+ match = true;
last_uid = cur_uid;
}
return mutt_hcache_delete(idata->hcache, key, imap_hcache_keylen(key));
}
+/**
+ * imap_hcache_store_uid_seqset - Store a UID Sequence Set in the header cache
+ * @param idata Server data
+ * @retval 0 Success
+ * @retval -1 Error
+ */
int imap_hcache_store_uid_seqset(struct ImapData *idata)
{
- struct Buffer *b;
- size_t seqset_size;
- int rc;
-
if (!idata->hcache)
return -1;
- b = mutt_buffer_new();
+ struct Buffer *b = mutt_buffer_new();
/* The seqset is likely large. Preallocate to reduce reallocs */
mutt_buffer_increase_size(b, HUGE_STRING);
imap_msn_index_to_uid_seqset(b, idata);
- seqset_size = b->dptr - b->data;
+ size_t seqset_size = b->dptr - b->data;
if (seqset_size == 0)
b->data[0] = '\0';
- rc = mutt_hcache_store_raw(idata->hcache, "/UIDSEQSET", 10, b->data,
- seqset_size + 1);
+ int rc = mutt_hcache_store_raw(idata->hcache, "/UIDSEQSET", 10, b->data, seqset_size + 1);
mutt_debug(5, "Stored /UIDSEQSET %s\n", b->data);
mutt_buffer_free(&b);
return rc;
}
+/**
+ * imap_hcache_clear_uid_seqset - Delete a UID Sequence Set from the header cache
+ * @param idata Server data
+ * @retval 0 Success
+ * @retval -1 Error
+ */
int imap_hcache_clear_uid_seqset(struct ImapData *idata)
{
if (!idata->hcache)
return mutt_hcache_delete(idata->hcache, "/UIDSEQSET", 10);
}
+/**
+ * imap_hcache_get_uid_seqset - Get a UID Sequence Set from the header cache
+ * @param idata Server data
+ * @retval ptr UID Sequence Set
+ * @retval NULL Error
+ */
char *imap_hcache_get_uid_seqset(struct ImapData *idata)
{
- char *hc_seqset, *seqset;
-
if (!idata->hcache)
return NULL;
- hc_seqset = mutt_hcache_fetch_raw(idata->hcache, "/UIDSEQSET", 10);
- seqset = mutt_str_strdup(hc_seqset);
+ char *hc_seqset = mutt_hcache_fetch_raw(idata->hcache, "/UIDSEQSET", 10);
+ char *seqset = mutt_str_strdup(hc_seqset);
mutt_hcache_free(idata->hcache, (void **) &hc_seqset);
mutt_debug(5, "Retrieved /UIDSEQSET %s\n", NONULL(seqset));
return mutt_account_match(a1_canon, a2_canon);
}
-/* Sequence set iteration */
-
+/**
+ * mutt_seqset_iterator_new - Create a new Sequence Set Iterator
+ * @param seqset Source Sequence Set
+ * @retval ptr Newly allocated Sequence Set Iterator
+ */
struct SeqsetIterator *mutt_seqset_iterator_new(const char *seqset)
{
struct SeqsetIterator *iter;
return iter;
}
-/* Returns: 0 when the next sequence is generated
- * 1 when the iterator is finished
- * -1 on error
+/**
+ * mutt_seqset_iterator_next - Get the next UID from a Sequence Set
+ * @param[in] iter Sequence Set Iterator
+ * @param[out] next Next UID in set
+ * @retval 0 Next sequence is generated
+ * @retval 1 Iterator is finished
+ * @retval -1 error
*/
int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next)
{
if (iter->in_range)
{
- if ((iter->down && iter->range_cur == (iter->range_end - 1)) ||
- (!iter->down && iter->range_cur == (iter->range_end + 1)))
+ if ((iter->down && (iter->range_cur == (iter->range_end - 1))) ||
+ (!iter->down && (iter->range_cur == (iter->range_end + 1))))
+ {
iter->in_range = 0;
+ }
}
if (!iter->in_range)
if (range_sep)
*range_sep++ = '\0';
- if (mutt_str_atoui(iter->substr_cur, &iter->range_cur))
+ if (mutt_str_atoui(iter->substr_cur, &iter->range_cur) != 0)
return -1;
if (range_sep)
{
- if (mutt_str_atoui(range_sep, &iter->range_end))
+ if (mutt_str_atoui(range_sep, &iter->range_end) != 0)
return -1;
}
else
return 0;
}
+/**
+ * mutt_seqset_iterator_free - Free a Sequence Set Iterator
+ * @param p_iter Iterator to free
+ */
void mutt_seqset_iterator_free(struct SeqsetIterator **p_iter)
{
- struct SeqsetIterator *iter;
-
if (!p_iter || !*p_iter)
return;
- iter = *p_iter;
+ struct SeqsetIterator *iter = *p_iter;
FREE(&iter->full_seqset);
- FREE(p_iter); /* __FREE_CHECKED__ */
+ FREE(p_iter);
}
*/
{ "imap_condstore", DT_BOOL, R_NONE, &ImapCondStore, 0 },
/*
- ** .pp
- ** When \fIset\fP, mutt will use the CONDSTORE extension (RFC 7162)
- ** if advertised by the server. Mutt's current implementation is basic,
- ** used only for initial message fetching and flag updates.
- ** .pp
- ** For some IMAP servers, enabling this will slightly speed up
- ** downloading initial messages. Unfortunately, Gmail is not one
- ** those, and displays worse performance when enabled. Your
- ** mileage may vary.
- */
+ ** .pp
+ ** When \fIset\fP, mutt will use the CONDSTORE extension (RFC 7162)
+ ** if advertised by the server. Mutt's current implementation is basic,
+ ** used only for initial message fetching and flag updates.
+ ** .pp
+ ** For some IMAP servers, enabling this will slightly speed up
+ ** downloading initial messages. Unfortunately, Gmail is not one
+ ** those, and displays worse performance when enabled. Your
+ ** mileage may vary.
+ */
{ "imap_delim_chars", DT_STRING, R_NONE, &ImapDelimChars, IP "/." },
/*
** .pp
*/
{ "imap_qresync", DT_BOOL, R_NONE, &ImapQResync, 0 },
/*
- ** .pp
- ** When \fIset\fP, mutt will use the QRESYNC extension (RFC 7162)
- ** if advertised by the server. Mutt's current implementation is basic,
- ** used only for initial message fetching and flag updates.
- ** .pp
- ** Note: this feature is currently experimental. If you experience
- ** strange behavior, such as duplicate or missing messages please
- ** file a bug report to let us know.
- */
+ ** .pp
+ ** When \fIset\fP, mutt will use the QRESYNC extension (RFC 7162)
+ ** if advertised by the server. Mutt's current implementation is basic,
+ ** used only for initial message fetching and flag updates.
+ ** .pp
+ ** Note: this feature is currently experimental. If you experience
+ ** strange behavior, such as duplicate or missing messages please
+ ** file a bug report to let us know.
+ */
{ "imap_servernoise", DT_BOOL, R_NONE, &ImapServernoise, true },
/*
** .pp
return 0;
}
-/* NOTE: this function's return value is different from mutt_atol.
+/**
+ * mutt_str_atoull - Convert ASCII string to an unsigned long long
+ * @param[in] str String to read
+ * @param[out] dst Store the result
+ * @retval 1 Successful conversion, with trailing characters
+ * @retval 0 Successful conversion
+ * @retval -1 Invalid input
*
- * returns: 1 - successful conversion, with trailing characters
- * 0 - successful conversion
- * -1 - invalid input
+ * @note This function's return value differs from the other functions.
+ * They return -1 if there is input beyond the number.
*/
int mutt_str_atoull(const char *str, unsigned long long *dst)
{
errno = 0;
*res = strtoull(str, &e, 10);
- if (*res == ULLONG_MAX && errno == ERANGE)
+ if ((*res == ULLONG_MAX) && (errno == ERANGE))
return -1;
- if (e && *e != '\0')
+ if (e && (*e != '\0'))
return 1;
return 0;
}
char *NntpPass; ///< Config: (nntp) Password for the news server
char *NntpUser; ///< Config: (nntp) Username for the news server
char *PopOauthRefreshCmd; ///< Config: (pop) External command to generate OAUTH refresh token
-char *PopPass; ///< Config: (pop) Password of the POP server
-char *PopUser; ///< Config: (pop) Username of the POP server
+char *PopPass; ///< Config: (pop) Password of the POP server
+char *PopUser; ///< Config: (pop) Username of the POP server
char *SmtpOauthRefreshCmd; ///< Config: (smtp) External command to generate OAUTH refresh token
char *SmtpPass; ///< Config: (smtp) Password for the SMTP server
* pgp_check_decryption_okay - Check GPG output for status codes
* @param fpin File to read from
* @retval 1 - no patterns were matched (if delegated to decryption_okay_regex)
- * @retval 0 - DECRYPTION_OKAY was seen, with no PLAINTEXT outside.
+ * @retval 0 - DECRYPTION_OKAY was seen, with no PLAINTEXT outside
* @retval -1 - No decryption status codes were encountered
- * @retval -2 - PLAINTEXT was encountered outside of DECRYPTION delimeters.
+ * @retval -2 - PLAINTEXT was encountered outside of DECRYPTION delimeters
* @retval -3 - DECRYPTION_FAILED was encountered
*
* Checks GnuPGP status fd output for various status codes indicating
short PopCheckinterval; ///< Config: (pop) Interval between checks for new mail
unsigned char PopDelete; ///< Config: (pop) After downloading POP messages, delete them on the server
char *PopHost; ///< Config: (pop) Url of the POP server
-bool PopLast; ///< Config: (pop) Use the 'LAST' command to fetch new mail
+bool PopLast; ///< Config: (pop) Use the 'LAST' command to fetch new mail
#ifdef USE_HCACHE
#define HC_FNAME "neomutt" /* filename for hcache as POP lacks paths */
snprintf(auth_cmd, auth_cmd_len, "AUTH OAUTHBEARER %s\r\n", oauthbearer);
FREE(&oauthbearer);
- ret = pop_query_d(pop_data, auth_cmd, strlen(auth_cmd),
+ ret =
+ pop_query_d(pop_data, auth_cmd, strlen(auth_cmd),
#ifdef DEBUG
- /* don't print the bearer token unless we're at the ungodly debugging level */
- (DebugLevel < MUTT_SOCK_LOG_FULL) ? "AUTH OAUTHBEARER *\r\n" :
+ /* don't print the bearer token unless we're at the ungodly debugging level */
+ (DebugLevel < MUTT_SOCK_LOG_FULL) ? "AUTH OAUTHBEARER *\r\n" :
#endif
NULL);
FREE(&auth_cmd);