}
struct rspamd_email_address *
-rspamd_email_address_from_smtp (const gchar *str, guint len)
+rspamd_email_address_from_smtp (const gchar *str, guint len, gint max_elements)
{
struct rspamd_email_address addr, *ret;
gsize nlen;
rspamd_email_address_check_and_add (const gchar *start, gsize len,
GPtrArray *res,
rspamd_mempool_t *pool,
- GString *ns)
+ GString *ns,
+ gint max_elements)
{
struct rspamd_email_address addr;
+ g_assert (res != NULL);
+
+ if (max_elements > 0 && res->len >= max_elements) {
+ msg_info_pool_check ("reached maximum number of elements %d when adding %v",
+ max_elements,
+ ns);
+
+ return FALSE;
+ }
+
/* The whole email is likely address */
memset (&addr, 0, sizeof (addr));
rspamd_smtp_addr_parse (start, len, &addr);
}
GPtrArray *
-rspamd_email_address_from_mime (rspamd_mempool_t *pool,
- const gchar *hdr, guint len,
- GPtrArray *src)
+rspamd_email_address_from_mime (rspamd_mempool_t *pool, const gchar *hdr,
+ guint len,
+ GPtrArray *src,
+ gint max_elements)
{
GPtrArray *res = src;
gboolean seen_at = FALSE;
rspamd_mempool_add_destructor (pool, rspamd_email_address_list_destroy,
res);
}
+ else if (max_elements > 0 && res->len >= max_elements) {
+ msg_info_pool_check ("reached maximum number of elements %d", max_elements);
+
+ return res;
+ }
ns = g_string_sized_new (len);
cpy = g_string_sized_new (len);
}
if (!rspamd_email_address_check_and_add (c, t - c + 1,
- res, pool, ns)) {
+ res, pool, ns, max_elements)) {
rspamd_email_address_add (pool, res, NULL, ns);
}
case parse_addr:
if (*p == '>') {
if (!rspamd_email_address_check_and_add (c, p - c + 1,
- res, pool, ns)) {
+ res, pool, ns, max_elements)) {
rspamd_email_address_add (pool, res, NULL, ns);
}
if (seen_at) {
/* The whole email is likely address */
if (!rspamd_email_address_check_and_add (c, p - c,
- res, pool, ns)) {
+ res, pool, ns, max_elements)) {
if (res->len == 0) {
rspamd_email_address_add (pool, res, NULL, ns);
}
case parse_addr:
if (p > c) {
if (!rspamd_email_address_check_and_add (c, p - c,
- res, pool, ns)) {
+ res, pool, ns, max_elements)) {
if (res->len == 0) {
rspamd_email_address_add (pool, res, NULL, ns);
}
* @param len length of string
* @return
*/
-struct rspamd_email_address *rspamd_email_address_from_smtp (
- const gchar *str, guint len);
+struct rspamd_email_address *rspamd_email_address_from_smtp (const gchar *str,
+ guint len,
+ gint max_elements);
/**
* Parses email address from the mime header, decodes names and return the array
* @param len
* @return
*/
-GPtrArray *rspamd_email_address_from_mime (rspamd_mempool_t *pool,
- const gchar *hdr,
- guint len,
- GPtrArray *src);
+GPtrArray *
+rspamd_email_address_from_mime (rspamd_mempool_t *pool, const gchar *hdr, guint len,
+ GPtrArray *src, gint max_elements);
/**
* Destroys list of email addresses
case 0x76F31A09F4352521ULL: /* to */
MESSAGE_FIELD (task, rcpt_mime) = rspamd_email_address_from_mime (task->task_pool,
rh->decoded, strlen (rh->decoded),
- MESSAGE_FIELD (task, rcpt_mime));
+ MESSAGE_FIELD (task, rcpt_mime), -1);
rh->flags |= RSPAMD_HEADER_TO|RSPAMD_HEADER_RCPT|RSPAMD_HEADER_UNIQUE;
break;
case 0x7EB117C1480B76ULL: /* cc */
MESSAGE_FIELD (task, rcpt_mime) = rspamd_email_address_from_mime (task->task_pool,
rh->decoded, strlen (rh->decoded),
- MESSAGE_FIELD (task, rcpt_mime));
+ MESSAGE_FIELD (task, rcpt_mime), -1);
rh->flags |= RSPAMD_HEADER_CC|RSPAMD_HEADER_RCPT|RSPAMD_HEADER_UNIQUE;
break;
case 0xE4923E11C4989C8DULL: /* bcc */
MESSAGE_FIELD (task, rcpt_mime) = rspamd_email_address_from_mime (task->task_pool,
rh->decoded, strlen (rh->decoded),
- MESSAGE_FIELD (task, rcpt_mime));
+ MESSAGE_FIELD (task, rcpt_mime), -1);
rh->flags |= RSPAMD_HEADER_BCC|RSPAMD_HEADER_RCPT|RSPAMD_HEADER_UNIQUE;
break;
case 0x41E1985EDC1CBDE4ULL: /* from */
MESSAGE_FIELD (task, from_mime) = rspamd_email_address_from_mime (task->task_pool,
rh->decoded, strlen (rh->decoded),
- MESSAGE_FIELD (task, from_mime));
+ MESSAGE_FIELD (task, from_mime), -1);
rh->flags |= RSPAMD_HEADER_FROM|RSPAMD_HEADER_SENDER|RSPAMD_HEADER_UNIQUE;
break;
case 0x43A558FC7C240226ULL: /* message-id */ {
case 0xEE4AA2EAAC61D6F4ULL: /* return-path */
if (task->from_envelope == NULL) {
task->from_envelope = rspamd_email_address_from_smtp (rh->decoded,
- strlen (rh->decoded));
+ strlen (rh->decoded), -1);
}
rh->flags = RSPAMD_HEADER_RETURN_PATH|RSPAMD_HEADER_UNIQUE;
break;
if (ucl_object_type (cur) == UCL_STRING) {
val = ucl_object_tostring (obj);
tmp_addr = rspamd_email_address_from_mime (pool, val,
- strlen (val), tmp_addr);
+ strlen (val), tmp_addr, -1);
}
else {
g_set_error (err,
cpy = rspamd_mempool_alloc (priv->pool, zero - pos);
memcpy (cpy, pos, zero - pos);
msg_debug_milter ("got mail: %*s", (int)(zero - pos), cpy);
- addr = rspamd_email_address_from_smtp (cpy, zero - pos);
+ addr = rspamd_email_address_from_smtp (cpy, zero - pos, -1);
if (addr) {
session->from = addr;
/* That actually should not happen */
cpy = rspamd_mempool_alloc (priv->pool, end - pos);
memcpy (cpy, pos, end - pos);
- addr = rspamd_email_address_from_smtp (cpy, end - pos);
+ addr = rspamd_email_address_from_smtp (cpy, end - pos, -1);
if (addr) {
session->from = addr;
memcpy (cpy, pos, end - pos);
msg_debug_milter ("got rcpt: %*s", (int)(zero - pos), cpy);
- addr = rspamd_email_address_from_smtp (cpy, zero - pos);
+ addr = rspamd_email_address_from_smtp (cpy, zero - pos, -1);
if (addr) {
if (!session->rcpts) {
msg_debug_milter ("got weird rcpt: %*s", (int)(end - pos),
pos);
/* That actually should not happen */
- addr = rspamd_email_address_from_smtp (cpy, end - pos);
+ addr = rspamd_email_address_from_smtp (cpy, end - pos, -1);
if (addr) {
if (!session->rcpts) {
else if (*p == ',' && start_addr != NULL && p > start_addr) {
/* We have finished address, check what we have */
addr = rspamd_email_address_from_smtp (start_addr,
- p - start_addr);
+ p - start_addr, -1);
if (addr) {
if (task->rcpt_envelope == NULL) {
if (start_addr && p > start_addr) {
switch (state) {
case normal_string:
- addr = rspamd_email_address_from_smtp (start_addr, end - start_addr);
+ addr = rspamd_email_address_from_smtp (start_addr, end - start_addr, -1);
if (addr) {
if (task->rcpt_envelope == NULL) {
IF_HEADER (FROM_HEADER) {
task->from_envelope = rspamd_email_address_from_smtp (
hv_tok->begin,
- hv_tok->len);
+ hv_tok->len, -1);
msg_debug_protocol ("read from header, value: %T", hv_tok);
if (!task->from_envelope) {
own_pool = TRUE;
}
- addrs = rspamd_email_address_from_mime (pool, str, len, NULL);
+ addrs = rspamd_email_address_from_mime (pool, str, len, NULL, -1);
if (addrs == NULL) {
lua_pushnil (L);