From 4ae5dc6bf798912b865ee7a25faedcacbf5841a4 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 4 Oct 2016 14:14:19 +0100 Subject: [PATCH] [Feature] Store `for` part in received headers --- src/libmime/message.h | 1 + src/ragel/smtp_received.rl | 2 +- src/ragel/smtp_received_parser.rl | 20 ++++++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/libmime/message.h b/src/libmime/message.h index 2a9201be88..e38420dbff 100644 --- a/src/libmime/message.h +++ b/src/libmime/message.h @@ -84,6 +84,7 @@ struct received_header { gchar *real_hostname; gchar *real_ip; gchar *by_hostname; + gchar *for_mbox; rspamd_inet_addr_t *addr; time_t timestamp; enum rspamd_received_type type; diff --git a/src/ragel/smtp_received.rl b/src/ragel/smtp_received.rl index e005dcc9ca..c1fd467037 100644 --- a/src/ragel/smtp_received.rl +++ b/src/ragel/smtp_received.rl @@ -44,7 +44,7 @@ msg_id = "<" id_left "@" id_right ">"; ID = CFWS "ID"i FWS ( Atom | msg_id ); - For = CFWS "FOR"i FWS ( Path | Mailbox ) %For_End; + For = CFWS "FOR"i FWS ( Path | Mailbox ) >For_Start %For_End; Additional_Registered_Clauses = CFWS Atom FWS String; Opt_info = Via? With? ID? For? Additional_Registered_Clauses?; # Here we make From part optional just because many received headers lack it diff --git a/src/ragel/smtp_received_parser.rl b/src/ragel/smtp_received_parser.rl index b2c73cab3d..c599e0495e 100644 --- a/src/ragel/smtp_received_parser.rl +++ b/src/ragel/smtp_received_parser.rl @@ -142,6 +142,8 @@ reported_ip_end = NULL; ip_start = NULL; ip_end = NULL; + for_start = NULL; + for_end = NULL; } action By_Start { @@ -155,6 +157,8 @@ reported_ip_end = NULL; ip_start = NULL; ip_end = NULL; + for_start = NULL; + for_end = NULL; } action By_End { @@ -210,8 +214,17 @@ } } - action For_End { + action For_Start { + for_start = p; + } + action For_End { + if (for_start && p > for_start) { + for_end = p; + len = for_end - for_start; + rh->for_mbox = rspamd_mempool_alloc (task->task_pool, len + 1); + rspamd_strlcpy (rh->for_mbox, for_start, len + 1); + } } action SMTP_proto { @@ -270,7 +283,8 @@ 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, *date_start; + *ip_start, *ip_end, *date_start, + *for_start, *for_end; const char *p = data, *pe = data + len, *eof; int cs, in_v6 = 0, *stack = NULL; gsize top = 0; @@ -292,6 +306,8 @@ rspamd_smtp_recieved_parse (struct rspamd_task *task, const char *data, size_t l ip_start = NULL; ip_end = NULL; date_start = NULL; + for_start = NULL; + for_end = NULL; rh->type = RSPAMD_RECEIVED_UNKNOWN; memset (&for_addr, 0, sizeof (for_addr)); -- 2.47.3