return -1;
}
+ if (HAS_ALL_BITS(flags, SMTP_ADDRESS_PARSE_FLAG_PRESERVE_RAW) &&
+ aparser.address.localpart != NULL) {
+ if (aparser.path &&
+ ((const unsigned char *)(path + 1) < aparser.parser.cur)) {
+ aparser.address.raw = t_strdup_until(
+ path + 1, aparser.parser.cur - 1);
+ } else {
+ aparser.address.raw = t_strdup_until(
+ path, aparser.parser.cur);
+ }
+ }
+
if (address_r != NULL)
*address_r = smtp_address_clone(pool, &aparser.address);
return 0;
SMTP_ADDRESS_PARSE_FLAG_ALLOW_EMPTY = BIT(1),
/* Allow an address without a domain part */
SMTP_ADDRESS_PARSE_FLAG_ALLOW_LOCALPART = BIT(2),
- /* Allow omission of the <...> brackets in a path */
+ /* Allow omission of the <...> brackets in a path. This flag is only
+ relevant for smtp_address_parse_path(). */
SMTP_ADDRESS_PARSE_FLAG_BRACKETS_OPTIONAL = BIT(3),
/* Allow localpart to have all kinds of bad unquoted characters by
parsing the last '@' in the string directly as the localpart/domain
cannot be used to construct a valid RFC 5321 address.
*/
SMTP_ADDRESS_PARSE_FLAG_ALLOW_BAD_LOCALPART = BIT(4),
+ /* Store an unparsed copy of the address in the `raw' field of struct
+ smtp_address. This flag is only relevant for
+ smtp_address_parse_path(). */
+ SMTP_ADDRESS_PARSE_FLAG_PRESERVE_RAW = BIT(5),
};
struct smtp_address {
.address = { .localpart = "user", .domain = "domain.tld" },
.output = "<user@domain.tld>"
},
+ /* Raw */
+ {
+ .input = "<>",
+ .flags = SMTP_ADDRESS_PARSE_FLAG_ALLOW_EMPTY |
+ SMTP_ADDRESS_PARSE_FLAG_PRESERVE_RAW,
+ .address = { .localpart = NULL, .domain = NULL, .raw = NULL }
+ },
+ {
+ .input = "<user>",
+ .flags = SMTP_ADDRESS_PARSE_FLAG_ALLOW_LOCALPART |
+ SMTP_ADDRESS_PARSE_FLAG_PRESERVE_RAW,
+ .address = { .localpart = "user", .domain = NULL,
+ .raw = "user" }
+ },
+ {
+ .input = "<user@domain.tld>",
+ .flags = SMTP_ADDRESS_PARSE_FLAG_PRESERVE_RAW,
+ .address = { .localpart = "user", .domain = "domain.tld",
+ .raw = "user@domain.tld" }
+ },
+ {
+ .input = "<@otherdomain.tld,@yetanotherdomain.tld:user@domain.tld>",
+ .flags = SMTP_ADDRESS_PARSE_FLAG_PRESERVE_RAW,
+ .address = { .localpart = "user", .domain = "domain.tld",
+ .raw = "@otherdomain.tld,@yetanotherdomain.tld:"
+ "user@domain.tld" },
+ .output = "<user@domain.tld>"
+ },
+ {
+ .input = "user@domain.tld",
+ .flags = SMTP_ADDRESS_PARSE_FLAG_BRACKETS_OPTIONAL |
+ SMTP_ADDRESS_PARSE_FLAG_PRESERVE_RAW,
+ .address = { .localpart = "user", .domain = "domain.tld",
+ .raw = "user@domain.tld"},
+ .output = "<user@domain.tld>"
+ },
};
unsigned int valid_path_parse_test_count =
parsed->domain),
null_strcmp(parsed->domain, test->domain) == 0);
}
+ if (parsed == NULL) {
+ /* nothing */
+ } else if (parsed->raw == NULL) {
+ test_out_quiet(t_strdup_printf("address->raw = (null)"),
+ (parsed->raw == test->raw));
+ } else {
+ test_out_quiet(t_strdup_printf("address->raw = \"%s\"",
+ parsed->raw),
+ null_strcmp(parsed->raw, test->raw) == 0);
+ }
}
static void test_smtp_path_parse_valid(void)