]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Distinguish URLs found in Subject
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 28 Mar 2017 13:25:56 +0000 (14:25 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 28 Mar 2017 13:25:56 +0000 (14:25 +0100)
src/libmime/message.c
src/libserver/url.c
src/libserver/url.h
src/lua/lua_url.c

index d445362b2bc49e1c2120e1513713999bb3e8db10..91e32be3326aa00c2aa37beba87494be06d5a52b 100644 (file)
@@ -632,8 +632,6 @@ rspamd_message_from_data (struct rspamd_task *task, const guchar *start,
 gboolean
 rspamd_message_parse (struct rspamd_task *task)
 {
-       GPtrArray *hdrs;
-       struct rspamd_mime_header *rh;
        struct rspamd_mime_text_part *p1, *p2;
        struct received_header *recv, *trecv;
        const gchar *p;
@@ -824,13 +822,11 @@ rspamd_message_parse (struct rspamd_task *task)
        }
 
        /* Parse urls inside Subject header */
-       hdrs = rspamd_message_get_header_array (task, "Subject", FALSE);
-
-       PTR_ARRAY_FOREACH (hdrs, i, rh) {
-               p = rh->decoded;
+       if (task->subject) {
+               p = task->subject;
                len = strlen (p);
                rspamd_url_find_multiple (task->task_pool, p, len, FALSE, NULL,
-                               rspamd_url_task_callback, task);
+                               rspamd_url_task_subject_callback, task);
        }
 
        /* Calculate distance for 2-parts messages */
index 0a1b26bb309c2dae89477c8ba69c28c2175764d3..1efae6019df185beb9b0182f25b33dc2da95a118 100644 (file)
@@ -2486,7 +2486,7 @@ rspamd_url_find_single (rspamd_mempool_t *pool, const gchar *in,
 
 
 void
-rspamd_url_task_callback (struct rspamd_url *url, gsize start_offset,
+rspamd_url_task_subject_callback (struct rspamd_url *url, gsize start_offset,
                gsize end_offset, gpointer ud)
 {
        struct rspamd_task *task = ud;
@@ -2495,7 +2495,7 @@ rspamd_url_task_callback (struct rspamd_url *url, gsize start_offset,
        gint rc;
 
        /* It is just a displayed URL, we should not check it for certain things */
-       url->flags |= RSPAMD_URL_FLAG_HTML_DISPLAYED;
+       url->flags |= RSPAMD_URL_FLAG_HTML_DISPLAYED|RSPAMD_URL_FLAG_SUBJECT;
 
        if (url->protocol == PROTOCOL_MAILTO) {
                if (url->userlen > 0) {
index 9a9522c50ca5c16ccdd4e0e67a5372f752eca0e4..14c0c5b696654e6456af14d6c953d082ddd3dcc7 100644 (file)
@@ -16,6 +16,7 @@ enum rspamd_url_flags {
        RSPAMD_URL_FLAG_REDIRECTED = 1 << 3,
        RSPAMD_URL_FLAG_HTML_DISPLAYED = 1 << 4,
        RSPAMD_URL_FLAG_FROM_TEXT = 1 << 5,
+       RSPAMD_URL_FLAG_SUBJECT = 1 << 6,
 };
 
 struct rspamd_url_tag {
@@ -163,7 +164,8 @@ void rspamd_url_find_single (rspamd_mempool_t *pool, const gchar *in,
  * @param end_offset
  * @param ud
  */
-void rspamd_url_task_callback (struct rspamd_url *url, gsize start_offset,
+void rspamd_url_task_subject_callback (struct rspamd_url *url,
+               gsize start_offset,
                gsize end_offset, gpointer ud);
 
 /**
index 9b69267a449bc438ad37ce91436c158f52d2d76f..8826bb41ca98620cc95191d0af4426cd6b7340db 100644 (file)
@@ -53,6 +53,7 @@ LUA_FUNCTION_DEF (url, is_phished);
 LUA_FUNCTION_DEF (url, is_redirected);
 LUA_FUNCTION_DEF (url, is_obscured);
 LUA_FUNCTION_DEF (url, is_html_displayed);
+LUA_FUNCTION_DEF (url, is_subject);
 LUA_FUNCTION_DEF (url, get_phished);
 LUA_FUNCTION_DEF (url, get_tag);
 LUA_FUNCTION_DEF (url, get_tags);
@@ -76,6 +77,7 @@ static const struct luaL_reg urllib_m[] = {
        LUA_INTERFACE_DEF (url, is_redirected),
        LUA_INTERFACE_DEF (url, is_obscured),
        LUA_INTERFACE_DEF (url, is_html_displayed),
+       LUA_INTERFACE_DEF (url, is_subject),
        LUA_INTERFACE_DEF (url, get_phished),
        LUA_INTERFACE_DEF (url, get_tag),
        LUA_INTERFACE_DEF (url, get_tags),
@@ -339,6 +341,26 @@ lua_url_is_html_displayed (lua_State *L)
        return 1;
 }
 
+/***
+ * @method url:is_subject()
+ * Check whether URL is found in subject
+ * @return {boolean} `true` if URL is found in subject
+ */
+static gint
+lua_url_is_subject (lua_State *L)
+{
+       struct rspamd_lua_url *url = lua_check_url (L, 1);
+
+       if (url != NULL) {
+               lua_pushboolean (L, url->url->flags & RSPAMD_URL_FLAG_SUBJECT);
+       }
+       else {
+               lua_pushnil (L);
+       }
+
+       return 1;
+}
+
 /***
  * @method url:get_tag(tag)
  * Returns list of string for a specific tagname for an url