]> granicus.if.org Git - neomutt/commitdiff
imap: remove ImapMbox from imap_prepare_mailbox
authorMehdi Abaakouk <sileht@sileht.net>
Tue, 13 Nov 2018 15:04:00 +0000 (16:04 +0100)
committerRichard Russon <rich@flatcap.org>
Thu, 15 Nov 2018 00:26:28 +0000 (00:26 +0000)
imap/imap.c
imap/imap_private.h
imap/util.c

index c32d00479fca5a58dee5dde4f58aab0e2a2efeeb..ca7fda3b952adbe2b94ad63a4586ab3d15dd441a 100644 (file)
@@ -329,7 +329,6 @@ static int sync_helper(struct ImapAccountData *adata, int right, int flag, const
 /**
  * imap_prepare_mailbox - Ensure we have a valid Mailbox
  * @param m                     Mailbox
- * @param mx                    Imap Mailbox
  * @param mailbox               Buffer for tidied mailbox path
  * @param mailboxlen            Length of buffer
  * @retval  0 Success
@@ -338,18 +337,11 @@ static int sync_helper(struct ImapAccountData *adata, int right, int flag, const
  * This method ensure we have a valid Mailbox object with the ImapAccountData
  * structure setuped and ready to use.
  */
-int imap_prepare_mailbox(struct Mailbox *m, struct ImapMbox *mx, char *mailbox, size_t mailboxlen)
+int imap_prepare_mailbox(struct Mailbox *m, char *mailbox, size_t mailboxlen)
 {
   if (!m || !m->account)
     return -1;
 
-  if ((imap_path_probe(m->path, NULL) != MUTT_IMAP) || imap_parse_path(m->path, mx))
-  {
-    mutt_debug(1, "Error parsing %s\n", m->path);
-    mutt_error(_("Bad mailbox name"));
-    return -1;
-  }
-
   struct ImapAccountData *adata = m->account->adata;
 
   mutt_account_hook(m->realpath);
@@ -357,9 +349,8 @@ int imap_prepare_mailbox(struct Mailbox *m, struct ImapMbox *mx, char *mailbox,
   if (imap_login(adata) < 0)
     return -1;
 
-  imap_fix_path(adata, mx->mbox, mailbox, mailboxlen);
-  if (!*mailbox)
-    mutt_str_strfcpy(mailbox, "INBOX", mailboxlen);
+  struct ImapMailboxData *mdata = m->mdata;
+  mutt_str_strfcpy(mailbox, mdata->name, mailboxlen);
   return 0;
 }
 
@@ -1390,14 +1381,12 @@ int imap_mailbox_check(struct Mailbox *m, bool check_stats)
   char name[LONG_STRING];
   char command[LONG_STRING * 2];
   char munged[LONG_STRING];
-  struct ImapMbox mx;
 
-  if (imap_prepare_mailbox(m, &mx, name, sizeof(name)))
+  if (imap_prepare_mailbox(m, name, sizeof(name)))
   {
     m->has_new = false;
     return -1;
   }
-  FREE(&mx.mbox);
 
   adata = m->account->adata;
 
@@ -2234,22 +2223,22 @@ static int imap_mbox_open(struct Context *ctx)
   char buf[PATH_MAX];
   char bufout[PATH_MAX];
   int count = 0;
-  struct ImapMbox mx, pmx;
+  struct ImapMbox pmx;
   int rc;
   const char *condstore = NULL;
 
-  rc = imap_prepare_mailbox(m, &mx, buf, sizeof(buf));
+  rc = imap_prepare_mailbox(m, buf, sizeof(buf));
   if (rc < 0)
   {
-    FREE(&mx.mbox);
     return -1;
   }
 
   struct ImapAccountData *adata = m->account->adata;
+  struct ImapMailboxData *mdata = m->mdata;
 
   FREE(&(adata->mbox_name));
-  adata->mbox_name = mutt_str_strdup(buf);
-  imap_qualify_path(buf, sizeof(buf), &mx, adata->mbox_name);
+  adata->mbox_name = mutt_str_strdup(mdata->name);
+  imap_qualify_path2(buf, sizeof(buf), &adata->conn_account, adata->mbox_name);
 
   mutt_str_strfcpy(m->path, buf, sizeof(m->path));
   mutt_str_strfcpy(m->realpath, m->path, sizeof(m->realpath));
@@ -2291,8 +2280,8 @@ static int imap_mbox_open(struct Context *ctx)
   }
   /* pipeline the postponed count if possible */
   pmx.mbox = NULL;
-  if ((imap_path_probe(Postponed, NULL) == MUTT_IMAP) &&
-      !imap_parse_path(Postponed, &pmx) && mutt_account_match(&pmx.account, &mx.account))
+  if ((imap_path_probe(Postponed, NULL) == MUTT_IMAP) && !imap_parse_path(Postponed, &pmx) &&
+      mutt_account_match(&pmx.account, &adata->conn_account))
   {
     imap_status(Postponed, true);
   }
@@ -2461,13 +2450,11 @@ static int imap_mbox_open(struct Context *ctx)
   }
 
   mutt_debug(2, "msg_count is %d\n", m->msg_count);
