From: Vsevolod Stakhov Date: Wed, 15 Jun 2016 07:33:26 +0000 (+0100) Subject: [Feature] Parse received date and ESMTPA proto X-Git-Tag: 1.3.0~334 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5a70a9191f3d0901f03372fabec66634618c91a4;p=rspamd.git [Feature] Parse received date and ESMTPA proto --- diff --git a/src/libmime/message.h b/src/libmime/message.h index 026233f3c..cacb4287b 100644 --- a/src/libmime/message.h +++ b/src/libmime/message.h @@ -59,6 +59,7 @@ struct mime_text_part { enum rspamd_received_type { RSPAMD_RECEIVED_SMTP = 0, RSPAMD_RECEIVED_ESMTP, + RSPAMD_RECEIVED_ESMTPA, RSPAMD_RECEIVED_ESMTPS, RSPAMD_RECEIVED_LMTP, RSPAMD_RECEIVED_IMAP, @@ -72,8 +73,8 @@ struct received_header { gchar *real_ip; gchar *by_hostname; rspamd_inet_addr_t *addr; + time_t timestamp; enum rspamd_received_type type; - gint is_error; }; struct raw_header { diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index cbcaf2ed5..bc31640fa 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -1436,8 +1436,7 @@ lua_task_get_received_headers (lua_State * L) for (i = 0; i < task->received->len; i ++) { rh = g_ptr_array_index (task->received, i); - if (rh->is_error || G_UNLIKELY ( - rh->from_ip == NULL && + if (G_UNLIKELY (rh->from_ip == NULL && rh->real_ip == NULL && rh->real_hostname == NULL && rh->by_hostname == NULL)) { @@ -1463,6 +1462,9 @@ lua_task_get_received_headers (lua_State * L) case RSPAMD_RECEIVED_ESMTPS: proto = "esmtps"; break; + case RSPAMD_RECEIVED_ESMTPA: + proto = "esmtpa"; + break; case RSPAMD_RECEIVED_LMTP: proto = "lmtp"; break; diff --git a/src/ragel/smtp_received.rl b/src/ragel/smtp_received.rl index 235c54906..02e850c9b 100644 --- a/src/ragel/smtp_received.rl +++ b/src/ragel/smtp_received.rl @@ -11,7 +11,13 @@ Addtl_Link = Atom; Link = "TCP" | Addtl_Link; Attdl_Protocol = Atom; - Protocol = "ESMTP" %ESMTP_proto | "SMTP" %SMTP_proto | "ESMTPS" %ESMTPS_proto | "LMTP" %LMTP_proto | "IMAP" %IMAP_proto | Attdl_Protocol; + Protocol = "ESMTP" %ESMTP_proto | + "SMTP" %SMTP_proto | + "ESMTPS" %ESMTPS_proto | + "ESMTPA" %ESMTPA_proto | + "LMTP" %LMTP_proto | + "IMAP" %IMAP_proto | + Attdl_Protocol; TCP_info = address_literal >Real_IP_Start %Real_IP_End | ( Domain >Real_Domain_Start %Real_Domain_End FWS address_literal >Real_IP_Start %Real_IP_End ); @@ -34,6 +40,6 @@ For = CFWS "FOR"i FWS ( Path | Mailbox ) %For_End; Additional_Registered_Clauses = CFWS Atom FWS String; Opt_info = Via? With? ID? For? Additional_Registered_Clauses?; - Received = From_domain By_domain Opt_info CFWS? ";" FWS date_time; + Received = From_domain By_domain Opt_info CFWS? ";" FWS date_time >Date_Start %Date_End; }%% diff --git a/src/ragel/smtp_received_parser.rl b/src/ragel/smtp_received_parser.rl index 5170c2806..7161eab96 100644 --- a/src/ragel/smtp_received_parser.rl +++ b/src/ragel/smtp_received_parser.rl @@ -220,6 +220,9 @@ action ESMTPS_proto { rh->type = RSPAMD_RECEIVED_ESMTPS; } + action ESMTPA_proto { + rh->type = RSPAMD_RECEIVED_ESMTPA; + } action ESMTP_proto { rh->type = RSPAMD_RECEIVED_ESMTP; } @@ -230,6 +233,22 @@ rh->type = RSPAMD_RECEIVED_IMAP; } + action Date_Start { + date_start = p; + } + action Date_End { + if (date_start && p > date_start) { + guint len; + char *tdate; + + len = p - date_start; + tdate = g_malloc (len + 1); + rspamd_strlcpy (tdate, date_start, len + 1); + rh->timestamp = g_mime_utils_header_decode_date (tdate, NULL); + g_free (tdate); + } + } + include smtp_received "smtp_received.rl"; main := Received; @@ -248,7 +267,7 @@ rspamd_smtp_recieved_parse (struct rspamd_task *task, const char *data, size_t l *real_ip_start, *real_ip_end, *reported_domain_start, *reported_domain_end, *reported_ip_start, *reported_ip_end, - *ip_start, *ip_end; + *ip_start, *ip_end, *date_start; const char *p = data, *pe = data + len, *eof; int cs, in_v6 = 0; @@ -263,6 +282,7 @@ rspamd_smtp_recieved_parse (struct rspamd_task *task, const char *data, size_t l reported_ip_end = NULL; ip_start = NULL; ip_end = NULL; + date_start = NULL; rh->type = RSPAMD_RECEIVED_UNKNOWN; memset (&for_addr, 0, sizeof (for_addr));