From 86ec8ef579ad9bb869cfa2fd5524712773b3d007 Mon Sep 17 00:00:00 2001 From: Rocco Rutte Date: Wed, 29 Apr 2009 11:53:01 +0200 Subject: [PATCH] Move Maildir/MH folder detection from mx.c to mh.c --- mailbox.h | 3 +++ mh.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ mx.c | 38 ++++---------------------------------- 3 files changed, 54 insertions(+), 34 deletions(-) diff --git a/mailbox.h b/mailbox.h index 542210b26..91e5dc71e 100644 --- a/mailbox.h +++ b/mailbox.h @@ -78,4 +78,7 @@ int mx_is_pop (const char *); int mx_access (const char*, int); int mx_check_empty (const char *); +int mx_is_maildir (const char *); +int mx_is_mh (const char *); + #endif diff --git a/mh.c b/mh.c index a4abd2852..d09dd487a 100644 --- a/mh.c +++ b/mh.c @@ -2225,3 +2225,50 @@ int mh_check_empty (const char *path) return r; } + +int mx_is_maildir (const char *path) +{ + char tmp[_POSIX_PATH_MAX]; + struct stat st; + + snprintf (tmp, sizeof (tmp), "%s/cur", path); + if (stat (tmp, &st) == 0 && S_ISDIR (st.st_mode)) + return 1; + return 0; +} + +int mx_is_mh (const char *path) +{ + char tmp[_POSIX_PATH_MAX]; + + snprintf (tmp, sizeof (tmp), "%s/.mh_sequences", path); + if (access (tmp, F_OK) == 0) + return 1; + + snprintf (tmp, sizeof (tmp), "%s/.xmhcache", path); + if (access (tmp, F_OK) == 0) + return 1; + + snprintf (tmp, sizeof (tmp), "%s/.mew_cache", path); + if (access (tmp, F_OK) == 0) + return 1; + + snprintf (tmp, sizeof (tmp), "%s/.mew-cache", path); + if (access (tmp, F_OK) == 0) + return 1; + + snprintf (tmp, sizeof (tmp), "%s/.sylpheed_cache", path); + if (access (tmp, F_OK) == 0) + return 1; + + /* + * ok, this isn't an mh folder, but mh mode can be used to read + * Usenet news from the spool. ;-) + */ + + snprintf (tmp, sizeof (tmp), "%s/.overview", path); + if (access (tmp, F_OK) == 0) + return 1; + + return 0; +} diff --git a/mx.c b/mx.c index 1aa49051d..4ed9eb1c8 100644 --- a/mx.c +++ b/mx.c @@ -370,42 +370,12 @@ int mx_get_magic (const char *path) if (S_ISDIR (st.st_mode)) { /* check for maildir-style mailbox */ - - snprintf (tmp, sizeof (tmp), "%s/cur", path); - if (stat (tmp, &st) == 0 && S_ISDIR (st.st_mode)) - return (M_MAILDIR); + if (mx_is_maildir (path)) + return M_MAILDIR; /* check for mh-style mailbox */ - - snprintf (tmp, sizeof (tmp), "%s/.mh_sequences", path); - if (access (tmp, F_OK) == 0) - return (M_MH); - - snprintf (tmp, sizeof (tmp), "%s/.xmhcache", path); - if (access (tmp, F_OK) == 0) - return (M_MH); - - snprintf (tmp, sizeof (tmp), "%s/.mew_cache", path); - if (access (tmp, F_OK) == 0) - return (M_MH); - - snprintf (tmp, sizeof (tmp), "%s/.mew-cache", path); - if (access (tmp, F_OK) == 0) - return (M_MH); - - snprintf (tmp, sizeof (tmp), "%s/.sylpheed_cache", path); - if (access (tmp, F_OK) == 0) - return (M_MH); - - /* - * ok, this isn't an mh folder, but mh mode can be used to read - * Usenet news from the spool. ;-) - */ - - snprintf (tmp, sizeof (tmp), "%s/.overview", path); - if (access (tmp, F_OK) == 0) - return (M_MH); - + if (mx_is_mh (path)) + return M_MH; } else if (st.st_size == 0) { -- 2.40.0