]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message_address_parse() - Change fill_missing parameter to flags
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 4 May 2018 16:31:26 +0000 (19:31 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 4 Jul 2018 09:08:55 +0000 (09:08 +0000)
This change allows adding more flags. The API is also backwards compatible
in a way that the old FALSE/TRUE values still map to compatible 0/1 flags.

src/doveadm/doveadm-mail-fetch.c
src/lib-lda/mail-deliver.c
src/lib-mail/message-address.c
src/lib-mail/message-address.h
src/lib-mail/message-part-data.c
src/lib-mail/test-message-address.c
src/lib-smtp/smtp-params.c
src/lib-storage/index/index-search.c
src/lib-storage/index/index-sort.c
src/lib-storage/mail-storage-settings.c
src/plugins/fts/fts-build-mail.c

index 71ba2ec5066b8a5730269540099d646b36cdd833..1d4fa91f6cc345b0fa62a59e690347b3a7e8e0e2 100644 (file)
@@ -167,7 +167,7 @@ static int fetch_hdr_field(struct fetch_cmd_context *ctx)
 
                addr = message_address_parse(pool_datastack_create(),
                                             str_data(str), str_len(str),
-                                            UINT_MAX, FALSE);
+                                            UINT_MAX, 0);
                str_truncate(str, 0);
                add_lf = FALSE;
                for (; addr != NULL; addr = addr->next) {
index ce5f2b5ab628708cde3dfd3faa56f297113d144e..84c109da8bd2620e98cec12001ddc8a05256ff84 100644 (file)
@@ -75,7 +75,7 @@ mail_deliver_get_message_address(struct mail *mail, const char *header)
                return NULL;
        addr = message_address_parse(pool_datastack_create(),
                                     (const unsigned char *)str,
-                                    strlen(str), 1, FALSE);
+                                    strlen(str), 1, 0);
        if (addr == NULL || addr->mailbox == NULL || addr->domain == NULL ||
            *addr->mailbox == '\0' || *addr->domain == '\0')
                return NULL;
index 0a437e4a30b1e6b3d9586c115dc3cd34bf1e7ecd..4880a545aeeb0daf5f518c5387eb32313bc721b7 100644 (file)
@@ -419,7 +419,8 @@ static int parse_path(struct message_address_parser_context *ctx)
 
 static struct message_address *
 message_address_parse_real(pool_t pool, const unsigned char *data, size_t size,
-                          unsigned int max_addresses, bool fill_missing)
+                          unsigned int max_addresses,
+                          enum message_address_parse_flags flags)
 {
        struct message_address_parser_context ctx;
 
@@ -429,7 +430,7 @@ message_address_parse_real(pool_t pool, const unsigned char *data, size_t size,
        ctx.parser.nul_replacement_str = RFC822_NUL_REPLACEMENT_STR;
        ctx.pool = pool;
        ctx.str = t_str_new(128);
-       ctx.fill_missing = fill_missing;
+       ctx.fill_missing = (flags & MESSAGE_ADDRESS_PARSE_FLAG_FILL_MISSING) != 0;
 
        if (rfc822_skip_lwsp(&ctx.parser) <= 0) {
                /* no addresses */
@@ -463,17 +464,18 @@ message_address_parse_path_real(pool_t pool, const unsigned char *data,
 
 struct message_address *
 message_address_parse(pool_t pool, const unsigned char *data, size_t size,
-                     unsigned int max_addresses, bool fill_missing)
+                     unsigned int max_addresses,
+                     enum message_address_parse_flags flags)
 {
        struct message_address *addr;
 
        if (pool->datastack_pool) {
                return message_address_parse_real(pool, data, size,
-                                                 max_addresses, fill_missing);
+                                                 max_addresses, flags);
        }
        T_BEGIN {
                addr = message_address_parse_real(pool, data, size,
-                                                 max_addresses, fill_missing);
+                                                 max_addresses, flags);
        } T_END;
        return addr;
 }
index 6dd32fed9e2b97ceec9faeacb0b5035897f52a75..3498df0ffecd413e9a6a095f6c61785b45ba71f4 100644 (file)
@@ -3,6 +3,12 @@
 
 struct smtp_address;
 
+enum message_address_parse_flags {
+       /* If enabled, missing mailbox and domain are set to MISSING_MAILBOX
+          and MISSING_DOMAIN strings. Otherwise they're set to "". */
+       MESSAGE_ADDRESS_PARSE_FLAG_FILL_MISSING = BIT(0),
+};
+
 /* group: ... ; will be stored like:
    {name = NULL, NULL, "group", NULL}, ..., {NULL, NULL, NULL, NULL}
 */
@@ -20,15 +26,12 @@ struct message_address {
        bool invalid_syntax;
 };
 
-/* Parse message addresses from given data. If fill_missing is TRUE, missing
-   mailbox and domain are set to MISSING_MAILBOX and MISSING_DOMAIN strings.
-   Otherwise they're set to "".
-
-   Note that giving an empty string will return NULL since there are no
-   addresses. */
+/* Parse message addresses from given data. Note that giving an empty string
+   will return NULL since there are no addresses. */
 struct message_address *
 message_address_parse(pool_t pool, const unsigned char *data, size_t size,
-                     unsigned int max_addresses, bool fill_missing);
+                     unsigned int max_addresses,
+                     enum message_address_parse_flags flags);
 
 /* Parse RFC 5322 "path" (Return-Path header) from given data. Returns -1 if
    the path is invalid and 0 otherwise.
index cee941239e74e333bb8021aad287830ef6dee26d..779d8107b5bfdcc0f2eae3be2bac1d31b617a9f5 100644 (file)
@@ -255,7 +255,8 @@ void message_part_envelope_parse_from_header(pool_t pool,
        if (addr_p != NULL) {
                *addr_p = message_address_parse(pool, hdr->full_value,
                                                hdr->full_value_len,
-                                               UINT_MAX, TRUE);
+                                               UINT_MAX,
+                                               MESSAGE_ADDRESS_PARSE_FLAG_FILL_MISSING);
        } else if (str_p != NULL) {
                *str_p = hdr_strdup(pool, hdr->full_value, hdr->full_value_len);
        }
index 0f5cae2a4d8770f6a4b20e1cba528ad2a3d555b6..41cad7945d0ba21e8958bfd69914257f2ac97483 100644 (file)
@@ -22,13 +22,15 @@ static bool cmp_addr(const struct message_address *a1,
 static const struct message_address *
 test_parse_address(const char *input, bool fill_missing)
 {
+       const enum message_address_parse_flags flags =
+               fill_missing ? MESSAGE_ADDRESS_PARSE_FLAG_FILL_MISSING : 0;
        /* duplicate the input (without trailing NUL) so valgrind notices
           if there's any out-of-bounds access */
        size_t input_len = strlen(input);
        unsigned char *input_dup = i_memdup(input, input_len);
        const struct message_address *addr =
                message_address_parse(pool_datastack_create(),
-                                     input_dup, input_len, UINT_MAX, fill_missing);
+                                     input_dup, input_len, UINT_MAX, flags);
        i_free(input_dup);
        return addr;
 }
