]> granicus.if.org Git - neomutt/commitdiff
probe imap
authorRichard Russon <rich@flatcap.org>
Sat, 25 Aug 2018 16:50:56 +0000 (17:50 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 26 Aug 2018 21:11:03 +0000 (22:11 +0100)
12 files changed:
browser.c
commands.c
complete.c
compose.c
imap/imap.c
imap/util.c
main.c
muttlib.c
mx.c
mx.h
postpone.c
send.c

index a793194ecaad6d7b7891f8956a1558e85181eb32..ecf4405623747411cdf8fd2bd9f08db546ceea85 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -983,7 +983,7 @@ static int examine_mailboxes(struct Menu *menu, struct BrowserState *state)
         mutt_pretty_mailbox(buffer, sizeof(buffer));
 
 #ifdef USE_IMAP
-      if (mx_is_imap(np->b->path))
+      if (imap_path_probe(np->b->path, NULL) == MUTT_IMAP)
       {
         add_folder(menu, state, buffer, NULL, NULL, np->b, NULL);
         continue;
@@ -1203,9 +1203,8 @@ static void init_menu(struct BrowserState *state, struct Menu *menu,
     char TargetDir[PATH_MAX] = "";
 
 #ifdef USE_IMAP
-    /* Use mx_is_imap to check what kind of dir is OldLastDir.
-     */
-    if (mx_is_imap(OldLastDir))
+    /* Check what kind of dir OldLastDir is. */
+    if (imap_path_probe(OldLastDir, NULL) == MUTT_IMAP)
     {
       mutt_str_strfcpy(TargetDir, OldLastDir, sizeof(TargetDir));
       imap_clean_path(TargetDir, sizeof(TargetDir));
@@ -1334,7 +1333,7 @@ void mutt_select_file(char *file, size_t filelen, int flags, char ***files, int
   {
     mutt_expand_path(file, filelen);
 #ifdef USE_IMAP
-    if (mx_is_imap(file))
+    if (imap_path_probe(file, NULL) == MUTT_IMAP)
     {
       init_state(&state, NULL);
       state.imap_browse = true;
@@ -1464,7 +1463,7 @@ void mutt_select_file(char *file, size_t filelen, int flags, char ***files, int
     }
 
 #ifdef USE_IMAP
-    if (!mailbox && mx_is_imap(LastDir))
+    if (!mailbox && (imap_path_probe(LastDir, NULL) == MUTT_IMAP))
     {
       init_state(&state, NULL);
       state.imap_browse = true;
@@ -1868,7 +1867,7 @@ void mutt_select_file(char *file, size_t filelen, int flags, char ***files, int
           mailbox = 0;
           mutt_expand_path(buf, sizeof(buf));
 #ifdef USE_IMAP
-          if (mx_is_imap(buf))
+          if (imap_path_probe(buf, NULL) == MUTT_IMAP)
           {
             mutt_str_strfcpy(LastDir, buf, sizeof(LastDir));
             destroy_state(&state);
@@ -2078,7 +2077,7 @@ void mutt_select_file(char *file, size_t filelen, int flags, char ***files, int
           examine_mailboxes(menu, &state);
         }
 #ifdef USE_IMAP
-        else if (mx_is_imap(LastDir))
+        else if (imap_path_probe(LastDir, NULL) == MUTT_IMAP)
         {
           init_state(&state, NULL);
           state.imap_browse = true;
index 09e6084403f07d685e6dcade23482826a4984e1b..fb4f63661ecca7fa862cc0c6852eb2f546f11ab5 100644 (file)
@@ -968,7 +968,7 @@ int mutt_save_message(struct Header *h, bool delete, bool decode, bool decrypt)
   mutt_message(_("Copying to %s..."), buf);
 
 #ifdef USE_IMAP
-  if (Context->magic == MUTT_IMAP && !(decode || decrypt) && mx_is_imap(buf))
+  if ((Context->magic == MUTT_IMAP) && !(decode || decrypt) && (imap_path_probe(buf, NULL) == MUTT_IMAP))
   {
     switch (imap_copy_messages(Context, h, buf, delete))
     {
index 76f60db691fbfa0fcf89d08671fc614ff60bd151..b1010bebbd465f988b58dd89b9ad10301e183635 100644 (file)
@@ -142,7 +142,7 @@ int mutt_complete(char *buf, size_t buflen)
   else
     mutt_str_strfcpy(imap_path, buf, sizeof(imap_path));
 
-  if (mx_is_imap(imap_path))
+  if (imap_path_probe(imap_path, NULL) == MUTT_IMAP)
     return imap_complete(buf, buflen, imap_path);
 #endif
 
index d0749cf40d19a1a0f0f59dd3fc0d8b2e429a660a..398cedc44b32a8371eabb6dd70eee3639df07d67 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -73,6 +73,9 @@
 #ifdef USE_POP
 #include "pop/pop.h"
 #endif
+#ifdef USE_IMAP
+#include "imap/imap.h"
+#endif
 
 /* These Config Variables are only used in compose.c */
 char *ComposeFormat; ///< Config: printf-like format string for the Compose panel's status bar
@@ -1431,7 +1434,7 @@ int mutt_compose_menu(struct Header *msg, char *fcc, size_t fcclen,
 #endif
           mutt_expand_path(fname, sizeof(fname));
 #ifdef USE_IMAP
-        if (!mx_is_imap(fname))
+        if (imap_path_probe(fname, NULL) != MUTT_IMAP)
 #endif
 #ifdef USE_POP
           if (pop_path_probe(fname, NULL) != MUTT_POP)
index da4ea6379004c8eca36e5ccd956acdf02abd9d7d..b842cc5c166ea4fa849ece268ac29239dda1a807 100644 (file)
@@ -1439,7 +1439,7 @@ int imap_mailbox_check(bool check_stats)
     /* Init newly-added mailboxes */
     if (np->b->magic == MUTT_UNKNOWN)
     {
-      if (mx_is_imap(np->b->path))
+      if (imap_path_probe(np->b->path, NULL) == MUTT_IMAP)
         np->b->magic = MUTT_IMAP;
     }
 
@@ -1714,7 +1714,7 @@ int imap_subscribe(char *path, bool subscribe)
   struct ImapMbox mx;
   size_t len = 0;
 
-  if (!mx_is_imap(path) || imap_parse_path(path, &mx) || !mx.mbox)
+  if ((imap_path_probe(path, NULL) != MUTT_IMAP) || imap_parse_path(path, &mx) || !mx.mbox)
   {
     mutt_error(_("Bad mailbox name"));
     return -1;
@@ -2051,7 +2051,7 @@ static int imap_mbox_open(struct Context *ctx)
   }
   /* pipeline the postponed count if possible */
   pmx.mbox = NULL;
-  if (mx_is_imap(Postponed) && !imap_parse_path(Postponed, &pmx) &&
+  if ((imap_path_probe(Postponed, NULL) == MUTT_IMAP) && !imap_parse_path(Postponed, &pmx) &&
       mutt_account_match(&pmx.account, &mx.account))
   {
     imap_status(Postponed, true);
@@ -2727,9 +2727,11 @@ int imap_path_probe(const char *path, const struct stat *st)
   if (!path)
     return MUTT_UNKNOWN;
 
-  enum UrlScheme scheme = url_check_scheme(path);
-  if ((scheme == U_IMAP) || (scheme == U_IMAPS))
-    return MUTT_IMAP;
+  if (mutt_str_strncasecmp(path, "imap://", 7) == 0)
+    return MUTT_NOTMUCH;
+
+  if (mutt_str_strncasecmp(path, "imaps://", 8) == 0)
+    return MUTT_NOTMUCH;
 
   return MUTT_UNKNOWN;
 }
index ad7445924f954ebdf710865b6f0894ab5a0bf830..f90a9287303bb28a4961c0de5f70965ec70d8263 100644 (file)
@@ -517,7 +517,7 @@ void imap_pretty_mailbox(char *path, const char *folder)
 
   tlen = mutt_str_strlen(target.mbox);
   /* check whether we can do '=' substitution */
-  if (mx_is_imap(folder) && !imap_parse_path(folder, &home))
+  if ((imap_path_probe(folder, NULL) == MUTT_IMAP) && !imap_parse_path(folder, &home))
   {
     hlen = mutt_str_strlen(home.mbox);
     if (tlen && mutt_account_match(&home.account, &target.account) &&
diff --git a/main.c b/main.c
index d2accd4afe9ac0b5c961938d1101615154425206..3b3cbffcf39cd0cbbc413331ab6bf9aa47c65364 100644 (file)
--- a/main.c
+++ b/main.c
@@ -794,7 +794,7 @@ int main(int argc, char *argv[], char *envp[])
     bool skip = false;
 #ifdef USE_IMAP
     /* we're not connected yet - skip mail folder creation */
-    skip |= mx_is_imap(fpath);
+    skip |= (imap_path_probe(fpath, NULL) == MUTT_IMAP);
 #endif
 #ifdef USE_NNTP
     skip |= (nntp_path_probe(fpath, NULL) == MUTT_NNTP);
index 6caf10a87002356245bf58770d2351eff279fa22..c9ccfdc76a9cbb07cfae8310951df5dc0bc26bdc 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -191,7 +191,7 @@ char *mutt_expand_path_regex(char *buf, size_t buflen, bool regex)
       {
 #ifdef USE_IMAP
         /* if folder = {host} or imap[s]://host/: don't append slash */
-        if (mx_is_imap(Folder) &&
+        if ((imap_path_probe(Folder, NULL) == MUTT_IMAP) &&
             (Folder[strlen(Folder) - 1] == '}' || Folder[strlen(Folder) - 1] == '/'))
         {
           mutt_str_strfcpy(p, Folder, sizeof(p));
@@ -300,7 +300,7 @@ char *mutt_expand_path_regex(char *buf, size_t buflen, bool regex)
 #ifdef USE_IMAP
   /* Rewrite IMAP path in canonical form - aids in string comparisons of
    * folders. May possibly fail, in which case buf should be the same. */
-  if (mx_is_imap(buf))
+  if (imap_path_probe(buf, NULL) == MUTT_IMAP)
     imap_expand_path(buf, buflen);
 #endif
 
@@ -1524,7 +1524,7 @@ int mutt_set_xdg_path(enum XdgType type, char *buf, size_t bufsize)
 void mutt_get_parent_path(char *path, char *buf, size_t buflen)
 {
 #ifdef USE_IMAP
-  if (mx_is_imap(path))
+  if (imap_path_probe(path, NULL) == MUTT_IMAP)
     imap_get_parent_path(path, buf, buflen);
   else
 #endif
diff --git a/mx.c b/mx.c
index 1c7ecd20504d6ebdfc6d9f36f9bf5b924bc83ba7..439fe88ae428cd5d17144d28cd21b0e17847590f 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -147,30 +147,6 @@ static bool mutt_is_spool(const char *str)
   return mutt_str_strcmp(Spoolfile, str) == 0;
 }
 
-#ifdef USE_IMAP
-/**
- * mx_is_imap - Is this an IMAP mailbox
- * @param p Mailbox string to test
- * @retval true It is an IMAP mailbox
- */
-bool mx_is_imap(const char *p)
-{
-  enum UrlScheme scheme;
-
-  if (!p)
-    return false;
-
-  if (*p == '{')
-    return true;
-
-  scheme = url_check_scheme(p);
-  if (scheme == U_IMAP || scheme == U_IMAPS)
-    return true;
-
-  return false;
-}
-#endif
-
 /**
  * mx_access - Wrapper for access, checks permissions on a given mailbox
  * @param path  Path of mailbox
@@ -184,7 +160,7 @@ bool mx_is_imap(const char *p)
 int mx_access(const char *path, int flags)
 {
 #ifdef USE_IMAP
-  if (mx_is_imap(path))
+  if (imap_path_probe(path, NULL) == MUTT_IMAP)
     return imap_access(path);
 #endif
 
@@ -478,7 +454,7 @@ static int trash_append(struct Context *ctx)
   }
 
 #ifdef USE_IMAP
-  if (Context->magic == MUTT_IMAP && mx_is_imap(Trash))
+  if (Context->magic == MUTT_IMAP && (imap_path_probe(Trash, NULL) == MUTT_IMAP))
   {
     if (imap_fast_trash(Context, Trash) == 0)
       return 0;
@@ -635,7 +611,7 @@ int mx_mbox_close(struct Context *ctx, int *index_hint)
     /* try to use server-side copy first */
     i = 1;
 
-    if (ctx->magic == MUTT_IMAP && mx_is_imap(mbox))
+    if ((ctx->magic == MUTT_IMAP) && (imap_path_probe(mbox, NULL) == MUTT_IMAP))
     {
       /* tag messages for moving, and clear old tags, if any */
       for (i = 0; i < ctx->msgcount; i++)
diff --git a/mx.h b/mx.h
index ebc3f92a95534cd047ee33f21600165b01a465d2..6f3f536ef22b82001a09e017dae930eee9d9e9c1 100644 (file)
--- a/mx.h
+++ b/mx.h
@@ -252,8 +252,4 @@ bool                mx_tags_is_supported(struct Context *ctx);
 void                mx_update_context(struct Context *ctx, int new_messages);
 void                mx_update_tables(struct Context *ctx, bool committing);
 
-#ifdef USE_IMAP
-bool mx_is_imap(const char *p);
-#endif
-
 #endif /* _MUTT_MX_H */
index b05051da5a6f0304c0ca776b8556301ffdbb8702..a66af71fea563f913694ebb00dc5e901abe3478d 100644 (file)
@@ -108,7 +108,7 @@ int mutt_num_postponed(bool force)
 
 #ifdef USE_IMAP
   /* LastModify is useless for IMAP */
-  if (mx_is_imap(Postponed))
+  if (imap_path_probe(Postponed, NULL) == MUTT_IMAP)
   {
     if (force)
     {
diff --git a/send.c b/send.c
index 26e88bdb1ea4b848ed06225ef5df60813353ac50..e15da4744dff8dd159c8ccbd686704a965f547b2 100644 (file)
--- a/send.c
+++ b/send.c
@@ -69,6 +69,9 @@
 #ifdef USE_NOTMUCH
 #include "notmuch/mutt_notmuch.h"
 #endif
+#ifdef USE_IMAP
+#include "imap/imap.h"
+#endif
 
 /* These Config Variables are only used in send.c */
 unsigned char AbortNoattach; ///< Config: Abort sending the email if attachments are missing
@@ -2277,7 +2280,7 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile,
    */
 
 #ifdef USE_IMAP
-  if ((flags & SEND_BATCH) && fcc[0] && mx_is_imap(fcc))
+  if ((flags & SEND_BATCH) && fcc[0] && (imap_path_probe(fcc, NULL) == MUTT_IMAP))
     fcc[0] = '\0';
 #endif