]> granicus.if.org Git - neomutt/commitdiff
imap: remove get_mailbox()
authorMehdi Abaakouk <sileht@sileht.net>
Tue, 13 Nov 2018 17:01:12 +0000 (18:01 +0100)
committerRichard Russon <rich@flatcap.org>
Thu, 15 Nov 2018 00:26:28 +0000 (00:26 +0000)
imap/browse.c
imap/imap.c
imap/imap_private.h
imap/util.c

index 8edf9c8dcb05d8f558d7193cf2449ce57c36bd5f..0aa212de04069b6b96a2bd4c8061bce90053da6a 100644 (file)
@@ -385,7 +385,7 @@ int imap_mailbox_create(const char *path)
   char name[LONG_STRING];
   short n;
 
-  adata = imap_adata_find(path, name, sizeof(name));
+  adata = imap_adata_find(path, name, sizeof(name), false);
   if (!adata)
   {
     mutt_debug(1, "Couldn't find open connection to %s\n", path);
@@ -435,7 +435,7 @@ int imap_mailbox_rename(const char *path)
   char oldname[LONG_STRING];
   char newname[PATH_MAX];
 
-  adata = imap_adata_find(path, oldname, sizeof(oldname));
+  adata = imap_adata_find(path, oldname, sizeof(oldname), false);
   if (!adata)
   {
     mutt_debug(1, "Couldn't find open connection to %s\n", path);
index 59b6ddcbeb8f6a1f60b409aa3b8dfd53775ce3b7..1eba93ed7a15b5040f544be70866059776a092dd 100644 (file)
@@ -354,34 +354,6 @@ int imap_prepare_mailbox(struct Mailbox *m, char *mailbox, size_t mailboxlen)
   return 0;
 }
 
-/**
- * get_mailbox - Split mailbox URI
- * @param path   Mailbox URI
- * @param adata  Imap Account data
- * @param buf    Buffer to store mailbox name
- * @param buflen Length of buffer
- * @retval  0 Success
- * @retval -1 Failure
- *
- * Split up a mailbox URI.  The connection info is stored in the ImapAccountData and
- * the mailbox name is stored in buf.
- * TODO(sileht): We should drop this method and pass a Context or Mailbox
- * object everywhere instead.
- */
-int get_mailbox(const char *path, struct ImapAccountData **adata, char *buf, size_t buflen)
-{
-  char tmp[LONG_STRING];
-
-  *adata = imap_adata_find(path, tmp, sizeof(tmp));
-  if (!*adata)
-    return -1;
-
-  imap_fix_path(*adata, tmp, buf, buflen);
-  if (!*buf)
-    mutt_str_strfcpy(buf, "INBOX", buflen);
-  return 0;
-}
-
 /**
  * do_search - Perform a search of messages
  * @param search  List of pattern to match
@@ -694,14 +666,15 @@ int imap_access(const char *path)
 {
   struct ImapAccountData *adata = NULL;
   char mailbox[LONG_STRING];
-  int rc;
 
-  rc = get_mailbox(path, &adata, mailbox, sizeof(mailbox));
-  if (rc < 0)
+  adata = imap_adata_find(path, mailbox, sizeof(mailbox), true);
+  if (!adata)
     return -1;
 
-  rc = imap_access2(adata, mailbox);
-  return rc;
+  if (mailbox[0] == '\0')
+    mutt_str_strfcpy(mailbox, "INBOX", sizeof(mailbox));
+
+  return imap_access2(adata, mailbox);
 }
 
 /**
@@ -1448,7 +1421,8 @@ int imap_status(const char *path, bool queue)
   char mbox[LONG_STRING];
   struct ImapStatus *status = NULL;
 
-  if (get_mailbox(path, &adata, buf, sizeof(buf)) < 0)
+  adata = imap_adata_find(path, buf, sizeof(buf), true);
+  if (!adata)
     return -1;
 
   /* We are in the folder we're polling - just return the mailbox count.
@@ -1623,10 +1597,9 @@ int imap_subscribe(char *path, bool subscribe)
   char errstr[STRING];
   struct Buffer err, token;
   size_t len = 0;
-  int rc;
 
-  rc = get_mailbox(path, &adata, buf, sizeof(buf));
-  if (rc < 0)
+  adata = imap_adata_find(path, buf, sizeof(buf), false);
+  if (!adata)
     return -1;
 
   if (ImapCheckSubscribed)
@@ -1685,7 +1658,7 @@ int imap_complete(char *buf, size_t buflen, char *path)
   int completions = 0;
   int rc;
 
-  adata = imap_adata_find(path, mailbox, sizeof(mailbox));
+  adata = imap_adata_find(path, mailbox, sizeof(mailbox), false);
   if (!adata)
   {
     mutt_str_strfcpy(buf, path, buflen);
index 50605a79a2077b0cfbea7c7d9a853a1b3e3309db..a4b5e861bbc80b98b30a3d0de4de9b34524e9239 100644 (file)
@@ -318,7 +318,7 @@ int imap_login(struct ImapAccountData *adata);
 void imap_logout(struct ImapAccountData **adata);
 int imap_sync_message_for_copy(struct ImapAccountData *adata, struct Email *e, struct Buffer *cmd, int *err_continue);
 bool imap_has_flag(struct ListHead *flag_list, const char *flag);
-struct ImapAccountData *imap_adata_find(const char *path, char *mailbox, size_t mailboxlen);
+struct ImapAccountData *imap_adata_find(const char *path, char *mailbox, size_t mailboxlen, bool fix_path);
 
 /* auth.c */
 int imap_authenticate(struct ImapAccountData *adata);
index d970a6537c9312eee80fb9cec13d42f66addc860..c69265982d3b746eb4ba2e9f81b34a4a045900e4 100644 (file)
@@ -126,7 +126,8 @@ struct ImapAccountData *imap_adata_get(struct Mailbox *m)
 /**
  * imap_adata_find - Find the Account data for this path
  */
-struct ImapAccountData *imap_adata_find(const char *path, char *mailbox, size_t mailboxlen)
+struct ImapAccountData *imap_adata_find(const char *path, char *mailbox,
+                                        size_t mailboxlen, bool fix_path)
 {
   // NOTE(sileht): Remove mx when we are able to pass Mailbox or Url there.
   struct ImapMbox mx;
@@ -145,7 +146,12 @@ struct ImapAccountData *imap_adata_find(const char *path, char *mailbox, size_t
     if (imap_account_match(&adata->conn_account, &mx.account))
     {
       if (mx.mbox)
-        mutt_str_strfcpy(mailbox, mx.mbox, mailboxlen);
+      {
+        if (fix_path)
+          imap_fix_path(adata, mx.mbox, mailbox, mailboxlen);
+        else
+          mutt_str_strfcpy(mailbox, mx.mbox, mailboxlen);
+      }
       return adata;
     }
   }
@@ -260,16 +266,13 @@ void imap_get_parent_path(const char *path, char *buf, size_t buflen)
   struct ImapAccountData *adata = NULL;
   char mbox[LONG_STRING], tmp[LONG_STRING];
 
-  adata = imap_adata_find(path, tmp, sizeof(tmp));
+  adata = imap_adata_find(path, tmp, sizeof(tmp), true);
   if (!adata || tmp[0] == '\0')
   {
     mutt_str_strfcpy(buf, path, buflen);
     return;
   }
 
-  /* Stores a fixed path in mbox */
-  imap_fix_path(adata, tmp, mbox, sizeof(mbox));
-
   /* Gets the parent mbox in mbox */
   imap_get_parent(mbox, adata->delim, mbox, sizeof(mbox));
 
@@ -289,13 +292,10 @@ void imap_clean_path(char *path, size_t plen)
   struct ImapAccountData *adata = NULL;
   char mbox[LONG_STRING], tmp[LONG_STRING];
 
-  adata = imap_adata_find(path, tmp, sizeof(tmp));
+  adata = imap_adata_find(path, tmp, sizeof(tmp), true);
   if (!adata || tmp[0] == '\0')
     return;
 
-  /* Stores a fixed path in mbox */
-  imap_fix_path(adata, tmp, mbox, sizeof(mbox));
-
   /* Returns a fully qualified IMAP url */
   imap_qualify_path2(path, plen, &adata->conn_account, mbox);
 }