]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Parse received date and ESMTPA proto
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 15 Jun 2016 07:33:26 +0000 (08:33 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 15 Jun 2016 07:33:26 +0000 (08:33 +0100)
src/libmime/message.h
src/lua/lua_task.c
src/ragel/smtp_received.rl
src/ragel/smtp_received_parser.rl

index 026233f3c6f0470526f60f57e1b7e015d1f7733c..cacb4287b696d8616442a88cb70a38432aec8b9b 100644 (file)
@@ -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 {
index cbcaf2ed501b247bc8fc9a1a41529b8cebabf33d..bc31640fa13fc53acae231f50d32704775a37fa3 100644 (file)
@@ -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;
index 235c54906b9235f2eba49a114cf31a7a37fa5e7e..02e850c9bdd5c60ed47ea8a979c1955b3b294fa5 100644 (file)
   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;
 
 }%%
index 5170c28064c22a262a420a5519aa1820fa5ab4d9..7161eab96a59ed74839775db8fb57da58f06ea1d 100644 (file)
   action ESMTPS_proto {
     rh->type = RSPAMD_RECEIVED_ESMTPS;
   }
+  action ESMTPA_proto {
+    rh->type = RSPAMD_RECEIVED_ESMTPA;
+  }
   action ESMTP_proto {
     rh->type = RSPAMD_RECEIVED_ESMTP;
   }
     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));