@@ -312,7 +314,8 @@ static void test_message_address(void)
        test_end();
 
        test_begin("message address parsing empty string");
-       test_assert(message_address_parse(unsafe_data_stack_pool, &uchar_nul, 0, 10, TRUE) == NULL);
+       test_assert(message_address_parse(unsafe_data_stack_pool, &uchar_nul, 0, 10,
+                                         MESSAGE_ADDRESS_PARSE_FLAG_FILL_MISSING) == NULL);
        str_truncate(str, 0);
        message_address_write(str, NULL);
        test_assert(str_len(str) == 0);
@@ -331,7 +334,7 @@ static void test_message_address_nuls(void)
 
        test_begin("message address parsing with NULs");
        addr = message_address_parse(pool_datastack_create(),
-                                    input, sizeof(input)-1, UINT_MAX, FALSE);
+                                    input, sizeof(input)-1, UINT_MAX, 0);
        test_assert(addr != NULL && cmp_addr(addr, &output));
        test_end();
 }
index de79ef0b29457d789e5b34bf6dfe5bf6393a209e..3c8178ef585285082b88ff717462f09a58b0981e 100644 (file)
@@ -708,7 +708,7 @@ smtp_params_rcpt_parse_orcpt_rfc822(const char *addr_str,
        struct smtp_address *addr;
 
        rfc822_addr = message_address_parse(pool_datastack_create(),
-               (const unsigned char *)addr_str, strlen(addr_str), 2, FALSE);
+               (const unsigned char *)addr_str, strlen(addr_str), 2, 0);
        if (rfc822_addr == NULL || rfc822_addr->invalid_syntax ||
            rfc822_addr->next != NULL ||
            smtp_address_create_from_msg(pool, rfc822_addr, &addr) < 0)
index ea438083a54dbf63330a5f73d380953af2eb535d..03977a267431d983f20310039efcfc235621c0d5 100644 (file)
@@ -588,7 +588,8 @@ static void search_header_arg(struct mail_search_arg *arg,
                        addr = message_address_parse(pool_datastack_create(),
                                                     ctx->hdr->full_value,
                                                     ctx->hdr->full_value_len,
-                                                    UINT_MAX, TRUE);
+                                                    UINT_MAX,
+                                                    MESSAGE_ADDRESS_PARSE_FLAG_FILL_MISSING);
                        str = t_str_new(ctx->hdr->value_len);
                        message_address_write(str, addr);
                        hdr.value = hdr.full_value = str_data(str);
index 3dc4763ad099593ced818d5d3c4c5be9fbdbc58a..a39ecadffacbf633843f361effc78e5c30f6b50d 100644 (file)
@@ -424,7 +424,8 @@ get_first_addr(struct mail *mail, const char *header,
 
        *addr_r = message_address_parse(pool_datastack_create(),
                                        (const unsigned char *)str,
-                                       strlen(str), 1, TRUE);
+                                       strlen(str), 1,
+                                       MESSAGE_ADDRESS_PARSE_FLAG_FILL_MISSING);
        return 0;
 }
 
index f846556b3c65ee023b7d8ea76b2830fadc903911..582529cdea2438d7fbe4393e753150d4fdce6cdb 100644 (file)
@@ -568,7 +568,7 @@ static bool parse_postmaster_address(const char *address, pool_t pool,
 
        addr = message_address_parse(pool,
                (const unsigned char *)address,
-               strlen(address), 2, FALSE);
+               strlen(address), 2, 0);
        if (addr == NULL || addr->domain == NULL || addr->invalid_syntax ||
            smtp_address_create_from_msg(pool, addr, &smtp_addr) < 0) {
                *error_r = t_strdup_printf(
index 3125f6c2e5604a23da8f0c9a17d4b05f0fb6cad4..b9689b084a461ed26902843b107205d7cb901e9b 100644 (file)
@@ -187,7 +187,7 @@ static int fts_build_mail_header(struct fts_mail_build_context *ctx,
                addr = message_address_parse(pool_datastack_create(),
                                             hdr->full_value,
                                             hdr->full_value_len,
-                                            UINT_MAX, FALSE);
+                                            UINT_MAX, 0);
                str = t_str_new(hdr->full_value_len);
                message_address_write(str, addr);