/* If browsing in "local"-mode, than we chose to define LastDir to
* MailDir
*/
- switch (mx_get_magic(CurrentFolder))
+ switch (mx_path_probe(CurrentFolder, NULL))
{
case MUTT_IMAP:
case MUTT_MAILDIR:
sizeof(buf));
}
- enum MailboxType magic = mx_get_magic(buf);
+ enum MailboxType magic = mx_path_probe(buf, NULL);
if ((magic == MUTT_MAILBOX_ERROR) || (magic == MUTT_UNKNOWN)
#ifdef USE_IMAP
|| state.entry[menu->current].inferiors
unlock_realpath(ctx);
- ctx->magic = mx_get_magic(ctx->path);
+ ctx->magic = mx_path_probe(ctx->path, NULL);
if (ctx->magic == MUTT_UNKNOWN)
{
mutt_error(_("Can't identify the contents of the compressed file"));
mutt_error(_("Compress command failed: %s"), ci->open);
goto oa_fail2;
}
- ctx->magic = mx_get_magic(ctx->path);
+ ctx->magic = mx_path_probe(ctx->path, NULL);
}
else
ctx->magic = MboxType;
bool mutt_comp_can_append(struct Context *ctx);
bool mutt_comp_can_read(const char *path);
int mutt_comp_valid_command(const char *cmd);
+int comp_path_probe(const char *path, const struct stat *st);
extern struct MxOps mx_comp_ops;
#endif
mutt_expand_path(buf, buflen);
- enum MailboxType magic = mx_get_magic(buf);
+ enum MailboxType magic = mx_path_probe(buf, NULL);
if ((magic == MUTT_MAILBOX_ERROR) || (magic == MUTT_UNKNOWN))
{
mutt_error(_("%s is not a mailbox"), buf);
int imap_subscribe(char *path, bool subscribe);
int imap_complete(char *buf, size_t buflen, char *path);
int imap_fast_trash(struct Context *ctx, char *dest);
+int imap_path_probe(const char *path, const struct stat *st);
extern struct MxOps mx_imap_ops;
FILE *f = NULL;
bool rc = false;
- enum MailboxType magic = mx_get_magic(path);
+ enum MailboxType magic = mx_path_probe(path, NULL);
if ((magic != MUTT_MBOX) && (magic != MUTT_MMDF))
return false;
else
#endif
if (stat(tmp->path, &sb) != 0 || (S_ISREG(sb.st_mode) && sb.st_size == 0) ||
- ((tmp->magic == MUTT_UNKNOWN) && (tmp->magic = mx_get_magic(tmp->path)) <= 0))
+ ((tmp->magic == MUTT_UNKNOWN) && (tmp->magic = mx_path_probe(tmp->path, NULL)) <= 0))
{
/* if the mailbox still doesn't exist, set the newly created flag to be
* ready for when it does. */
bool mx_is_maildir(const char *path);
bool mx_is_mh(const char *path);
+int maildir_path_probe(const char *path, const struct stat *st);
+int mh_path_probe(const char *path, const struct stat *st);
#ifdef USE_HCACHE
int mh_sync_mailbox_message(struct Context *ctx, int msgno, header_cache_t *hc);
#define MMDF_SEP "\001\001\001\001\n"
void mbox_reset_atime(struct Context *ctx, struct stat *st);
+int mbox_path_probe(const char *path, const struct stat *st);
#endif /* _MBOX_MBOX_H */
int ret = 0;
int rc;
- enum MailboxType magic = mx_get_magic(s);
+ enum MailboxType magic = mx_path_probe(s, NULL);
#ifdef USE_POP
if (magic == MUTT_POP)
/**
* mx_ops - All the Mailbox backends
*/
-const struct MxOps *mx_ops[] = {
-#ifdef USE_COMPRESSED
- &mx_comp_ops,
-#endif
+static const struct MxOps *mx_ops[] = {
+ /* These mailboxes can be recognised by their Url scheme */
#ifdef USE_IMAP
&mx_imap_ops,
-#endif
- &mx_maildir_ops,
- &mx_mbox_ops,
- &mx_mh_ops,
- &mx_mmdf_ops,
-#ifdef USE_NNTP
- &mx_nntp_ops,
#endif
#ifdef USE_NOTMUCH
&mx_notmuch_ops,
#endif
#ifdef USE_POP
&mx_pop_ops,
+#endif
+#ifdef USE_NNTP
+ &mx_nntp_ops,
+#endif
+
+ /* Local mailboxes */
+ &mx_maildir_ops,
+ &mx_mbox_ops,
+ &mx_mh_ops,
+ &mx_mmdf_ops,
+
+ /* If everything else fails... */
+#ifdef USE_COMPRESSED
+ &mx_comp_ops,
#endif
NULL,
};
}
#endif
-/**
- * mx_get_magic - Identify the type of mailbox
- * @param path Mailbox path to test
- * @retval -1 Error, can't identify mailbox
- * @retval >0 Success, e.g. #MUTT_IMAP
- */
-enum MailboxType mx_get_magic(const char *path)
-{
- if (!path)
- return MUTT_UNKNOWN;
-
-#ifdef USE_IMAP
- if (mx_is_imap(path))
- return MUTT_IMAP;
-#endif /* USE_IMAP */
-
-#ifdef USE_POP
- if (mx_is_pop(path))
- return MUTT_POP;
-#endif /* USE_POP */
-
-#ifdef USE_NNTP
- if (mx_is_nntp(path))
- return MUTT_NNTP;
-#endif /* USE_NNTP */
-
-#ifdef USE_NOTMUCH
- if (mx_is_notmuch(path))
- return MUTT_NOTMUCH;
-#endif
-
- struct stat st;
- enum MailboxType magic = MUTT_UNKNOWN;
- FILE *f = NULL;
-
- if (stat(path, &st) == -1)
- {
- mutt_debug(1, "unable to stat %s: %s (errno %d).\n", path, strerror(errno), errno);
- return -1;
- }
-
- if (S_ISDIR(st.st_mode))
- {
- /* check for maildir-style mailbox */
- if (mx_is_maildir(path))
- return MUTT_MAILDIR;
-
- /* check for mh-style mailbox */
- if (mx_is_mh(path))
- return MUTT_MH;
- }
- else if (st.st_size == 0)
- {
- /* hard to tell what zero-length files are, so assume the default magic */
- if (MboxType == MUTT_MBOX || MboxType == MUTT_MMDF)
- return MboxType;
- else
- return MUTT_MBOX;
- }
- else if ((f = fopen(path, "r")))
- {
- struct utimbuf times;
- int ch;
-
- /* Some mailbox creation tools erroneously append a blank line to
- * a file before appending a mail message. This allows neomutt to
- * detect magic for and thus open those files. */
- while ((ch = fgetc(f)) != EOF)
- {
- if (ch != '\n' && ch != '\r')
- {
- ungetc(ch, f);
- break;
- }
- }
-
- char tmp[STRING];
- if (fgets(tmp, sizeof(tmp), f))
- {
- if (mutt_str_strncmp("From ", tmp, 5) == 0)
- magic = MUTT_MBOX;
- else if (mutt_str_strcmp(MMDF_SEP, tmp) == 0)
- magic = MUTT_MMDF;
- }
- mutt_file_fclose(&f);
-
- if (!CheckMboxSize)
- {
- /* need to restore the times here, the file was not really accessed,
- * only the type was accessed. This is important, because detection
- * of "new mail" depends on those times set correctly.
- */
- times.actime = st.st_atime;
- times.modtime = st.st_mtime;
- utime(path, ×);
- }
- }
- else
- {
- mutt_debug(1, "unable to open file %s for reading.\n", path);
- return MUTT_MAILBOX_ERROR;
- }
-
-#ifdef USE_COMPRESSED
- /* If there are no other matches, see if there are any
- * compress hooks that match */
- if ((magic == MUTT_UNKNOWN) && mutt_comp_can_read(path))
- return MUTT_COMPRESSED;
-#endif
- return magic;
-}
-
/**
* mx_access - Wrapper for access, checks permissions on a given mailbox
* @param path Path of mailbox
struct stat sb;
ctx->append = true;
- ctx->magic = mx_get_magic(ctx->path);
+ ctx->magic = mx_path_probe(ctx->path, NULL);
if (ctx->magic == MUTT_UNKNOWN)
{
mutt_error(_("%s is not a mailbox"), ctx->path);
return ctx;
}
- ctx->magic = mx_get_magic(path);
+ ctx->magic = mx_path_probe(path, NULL);
ctx->mx_ops = mx_get_ops(ctx->magic);
if ((ctx->magic == MUTT_UNKNOWN) || (ctx->magic == MUTT_MAILBOX_ERROR) || !ctx->mx_ops)
*/
int mx_check_empty(const char *path)
{
- switch (mx_get_magic(path))
+ switch (mx_path_probe(path, NULL))
{
case MUTT_MBOX:
case MUTT_MMDF:
int mx_check_empty(const char *path);
int mx_check_mailbox(struct Context *ctx, int *index_hint);
void mx_fastclose_mailbox(struct Context *ctx);
-enum MailboxType mx_get_magic(const char *path);
const struct MxOps *mx_get_ops(enum MailboxType magic);
bool mx_tags_is_supported(struct Context *ctx);
void mx_update_context(struct Context *ctx, int new_messages);
extern struct NntpServer *CurrentNewsSrv;
int nntp_compare_order(const void *a, const void *b);
+int nntp_path_probe(const char *path, const struct stat *st);
extern struct MxOps mx_nntp_ops;
* functions usable outside notmuch Context
*/
int nm_nonctx_get_count(char *path, int *all, int *new);
+int nm_path_probe(const char *path, const struct stat *st);
extern struct MxOps mx_notmuch_ops;
extern struct MxOps mx_pop_ops;
void pop_fetch_mail(void);
+int pop_path_probe(const char *path, const struct stat *st);
#endif /* _POP_POP_H */