From: Vsevolod Stakhov Date: Tue, 24 May 2016 11:25:24 +0000 (+0100) Subject: [Fix] Add workaround for gmime CTE stupidity X-Git-Tag: 1.3.0~442 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=74b6dadc119b54322a926ad68a6ab445016da243;p=rspamd.git [Fix] Add workaround for gmime CTE stupidity --- diff --git a/src/libmime/mime_expressions.c b/src/libmime/mime_expressions.c index 3fad7c568..427b3654c 100644 --- a/src/libmime/mime_expressions.c +++ b/src/libmime/mime_expressions.c @@ -1262,13 +1262,11 @@ rspamd_compare_transfer_encoding (struct rspamd_task * task, GArray * args, void *unused) { - GMimeObject *part; -#ifndef GMIME24 - GMimePartEncodingType enc_req, part_enc; -#else - GMimeContentEncoding enc_req, part_enc; -#endif + GPtrArray *headerlist; struct expression_argument *arg; + guint i; + struct raw_header *rh; + static const char *hname = "Content-Transfer-Encoding"; if (args == NULL) { msg_warn_task ("no parameters to function"); @@ -1281,47 +1279,42 @@ rspamd_compare_transfer_encoding (struct rspamd_task * task, return FALSE; } -#ifndef GMIME24 - enc_req = g_mime_part_encoding_from_string (arg->data); - if (enc_req == GMIME_PART_ENCODING_DEFAULT) { -#else - enc_req = g_mime_content_encoding_from_string (arg->data); - if (enc_req == GMIME_CONTENT_ENCODING_DEFAULT) { -#endif - msg_warn_task ("bad encoding type: %s", (gchar *)arg->data); - return FALSE; - } + headerlist = rspamd_message_get_header_array (task, hname, FALSE); - part = g_mime_message_get_mime_part (task->message); - if (part) { - if (GMIME_IS_PART (part)) { -#ifndef GMIME24 - part_enc = g_mime_part_get_encoding (GMIME_PART (part)); - if (part_enc == GMIME_PART_ENCODING_DEFAULT) { - /* Assume 7bit as default transfer encoding */ - part_enc = GMIME_PART_ENCODING_7BIT; + if (headerlist) { + for (i = 0; i < headerlist->len; i ++) { + rh = g_ptr_array_index (headerlist, i); + + if (rh->decoded == NULL) { + continue; } -#else - part_enc = g_mime_part_get_content_encoding (GMIME_PART (part)); - if (part_enc == GMIME_CONTENT_ENCODING_DEFAULT) { - /* Assume 7bit as default transfer encoding */ - part_enc = GMIME_CONTENT_ENCODING_7BIT; + + if (g_ascii_strcasecmp (rh->decoded, arg->data) == 0) { + return TRUE; } -#endif + } + } + /* + * In fact, we need to check 'Content-Transfer-Encoding' for each part + * as gmime has 'strange' assumptions + */ + headerlist = rspamd_message_get_mime_header_array (task, + arg->data, + FALSE); - debug_task ("got encoding in part: %d and compare with %d", - (gint)part_enc, - (gint)enc_req); -#ifndef GMIME24 - g_object_unref (part); -#endif + if (headerlist) { + for (i = 0; i < headerlist->len; i ++) { + rh = g_ptr_array_index (headerlist, i); - return part_enc == enc_req; + if (rh->decoded == NULL) { + continue; + } + + if (g_ascii_strcasecmp (rh->decoded, arg->data) == 0) { + return TRUE; + } } -#ifndef GMIME24 - g_object_unref (part); -#endif } return FALSE;