aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmime
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-16 12:29:01 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-16 12:29:01 +0100
commitc47156cb81dd8b3a9b04967da91310740cdf211f (patch)
tree99e08828246a87fbc635fe5f8649e7495d2d932f /src/libmime
parent8167af6e6515eda26296fcaaf8a742bbf468348b (diff)
downloadrspamd-c47156cb81dd8b3a9b04967da91310740cdf211f.tar.gz
rspamd-c47156cb81dd8b3a9b04967da91310740cdf211f.zip
[Fix] Fix various issues with parsing of the received headers
Diffstat (limited to 'src/libmime')
-rw-r--r--src/libmime/email_addr.c26
-rw-r--r--src/libmime/email_addr.h13
-rw-r--r--src/libmime/message.h1
3 files changed, 40 insertions, 0 deletions
diff --git a/src/libmime/email_addr.c b/src/libmime/email_addr.c
index 8376e8f78..3b9f31de9 100644
--- a/src/libmime/email_addr.c
+++ b/src/libmime/email_addr.c
@@ -485,3 +485,29 @@ rspamd_email_address_list_destroy (gpointer ptr)
g_ptr_array_free (ar, TRUE);
}
+
+void rspamd_smtp_maybe_process_smtp_comment (struct rspamd_task *task,
+ const char *data, size_t len,
+ struct received_header *rh)
+{
+ if (!rh->by_hostname) {
+ /* Heuristic to detect IP addresses like in Exim received:
+ * [xxx]:port or [xxx]
+ */
+
+ if (*data == '[' && len > 2) {
+ const gchar *p = data + 1;
+ gsize iplen = rspamd_memcspn (p, "]", len - 1);
+
+ if (iplen > 0) {
+ guchar tbuf[sizeof(struct in6_addr) + sizeof(guint32)];
+
+ if (rspamd_parse_inet_address_ip4 (p, iplen, tbuf) ||
+ rspamd_parse_inet_address_ip6 (p, iplen, tbuf)) {
+ rh->comment_ip = rspamd_mempool_alloc (task->task_pool, iplen + 1);
+ rspamd_strlcpy (rh->comment_ip, p, iplen + 1);
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/libmime/email_addr.h b/src/libmime/email_addr.h
index 8c9b54713..129d2ba44 100644
--- a/src/libmime/email_addr.h
+++ b/src/libmime/email_addr.h
@@ -51,6 +51,19 @@ struct rspamd_email_address {
guchar flags;
};
+struct received_header;
+struct rspamd_task;
+/**
+ * Try to parse SMTP comment to process stupid Exim received headers
+ * @param task
+ * @param data
+ * @param len
+ * @param rh
+ */
+void rspamd_smtp_maybe_process_smtp_comment (struct rspamd_task *task,
+ const char *data, size_t len,
+ struct received_header *rh);
+
/**
* Create email address from a single rfc822 address (e.g. from mail from:)
* @param str string to use
diff --git a/src/libmime/message.h b/src/libmime/message.h
index 205bf5bb2..17077860d 100644
--- a/src/libmime/message.h
+++ b/src/libmime/message.h
@@ -144,6 +144,7 @@ struct received_header {
gchar *real_ip;
gchar *by_hostname;
gchar *for_mbox;
+ gchar *comment_ip;
rspamd_inet_addr_t *addr;
struct rspamd_mime_header *hdr;
time_t timestamp;