diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-06-21 19:49:18 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-06-21 19:49:18 +0300 |
commit | 6483314a52d2443bde4ee51f81650f808c0298a2 (patch) | |
tree | 80148bc2358bef554ef5fd9c623d6049bf5e4537 /lib | |
parent | 64947de3807c4ad8a9446b00d221376d1392fa91 (diff) | |
download | mailutils-6483314a52d2443bde4ee51f81650f808c0298a2.tar.gz mailutils-6483314a52d2443bde4ee51f81650f808c0298a2.tar.bz2 |
Make the list of textual mime types configurable
* decodemail/decodemail.c: Request the "mime" configuration capability.
* lib/mdecode.c: Make the list of textual mime types configurable via
the mime.text-type configuration statement.
* lib/muaux.h (mu_cli_capa_mime): New extern.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mdecode.c | 127 | ||||
-rw-r--r-- | lib/muaux.h | 2 |
2 files changed, 115 insertions, 14 deletions
diff --git a/lib/mdecode.c b/lib/mdecode.c index c55aef5e9..0edd87b58 100644 --- a/lib/mdecode.c +++ b/lib/mdecode.c @@ -16,29 +16,128 @@ #include <config.h> #include <mailutils/mailutils.h> +#include <mailutils/imaputil.h> + +static mu_list_t text_mime_list; + +static char const *default_text_types[] = { + "text/*", + "x-cshell", + "x-perl", + "x-shell", + "x-csource", + NULL +}; + +static void text_mime_add (char const *s); + +struct mime_pattern +{ + char *pat_type; + char *pat_subtype; +}; static int -is_text_part (mu_content_type_t ct) +text_mime_cmp (const void *item, const void *ptr) +{ + const struct mime_pattern *pat = item; + mu_content_type_t ct = (mu_content_type_t) ptr; + if (mu_imap_wildmatch_ci (pat->pat_type, ct->type, 0) == 0 + && (pat->pat_subtype == NULL + || mu_imap_wildmatch (pat->pat_subtype, ct->subtype, '/') == 0)) + return 0; + return 1; +} + +static void +text_mime_init (void) { - if (mu_c_strcasecmp (ct->type, "text") == 0) - return 1; - if (mu_c_strcasecmp (ct->type, "application") == 0) + if (!text_mime_list) { - static char *textapp[] = { - "x-cshell", - "x-perl", - "x-shell", - "x-csource", - NULL - }; int i; - for (i = 0; textapp[i]; i++) - if (mu_c_strcasecmp (ct->subtype, textapp[i]) == 0) - return 1; + int rc = mu_list_create (&text_mime_list); + if (rc) + { + mu_diag_funcall (MU_DIAG_ERROR, "mu_list_create", NULL, rc); + mu_alloc_die (); + } + mu_list_set_destroy_item (text_mime_list, mu_list_free_item); + mu_list_set_comparator (text_mime_list, text_mime_cmp); + + for (i = 0; default_text_types[i]; i++) + text_mime_add (default_text_types[i]); + } +} + +static void +text_mime_add (char const *s) +{ + int rc; + struct mime_pattern *mp; + char *p; + + text_mime_init (); + + mp = mu_alloc (sizeof *mp + strlen (s) + 1); + mp->pat_type = (char*)(mp + 1); + strcpy (mp->pat_type, s); + p = strchr (mp->pat_type, '/'); + if (p) + *p++ = 0; + mp->pat_subtype = p; + rc = mu_list_append (text_mime_list, mp); + if (rc) + { + mu_diag_funcall (MU_DIAG_ERROR, "mu_list_append", NULL, rc); + mu_alloc_die (); + } +} + +static int +cb_text_type (void *data, mu_config_value_t *val) +{ + size_t i; + + switch (val->type) + { + case MU_CFG_STRING: + text_mime_add (val->v.string); + break; + + case MU_CFG_LIST: + for (i = 0; i < val->v.arg.c; i++) + { + if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING)) + return 1; + text_mime_add (val->v.arg.v[i].v.string); + } + break; + + default: + mu_error ("%s", _("expected string or list")); } return 0; } +static struct mu_cfg_param mime_param[] = { + { "text-type", mu_cfg_callback, NULL, 0, cb_text_type, + N_("Define textual mime types."), + N_("arg: pattern or list of patterns") }, + { NULL } +}; + +struct mu_cli_capa mu_cli_capa_mime = { + .name = "mime", + .cfg = mime_param +}; + +static int +is_text_part (mu_content_type_t ct) +{ + text_mime_init (); + return mu_list_locate (text_mime_list, ct, NULL) == 0; +} + static int charset_setup (mu_stream_t *pstr, mu_content_type_t ct, char const *charset) { diff --git a/lib/muaux.h b/lib/muaux.h index a5c5683b5..add0bd445 100644 --- a/lib/muaux.h +++ b/lib/muaux.h @@ -39,3 +39,5 @@ int unistr_is_substring_dn (char const *haystack, char const *needle); int message_body_stream (mu_message_t msg, int unix_header, char const *charset, mu_stream_t *pstr); +extern struct mu_cli_capa mu_cli_capa_mime; + |