diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-20 17:39:17 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-20 17:39:17 +0000 |
commit | c220a5f224447b6707e7fdab042f51629efcc7ba (patch) | |
tree | 8c6bc17796de498cab184d8467bfad3f48ac9d6d | |
parent | a1d22e97dfbe18eb0c71c064c446af8822c2c88c (diff) | |
download | rspamd-c220a5f224447b6707e7fdab042f51629efcc7ba.tar.gz rspamd-c220a5f224447b6707e7fdab042f51629efcc7ba.zip |
[Feature] Add own routine to generate a message id
-rw-r--r-- | src/libmime/message.c | 2 | ||||
-rw-r--r-- | src/libmime/mime_headers.c | 19 | ||||
-rw-r--r-- | src/libmime/mime_headers.h | 7 |
3 files changed, 27 insertions, 1 deletions
diff --git a/src/libmime/message.c b/src/libmime/message.c index 4b2330ed2..4fdc8ab55 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -573,7 +573,7 @@ rspamd_message_from_data (struct rspamd_task *task, const guchar *start, part->parsed_data.len = len; /* Generate message ID */ - mid = g_mime_utils_generate_message_id ("localhost.localdomain"); + mid = rspamd_mime_message_id_generate ("localhost.localdomain"); rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) g_free, mid); task->message_id = mid; diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c index 0c47988de..7cfe3112c 100644 --- a/src/libmime/mime_headers.c +++ b/src/libmime/mime_headers.c @@ -18,6 +18,7 @@ #include "smtp_parsers.h" #include "mime_encoding.h" #include "task.h" +#include "contrib/libottery/ottery.h" static void rspamd_mime_header_add (struct rspamd_task *task, @@ -601,3 +602,21 @@ rspamd_mime_header_encode (const gchar *in, gsize len) return out; } + +gchar * +rspamd_mime_message_id_generate (const gchar *fqdn) +{ + GString *out; + guint64 rnd, clk; + + out = g_string_sized_new (strlen (fqdn) + 22); + rnd = ottery_rand_uint64 (); + clk = rspamd_get_calendar_ticks () * 1e6; + + rspamd_printf_gstring (out, "%*bs.%*bs@%s", + (gint)sizeof (guint64) - 3, (guchar *)&clk, + (gint)sizeof (guint64), (gchar *)&rnd, + fqdn); + + return g_string_free (out, FALSE); +} diff --git a/src/libmime/mime_headers.h b/src/libmime/mime_headers.h index 1310c0b75..06d40c516 100644 --- a/src/libmime/mime_headers.h +++ b/src/libmime/mime_headers.h @@ -66,4 +66,11 @@ gchar * rspamd_mime_header_decode (rspamd_mempool_t *pool, const gchar *in, */ gchar * rspamd_mime_header_encode (const gchar *in, gsize len); +/** + * Generate new unique message id + * @param fqdn + * @return + */ +gchar * rspamd_mime_message_id_generate (const gchar *fqdn); + #endif /* SRC_LIBMIME_MIME_HEADERS_H_ */ |