diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-19 17:07:32 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-19 17:07:32 +0000 |
commit | 287256b3f36cf0c19b8223eaf10eb5e0ae24501c (patch) | |
tree | a29312c1bfd48dc31ce7e6e067958427beb42426 | |
parent | 3ed1b3df679a0dbff89baa2dcd02c9ae42d7400f (diff) | |
download | rspamd-287256b3f36cf0c19b8223eaf10eb5e0ae24501c.tar.gz rspamd-287256b3f36cf0c19b8223eaf10eb5e0ae24501c.zip |
[Minor] Treat utf especially
-rw-r--r-- | src/libmime/mime_encoding.c | 14 | ||||
-rw-r--r-- | src/libmime/mime_encoding.h | 4 | ||||
-rw-r--r-- | src/libmime/mime_headers.c | 6 | ||||
-rw-r--r-- | src/libmime/mime_headers.h | 2 |
4 files changed, 19 insertions, 7 deletions
diff --git a/src/libmime/mime_encoding.c b/src/libmime/mime_encoding.c index 47b490b73..b33312faf 100644 --- a/src/libmime/mime_encoding.c +++ b/src/libmime/mime_encoding.c @@ -18,6 +18,7 @@ #include "libutil/mem_pool.h" #include "libutil/regexp.h" #include "libserver/task.h" +#include "mime_encoding.h" #include "message.h" #include <iconv.h> @@ -209,6 +210,16 @@ rspamd_mime_to_utf8_byte_array (GByteArray *in, gsize outlen, pos; iconv_t ic; gsize remain, ret, inremain = in->len; + rspamd_ftok_t charset_tok; + + RSPAMD_FTOK_FROM_STR (&charset_tok, enc); + + if (rspamd_mime_charset_utf_check (&charset_tok, (gchar *)in->data, in->len)) { + g_byte_array_set_size (out, in->len); + memcpy (out->data, in->data, out->len); + + return TRUE; + } ic = iconv_open (UTF8_CHARSET, enc); @@ -264,7 +275,8 @@ rspamd_mime_to_utf8_byte_array (GByteArray *in, } gboolean -rspamd_mime_charset_utf_check (rspamd_ftok_t *charset, gchar *in, gsize len) +rspamd_mime_charset_utf_check (rspamd_ftok_t *charset, + gchar *in, gsize len) { const gchar *end, *p; gsize remain = len; diff --git a/src/libmime/mime_encoding.h b/src/libmime/mime_encoding.h index eb3a59942..a4999266f 100644 --- a/src/libmime/mime_encoding.h +++ b/src/libmime/mime_encoding.h @@ -29,8 +29,8 @@ struct rspamd_mime_text_part; * @param in * @return */ -const gchar * rspamd_mime_detect_charset (rspamd_mempool_t *pool, - const rspamd_ftok_t *in); +const gchar * rspamd_mime_detect_charset (const rspamd_ftok_t *in, + rspamd_mempool_t *pool); /** * Convert text chunk to utf-8. Input encoding is substituted using diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c index 68d0cb406..9d36abf88 100644 --- a/src/libmime/mime_headers.c +++ b/src/libmime/mime_headers.c @@ -331,7 +331,7 @@ rspamd_mime_header_maybe_save_token (rspamd_mempool_t *pool, GString *out, /* We need to flush and decode old token to out string */ if (rspamd_mime_to_utf8_byte_array (token, decoded_token, - rspamd_mime_detect_charset (pool, new_charset))) { + rspamd_mime_detect_charset (new_charset, pool))) { g_string_append_len (out, decoded_token->data, decoded_token->len); } @@ -341,7 +341,7 @@ rspamd_mime_header_maybe_save_token (rspamd_mempool_t *pool, GString *out, memcpy (old_charset, new_charset, sizeof (*old_charset)); } -gchar * +GString * rspamd_mime_header_decode (rspamd_mempool_t *pool, const gchar *in, gsize inlen) { @@ -501,5 +501,5 @@ rspamd_mime_header_decode (rspamd_mempool_t *pool, const gchar *in, break; } - return g_string_free (out, FALSE); + return out; } diff --git a/src/libmime/mime_headers.h b/src/libmime/mime_headers.h index f3ad54fb4..b1a048fd8 100644 --- a/src/libmime/mime_headers.h +++ b/src/libmime/mime_headers.h @@ -55,7 +55,7 @@ void rspamd_mime_headers_process (struct rspamd_task *task, GHashTable *target, * @param inlen * @return */ -gchar *rspamd_mime_header_decode (rspamd_mempool_t *pool, const gchar *in, +GString * rspamd_mime_header_decode (rspamd_mempool_t *pool, const gchar *in, gsize inlen); #endif /* SRC_LIBMIME_MIME_HEADERS_H_ */ |