From: Richard Russon Date: Sat, 25 Aug 2018 16:50:56 +0000 (+0100) Subject: probe imap X-Git-Tag: 2019-10-25~682^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d2b5b02d521b7ca01b8786cecb7307ba6d91f323;p=neomutt probe imap --- diff --git a/browser.c b/browser.c index a793194ec..ecf440562 100644 --- 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; diff --git a/commands.c b/commands.c index 09e608440..fb4f63661 100644 --- a/commands.c +++ b/commands.c @@ -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)) { diff --git a/complete.c b/complete.c index 76f60db69..b1010bebb 100644 --- a/complete.c +++ b/complete.c @@ -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 diff --git a/compose.c b/compose.c index d0749cf40..398cedc44 100644 --- 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) diff --git a/imap/imap.c b/imap/imap.c index da4ea6379..b842cc5c1 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -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; } diff --git a/imap/util.c b/imap/util.c index ad7445924..f90a92873 100644 --- a/imap/util.c +++ b/imap/util.c @@ -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 d2accd4af..3b3cbffcf 100644 --- 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); diff --git a/muttlib.c b/muttlib.c index 6caf10a87..c9ccfdc76 100644 --- 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 1c7ecd205..439fe88ae 100644 --- 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 ebc3f92a9..6f3f536ef 100644 --- 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 */ diff --git a/postpone.c b/postpone.c index b05051da5..a66af71fe 100644 --- a/postpone.c +++ b/postpone.c @@ -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 26e88bdb1..e15da4744 100644 --- 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