diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-05-06 14:39:01 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-05-06 14:39:01 +0100 |
commit | b058b87fa17b8142a4970d1fedc17fff9c1bedfa (patch) | |
tree | af01f959ddba1fd7498bfb7c049372712e8c61ee | |
parent | bc40fb5b409f728123bcb03bf904c01e45a1d887 (diff) | |
download | rspamd-b058b87fa17b8142a4970d1fedc17fff9c1bedfa.tar.gz rspamd-b058b87fa17b8142a4970d1fedc17fff9c1bedfa.zip |
[Minor] Convert milter macros to HTTP headers
-rw-r--r-- | src/libserver/milter.c | 52 | ||||
-rw-r--r-- | src/libserver/protocol_internal.h | 2 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/libserver/milter.c b/src/libserver/milter.c index a45f19c77..15835a801 100644 --- a/src/libserver/milter.c +++ b/src/libserver/milter.c @@ -424,6 +424,11 @@ rspamd_milter_process_command (struct rspamd_milter_session *session, msg_debug_milter ("got macro: %T -> %T", name_tok, value_tok); + if (rspamd_ftok_cstr_equal (name_tok, "{mail_host}", FALSE)) { + session->hostname = rspamd_fstring_assign (session->hostname, + value_tok->begin, value_tok->len); + } + cmdlen -= zero_val - pos; pos = zero_val + 1; } @@ -1085,6 +1090,51 @@ rspamd_milter_session_ref (struct rspamd_milter_session *session) return session; } +#define IF_MACRO(lit) RSPAMD_FTOK_ASSIGN (&srch, (lit)); \ + found = g_hash_table_lookup (session->macros, &srch); \ + if (found) + +static void +rspamd_milter_macro_http (struct rspamd_milter_session *session, + struct rspamd_http_message *msg) +{ + rspamd_ftok_t *found, srch; + + /* + * We assume postfix macros here, sendmail ones might be slightly + * different + */ + + if (!session->macros) { + return; + } + + IF_MACRO("i") { + rspamd_http_message_add_header_len (msg, QUEUE_ID_HEADER, + found->begin, found->len); + } + + IF_MACRO("{daemon_name}") { + rspamd_http_message_add_header_len (msg, MTA_TAG_HEADER, + found->begin, found->len); + } + + IF_MACRO("{v}") { + rspamd_http_message_add_header_len (msg, USER_AGENT_HEADER, + found->begin, found->len); + } + + IF_MACRO("{cipher}") { + rspamd_http_message_add_header_len (msg, TLS_CIPHER_HEADER, + found->begin, found->len); + } + + IF_MACRO("{tls_version}") { + rspamd_http_message_add_header_len (msg, TLS_VERSION_HEADER, + found->begin, found->len); + } +} + struct rspamd_http_message * rspamd_milter_to_http (struct rspamd_milter_session *session) { @@ -1125,5 +1175,7 @@ rspamd_milter_to_http (struct rspamd_milter_session *session) } } + rspamd_milter_macro_http (session, msg); + return msg; }
\ No newline at end of file diff --git a/src/libserver/protocol_internal.h b/src/libserver/protocol_internal.h index ac588386b..7be821462 100644 --- a/src/libserver/protocol_internal.h +++ b/src/libserver/protocol_internal.h @@ -75,6 +75,8 @@ #define USER_AGENT_HEADER "User-Agent" #define MTA_TAG_HEADER "MTA-Tag" #define PROFILE_HEADER "Profile" +#define TLS_CIPHER_HEADER "TLS-Cipher" +#define TLS_VERSION_HEADER "TLS-Version" #endif //RSPAMD_PROTOCOL_INTERNAL_H |