aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmime/email_addr.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-25 09:51:00 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-25 09:51:00 +0100
commit123cc06dc7d18a7afa37bbcd37fa0019941fee8a (patch)
tree54b15e8be86ec34559451dc3ca7dbc1031332433 /src/libmime/email_addr.c
parentdc5966e5907dc159452ebe86b4ac6d656f7c806d (diff)
downloadrspamd-123cc06dc7d18a7afa37bbcd37fa0019941fee8a.tar.gz
rspamd-123cc06dc7d18a7afa37bbcd37fa0019941fee8a.zip
[Feature] Normalize quoted addresses
Diffstat (limited to 'src/libmime/email_addr.c')
-rw-r--r--src/libmime/email_addr.c15
1 files changed, 15 insertions, 0 deletions
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;