local invalid_factor = 0
local rh = task:get_received_headers()
local time_factor = 0
- local tls_factor = 0
+ local secure_factor = 0
+ local fun = require "fun"
if rh and #rh > 0 then
- local ntotal = 1.0 * #rh
- count_factor = 1.0 / ntotal
+ local ntotal = 0.0
local init_time = 0
- for _,rc in ipairs(rh) do
+ fun.each(function(rc)
+ ntotal = ntotal + 1.0
+
if not rc.by_hostname then
- invalid_factor = invalid_factor + 1
+ invalid_factor = invalid_factor + 1.0
end
if init_time == 0 and rc.timestamp then
init_time = rc.timestamp
time_factor = time_factor + math.abs(init_time - rc.timestamp)
init_time = rc.timestamp
end
- if rc.proto and (rc.proto == 'esmtps') then
- tls_factor = tls_factor + 1
+ if rc.flags and (rc.flags['ssl'] or rc.flags['authenticated']) then
+ secure_factor = secure_factor + 1.0
end
- end
+ end,
+ fun.filter(function(rc) return not rc.flags or not rc.flags['artificial'] end, rh))
invalid_factor = invalid_factor / ntotal
- tls_factor = tls_factor / ntotal
+ secure_factor = secure_factor / ntotal
+ count_factor = 1.0 / ntotal
if time_factor ~= 0 then
time_factor = 1.0 / time_factor
end
end
- return {count_factor, invalid_factor, time_factor, tls_factor}
+ return {count_factor, invalid_factor, time_factor, secure_factor}
end
local function meta_urls_function(task)
trecv = rspamd_mempool_alloc0 (task->task_pool,
sizeof (struct received_header));
+ trecv->flags |= RSPAMD_RECEIVED_FLAG_ARTIFICIAL;
trecv->real_ip = rspamd_mempool_strdup (task->task_pool,
rspamd_inet_address_to_string (task->from_addr));
trecv->from_ip = trecv->real_ip;
RSPAMD_RECEIVED_UNKNOWN
};
+#define RSPAMD_RECEIVED_FLAG_ARTIFICIAL (1 << 0)
+#define RSPAMD_RECEIVED_FLAG_SSL (1 << 1)
+#define RSPAMD_RECEIVED_FLAG_AUTHENTICATED (1 << 2)
+
struct received_header {
gchar *from_hostname;
gchar *from_ip;
struct rspamd_mime_header *hdr;
time_t timestamp;
enum rspamd_received_type type;
+ gint flags;
};
/**
recv->hdr = rh;
rspamd_smtp_recieved_parse (task, rh->decoded,
strlen (rh->decoded), recv);
+ /* Set flags */
+ if (recv->type == RSPAMD_RECEIVED_ESMTPA ||
+ recv->type == RSPAMD_RECEIVED_ESMTPSA) {
+ recv->flags |= RSPAMD_RECEIVED_FLAG_AUTHENTICATED;
+ }
+ if (recv->type == RSPAMD_RECEIVED_ESMTPS ||
+ recv->type == RSPAMD_RECEIVED_ESMTPSA) {
+ recv->flags |= RSPAMD_RECEIVED_FLAG_SSL;
+ }
+
g_ptr_array_add (task->received, recv);
break;
case 0x76F31A09F4352521ULL: /* to */
for (i = 0; i < task->received->len; i ++) {
rh = g_ptr_array_index (task->received, i);
- lua_createtable (L, 0, 9);
+ lua_createtable (L, 0, 10);
if (rh->hdr && rh->hdr->decoded) {
rspamd_lua_table_set (L, "raw", rh->hdr->decoded);
}
+ lua_pushstring (L, "flags");
+ lua_createtable (L, 0, 3);
+
+ lua_pushstring (L, "artificial");
+ if (rh->flags & RSPAMD_RECEIVED_FLAG_ARTIFICIAL) {
+ lua_pushboolean (L, true);
+ }
+ else {
+ lua_pushboolean (L, false);
+ }
+ lua_settable (L, -3);
+
+ lua_pushstring (L, "authenticated");
+ if (rh->flags & RSPAMD_RECEIVED_FLAG_AUTHENTICATED) {
+ lua_pushboolean (L, true);
+ }
+ else {
+ lua_pushboolean (L, false);
+ }
+ lua_settable (L, -3);
+
+ lua_pushstring (L, "ssl");
+ if (rh->flags & RSPAMD_RECEIVED_FLAG_SSL) {
+ lua_pushboolean (L, true);
+ }
+ else {
+ lua_pushboolean (L, false);
+ }
+ lua_settable (L, -3);
+
+ lua_settable (L, -3);
+
if (G_UNLIKELY (rh->from_ip == NULL &&
rh->real_ip == NULL &&
rh->real_hostname == NULL &&