summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-03-02 12:18:11 +0200
committerSergey Poznyakoff <gray@gnu.org>2019-03-02 12:36:06 +0200
commit1ed195f6b39a8ded621ebb00b04b0418b8cc4e8f (patch)
tree8af5039d1718a083821755329a3587f1c842acdf
parent169099f43bfd1a45398139c27df5ebc4375f6a7d (diff)
downloadmailutils-1ed195f6b39a8ded621ebb00b04b0418b8cc4e8f.tar.gz
mailutils-1ed195f6b39a8ded621ebb00b04b0418b8cc4e8f.tar.bz2
Implement different accuracy levels for the mailbox format detection
Selecting the accuracy level allows the user to achieve the desired balance between the speed of the folder scan and accuracy of mailbox format detection. The accuracy level can be set either from the configuration file, using the mailbox.accuracy-level statement, or from the environment, using the MU_AUTODETECT_ACCURACY variable. The default accuracy level 1 discerns valid mbox and dotmail mailboxes providing reasonable scan speed. Level 0 (previous default) does not discern them, but provides maximal speed. Level 2 and higher provide better accuracy at the price of speed. * include/mailutils/url.h (MU_AUTODETECT_ACCURACY_AUTO) (MU_AUTODETECT_ACCURACY_FAST) (MU_AUTODETECT_ACCURACY_DEFAULT): New constants. (mu_scheme_autodetect_p): New proto, moved here from util.h (mu_set_autodetect_accuracy) (mu_autodetect_accuracy): New protos. * libmailutils/base/schemeauto.c (mu_set_autodetect_accuracy) mu_autodetect_accuracy): New functions. * libmailutils/cli/stdcapa.c: New configuration statement: mailbox.autodetect-accuracy. * libmailutils/url/create.c (_mu_url_create_internal): Assume the "file" scheme if the MU_URL_PARSE_LOCAL flag is set. * libproto/dotmail/folder.c: Implement format detection. Three accuracy levels: 0, 1, and >1 * libproto/mbox/folder.c (_mbox_is_scheme): Implement default format detection. * libproto/dotmail/tests/Makefile.am: Add new test. * libproto/dotmail/tests/autodetect.at: New test. * libproto/dotmail/tests/dm_detect.c: New file. * libproto/dotmail/tests/testsuite.at: Add new test.
-rw-r--r--include/mailutils/url.h18
-rw-r--r--include/mailutils/util.h1
-rw-r--r--libmailutils/base/schemeauto.c26
-rw-r--r--libmailutils/cli/stdcapa.c84
-rw-r--r--libmailutils/url/create.c6
-rw-r--r--libproto/dotmail/folder.c69
-rw-r--r--libproto/dotmail/tests/.gitignore1
-rw-r--r--libproto/dotmail/tests/Makefile.am4
-rw-r--r--libproto/dotmail/tests/autodetect.at137
-rw-r--r--libproto/dotmail/tests/dm_detect.c43
-rw-r--r--libproto/dotmail/tests/testsuite.at1
-rw-r--r--libproto/mbox/folder.c29
12 files changed, 371 insertions, 48 deletions
diff --git a/include/mailutils/url.h b/include/mailutils/url.h
index ae710b7e5..be9ea20a0 100644
--- a/include/mailutils/url.h
+++ b/include/mailutils/url.h
@@ -152,6 +152,24 @@ int mu_url_add_param (mu_url_t url, size_t pc, const char **pv);
int mu_url_clear_param (mu_url_t url);
int mu_url_add_query (mu_url_t url, size_t pc, const char **pv);
int mu_url_clear_query (mu_url_t url);
+
+ /* Mailbox format autodetection accuracy levels */
+enum
+ {
+ /* Auto: accuracy will be set from the environment variable
+ MU_AUTODETECT_ACCURACY */
+ MU_AUTODETECT_ACCURACY_AUTO = -1,
+ /* Do only a rough estimation of the mailbox format: fastest but
+ possibly inaccurate. */
+ MU_AUTODETECT_ACCURACY_FAST = 0,
+ /* Default: minimal accuracy */
+ MU_AUTODETECT_ACCURACY_DEFAULT = 1,
+ /* Any non-negative value also allowed */
+ };
+
+int mu_scheme_autodetect_p (mu_url_t);
+void mu_set_autodetect_accuracy (int v);
+int mu_autodetect_accuracy (void);
#ifdef __cplusplus
}
diff --git a/include/mailutils/util.h b/include/mailutils/util.h
index 26c9bb359..80ae606c2 100644
--- a/include/mailutils/util.h
+++ b/include/mailutils/util.h
@@ -241,7 +241,6 @@ int mu_getmaxfd (void);
/* Get the host name, doing a gethostbyname() if possible. */
int mu_get_host_name (char **host);
int mu_spawnvp (const char *prog, char *av[], int *stat);
-int mu_scheme_autodetect_p (mu_url_t);
int mu_set_user_privileges (uid_t uid, gid_t *gidv, size_t gidc);
int mu_switch_to_privs (uid_t uid, gid_t gid, mu_list_t retain_groups);
diff --git a/libmailutils/base/schemeauto.c b/libmailutils/base/schemeauto.c
index 78f23d9e7..dc374110b 100644
--- a/libmailutils/base/schemeauto.c
+++ b/libmailutils/base/schemeauto.c
@@ -1,4 +1,3 @@
-/* Returns true if SCHEME represents a local (autodetect) mail folder. */
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999-2019 Free Software Foundation, Inc.
@@ -19,7 +18,7 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
-
+#include <stdlib.h>
#include <mailutils/url.h>
/* Returns true if SCHEME represents a local (autodetect) mail folder. */
@@ -33,4 +32,25 @@ mu_scheme_autodetect_p (mu_url_t url)
}
return 0;
}
-
+
+static int accuracy = MU_AUTODETECT_ACCURACY_AUTO;
+
+void
+mu_set_autodetect_accuracy (int v)
+{
+ accuracy = v;
+}
+
+int
+mu_autodetect_accuracy (void)
+{
+ if (accuracy == MU_AUTODETECT_ACCURACY_AUTO)
+ {
+ char *p = getenv ("MU_AUTODETECT_ACCURACY");
+ if (!p)
+ accuracy = MU_AUTODETECT_ACCURACY_DEFAULT;
+ else
+ accuracy = atoi (p);
+ }
+ return accuracy;
+}
diff --git a/libmailutils/cli/stdcapa.c b/libmailutils/cli/stdcapa.c
index b02ca397f..9310edfbe 100644
--- a/libmailutils/cli/stdcapa.c
+++ b/libmailutils/cli/stdcapa.c
@@ -29,8 +29,9 @@
#include <mailutils/registrar.h>
#include <mailutils/locker.h>
#include <mailutils/mu_auth.h>
+#include <mailutils/url.h>
-/* *************************************************************************
+/* *************************************************************************
* Logging section
* ************************************************************************* */
static void
@@ -40,13 +41,13 @@ cli_log_facility (struct mu_parseopt *po, struct mu_option *opt,
if (mu_string_to_syslog_facility (arg, &mu_log_facility))
mu_parseopt_error (po, _("unknown syslog facility `%s'"), arg);
}
-
+
static int
cb_facility (void *data, mu_config_value_t *val)
{
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
-
+
if (mu_string_to_syslog_facility (val->v.string, &mu_log_facility))
{
mu_error (_("unknown syslog facility `%s'"), val->v.string);
@@ -59,7 +60,7 @@ static int
cb_severity (void *data, mu_config_value_t *val)
{
unsigned n;
-
+
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
if (mu_severity_from_string (val->v.string, &n))
@@ -69,7 +70,7 @@ cb_severity (void *data, mu_config_value_t *val)
}
mu_log_severity_threshold = n;
return 0;
-}
+}
static struct mu_cfg_param logging_cfg[] = {
{ "syslog", mu_c_bool, &mu_log_syslog, 0, NULL,
@@ -84,7 +85,7 @@ static struct mu_cfg_param logging_cfg[] = {
{ "facility", mu_cfg_callback, NULL, 0, cb_facility,
N_("Set syslog facility. Arg is one of the following: user, daemon, "
"auth, authpriv, mail, cron, local0 through local7 (case-insensitive), "
- "or a facility number."),
+ "or a facility number."),
/* TRANSLATORS: Translate only arg: and <number>, rest are keywords */
N_("arg: auth|authpriv|mail|local0-local7|<number>") },
{ "session-id", mu_c_bool, &mu_log_session_id, 0, NULL,
@@ -109,8 +110,8 @@ logging_commit (void *unused)
MU_STRERR_SYSLOG : MU_STRERR_STDERR);
}
-/* *************************************************************************
- * Mailer
+/* *************************************************************************
+ * Mailer
* ************************************************************************* */
static void
cli_mailer (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
@@ -132,7 +133,7 @@ static int
cb_mailer (void *data, mu_config_value_t *val)
{
int rc;
-
+
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
rc = mu_mailer_set_url_default (val->v.string);
@@ -149,7 +150,7 @@ static struct mu_cfg_param mailer_cfg[] = {
{ NULL }
};
-/* *************************************************************************
+/* *************************************************************************
* Debugging
* ************************************************************************* */
static void
@@ -234,7 +235,7 @@ cb_mailbox_type (void *data, mu_config_value_t *val)
mu_error (_("invalid mailbox type: %s"), val->v.string);
return 0;
}
-
+
static int
cb_folder (void *data, mu_config_value_t *val)
{
@@ -244,6 +245,36 @@ cb_folder (void *data, mu_config_value_t *val)
return 0;
}
+static int
+cb_autodetect_accuracy (void *data, mu_config_value_t *val)
+{
+ int v;
+ char *errmsg;
+
+ if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+ return 1;
+ if (strcmp (val->v.string, "auto") == 0)
+ v = MU_AUTODETECT_ACCURACY_AUTO;
+ else if (strcmp (val->v.string, "fast") == 0)
+ v = MU_AUTODETECT_ACCURACY_FAST;
+ else if (strcmp (val->v.string, "minimal") == 0
+ || strcmp (val->v.string, "default") == 0)
+ v = MU_AUTODETECT_ACCURACY_DEFAULT;
+ else
+ {
+ int rc = mu_str_to_c (val->v.string, mu_c_int, &v, &errmsg);
+ if (rc)
+ {
+ mu_error (_("conversion failed: %s"),
+ errmsg ? errmsg : mu_strerror (rc));
+ free (errmsg);
+ }
+ else
+ mu_set_autodetect_accuracy (v);
+ }
+ return 0;
+}
+
static struct mu_cfg_param mailbox_cfg[] = {
{ "mail-spool", mu_cfg_callback, NULL, 0, cb_mail_spool,
N_("Use specified URL as a mailspool directory."),
@@ -257,6 +288,15 @@ static struct mu_cfg_param mailbox_cfg[] = {
{ "folder", mu_cfg_callback, NULL, 0, cb_folder,
N_("Default user mail folder"),
N_("dir: string") },
+ { "autodetect-accuracy", mu_cfg_callback, NULL, 0, cb_autodetect_accuracy,
+ N_("Accuracy level of mailbox format autodetection. Argument is either a"
+ " decimal number or any of the following constants:\n"
+ " auto - set accuracy level from the environment variable\n"
+ " MU_AUTODETECT_ACCURACY (default)\n"
+ " fast - do only a rough estimation of the mailbox format: fastest,\n"
+ " but possibly inaccurate\n"
+ " minimal - good balance between speed and accuracy"),
+ N_("n: number") },
{ NULL }
};
@@ -268,7 +308,7 @@ cb_locker_flags (void *data, mu_config_value_t *val)
{
int flags = 0;
char const *s;
-
+
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
@@ -279,19 +319,19 @@ cb_locker_flags (void *data, mu_config_value_t *val)
case 'E':
flags |= MU_LOCKER_EXTERNAL;
break;
-
+
case 'R':
flags |= MU_LOCKER_RETRY;
break;
-
+
case 'T':
flags |= MU_LOCKER_TIME;
break;
-
+
case 'P':
flags |= MU_LOCKER_PID;
break;
-
+
default:
mu_error (_("invalid lock flag `%c'"), *s);
}
@@ -306,7 +346,7 @@ cb_locker_retry_timeout (void *data, mu_config_value_t *val)
int rc;
time_t t;
char *errmsg;
-
+
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
rc = mu_str_to_c (val->v.string, mu_c_time, &t, &errmsg);
@@ -330,7 +370,7 @@ cb_locker_retry_count (void *data, mu_config_value_t *val)
int rc;
size_t n;
char *errmsg;
-
+
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
rc = mu_str_to_c (val->v.string, mu_c_size, &n, &errmsg);
@@ -354,7 +394,7 @@ cb_locker_expire_timeout (void *data, mu_config_value_t *val)
int rc;
time_t t;
char *errmsg;
-
+
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
rc = mu_str_to_c (val->v.string, mu_c_time, &t, &errmsg);
@@ -381,7 +421,7 @@ cb_locker_external (void *data, mu_config_value_t *val)
mu_locker_set_default_flags (MU_LOCKER_TIME, mu_locker_set_bit);
return 0;
}
-
+
static struct mu_cfg_param locking_cfg[] = {
/* FIXME: Flags are superfluous. */
{ "flags", mu_cfg_callback, NULL, 0, cb_locker_flags,
@@ -409,7 +449,7 @@ static int
cb_email_addr (void *data, mu_config_value_t *val)
{
int rc;
-
+
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
@@ -424,7 +464,7 @@ static int
cb_email_domain (void *data, mu_config_value_t *val)
{
int rc;
-
+
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
diff --git a/libmailutils/url/create.c b/libmailutils/url/create.c
index 3b19a4f2c..5d1d0c501 100644
--- a/libmailutils/url/create.c
+++ b/libmailutils/url/create.c
@@ -457,7 +457,11 @@ _mu_url_create_internal (struct mu_url_ctx *ctx, mu_url_t hint)
url->flags |= MU_URL_PATH;
}
else
- rc = _mu_url_ctx_parse (ctx);
+ {
+ if (ctx->flags & MU_URL_PARSE_LOCAL)
+ scheme = "file";
+ rc = _mu_url_ctx_parse (ctx);
+ }
if (rc)
return rc;
diff --git a/libproto/dotmail/folder.c b/libproto/dotmail/folder.c
index e58c1bf59..bd615bafc 100644
--- a/libproto/dotmail/folder.c
+++ b/libproto/dotmail/folder.c
@@ -16,12 +16,69 @@
#include <config.h>
#include <sys/stat.h>
+#include <stdio.h>
#include <errno.h>
+#include <string.h>
#include <mailutils/sys/dotmail.h>
#include <mailutils/sys/folder.h>
#include <mailutils/sys/registrar.h>
#include <mailutils/url.h>
#include <mailutils/util.h>
+#include <mailutils/cctype.h>
+
+/* Return MU_FOLDER_ATTRIBUTE_FILE if NAME looks like a dotmail
+ mailbox.
+
+ If MU_AUTODETECT_ACCURACY is 0 (i.e. autodetection is disabled),
+ always returns MU_FOLDER_ATTRIBUTE_FILE.
+
+ Otherwise, the function analyzes first 128 bytes from file. If they
+ look like a message header start, i.e. match "^[A-Za-z_][A-Za-z0-9_-]*:",
+ then the file is considered a dotmail mailbox.
+
+ Additionally, if MU_AUTODETECT_ACCURACY is greater than 1, the last
+ 3 characters of the file are considered. For valid dotmail they must
+ be "\n.\n".
+*/
+static int
+dotmail_detect (char const *name)
+{
+ FILE *fp;
+ int rc = 0;
+
+ if (mu_autodetect_accuracy () == 0)
+ return MU_FOLDER_ATTRIBUTE_FILE;
+
+ fp = fopen (name, "r");
+ if (fp)
+ {
+ size_t i;
+ int c;
+ /* Allowed character classes for first and subsequent characters
+ in the first line: */
+ int allowed[] = { MU_CTYPE_IDENT, MU_CTYPE_HEADR };
+
+ for (i = 0;
+ i < 128
+ && (c = getc (fp)) != EOF
+ && mu_c_is_class (c, allowed[i>0]);
+ i++)
+ ;
+ if (c == ':')
+ {
+ /* Possibly a header line */
+ char buf[3];
+ if (mu_autodetect_accuracy () == 1
+ || (fseek (fp, -3, SEEK_END) == 0
+ && fread (buf, 3, 1, fp) == 1
+ && memcmp (buf, "\n.\n", 3) == 0))
+ rc = MU_FOLDER_ATTRIBUTE_FILE;
+ }
+ fclose (fp);
+ }
+
+ return rc;
+}
static int
dotmail_is_scheme (mu_record_t record, mu_url_t url, int flags)
@@ -43,7 +100,7 @@ dotmail_is_scheme (mu_record_t record, mu_url_t url, int flags)
}
return 0;
}
-
+
if (S_ISREG (st.st_mode) || S_ISCHR (st.st_mode))
{
if (st.st_size == 0)
@@ -52,10 +109,10 @@ dotmail_is_scheme (mu_record_t record, mu_url_t url, int flags)
}
else if (flags & MU_FOLDER_ATTRIBUTE_FILE)
{
- rc |= MU_FOLDER_ATTRIBUTE_FILE;
- }
+ rc |= dotmail_detect (path);
+ }
}
-
+
if ((flags & MU_FOLDER_ATTRIBUTE_DIRECTORY)
&& S_ISDIR (st.st_mode))
rc |= MU_FOLDER_ATTRIBUTE_DIRECTORY;
@@ -70,11 +127,11 @@ static struct _mu_record _dotmail_record =
MU_RECORD_LOCAL,
MU_URL_SCHEME | MU_URL_PATH | MU_URL_PARAM,
MU_URL_PATH,
- mu_url_expand_path, /* URL init. */
+ mu_url_expand_path, /* URL init. */
mu_dotmail_mailbox_init, /* Mailbox init. */
NULL, /* Mailer init. */
_mu_fsfolder_init, /* Folder init. */
- NULL, /* No need for an back pointer. */
+ NULL, /* No need for back pointer. */
dotmail_is_scheme, /* _is_scheme method. */
NULL, /* _get_url method. */
NULL, /* _get_mailbox method. */
diff --git a/libproto/dotmail/tests/.gitignore b/libproto/dotmail/tests/.gitignore
index 222fed285..3049d1569 100644
--- a/libproto/dotmail/tests/.gitignore
+++ b/libproto/dotmail/tests/.gitignore
@@ -1,5 +1,6 @@
/atconfig
/atlocal
+/dm_detect
/dm_mbox
/dm_mesg
/dm_qget
diff --git a/libproto/dotmail/tests/Makefile.am b/libproto/dotmail/tests/Makefile.am
index 66cee6f30..a033346e7 100644
--- a/libproto/dotmail/tests/Makefile.am
+++ b/libproto/dotmail/tests/Makefile.am
@@ -42,7 +42,8 @@ AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@
noinst_PROGRAMS = \
dm_mbox\
dm_mesg\
- dm_qget
+ dm_qget\
+ dm_detect
LDADD = ${MU_LIB_DOTMAIL} ${MU_LIB_MAILUTILS}
@@ -52,6 +53,7 @@ LDADD = ${MU_LIB_DOTMAIL} ${MU_LIB_MAILUTILS}
TESTSUITE_AT = \
testsuite.at\
+ autodetect.at\
count.at\
env.at\
attr.at\
diff --git a/libproto/dotmail/tests/autodetect.at b/libproto/dotmail/tests/autodetect.at
new file mode 100644
index 000000000..0f484ab0d
--- /dev/null
+++ b/libproto/dotmail/tests/autodetect.at
@@ -0,0 +1,137 @@
+# GNU Mailutils -- a suite of utilities for electronic mail
+# Copyright (C) 2019 Free Software Foundation, Inc.
+#
+# This library is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([format detection])
+AT_KEYWORDS([autodetect])
+AT_CHECK(
+[AT_DATA([empty],[])
+
+# Valid dotmail mailbox
+AT_DATA([dotmail],
+[Received: (from hare@wonder.land)
+ by wonder.land id 3301
+ for alice@wonder.land; Mon, 29 Jul 2002 22:00:06 +0100
+Date: Mon, 29 Jul 2002 22:00:01 +0100
+From: March Hare <hare@wonder.land>
+Message-Id: <200207292200.3301@wonder.land>
+To: Alice <alice@wonder.land>
+Subject: Invitation
+Return-Path: hare@wonder.land
+
+Have some wine
+.
+Received: (from alice@wonder.land)
+ by wonder.land id 3302
+ for hare@wonder.land; Mon, 29 Jul 2002 22:00:07 +0100
+Date: Mon, 29 Jul 2002 22:00:02 +0100
+From: Alice <alice@wonder.land>
+Message-Id: <200207292200.3302@wonder.land>
+To: March Hare <hare@wonder.land>
+Subject: Re: Invitation
+Return-Path: alice@wonder.land
+
+I don't see any wine
+.
+])
+
+# Valid mbox mailbox
+AT_DATA([mbox],
+[From hare@wonder.land Mon Jul 29 22:00:08 2002
+Received: (from hare@wonder.land)
+ by wonder.land id 3301
+ for alice@wonder.land; Mon, 29 Jul 2002 22:00:06 +0100
+Date: Mon, 29 Jul 2002 22:00:01 +0100
+From: March Hare <hare@wonder.land>
+Message-Id: <200207292200.3301@wonder.land>
+To: Alice <alice@wonder.land>
+Subject: Invitation
+
+Have some wine
+
+])
+
+# Malformed dotmail: no final dot
+AT_DATA([nodot],
+[Received: (from hare@wonder.land)
+ by wonder.land id 3301
+ for alice@wonder.land; Mon, 29 Jul 2002 22:00:06 +0100
+Date: Mon, 29 Jul 2002 22:00:01 +0100
+From: March Hare <hare@wonder.land>
+Message-Id: <200207292200.3301@wonder.land>
+To: Alice <alice@wonder.land>
+Subject: Invitation
+Return-Path: hare@wonder.land
+
+Have some wine
+.
+Received: (from alice@wonder.land)
+ by wonder.land id 3302
+ for hare@wonder.land; Mon, 29 Jul 2002 22:00:07 +0100
+Date: Mon, 29 Jul 2002 22:00:02 +0100
+From: Alice <alice@wonder.land>
+Message-Id: <200207292200.3302@wonder.land>
+To: March Hare <hare@wonder.land>
+Subject: Re: Invitation
+Return-Path: alice@wonder.land
+
+I don't see any wine
+])
+
+# Garbage input that is similar to header line
+AT_DATA([badheader],
+[Something-that-looks-like-A%: header
+text
+.
+])
+
+# Garbage input
+AT_DATA([garbage],
+[ZZKTJVLRF97GGVYv+hMsbO2gHUe/4ra31zXffN9vS10FG8lUBixFJJ9kv+F1/5muYhG6n2JrrLC9ZScpn9zNRrMqLVH/9slNBadT6fZL9hAmxyYQUMbqcCmsmn3A7rNVfKgfubufBpsUg/dzqsJWN4DOPQACSVYMY2DIGmEYt2Rdt3s1/VdpJZhaHEETWQzXyaG0iAZn4r2iD2InJHPOalG7WJhj1cCHHToEA029GRMx6uHhOWBjXT5P0H3ebhEujbIBj9e6aX5u42jg/+YuCoVpy8fbESHiB3gc9ijKgyGrVLBQLkikc6sK7E8xjwGhu75G4LKVTctff8UyqRjgUR5eA7TuI9+VmCnO7pf5LR/QDFzV1smrfR1BzX3dudbjdCyR3xW2oYFyWRJDlycFULVuRmG87u795P4DOeH6/+I32AnJeJNX40vEzprqQwdxdkifBtcDiKvhcecFgbQLIw4OKrOEuFBMraViHC6ZFkLBNf6aXBk+xiv6U8ogDH4a1+
+])
+export MU_AUTODETECT_ACCURACY
+for MU_AUTODETECT_ACCURACY in 0 1 2
+do
+ echo "MU_AUTODETECT_ACCURACY=$MU_AUTODETECT_ACCURACY"
+ dm_detect empty dotmail mbox nodot badheader garbage
+done
+],
+[0],
+[MU_AUTODETECT_ACCURACY=0
+empty: 2
+dotmail: 2
+mbox: 2
+nodot: 2
+badheader: 2
+garbage: 2
+MU_AUTODETECT_ACCURACY=1
+empty: 2
+dotmail: 2
+mbox: 0
+nodot: 2
+badheader: 0
+garbage: 0
+MU_AUTODETECT_ACCURACY=2
+empty: 2
+dotmail: 2
+mbox: 0
+nodot: 0
+badheader: 0
+garbage: 0
+])
+AT_CLEANUP
+
+
+
diff --git a/libproto/dotmail/tests/dm_detect.c b/libproto/dotmail/tests/dm_detect.c
new file mode 100644
index 000000000..cc4d85734
--- /dev/null
+++ b/libproto/dotmail/tests/dm_detect.c
@@ -0,0 +1,43 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2019 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <mailutils/mailutils.h>
+
+int
+main (int argc, char **argv)
+{
+ mu_record_t rec;
+ mu_url_t url;
+
+ mu_set_program_name (argv[0]);
+ mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
+ mu_registrar_record (mu_dotmail_record);
+
+ MU_ASSERT (mu_registrar_lookup_scheme ("dotmail", &rec));
+
+ while (--argc)
+ {
+ char *name = *++argv;
+ int n;
+ MU_ASSERT (mu_url_create_hint (&url, name,
+ MU_URL_PARSE_SLASH | MU_URL_PARSE_LOCAL,
+ NULL));
+ n = mu_record_is_scheme (rec, url, MU_FOLDER_ATTRIBUTE_FILE);
+ mu_printf ("%s: %d\n", name, n);
+ mu_url_destroy (&url);
+ }
+ return 0;
+}
diff --git a/libproto/dotmail/tests/testsuite.at b/libproto/dotmail/tests/testsuite.at
index 66fe16b49..10e73489f 100644
--- a/libproto/dotmail/tests/testsuite.at
+++ b/libproto/dotmail/tests/testsuite.at
@@ -42,4 +42,5 @@ m4_include([uid.at])
m4_include([qget.at])
m4_include([append.at])
m4_include([delete.at])
+m4_include([autodetect.at])
diff --git a/libproto/mbox/folder.c b/libproto/mbox/folder.c
index 3a6796c1e..906ffae73 100644
--- a/libproto/mbox/folder.c
+++ b/libproto/mbox/folder.c
@@ -73,22 +73,23 @@ _mbox_is_scheme (mu_record_t record, mu_url_t url, int flags)
}
else if (flags & MU_FOLDER_ATTRIBUTE_FILE)
{
-#if 0
- /* FIXME: This effectively sieves out all non-mailbox files,
- but it makes mu_folder_enumerate crawl, which is
- intolerable for imap4d LIST command. */
- int fd = open (path, O_RDONLY);
- if (fd != -1)
+ if (mu_autodetect_accuracy () > 0)
{
- char buf[5];
- if (read (fd, buf, 5) == 5)
- if (memcmp (buf, "From ", 5) == 0)
- rc |= MU_FOLDER_ATTRIBUTE_FILE;
- close (fd);
+ /* FIXME: This effectively sieves out all non-mailbox files,
+ but it makes mu_folder_enumerate crawl, which is
+ intolerable for imap4d LIST command. */
+ int fd = open (path, O_RDONLY);
+ if (fd != -1)
+ {
+ char buf[5];
+ if (read (fd, buf, 5) == 5)
+ if (memcmp (buf, "From ", 5) == 0)
+ rc |= MU_FOLDER_ATTRIBUTE_FILE;
+ close (fd);
+ }
}
-#else
- rc |= MU_FOLDER_ATTRIBUTE_FILE;
-#endif
+ else
+ rc |= MU_FOLDER_ATTRIBUTE_FILE;
}
}

Return to:

Send suggestions and report system problems to the System administrator.