/**
* msg_cache_open - Open a message cache
- * @param adata Imap Account data
+ * @param m Selected Imap Mailbox
* @retval ptr Success, using existing cache
* @retval ptr Success, opened new cache
* @retval NULL Failure
*/
-static struct BodyCache *msg_cache_open(struct ImapAccountData *adata)
+static struct BodyCache *msg_cache_open(struct Mailbox *m)
{
- struct ImapMboxData *mdata = adata->mailbox->mdata;
+ struct ImapAccountData *adata = imap_adata_get(m);
+ struct ImapMboxData *mdata = imap_mdata_get(m);
+
+ if (!adata || adata->mailbox != m)
+ return NULL;
+
char mailbox[PATH_MAX];
if (mdata->bcache)
/**
* msg_cache_get - Get the message cache entry for an email
- * @param adata Imap Account data
+ * @param m Selected Imap Mailbox
* @param e Email
* @retval ptr Success, handle of cache entry
* @retval NULL Failure
*/
-static FILE *msg_cache_get(struct ImapAccountData *adata, struct Email *e)
+static FILE *msg_cache_get(struct Mailbox *m, struct Email *e)
{
- if (!adata || !e)
- return NULL;
+ struct ImapAccountData *adata = imap_adata_get(m);
+ struct ImapMboxData *mdata = imap_mdata_get(m);
- struct ImapMboxData *mdata = adata->mailbox->mdata;
+ if (!e || !adata || adata->mailbox != m)
+ return NULL;
- mdata->bcache = msg_cache_open(adata);
+ mdata->bcache = msg_cache_open(m);
char id[64];
snprintf(id, sizeof(id), "%u-%u", mdata->uid_validity, imap_edata_get(e)->uid);
return mutt_bcache_get(mdata->bcache, id);
/**
* msg_cache_put - Put an email into the message cache
- * @param adata Imap Account data
+ * @param m Selected Imap Mailbox
* @param e Email
* @retval ptr Success, handle of cache entry
* @retval NULL Failure
*/
-static FILE *msg_cache_put(struct ImapAccountData *adata, struct Email *e)
+static FILE *msg_cache_put(struct Mailbox *m, struct Email *e)
{
- if (!adata || !e)
- return NULL;
+ struct ImapAccountData *adata = imap_adata_get(m);
+ struct ImapMboxData *mdata = imap_mdata_get(m);
- struct ImapMboxData *mdata = adata->mailbox->mdata;
+ if (!e || !adata || adata->mailbox != m)
+ return NULL;
- mdata->bcache = msg_cache_open(adata);
+ mdata->bcache = msg_cache_open(m);
char id[64];
snprintf(id, sizeof(id), "%u-%u", mdata->uid_validity, imap_edata_get(e)->uid);
return mutt_bcache_put(mdata->bcache, id);
/**
* msg_cache_commit - Add to the message cache
- * @param adata Imap Account data
+ * @param m Selected Imap Mailbox
* @param e Email
* @retval 0 Success
* @retval -1 Failure
*/
-static int msg_cache_commit(struct ImapAccountData *adata, struct Email *e)
+static int msg_cache_commit(struct Mailbox *m, struct Email *e)
{
- if (!adata || !e)
- return -1;
+ struct ImapAccountData *adata = imap_adata_get(m);
+ struct ImapMboxData *mdata = imap_mdata_get(m);
- struct ImapMboxData *mdata = adata->mailbox->mdata;
+ if (!e || !adata || adata->mailbox != m)
+ return -1;
- mdata->bcache = msg_cache_open(adata);
+ mdata->bcache = msg_cache_open(m);
char id[64];
snprintf(id, sizeof(id), "%u-%u", mdata->uid_validity, imap_edata_get(e)->uid);
static int msg_cache_clean_cb(const char *id, struct BodyCache *bcache, void *data)
{
unsigned int uv, uid;
- struct ImapAccountData *adata = data;
- struct ImapMboxData *mdata = adata->mailbox->mdata;
+ struct ImapMboxData *mdata = data;
if (sscanf(id, "%u-%u", &uv, &uid) != 2)
return 0;
/**
* read_headers_fetch_new - Retrieve new messages from the server
- * @param[in] adata Imap Account data
+ * @param[in] m Imap Selected Mailbox
* @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
* @retval 0 Success
* @retval -1 Error
*/
-static int read_headers_fetch_new(struct ImapAccountData *adata, unsigned int msn_begin,
+static int read_headers_fetch_new(struct Mailbox *m, unsigned int msn_begin,
unsigned int msn_end, bool evalhc,
unsigned int *maxuid, bool initial_download)
{
"CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL "
"X-ORIGINAL-TO";
- struct Mailbox *m = adata->mailbox;
- struct ImapMboxData *mdata = adata->mailbox->mdata;
+ struct ImapAccountData *adata = imap_adata_get(m);
+ struct ImapMboxData *mdata = imap_mdata_get(m);
int idx = m->msg_count;
+ if (!adata || adata->mailbox != m)
+ return -1;
+
if (mutt_bit_isset(adata->capabilities, IMAP_CAP_IMAP4REV1))
{
safe_asprintf(&hdrreq, "BODY.PEEK[HEADER.FIELDS (%s%s%s)]", want_headers,
/**
* imap_read_headers - Read headers from the server
- * @param adata Imap Account data
+ * @param m Imap Selected Mailbox
* @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
* the last message read. It will return a value other than msn_end if mail
* comes in while downloading headers (in theory).
*/
-int imap_read_headers(struct ImapAccountData *adata, unsigned int msn_begin,
+int imap_read_headers(struct Mailbox *m, unsigned int msn_begin,
unsigned int msn_end, bool initial_download)
{
int oldmsgcount;
char *uid_seqset = NULL;
#endif /* USE_HCACHE */
- struct Mailbox *m = adata->mailbox;
+ struct ImapAccountData *adata = imap_adata_get(m);
struct ImapMboxData *mdata = imap_mdata_get(m);
+ if (!adata || adata->mailbox != m)
+ return -1;
/* make sure context has room to hold the mailbox */
while (msn_end > m->hdrmax)
}
#endif /* USE_HCACHE */
- if (read_headers_fetch_new(adata, msn_begin, msn_end, evalhc, &maxuid, initial_download) < 0)
+ if (read_headers_fetch_new(m, msn_begin, msn_end, evalhc, &maxuid, initial_download) < 0)
goto bail;
if (maxuid && mdata->uid_next < maxuid + 1)
/**
* imap_cache_del - Delete an email from the body cache
- * @param adata Imap Account data
+ * @param m Selected Imap Mailb
* @param e Email
* @retval 0 Success
* @retval -1 Failure
*/
-int imap_cache_del(struct ImapAccountData *adata, struct Email *e)
+int imap_cache_del(struct Mailbox *m, struct Email *e)
{
- if (!adata || !e)
+ struct ImapAccountData *adata = imap_adata_get(m);
+ struct ImapMboxData *mdata = imap_mdata_get(m);
+
+ if (!e || !adata || adata->mailbox != m)
return -1;
- struct ImapMboxData *mdata = adata->mailbox->mdata;
- mdata->bcache = msg_cache_open(adata);
+ mdata->bcache = msg_cache_open(m);
char id[64];
snprintf(id, sizeof(id), "%u-%u", mdata->uid_validity, imap_edata_get(e)->uid);
return mutt_bcache_del(mdata->bcache, id);
/**
* imap_cache_clean - Delete all the entries in the message cache
- * @param adata Imap Account data
+ * @param m SelectedImap Mailbox
* @retval 0 Always
*/
-int imap_cache_clean(struct ImapAccountData *adata)
+int imap_cache_clean(struct Mailbox *m)
{
- struct ImapMboxData *mdata = adata->mailbox->mdata;
- mdata->bcache = msg_cache_open(adata);
- mutt_bcache_list(mdata->bcache, msg_cache_clean_cb, adata);
+ struct ImapAccountData *adata = imap_adata_get(m);
+ struct ImapMboxData *mdata = imap_mdata_get(m);
+
+ if (!adata || adata->mailbox != m)
+ return -1;
+
+ mdata->bcache = msg_cache_open(m);
+ mutt_bcache_list(mdata->bcache, msg_cache_clean_cb, mdata);
return 0;
}
/**
* imap_set_flags - fill the message header according to the server flags
- * @param[in] adata Imap Account data
+ * @param[in] m Imap Selected Mailbox
* @param[in] e Email
* @param[in] s Command string
* @param[out] server_changes Flags have changed
* case of e->changed, if a change to a flag _would_ have been
* made.
*/
-char *imap_set_flags(struct ImapAccountData *adata, struct Email *e, char *s, int *server_changes)
+char *imap_set_flags(struct Mailbox *m, struct Email *e, char *s, int *server_changes)
{
- struct Mailbox *m = adata->mailbox;
+ struct ImapAccountData *adata = imap_adata_get(m);
+ if (!adata || adata->mailbox != m)
+ return NULL;
+
struct ImapHeader newh = { 0 };
struct ImapEmailData old_edata;
bool readonly;
struct ImapAccountData *adata = imap_adata_get(m);
struct ImapMboxData *mdata = imap_mdata_get(m);
+
+ if (!adata || adata->mailbox != m)
+ return -1;
+
struct Email *e = m->hdrs[msgno];
- msg->fp = msg_cache_get(adata, e);
+ msg->fp = msg_cache_get(m, e);
if (msg->fp)
{
if (imap_edata_get(e)->parsed)
if (output_progress)
mutt_message(_("Fetching message..."));
- msg->fp = msg_cache_put(adata, e);
+ msg->fp = msg_cache_put(m, e);
if (!msg->fp)
{
cache->uid = imap_edata_get(e)->uid;
* incrementally update flags later, this won't stop us syncing */
else if (mutt_str_startswith(pc, "FLAGS", CASE_IGNORE) && !e->changed)
{
- pc = imap_set_flags(adata, e, pc, NULL);
+ pc = imap_set_flags(m, e, pc, NULL);
if (!pc)
goto bail;
}
if (!fetched || !imap_code(adata->buf))
goto bail;
- msg_cache_commit(adata, e);
+ msg_cache_commit(m, e);
parsemsg:
/* Update the header information. Previously, we only downloaded a
/* retry message parse if cached message is empty */
if (!retried && ((e->lines == 0) || (e->content->length == 0)))
{
- imap_cache_del(adata, e);
+ imap_cache_del(m, e);
retried = true;
goto parsemsg;
}
bail:
mutt_file_fclose(&msg->fp);
- imap_cache_del(adata, e);
+ imap_cache_del(m, e);
if (cache->path)
{
unlink(cache->path);