diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-03-02 12:18:11 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-03-02 12:36:06 +0200 |
commit | 1ed195f6b39a8ded621ebb00b04b0418b8cc4e8f (patch) | |
tree | 8af5039d1718a083821755329a3587f1c842acdf /libmailutils | |
parent | 169099f43bfd1a45398139c27df5ebc4375f6a7d (diff) | |
download | mailutils-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.
Diffstat (limited to 'libmailutils')
-rw-r--r-- | libmailutils/base/schemeauto.c | 26 | ||||
-rw-r--r-- | libmailutils/cli/stdcapa.c | 84 | ||||
-rw-r--r-- | libmailutils/url/create.c | 6 |
3 files changed, 90 insertions, 26 deletions
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; |