From: Richard Russon Date: Wed, 10 Oct 2018 15:00:28 +0000 (+0100) Subject: imap: factor out get_adata X-Git-Tag: 2019-10-25~609 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29adf87c925a73732cc95298e19fda5705f1b689;p=neomutt imap: factor out get_adata --- diff --git a/imap/imap.c b/imap/imap.c index 5bedafd2b..0e773467b 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -490,7 +490,7 @@ static int compile_search(struct Mailbox *mailbox, const struct Pattern *pat, break; case MUTT_SERVERSEARCH: { - struct ImapAccountData *adata = mailbox->data; + struct ImapAccountData *adata = imap_get_adata(mailbox); if (!mutt_bit_isset(adata->capabilities, X_GM_EXT1)) { mutt_error(_("Server-side custom search not supported: %s"), pat->p.str); @@ -716,9 +716,9 @@ int imap_rename_mailbox(struct ImapAccountData *adata, struct ImapMbox *mx, cons int imap_delete_mailbox(struct Mailbox *mailbox, struct ImapMbox *mx) { char buf[PATH_MAX], mbox[PATH_MAX]; - struct ImapAccountData *adata = NULL; + struct ImapAccountData *adata = imap_get_adata(mailbox); - if (!mailbox || !mailbox->data) + if (!mailbox || !adata) { adata = imap_conn_find(&mx->account, ImapPassive ? MUTT_IMAP_CONN_NONEW : 0); if (!adata) @@ -1371,7 +1371,8 @@ int imap_sync_message_for_copy(struct ImapAccountData *adata, struct Email *e, */ int imap_check_mailbox(struct Mailbox *mailbox, bool force) { - return imap_check(mailbox->data, force); + struct ImapAccountData *adata = imap_get_adata(mailbox); + return imap_check(adata, force); } /** @@ -1690,7 +1691,7 @@ void imap_mboxcache_free(struct ImapAccountData *adata) int imap_search(struct Mailbox *mailbox, const struct Pattern *pat) { struct Buffer buf; - struct ImapAccountData *adata = mailbox->data; + struct ImapAccountData *adata = imap_get_adata(mailbox); for (int i = 0; i < mailbox->msg_count; i++) mailbox->hdrs[i]->matched = false; @@ -1899,7 +1900,7 @@ int imap_fast_trash(struct Mailbox *mailbox, char *dest) struct Buffer *sync_cmd = NULL; int err_continue = MUTT_NO; - struct ImapAccountData *adata = mailbox->data; + struct ImapAccountData *adata = imap_get_adata(mailbox); if (imap_parse_path(dest, &mx)) { @@ -2010,7 +2011,7 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) int oldsort; int rc; - struct ImapAccountData *adata = ctx->mailbox->data; + struct ImapAccountData *adata = imap_get_adata(ctx->mailbox); if (adata->state < IMAP_SELECTED) { @@ -2505,11 +2506,11 @@ static int imap_mbox_open_append(struct Context *ctx, int flags) */ static int imap_mbox_check(struct Context *ctx, int *index_hint) { - int rc; (void) index_hint; imap_allow_reopen(ctx); - rc = imap_check(ctx->mailbox->data, false); + struct ImapAccountData *adata = imap_get_adata(ctx->mailbox); + int rc = imap_check(adata, false); /* NOTE - ctx might have been changed at this point. In particular, * ctx->mailbox could be NULL. Beware. */ imap_disallow_reopen(ctx); @@ -2523,7 +2524,7 @@ static int imap_mbox_check(struct Context *ctx, int *index_hint) */ static int imap_mbox_close(struct Context *ctx) { - struct ImapAccountData *adata = ctx->mailbox->data; + struct ImapAccountData *adata = imap_get_adata(ctx->mailbox); /* Check to see if the mailbox is actually open */ if (!adata) return 0; @@ -2597,7 +2598,7 @@ static int imap_tags_edit(struct Context *ctx, const char *tags, char *buf, size { char *new = NULL; char *checker = NULL; - struct ImapAccountData *adata = ctx->mailbox->data; + struct ImapAccountData *adata = imap_get_adata(ctx->mailbox); /* Check for \* flags capability */ if (!imap_has_flag(&adata->flags, NULL)) @@ -2684,7 +2685,7 @@ static int imap_tags_commit(struct Context *ctx, struct Email *e, char *buf) struct Buffer *cmd = NULL; char uid[11]; - struct ImapAccountData *adata = ctx->mailbox->data; + struct ImapAccountData *adata = imap_get_adata(ctx->mailbox); if (*buf == '\0') buf = NULL; diff --git a/imap/imap_private.h b/imap/imap_private.h index 2f36dbb75..ffab848d8 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -37,6 +37,7 @@ struct Context; struct Email; struct ImapEmailData; struct ImapMbox; +struct Mailbox; struct Message; struct Progress; @@ -327,6 +328,7 @@ int imap_msg_close(struct Context *ctx, struct Message *msg); int imap_msg_commit(struct Context *ctx, struct Message *msg); /* util.c */ +struct ImapAccountData *imap_get_adata(struct Mailbox *m); #ifdef USE_HCACHE header_cache_t *imap_hcache_open(struct ImapAccountData *adata, const char *path); void imap_hcache_close(struct ImapAccountData *adata); diff --git a/imap/message.c b/imap/message.c index 56c6299ac..037d7c8e9 100644 --- a/imap/message.c +++ b/imap/message.c @@ -393,7 +393,7 @@ static int msg_fetch_header(struct Mailbox *mailbox, struct ImapHeader *h, int rc = -1; /* default now is that string isn't FETCH response */ int parse_rc; - struct ImapAccountData *adata = mailbox->data; + struct ImapAccountData *adata = imap_get_adata(mailbox); if (buf[0] != '*') return rc; @@ -1352,7 +1352,7 @@ int imap_append_message(struct Context *ctx, struct Message *msg) struct ImapMbox mx; int rc; - struct ImapAccountData *adata = ctx->mailbox->data; + struct ImapAccountData *adata = imap_get_adata(ctx->mailbox); if (imap_parse_path(ctx->mailbox->path, &mx)) return -1; @@ -1486,7 +1486,7 @@ int imap_copy_messages(struct Context *ctx, struct Email *e, char *dest, bool de int err_continue = MUTT_NO; int triedcreate = 0; - struct ImapAccountData *adata = ctx->mailbox->data; + struct ImapAccountData *adata = imap_get_adata(ctx->mailbox); if (imap_parse_path(dest, &mx)) { @@ -1797,7 +1797,7 @@ int imap_msg_open(struct Context *ctx, struct Message *msg, int msgno) bool fetched = false; int output_progress; - struct ImapAccountData *adata = ctx->mailbox->data; + struct ImapAccountData *adata = imap_get_adata(ctx->mailbox); struct Email *e = ctx->mailbox->hdrs[msgno]; msg->fp = msg_cache_get(adata, e); diff --git a/imap/util.c b/imap/util.c index 87690dde0..0bb418fc4 100644 --- a/imap/util.c +++ b/imap/util.c @@ -64,6 +64,16 @@ char *ImapDelimChars; ///< Config: (imap) Characters that denote separators in IMAP folders short ImapPipelineDepth; ///< Config: (imap) Number of IMAP commands that may be queued up +/** + * imap_get_adata - Get the Account data for this mailbox + */ +struct ImapAccountData *imap_get_adata(struct Mailbox *m) +{ + if (!m || (m->magic != MUTT_IMAP)) + return NULL; + return m->data; +} + /** * imap_expand_path - Canonicalise an IMAP path * @param buf Buffer containing path @@ -1106,11 +1116,12 @@ int imap_wait_keepalive(pid_t pid) */ void imap_allow_reopen(struct Context *ctx) { - struct ImapAccountData *adata = NULL; - if (!ctx || !ctx->mailbox->data || ctx->mailbox->magic != MUTT_IMAP) + if (!ctx) + return; + struct ImapAccountData *adata = imap_get_adata(ctx->mailbox); + if (!adata) return; - adata = ctx->mailbox->data; if (adata->ctx == ctx) adata->reopen |= IMAP_REOPEN_ALLOW; } @@ -1121,11 +1132,12 @@ void imap_allow_reopen(struct Context *ctx) */ void imap_disallow_reopen(struct Context *ctx) { - struct ImapAccountData *adata = NULL; - if (!ctx || !ctx->mailbox || !ctx->mailbox->data || ctx->mailbox->magic != MUTT_IMAP) + if (!ctx) + return; + struct ImapAccountData *adata = imap_get_adata(ctx->mailbox); + if (!adata) return; - adata = ctx->mailbox->data; if (adata->ctx == ctx) adata->reopen &= ~IMAP_REOPEN_ALLOW; }