#include "printf.h"
#include "smtp_parsers.h"
-static void
-rspamd_email_addr_dtor (struct rspamd_email_address *addr)
-{
- 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_free (addr);
-}
-
static void
rspamd_email_address_unescape (struct rspamd_email_address *addr)
{
ret->flags |= RSPAMD_EMAIL_ADDR_ADDR_ALLOCATED;
}
- REF_INIT_RETAIN (ret, rspamd_email_addr_dtor);
-
return ret;
}
return NULL;
}
-struct rspamd_email_address *
-rspamd_email_address_ref (struct rspamd_email_address *addr)
+void
+rspamd_email_address_free (struct rspamd_email_address *addr)
{
- REF_RETAIN (addr);
+ if (addr->flags & RSPAMD_EMAIL_ADDR_ADDR_ALLOCATED) {
+ g_free ((void *)addr->addr);
+ }
- return addr;
-}
+ if (addr->flags & RSPAMD_EMAIL_ADDR_USER_ALLOCATED) {
+ g_free ((void *)addr->user);
+ }
-void
-rspamd_email_address_unref (struct rspamd_email_address *addr)
-{
- REF_RELEASE (addr);
+ g_free (addr);
}
static inline void
elt->flags |= RSPAMD_EMAIL_ADDR_ADDR_ALLOCATED;
}
- REF_INIT_RETAIN (elt, rspamd_email_addr_dtor);
-
if (name->len > 0) {
elt->name = rspamd_mime_header_decode (pool, name->str, name->len);
- elt->name_len = strlen (elt->name);
}
g_ptr_array_add (ar, elt);
struct rspamd_email_address *addr;
PTR_ARRAY_FOREACH (ar, i, addr) {
- REF_RELEASE (addr);
+ rspamd_email_address_free (addr);
}
g_ptr_array_free (ar, TRUE);
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_HAS_BACKSLASH = (1 << 6),
- RSPAMD_EMAIL_ADDR_ADDR_ALLOCATED = (1 << 7),
- RSPAMD_EMAIL_ADDR_USER_ALLOCATED = (1 << 8),
- RSPAMD_EMAIL_ADDR_HAS_8BIT = (1 << 9),
+ RSPAMD_EMAIL_ADDR_HAS_BACKSLASH = (1 << 5),
+ RSPAMD_EMAIL_ADDR_ADDR_ALLOCATED = (1 << 6),
+ RSPAMD_EMAIL_ADDR_USER_ALLOCATED = (1 << 7),
+ RSPAMD_EMAIL_ADDR_HAS_8BIT = (1 << 8),
};
/*
guint raw_len;
guint addr_len;
- guint user_len;
guint domain_len;
- guint name_len;
- enum rspamd_email_address_flags flags;
-
- ref_entry_t ref;
+ guint16 user_len;
+ guchar flags;
};
/**
*/
void rspamd_email_address_list_destroy (gpointer ptr);
-struct rspamd_email_address * rspamd_email_address_ref (
- struct rspamd_email_address *addr);
-
-void rspamd_email_address_unref (struct rspamd_email_address *addr);
+void rspamd_email_address_free (struct rspamd_email_address *addr);
#endif /* SRC_LIBMIME_EMAIL_ADDR_H_ */
lua_settable (L, -3);
}
- if (addr->name_len > 0) {
+ if (addr->name) {
lua_pushstring (L, "name");
- lua_pushlstring (L, addr->name, addr->name_len);
+ lua_pushstring (L, addr->name);
lua_settable (L, -3);
}
else {
{
struct rspamd_email_address *addr;
const gchar *p;
+ gchar *dst;
gsize len;
g_assert (paddr != NULL);
return FALSE;
}
- addr = rspamd_mempool_alloc0 (task->task_pool, sizeof (*addr));
+ addr = g_malloc0 (sizeof (*addr));
lua_pushstring (L, "name");
lua_gettable (L, pos);
if (lua_type (L, -1) == LUA_TSTRING) {
p = lua_tolstring (L, -1, &len);
- addr->name = (const gchar *)rspamd_mempool_alloc (task->task_pool, len);
- memcpy ((gchar *)addr->name, p, len);
- addr->name_len = len;
+ dst = rspamd_mempool_alloc (task->task_pool, len + 1);
+ rspamd_strlcpy (dst, p, len + 1);
+ addr->name = dst;
}
lua_pop (L, 1);
}
else {
/* Construct raw addr */
- len = addr->addr_len + addr->name_len + 3;
- addr->raw = (const gchar *)rspamd_mempool_alloc (task->task_pool, len);
- if (addr->name_len > 0) {
- addr->raw_len = rspamd_snprintf ((gchar *)addr->raw, len, "%*s <%*s>",
- (int)addr->name_len, addr->name,
+ len = addr->addr_len + 3;
+
+ if (addr->name) {
+ len += strlen (addr->name) + 1;
+ dst = rspamd_mempool_alloc (task->task_pool, len + 1);
+
+ addr->raw_len = rspamd_snprintf (dst, len, "%s <%*s>",
+ addr->name,
(int)addr->addr_len, addr->addr);
}
else {
- addr->raw_len = rspamd_snprintf ((gchar *)addr->raw, len, "<%*s@%*s>",
- (int)addr->name_len, addr->name,
- (int)addr->addr_len, addr->addr);
+ dst = rspamd_mempool_alloc (task->task_pool, len + 1);
+
+ addr->raw_len = rspamd_snprintf (dst, len, "<%*s@%*s>",
+ (int)addr->user_len, addr->user,
+ (int)addr->domain_len, addr->domain);
}
+
+ addr->raw = dst;
}
lua_pop (L, 1);
break;
}
if (ptrs) {
- lua_pushvalue (L, pos);
+ guint i;
+ struct rspamd_email_address *tmp;
+
+ PTR_ARRAY_FOREACH (ptrs, i, tmp) {
+ rspamd_email_address_free (tmp);
+ }
+
g_ptr_array_set_size (ptrs, 0);
+ lua_pushvalue (L, pos);
for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) {
if (lua_import_email_address (L, task, lua_gettop (L), &addr)) {
g_ptr_array_add (ptrs, addr);
- addr = NULL;
}
}
if (addrs) {
if (lua_import_email_address (L, task, pos, &addr)) {
+ guint i;
+ struct rspamd_email_address *tmp;
+
+ PTR_ARRAY_FOREACH (addrs, i, tmp) {
+ rspamd_email_address_free (tmp);
+ }
+
g_ptr_array_set_size (addrs, 0);
g_ptr_array_add (addrs, addr);
lua_pushboolean (L, true);
}
}
else if (paddr) {
- if (lua_import_email_address (L, task, pos, paddr)) {
+ if (lua_import_email_address (L, task, pos, &addr)) {
+
+ if (paddr) {
+ rspamd_email_address_free (*paddr);
+ }
+
+ *paddr = addr;
lua_pushboolean (L, true);
}
else {