#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);
}
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;
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;
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),
};
/*
{'<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)