From 3b442dfa9726d3991213a3e3db894b462bcae479 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 22 Dec 2016 17:05:03 +0000 Subject: [Minor] More fixes to parsing of mime addresses --- src/libmime/email_addr.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/libmime') diff --git a/src/libmime/email_addr.c b/src/libmime/email_addr.c index 309382462..1b97a842c 100644 --- a/src/libmime/email_addr.c +++ b/src/libmime/email_addr.c @@ -146,6 +146,7 @@ rspamd_email_address_add (rspamd_mempool_t *pool, if (name->len > 0) { elt->name = rspamd_mime_header_decode (pool, name->str, name->len); + elt->name_len = strlen (elt->name); } g_ptr_array_add (ar, elt); @@ -181,12 +182,13 @@ rspamd_email_address_from_mime (rspamd_mempool_t *pool, if (*p == '"') { /* We need to strip last spaces and update `ns` */ if (p > c) { - t = p; + t = p - 1; + while (t > c && g_ascii_isspace (*t)) { t --; } - g_string_append_len (ns, c, t - c); + g_string_append_len (ns, c, t - c + 1); } state = parse_quoted; @@ -194,12 +196,13 @@ rspamd_email_address_from_mime (rspamd_mempool_t *pool, } else if (*p == '<') { if (p > c) { - t = p; + t = p - 1; + while (t > c && g_ascii_isspace (*t)) { t --; } - g_string_append_len (ns, c, t - c); + g_string_append_len (ns, c, t - c + 1); } c = p; @@ -212,11 +215,12 @@ rspamd_email_address_from_mime (rspamd_mempool_t *pool, * e.g. Some name name@domain.com */ t = p; + while (t > c && g_ascii_isspace (*t)) { t --; } - rspamd_smtp_addr_parse (c, t - c, &addr); + rspamd_smtp_addr_parse (c, t - c + 1, &addr); if (addr.flags & RSPAMD_EMAIL_ADDR_VALID) { rspamd_email_address_add (pool, res, &addr, ns); @@ -275,7 +279,7 @@ rspamd_email_address_from_mime (rspamd_mempool_t *pool, case parse_name: case parse_addr: if (p > c) { - rspamd_smtp_addr_parse (c, p - c + 1, &addr); + rspamd_smtp_addr_parse (c, p - c, &addr); if (addr.flags & RSPAMD_EMAIL_ADDR_VALID) { rspamd_email_address_add (pool, res, &addr, ns); -- cgit v1.2.3