SET(RAGEL_DEPENDS "${CMAKE_SOURCE_DIR}/src/ragel/smtp_address.rl"
"${CMAKE_SOURCE_DIR}/src/ragel/smtp_date.rl"
"${CMAKE_SOURCE_DIR}/src/ragel/smtp_ip.rl"
- "${CMAKE_SOURCE_DIR}/src/ragel/smtp_whitespace.rl"
+ "${CMAKE_SOURCE_DIR}/src/ragel/smtp_base.rl"
"${CMAKE_SOURCE_DIR}/src/ragel/smtp_received.rl"
"${CMAKE_SOURCE_DIR}/src/ragel/content_disposition.rl")
RAGEL_TARGET(ragel_smtp_addr
DEPENDS ${RAGEL_DEPENDS}
COMPILE_FLAGS -T1
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/smtp_addr_parser.rl.c)
-RAGEL_TARGET(ragel_smtp_received
- INPUTS ${CMAKE_SOURCE_DIR}/src/ragel/smtp_received_parser.rl
- DEPENDS ${RAGEL_DEPENDS}
- COMPILE_FLAGS -T1
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/smtp_received_parser.rl.c)
RAGEL_TARGET(ragel_content_disposition
INPUTS ${CMAKE_SOURCE_DIR}/src/ragel/content_disposition_parser.rl
DEPENDS ${RAGEL_DEPENDS}
DEPENDS ${RAGEL_DEPENDS}
COMPILE_FLAGS -G2
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/date_parser.rl.c)
+RAGEL_TARGET(ragel_smtp_ip
+ INPUTS ${CMAKE_SOURCE_DIR}/src/ragel/smtp_ip_parser.rl
+ DEPENDS ${RAGEL_DEPENDS}
+ COMPILE_FLAGS -G2
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ip_parser.rl.c)
######################### LINK SECTION ###############################
ADD_LIBRARY(rspamd-server STATIC
${CMAKE_CURRENT_BINARY_DIR}/modules.c
${PLUGINSSRC}
"${RAGEL_ragel_smtp_addr_OUTPUTS}"
- "${RAGEL_ragel_smtp_received_OUTPUTS}"
"${RAGEL_ragel_newlines_strip_OUTPUTS}"
"${RAGEL_ragel_content_type_OUTPUTS}"
"${RAGEL_ragel_content_disposition_OUTPUTS}"
"${RAGEL_ragel_rfc2047_OUTPUTS}"
- "${RAGEL_ragel_smtp_date_OUTPUTS}")
+ "${RAGEL_ragel_smtp_date_OUTPUTS}"
+ "${RAGEL_ragel_smtp_ip_OUTPUTS}")
TARGET_LINK_LIBRARIES(rspamd-server rspamd-http-parser)
TARGET_LINK_LIBRARIES(rspamd-server rspamd-cdb)
TARGET_LINK_LIBRARIES(rspamd-server rspamd-lpeg)
DL_APPEND (head, cur_part);
}
- while (p > end) {
+ while (p < end) {
if (*p == ';') {
/* We are at the date separator, stop here */
*date_pos = p - (const guchar *)data + 1;
{
const gchar *p, *end;
gsize hlen = 0;
+ gboolean seen_dot = FALSE;
p = begin;
end = begin + len;
while (p < end) {
- if (rspamd_url_is_domain (*p)) {
+ if (!g_ascii_isspace (*p) && rspamd_url_is_domain (*p)) {
+ if (*p == '.') {
+ seen_dot = TRUE;
+ }
+
hlen ++;
}
+ else {
+ break;
+ }
p ++;
}
if (hlen > 0) {
- if (p == end || g_ascii_isspace (*p) || *p == '[' || *p == '(') {
- /* We have some hostname, accept it */
+ if (p == end) {
+ /* All data looks like a hostname */
+ gchar *dest;
+
+ dest = rspamd_mempool_alloc (task->task_pool,
+ hlen + 1);
+ rspamd_strlcpy (dest, begin, hlen + 1);
+ *pdest = dest;
+
+ return TRUE;
+ }
+ else if (seen_dot && (g_ascii_isspace (*p) || *p == '[' || *p == '(')) {
gchar *dest;
dest = rspamd_mempool_alloc (task->task_pool,
const gchar *brace_pos = memchr (comment->data, ']', comment->dlen);
if (brace_pos) {
- addr = rspamd_parse_smtp_ip (comment->data,
- brace_pos - comment->data + 1,
+ addr = rspamd_parse_inet_address_pool (comment->data + 1,
+ brace_pos - comment->data - 1,
task->task_pool);
if (addr) {
ebrace_pos = memchr (obrace_pos, ']', dend - obrace_pos);
if (ebrace_pos) {
- addr = rspamd_parse_smtp_ip (obrace_pos,
- ebrace_pos - obrace_pos + 1,
+ addr = rspamd_parse_inet_address_pool (obrace_pos + 1,
+ ebrace_pos - obrace_pos - 1,
task->task_pool);
if (addr) {
rspamd_inet_addr_t *addr;
if (brace_pos) {
- addr = rspamd_parse_smtp_ip (rpart->data,
- brace_pos - rpart->data + 1,
+ addr = rspamd_parse_inet_address_pool (rpart->data + 1,
+ brace_pos - rpart->data - 1,
task->task_pool);
if (addr) {
size_t len,
struct received_header *rh)
{
- goffset date_pos = 0;
+ goffset date_pos = -1;
struct rspamd_received_part *head, *cur;
rspamd_ftok_t t1, t2;
}
}
+ break;
+ default:
+ /* Do nothing */
break;
}
}
rh->from_hostname = rh->real_hostname;
}
+ if (date_pos > 0 && date_pos < len) {
+ rh->timestamp = rspamd_parse_smtp_date (data + date_pos,
+ len - date_pos);
+ }
+
return 0;
}
\ No newline at end of file
for exim-dev@exim.org; Sat, 30 Jun 2018 02:54:24 +0100]],
{
from_hostname = 'smtp.spodhuis.org',
- from_ip = '2a02:898:31:0:48:4558:736d:7470',
- real_ip = '2a02:898:31:0:48:4558:736d:7470',
+ from_ip = '2a02:898:31::48:4558:736d:7470',
+ real_ip = '2a02:898:31::48:4558:736d:7470',
by_hostname = 'hummus.csx.cam.ac.uk',
}
},
real_ip = '1.1.1.1',
}
},
- {'from [192.83.172.101] by (HELLO 148.251.238.35 ) (148.251.238.35) by guovswzqkvry051@sohu.com with gg login by AOL 6.0 for Windows US sub 008 SMTP ; Tue, 03 Jul 2018 09:01:47 -0300',
+ {'from [192.83.172.101] (HELLO 148.251.238.35) (148.251.238.35) by guovswzqkvry051@sohu.com with gg login by AOL 6.0 for Windows US sub 008 SMTP ; Tue, 03 Jul 2018 09:01:47 -0300',
{
from_ip = '192.83.172.101',
by_hostname = '',
- }
+ },
+ },
+ {'from [61.174.163.26] (helo=host) by sc8-sf-list1.sourceforge.net with smtp (Exim 3.31-VA-mm2 #1 (Debian)) id 18t2z0-0001NX-00 for <razor-users@lists.sourceforge.net>; Wed, 12 Mar 2003 01:57:10 -0800',
+ {
+ from_ip = '61.174.163.26',
+ by_hostname = 'sc8-sf-list1.sourceforge.net',
+ },
},
+ {[[from [127.0.0.1] (unknown [65.19.167.131])
+ (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
+ (Client did not present a certificate)
+ by mail01.someotherdomain.org (Postfix) with ESMTPSA id 43tYMW2yKHz50MHS
+ for <user2@somedomain.com>; Mon, 4 Feb 2019 16:39:35 +0000 (GMT)]],
+ {
+ from_ip = '65.19.167.131',
+ real_ip = '65.19.167.131',
+ by_hostname = 'mail01.someotherdomain.org',
+ }
+ }
}
local task = ffi.C.rspamd_task_new(nil, nil)