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) {
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;
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;
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 */
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;
}
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}
*/
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.
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);
}
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;
}
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);
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();
}
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)
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);
*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;
}
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(
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);