]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add attachment detection settings
authorAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 20 Nov 2017 08:09:23 +0000 (10:09 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 17 Jan 2018 13:48:00 +0000 (15:48 +0200)
src/lib-storage/mail-storage-settings.c
src/lib-storage/mail-storage-settings.h

index 2ade327313c7de0d4720a3d204c85904f8f132a7..567456e64560b78e8e08ffe5b97ea8c720ab4e2a 100644 (file)
@@ -33,6 +33,7 @@ static const struct setting_define mail_storage_setting_defines[] = {
        DEF(SET_STR_VARS, mail_attachment_dir),
        DEF(SET_STR, mail_attachment_hash),
        DEF(SET_SIZE, mail_attachment_min_size),
+       DEF(SET_STR, mail_attachment_detection_options),
        DEF(SET_STR_VARS, mail_attribute_dict),
        DEF(SET_UINT, mail_prefetch_count),
        DEF(SET_STR, mail_cache_fields),
@@ -92,6 +93,7 @@ const struct mail_storage_settings mail_storage_default_settings = {
        .mail_attachment_dir = "",
        .mail_attachment_hash = "%{sha1}",
        .mail_attachment_min_size = 1024*128,
+       .mail_attachment_detection_options = "",
        .mail_attribute_dict = "",
        .mail_prefetch_count = 0,
        .mail_cache_fields = "flags",
@@ -402,7 +404,7 @@ fix_base_path(struct mail_user_settings *set, pool_t pool, const char **str)
 }
 
 /* <settings checks> */
-static bool mail_storage_settings_check(void *_set, pool_t pool ATTR_UNUSED,
+static bool mail_storage_settings_check(void *_set, pool_t pool,
                                        const char **error_r)
 {
        struct mail_storage_settings *set = _set;
@@ -522,6 +524,34 @@ static bool mail_storage_settings_check(void *_set, pool_t pool ATTR_UNUSED,
        }
 #endif
 
+       /* parse mail_attachment_indicator_options */
+       if (*set->mail_attachment_detection_options != '\0') {
+               ARRAY_TYPE(const_string) content_types;
+               p_array_init(&content_types, pool, 2);
+
+               const char *const *options =
+                       t_strsplit_spaces(set->mail_attachment_detection_options, " ");
+
+               while(*options != NULL) {
+                       const char *opt = *options;
+
+                       if (strcmp(opt, "add-flags-on-save") == 0) {
+                               set->parsed_mail_attachment_detection_add_flags_on_save = TRUE;
+                       } else if (strcmp(opt, "add-flags-on-fetch") == 0) {
+                               set->parsed_mail_attachment_detection_add_flags_on_fetch = TRUE;
+                       } else if (strcmp(opt, "exclude-inlined") == 0) {
+                               set->parsed_mail_attachment_exclude_inlined = TRUE;
+                       } else if (strncmp(opt, "content-type=", 13) == 0) {
+                               const char *value = p_strdup(pool, opt+13);
+                               array_append(&content_types, &value, 1);
+                       }
+                       options++;
+               }
+
+               array_append_zero(&content_types);
+               set->parsed_mail_attachment_content_type_filter = array_idx(&content_types, 0);
+       }
+
        return TRUE;
 }
 
index 9e17cb9d609b75a5b24a6465bc2fecca47241c7e..9ddae3beefeb8f112d32f904da33967774cbdac2 100644 (file)
@@ -67,12 +67,18 @@ struct mail_storage_settings {
        const char *ssl_client_ca_dir;
        const char *ssl_client_ca_file;
        const char *ssl_crypto_device;
+       const char *mail_attachment_detection_options;
 
        enum file_lock_method parsed_lock_method;
        enum fsync_mode parsed_fsync_mode;
        /* May be NULL - use mail_storage_get_postmaster_address() instead of
           directly accessing this. */
        const struct message_address *_parsed_postmaster_address;
+
+       const char *const *parsed_mail_attachment_content_type_filter;
+       bool parsed_mail_attachment_exclude_inlined;
+       bool parsed_mail_attachment_detection_add_flags_on_save;
+       bool parsed_mail_attachment_detection_add_flags_on_fetch;
 };
 
 struct mail_namespace_settings {