aboutsummaryrefslogtreecommitdiffstats
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
parentdc5966e5907dc159452ebe86b4ac6d656f7c806d (diff)
downloadrspamd-123cc06dc7d18a7afa37bbcd37fa0019941fee8a.tar.gz
rspamd-123cc06dc7d18a7afa37bbcd37fa0019941fee8a.zip
[Feature] Normalize quoted addresses
-rw-r--r--src/libmime/email_addr.c15
-rw-r--r--src/libmime/email_addr.h3
-rw-r--r--test/lua/unit/smtp_addr.lua4
3 files changed, 19 insertions, 3 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;
diff --git a/src/libmime/email_addr.h b/src/libmime/email_addr.h
index 1397d84ac..7009c472d 100644
--- a/src/libmime/email_addr.h
+++ b/src/libmime/email_addr.h
@@ -27,7 +27,8 @@ enum rspamd_email_address_flags {
RSPAMD_EMAIL_ADDR_BRACED = (1 << 2),
RSPAMD_EMAIL_ADDR_QUOTED = (1 << 3),
RSPAMD_EMAIL_ADDR_EMPTY = (1 << 4),
- RSPAMD_EMAIL_ADDR_SMTP = (1 << 5)
+ RSPAMD_EMAIL_ADDR_SMTP = (1 << 5),
+ RSPAMD_EMAIL_ADDR_ALLOCATED = (1 << 6),
};
/*
diff --git a/test/lua/unit/smtp_addr.lua b/test/lua/unit/smtp_addr.lua
index 4dd6fef87..c221950c5 100644
--- a/test/lua/unit/smtp_addr.lua
+++ b/test/lua/unit/smtp_addr.lua
@@ -29,8 +29,8 @@ context("SMTP address check functions", function()
{'<a@example.com>', {user = 'a', domain = 'example.com', addr = 'a@example.com'}},
{'a@example.com', {user = 'a', domain = 'example.com', addr = 'a@example.com'}},
{'a+b@example.com', {user = 'a+b', domain = 'example.com', addr = 'a+b@example.com'}},
- {'"a"@example.com', {user = 'a', domain = 'example.com', addr = '"a"@example.com'}},
- {'"a+b"@example.com', {user = 'a+b', domain = 'example.com', addr = '"a+b"@example.com'}},
+ {'"a"@example.com', {user = 'a', domain = 'example.com', addr = 'a@example.com'}},
+ {'"a+b"@example.com', {user = 'a+b', domain = 'example.com', addr = 'a+b@example.com'}},
}
each(function(case)