-  FREE(&mx.mbox);
   return 0;
 
 fail:
   if (adata->state == IMAP_SELECTED)
     adata->state = IMAP_AUTHENTICATED;
-  FREE(&mx.mbox);
   return -1;
 }
 
@@ -2480,13 +2467,11 @@ static int imap_mbox_open_append(struct Mailbox *m, int flags)
     return -1;
 
   char mailbox[PATH_MAX];
-  struct ImapMbox mx;
   int rc;
 
   /* in APPEND mode, we appear to hijack an existing IMAP connection -
    * ctx is brand new and mostly empty */
-  rc = imap_prepare_mailbox(m, &mx, mailbox, sizeof(mailbox));
-  FREE(&mx.mbox);
+  rc = imap_prepare_mailbox(m, mailbox, sizeof(mailbox));
   if (rc < 0)
     return -1;
 
index 0b70803c4feeda32aefdde082d7b87942c3dfc02..c77a5f6409ef539921d9e3780546b259675d22db 100644 (file)
@@ -371,6 +371,7 @@ char *imap_get_qualifier(char *buf);
 int imap_mxcmp(const char *mx1, const char *mx2);
 char *imap_next_word(char *s);
 void imap_qualify_path(char *buf, size_t buflen, struct ImapMbox *mx, char *path);
+void imap_qualify_path2(char *buf, size_t buflen, struct ConnAccount *conn_account, char *path);
 void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick);
 void imap_unquote_string(char *s);
 void imap_munge_mbox_name(struct ImapAccountData *adata, char *dest, size_t dlen, const char *src);
index 6a66e317cec37f1109508612e2d57ddc4edc741e..22f2ace65b05afb167fb3389547af753d5765353 100644 (file)
@@ -964,6 +964,21 @@ void imap_qualify_path(char *buf, size_t buflen, struct ImapMbox *mx, char *path
   url_tostring(&url, buf, buflen, 0);
 }
 
+/**
+ * imap_qualify_path2 - Make an absolute IMAP folder target
+ * @param buf    Buffer for the result
+ * @param buflen Length of buffer
+ * @param conn_account     ConnAccount of the account
+ * @param path   Path relative to the mailbox
+ */
+void imap_qualify_path2(char *buf, size_t buflen, struct ConnAccount *conn_account, char *path)
+{
+  struct Url url;
+  mutt_account_tourl(conn_account, &url);
+  url.path = path;
+  url_tostring(&url, buf, buflen, 0);
+}
+
 /**
  * imap_quote_string - quote string according to IMAP rules
  * @param dest           Buffer for the result