]> granicus.if.org Git - neomutt/commitdiff
imap: factor out get_adata
authorRichard Russon <rich@flatcap.org>
Wed, 10 Oct 2018 15:00:28 +0000 (16:00 +0100)
committerRichard Russon <rich@flatcap.org>
Wed, 10 Oct 2018 22:12:51 +0000 (23:12 +0100)
imap/imap.c
imap/imap_private.h
imap/message.c
imap/util.c

index 5bedafd2ba84595ebd26c3735233d14ae24eb07d..0e773467bf57617817077e857c2761ef2a07ba99 100644 (file)
@@ -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;
index 2f36dbb755035dfb0cf9f105c72c80a6c05e64db..ffab848d8b34395c3d0d956253c2a5a8089cf0f9 100644 (file)
@@ -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);
index 56c6299ac01eac4ce1440f9c7f0bd4635724e3cb..037d7c8e9367978ba854258fb594e933913289ad 100644 (file)
@@ -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);
index 87690dde0c133743283b787d4f552303f9f27a7f..0bb418fc4486649d2e5844989032599df9158ba6 100644 (file)
 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;
 }