From 123cc06dc7d18a7afa37bbcd37fa0019941fee8a Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 25 Apr 2016 09:51:00 +0100 Subject: [Feature] Normalize quoted addresses --- src/libmime/email_addr.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/libmime/email_addr.c') diff --git a/src/libmime/email_addr.c b/src/libmime/email_addr.c index afb92b183..6dfc6f0c6 100644 --- a/src/libmime/email_addr.c +++ b/src/libmime/email_addr.c @@ -17,12 +17,16 @@ #include "config.h" #include "email_addr.h" #include "message.h" +#include "printf.h" #include "./parsers/smtp_addr_parser.c" static void rspamd_email_addr_dtor (struct rspamd_email_address *addr) { + if (addr->flags & RSPAMD_EMAIL_ADDR_ALLOCATED) { + g_free ((void *)addr->addr); + } g_slice_free1 (sizeof (*addr), addr); } @@ -30,6 +34,7 @@ struct rspamd_email_address * rspamd_email_address_from_smtp (const gchar *str, guint len) { struct rspamd_email_address addr, *ret; + gsize nlen; if (str == NULL || len == 0) { return NULL; @@ -41,6 +46,16 @@ rspamd_email_address_from_smtp (const gchar *str, guint len) ret = g_slice_alloc (sizeof (*ret)); memcpy (ret, &addr, sizeof (addr)); + if ((ret->flags & RSPAMD_EMAIL_ADDR_QUOTED) && ret->addr[0] == '"') { + /* We need to unquote addr */ + nlen = ret->domain_len + ret->user_len + 2; + ret->addr = g_malloc (nlen + 1); + ret->addr_len = rspamd_snprintf ((char *)ret->addr, nlen, "%*s@%*s", + (gint)ret->user_len, ret->user, + (gint)ret->domain_len, ret->domain); + ret->flags |= RSPAMD_EMAIL_ADDR_ALLOCATED; + } + REF_INIT_RETAIN (ret, rspamd_email_addr_dtor); return ret; -- cgit v1.2.3