aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmime/email_addr.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-25 10:10:16 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-25 10:10:16 +0100
commit5ea8345fa3deb583cc99d9d7aa7659b90aad3743 (patch)
tree9e3d737fea0e9cedf822b1237fb5298ce532de44 /src/libmime/email_addr.c
parenta8ed49768138129c1d4f92e1adae5803219b21cb (diff)
downloadrspamd-5ea8345fa3deb583cc99d9d7aa7659b90aad3743.tar.gz
rspamd-5ea8345fa3deb583cc99d9d7aa7659b90aad3743.zip
[Feature] Unescape and unquote smtp addresses
Diffstat (limited to 'src/libmime/email_addr.c')
-rw-r--r--src/libmime/email_addr.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/libmime/email_addr.c b/src/libmime/email_addr.c
index 6dfc6f0c6..9305e4693 100644
--- a/src/libmime/email_addr.c
+++ b/src/libmime/email_addr.c
@@ -24,12 +24,44 @@
static void
rspamd_email_addr_dtor (struct rspamd_email_address *addr)
{
- if (addr->flags & RSPAMD_EMAIL_ADDR_ALLOCATED) {
+ if (addr->flags & RSPAMD_EMAIL_ADDR_ADDR_ALLOCATED) {
g_free ((void *)addr->addr);
}
+
+ if (addr->flags & RSPAMD_EMAIL_ADDR_USER_ALLOCATED) {
+ g_free ((void *)addr->user);
+ }
+
g_slice_free1 (sizeof (*addr), addr);
}
+static void
+rspamd_email_address_unescape (struct rspamd_email_address *addr)
+{
+ const char *h, *end;
+ char *t, *d;
+
+ if (addr->user_len == 0) {
+ return;
+ }
+
+ d = g_malloc (addr->user_len);
+ t = d;
+ h = addr->user;
+ end = h + addr->user_len;
+
+ while (h < end) {
+ if (*h != '\\') {
+ *t++ = *h;
+ }
+ h ++;
+ }
+
+ addr->user = d;
+ addr->user_len = t - d;
+ addr->flags |= RSPAMD_EMAIL_ADDR_USER_ALLOCATED;
+}
+
struct rspamd_email_address *
rspamd_email_address_from_smtp (const gchar *str, guint len)
{
@@ -47,13 +79,18 @@ rspamd_email_address_from_smtp (const gchar *str, guint len)
memcpy (ret, &addr, sizeof (addr));
if ((ret->flags & RSPAMD_EMAIL_ADDR_QUOTED) && ret->addr[0] == '"') {
+ if (ret->flags & RSPAMD_EMAIL_ADDR_HAS_BACKSLASH) {
+ /* We also need to unquote user */
+ rspamd_email_address_unescape (ret);
+ }
+
/* 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;
+ ret->flags |= RSPAMD_EMAIL_ADDR_ADDR_ALLOCATED;
}
REF_INIT_RETAIN (ret, rspamd_email_addr_dtor);