diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | config.h.in | 2 | ||||
-rw-r--r-- | perl/Rspamd.xs | 91 | ||||
-rw-r--r-- | perl/Rspamd/Hash.xs | 34 | ||||
-rw-r--r-- | perl/Rspamd/InternetAddress.xs | 52 | ||||
-rw-r--r-- | perl/Rspamd/Message.xs | 68 | ||||
-rw-r--r-- | perl/Rspamd/Object.xs | 16 | ||||
-rw-r--r-- | perl/Rspamd/Part.xs | 46 | ||||
-rw-r--r-- | src/filter.c | 4 | ||||
-rw-r--r-- | src/message.c | 35 | ||||
-rw-r--r-- | src/plugins/regexp.c | 4 | ||||
-rw-r--r-- | utils/url_extracter.c | 17 |
12 files changed, 353 insertions, 17 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e86c56999..060541513 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,7 @@ pkg_check_modules(GMIME2 gmime-2.0) # Try to link with gmime24 IF(NOT GMIME2_FOUND) pkg_check_modules(GMIME2 REQUIRED gmime-2.4) + SET(GMIME24 "yes") ENDIF(NOT GMIME2_FOUND) IF(NOT GLIB2_FOUND OR NOT GMIME2_FOUND) diff --git a/config.h.in b/config.h.in index 23aabf666..a1b3d932a 100644 --- a/config.h.in +++ b/config.h.in @@ -80,6 +80,8 @@ #cmakedefine DEBUG_MODE 1 +#cmakedefine GMIME24 1 + #define RVERSION "${RSPAMD_VERSION}" #define RSPAMD_MASTER_SITE_URL "${RSPAMD_MASTER_SITE_URL}" diff --git a/perl/Rspamd.xs b/perl/Rspamd.xs index c6c33c007..8eb916a57 100644 --- a/perl/Rspamd.xs +++ b/perl/Rspamd.xs @@ -35,8 +35,13 @@ typedef struct _GMimeHeader { } local_GMimeHeader; /* enums */ -typedef GMimePartEncodingType Mail__Rspamd__PartEncodingType; +#ifdef GMIME24 +typedef GMimeContentEncoding Mail__Rspamd__PartEncodingType; +typedef int Mail__Rspamd__InternetAddressType; +#else typedef InternetAddressType Mail__Rspamd__InternetAddressType; +typedef GMimePartEncodingType Mail__Rspamd__PartEncodingType; +#endif /* C types */ typedef GMimeObject * Mail__Rspamd__Object; @@ -48,7 +53,11 @@ typedef GMimeMessage * Mail__Rspamd__Message; typedef GMimeMessagePart * Mail__Rspamd__MessagePart; typedef GMimeMessagePartial * Mail__Rspamd__MessagePartial; typedef InternetAddress * Mail__Rspamd__InternetAddress; +#ifdef GMIME24 +typedef GMimeContentDisposition * Mail__Rspamd__Disposition; +#else typedef GMimeDisposition * Mail__Rspamd__Disposition; +#endif typedef GMimeContentType * Mail__Rspamd__ContentType; typedef GMimeCharset * Mail__Rspamd__Charset; @@ -131,8 +140,9 @@ enum { static GList * local_message_get_header(GMimeMessage *message, const char *field) { - struct raw_header *h; GList * gret = NULL; +#ifndef GMIME24 + struct raw_header *h; if (field == NULL) { return NULL; @@ -145,6 +155,27 @@ local_message_get_header(GMimeMessage *message, const char *field) h = h->next; } return gret; +#else + GMimeHeaderList *ls; + GMimeHeaderIter *iter; + const char *name; + + ls = GMIME_OBJECT(message)->headers; + + if (g_mime_header_list_get_iter (ls, iter)) { + while (g_mime_header_iter_is_valid (iter)) { + name = g_mime_header_iter_get_name (iter); + if (!g_strncasecmp (field, name, strlen (name))) { + gret = g_list_prepend (gret, g_strdup (g_mime_header_iter_get_value (iter))); + } + if (!g_mime_header_iter_next (iter)) { + break; + } + } + } + + return gret; +#endif } /** @@ -164,6 +195,35 @@ local_mime_message_set_date_from_string (GMimeMessage *message, const gchar *str g_mime_message_set_date (message, date, offset); } +#ifdef GMIME24 + +#define ADD_RECIPIENT_TEMPLATE(type,def) \ +static void \ +local_message_add_recipients_from_string_##type (GMimeMessage *message, const gchar *string, const gchar *value) \ +{ \ + InternetAddressList *il, *new; \ + \ + il = g_mime_message_get_recipients (message, (def)); \ + new = internet_address_list_parse_string (string); \ + internet_address_list_append (il, new); \ +} \ + +ADD_RECIPIENT_TEMPLATE(to, GMIME_RECIPIENT_TYPE_TO) +ADD_RECIPIENT_TEMPLATE(cc, GMIME_RECIPIENT_TYPE_CC) +ADD_RECIPIENT_TEMPLATE(bcc, GMIME_RECIPIENT_TYPE_BCC) + +#define GET_RECIPIENT_TEMPLATE(type,def) \ +static InternetAddressList* \ +local_message_get_recipients_##type (GMimeMessage *message, const char *unused) \ +{ \ + return g_mime_message_get_recipients (message, (def)); \ +} + +GET_RECIPIENT_TEMPLATE(to, GMIME_RECIPIENT_TYPE_TO) +GET_RECIPIENT_TEMPLATE(cc, GMIME_RECIPIENT_TYPE_CC) +GET_RECIPIENT_TEMPLATE(bcc, GMIME_RECIPIENT_TYPE_BCC) + +#endif /* different declarations for different types of set and get functions */ @@ -209,15 +269,28 @@ static struct { } fieldfunc[] = { { "From", g_mime_message_get_sender, NULL, NULL, g_mime_message_set_sender, NULL, FUNC_CHARPTR }, { "Reply-To", g_mime_message_get_reply_to, NULL, NULL, g_mime_message_set_reply_to, NULL, FUNC_CHARPTR }, +#ifndef GMIME24 { "To", NULL, g_mime_message_get_recipients, NULL, NULL, g_mime_message_add_recipients_from_string, FUNC_IA }, { "Cc", NULL, g_mime_message_get_recipients, NULL, NULL, g_mime_message_add_recipients_from_string, FUNC_IA }, { "Bcc", NULL, g_mime_message_get_recipients, NULL, NULL, g_mime_message_add_recipients_from_string, FUNC_IA }, - { "Subject", g_mime_message_get_subject, NULL, NULL, g_mime_message_set_subject, NULL, FUNC_CHARPTR }, { "Date", g_mime_message_get_date_string, NULL, NULL, local_mime_message_set_date_from_string, NULL, FUNC_CHARFREEPTR }, +#else + { "To", NULL, local_message_get_recipients_to, NULL, NULL, local_message_add_recipients_from_string_to, FUNC_IA }, + { "Cc", NULL, local_message_get_recipients_cc, NULL, NULL, local_message_add_recipients_from_string_cc, FUNC_IA }, + { "Bcc", NULL, local_message_get_recipients_bcc, NULL, NULL, local_message_add_recipients_from_string_bcc, FUNC_IA }, + { "Date", g_mime_message_get_date_as_string, NULL, NULL, local_mime_message_set_date_from_string, NULL, FUNC_CHARFREEPTR }, +#endif + { "Subject", g_mime_message_get_subject, NULL, NULL, g_mime_message_set_subject, NULL, FUNC_CHARPTR }, { "Message-Id", g_mime_message_get_message_id, NULL, NULL, g_mime_message_set_message_id, NULL, FUNC_CHARPTR }, +#ifndef GMIME24 { NULL, NULL, NULL, local_message_get_header, NULL, g_mime_message_add_header, FUNC_LIST } +#else + { NULL, NULL, NULL, local_message_get_header, NULL, g_mime_object_append_header, FUNC_LIST } +#endif }; + + /** * message_set_header: set header of any type excluding special (Content- and MIME-Version:) **/ @@ -259,7 +332,7 @@ static GList * message_get_header(GMimeMessage *message, const char *field) { gint i; - char * ret = NULL; + char * ret = NULL, *ia_string; GList * gret = NULL; InternetAddressList *ia_list = NULL, *ia; @@ -276,13 +349,21 @@ message_get_header(GMimeMessage *message, const char *field) { ia_list = (*(fieldfunc[i].rcptfunc))(message, field); gret = g_list_alloc(); ia = ia_list; +#ifndef GMIME24 while (ia && ia->address) { - char *ia_string; ia_string = internet_address_to_string ((InternetAddress *)ia->address, FALSE); gret = g_list_append (gret, ia_string); ia = ia->next; } +#else + i = internet_address_list_length (ia); + while (i > 0) { + ia_string = internet_address_to_string (internet_address_list_get_address (ia, i), FALSE); + gret = g_list_append (gret, ia_string); + -- i; + } +#endif break; case FUNC_LIST: gret = (*(fieldfunc[i].getlistfunc))(message, field); diff --git a/perl/Rspamd/Hash.xs b/perl/Rspamd/Hash.xs index b61cebc39..5a32fa6a1 100644 --- a/perl/Rspamd/Hash.xs +++ b/perl/Rspamd/Hash.xs @@ -179,12 +179,17 @@ hash_NEXTKEY(obj, lastkey = NULL) ALIAS: Mail::Rspamd::Hash::Header::FIRSTKEY = 1 PREINIT: - char * key = NULL; - char * value = NULL; + const char * key = NULL; + const char * value = NULL; Mail__Rspamd__Message msg; I32 gimme = GIMME_V; gint i, j, found; +#ifdef GMIME24 + GMimeHeaderList *hl; + GMimeHeaderIter *iter; +#else local_GMimeHeader * header; +#endif struct raw_header *h; INIT: if (ix == 1) { @@ -194,6 +199,24 @@ hash_NEXTKEY(obj, lastkey = NULL) msg = obj->objptr; ++obj->keyindex; i = obj->keyindex; +#ifdef GMIME24 + hl = g_mime_object_get_header_list (GMIME_OBJECT (msg)); + j = 0; + found = 0; + if (g_mime_header_list_get_iter (hl, iter)) { + while (g_mime_header_iter_is_valid (iter)) { + if (j >= i) { + key = g_mime_header_iter_get_name (iter); + value = g_mime_header_iter_get_value (iter); + found = 1; + break; + } + if (!g_mime_header_iter_next (iter)) { + break; + } + } + } +#else header = GMIME_OBJECT(msg)->headers; h = header->headers; @@ -209,6 +232,7 @@ hash_NEXTKEY(obj, lastkey = NULL) j++; h = h->next; } +#endif if (!found && key == NULL) { obj->keyindex = -1; @@ -223,9 +247,11 @@ hash_NEXTKEY(obj, lastkey = NULL) XPUSHs (sv_2mortal (newSVpv (value, 0))); } /* THE HACK - FETCH method would get value indirectly */ - obj->fetchvalue = value; + obj->fetchvalue = (char *)value; } +#ifndef GMIME24 + void hash_CLEAR(obj) Mail::Rspamd::Hash::Header obj @@ -255,4 +281,4 @@ hash_CLEAR(obj) g_mime_header_destroy (header); GMIME_OBJECT(message)->headers = g_mime_header_new (); - +#endif diff --git a/perl/Rspamd/InternetAddress.xs b/perl/Rspamd/InternetAddress.xs index 834117bbe..6ccf30ce3 100644 --- a/perl/Rspamd/InternetAddress.xs +++ b/perl/Rspamd/InternetAddress.xs @@ -5,15 +5,23 @@ rspamd_internet_address_new (Class, name, address) CASE: items <= 1 char * Class CODE: +#ifdef GMIME24 + XSRETURN_UNDEF; +#else RETVAL = internet_address_new (); plist = g_list_prepend (plist, RETVAL); +#endif OUTPUT: RETVAL CASE: items == 2 char * Class char * name CODE: +#ifdef GMIME24 + RETVAL = internet_address_group_new (name); +#else RETVAL = internet_address_new_group (name); +#endif plist = g_list_prepend (plist, RETVAL); OUTPUT: RETVAL @@ -22,7 +30,11 @@ rspamd_internet_address_new (Class, name, address) char * name char * address CODE: +#ifdef GMIME24 + RETVAL = internet_address_mailbox_new (name, address); +#else RETVAL = internet_address_new_name (name, address); +#endif plist = g_list_prepend (plist, RETVAL); OUTPUT: RETVAL @@ -42,19 +54,48 @@ rspamd_internet_address_parse_string (str) PREINIT: InternetAddressList * addrlist; AV * retav; + int i; CODE: +#ifdef GMIME24 + addrlist = internet_address_list_parse_string (str); +#else addrlist = internet_address_parse_string (str); +#endif retav = newAV (); +#ifdef GMIME24 + i = internet_address_list_length (addrlist); + while (i > 0) { + SV * address = newSViv(0); + sv_setref_pv (address, "Mail::Rspamd::InternetAddress", (Mail__Rspamd__InternetAddress)internet_address_list_get_address (addrlist, i)); + av_push (retav, address); + -- i; + } +#else while (addrlist) { SV * address = newSViv (0); sv_setref_pv (address, "Mail::Rspamd::InternetAddress", (Mail__Rspamd__InternetAddress)(addrlist->address)); av_push (retav, address); addrlist = addrlist->next; } +#endif RETVAL = retav; OUTPUT: RETVAL +#ifdef GMIME24 + +void +interface_ia_set (ia, value) + Mail::Rspamd::InternetAddress ia + char * value + INTERFACE_MACRO: + XSINTERFACE_FUNC + XSINTERFACE_FUNC_RSPAMD_IA_SET + INTERFACE: + set_name + +#else + void interface_ia_set (ia, value) Mail::Rspamd::InternetAddress ia @@ -66,6 +107,8 @@ interface_ia_set (ia, value) set_name set_addr +#endif + SV * rspamd_internet_address_to_string (ia, encode = TRUE) Mail::Rspamd::InternetAddress ia @@ -99,7 +142,11 @@ rspamd_internet_address_set_group (ia, ...) addr = INT2PTR (Mail__Rspamd__InternetAddress, tmp); } if (addr) { +#ifdef GMIME24 + internet_address_list_add (addrlist, addr); +#else internet_address_list_append (addrlist, addr); +#endif } } if (addrlist) { @@ -117,8 +164,11 @@ Mail::Rspamd::InternetAddressType rspamd_internet_address_type (ia) Mail::Rspamd::InternetAddress ia CODE: +#ifndef GMIME24 RETVAL = ia->type; +#else + XSRETURN_UNDEF; +#endif OUTPUT: RETVAL - diff --git a/perl/Rspamd/Message.xs b/perl/Rspamd/Message.xs index 6e3a16d8b..e8f0571bc 100644 --- a/perl/Rspamd/Message.xs +++ b/perl/Rspamd/Message.xs @@ -26,7 +26,19 @@ rspamd_message_add_recipient(message, type, name, address) const char * name const char * address CODE: +#ifndef GMIME24 g_mime_message_add_recipient (message, type, name, address); +#else + if (!g_strcasecmp (type, "to")) { + g_mime_message_add_recipient (message, GMIME_RECIPIENT_TYPE_TO, name, address); + } + else if (!g_strcasecmp (type, "cc")) { + g_mime_message_add_recipient (message, GMIME_RECIPIENT_TYPE_CC, name, address); + } + else if (!g_strcasecmp (type, "bcc")) { + g_mime_message_add_recipient (message, GMIME_RECIPIENT_TYPE_BCC, name, address); + } +#endif void rspamd_message_add_recipients_from_string(message, type, recipients) @@ -34,17 +46,25 @@ rspamd_message_add_recipients_from_string(message, type, recipients) char * type const char * recipients CODE: +#ifndef GMIME24 g_mime_message_add_recipients_from_string (message, type, recipients); +#else + /* XXX: add code here */ + XSRETURN_UNDEF; +#endif + AV * rspamd_message_get_recipients(message, type) Mail::Rspamd::Message message const char * type PREINIT: - const InternetAddressList * rcpt; + InternetAddressList * rcpt; AV * retav; + int i; CODE: retav = newAV(); +#ifndef GMIME24 rcpt = g_mime_message_get_recipients (message, type); while (rcpt) { SV * address = newSViv(0); @@ -52,6 +72,24 @@ rspamd_message_get_recipients(message, type) av_push(retav, address); rcpt = rcpt->next; } +#else + if (!g_strcasecmp (type, "to")) { + rcpt = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO); + } + else if (!g_strcasecmp (type, "cc")) { + rcpt = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC); + } + else if (!g_strcasecmp (type, "bcc")) { + rcpt = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_BCC); + } + i = internet_address_list_length (rcpt); + while (i > 0) { + SV * address = newSViv(0); + sv_setref_pv(address, "Mail::Rspamd::InternetAddress", (Mail__Rspamd__InternetAddress)internet_address_list_get_address(rcpt, i)); + av_push(retav, address); + -- i; + } +#endif RETVAL = retav; OUTPUT: RETVAL @@ -113,7 +151,11 @@ rspamd_message_get_date (message) char * str; PPCODE: if (gimme == G_SCALAR) { +#ifdef GMIME24 + str = g_mime_message_get_date_as_string (message); +#else str = g_mime_message_get_date_string (message); +#endif if (str) { XPUSHs (sv_2mortal (newSVpv (str,0))); g_free (str); @@ -130,14 +172,23 @@ rspamd_message_set_header (message, field, value) const char * field const char * value CODE: +#ifdef GMIME24 + g_mime_object_set_header (GMIME_OBJECT (message), field, value); +#else g_mime_message_set_header (message, field, value); +#endif void rspamd_message_remove_header (message, field) Mail::Rspamd::Message message const char * field CODE: +#ifdef GMIME24 g_mime_object_remove_header (GMIME_OBJECT (message), field); +#else + g_mime_message_remove_header (message, field); +#endif + void rspamd_message_add_header (message, field, value) @@ -145,14 +196,22 @@ rspamd_message_add_header (message, field, value) const char * field const char * value CODE: +#ifdef GMIME24 + g_mime_object_set_header (GMIME_OBJECT (message), field, value); +#else g_mime_message_set_header (message, field, value); +#endif const char * rspamd_message_get_header (message, field) Mail::Rspamd::Message message const char * field CODE: +#ifdef GMIME24 + RETVAL = g_mime_object_get_header (GMIME_OBJECT (message), field); +#else RETVAL = g_mime_message_get_header (message, field); +#endif OUTPUT: RETVAL @@ -164,6 +223,7 @@ rspamd_message_set_mime_part (message, mime_part) g_mime_message_set_mime_part (message, GMIME_OBJECT (mime_part)); plist = g_list_remove (plist, mime_part); +#if !defined(GMIME24) SV * rspamd_message_get_body (message, want_plain = 1, is_html = 0) CASE: items == 1 @@ -210,6 +270,8 @@ rspamd_message_get_body (message, want_plain = 1, is_html = 0) OUTPUT: is_html RETVAL + +#endif SV * rspamd_message_get_headers(message) @@ -217,7 +279,11 @@ rspamd_message_get_headers(message) PREINIT: char * textdata; CODE: +#ifdef GMIME24 + textdata = g_mime_object_get_headers (GMIME_OBJECT (message)); +#else textdata = g_mime_message_get_headers (message); +#endif if (textdata == NULL) { RETVAL = &PL_sv_undef; } diff --git a/perl/Rspamd/Object.xs b/perl/Rspamd/Object.xs index 89bc09bf8..cf5fffb11 100644 --- a/perl/Rspamd/Object.xs +++ b/perl/Rspamd/Object.xs @@ -13,7 +13,7 @@ rspamd_object_get_content_type (mime_object) Mail::Rspamd::Object mime_object PREINIT: char * textdata; - const GMimeContentType *ct; + GMimeContentType *ct; CODE: ct = g_mime_object_get_content_type (mime_object); textdata = g_mime_content_type_to_string (ct); @@ -132,6 +132,19 @@ rspamd_object_get_content_length(mime_object) lsize = (mime_part->content && mime_part->content->stream) ? g_mime_stream_length (mime_part->content->stream) : 0; if (lsize) { +#ifdef GMIME24 + GMimeContentEncoding enc; + + enc = _mime_part_get_encoding (mime_part); + switch (enc) { + case GMIME_CONTENT_ENCODING_BASE64: + lsize = BASE64_ENCODE_LEN (lsize); + break; + case GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE: + lsize = QP_ENCODE_LEN (lsize); + break; + } +#else GMimePartEncodingType enc; enc = g_mime_part_get_encoding (mime_part); @@ -143,6 +156,7 @@ rspamd_object_get_content_length(mime_object) lsize = QP_ENCODE_LEN (lsize); break; } +#endif } } } diff --git a/perl/Rspamd/Part.xs b/perl/Rspamd/Part.xs index b95a5fc99..5401a1e08 100644 --- a/perl/Rspamd/Part.xs +++ b/perl/Rspamd/Part.xs @@ -31,7 +31,6 @@ interface_p_set(mime_part, value) set_content_description set_content_md5 set_content_location - set_content_disposition set_filename @@ -45,9 +44,10 @@ interface_p_get(mime_part) get_content_description get_content_md5 get_content_location - get_content_disposition get_filename +#if !defined(GMIME24) + void rspamd_part_set_content_header (mime_part, field, value) Mail::Rspamd::Part mime_part @@ -65,6 +65,8 @@ rspamd_part_get_content_header (mime_part, field) OUTPUT: RETVAL +#endif + void rspamd_part_set_content_type (mime_part, content_type) Mail::Rspamd::Part mime_part @@ -92,8 +94,13 @@ rspamd_part_get_encoding (mime_part) const char * rspamd_part_encoding_to_string (encoding) Mail::Rspamd::PartEncodingType encoding + PREINIT: CODE: +#ifdef GMIME24 + RETVAL = g_mime_content_encoding_to_string (encoding); +#else RETVAL = g_mime_part_encoding_to_string (encoding); +#endif OUTPUT: RETVAL @@ -101,7 +108,11 @@ Mail::Rspamd::PartEncodingType rspamd_part_encoding_from_string (encoding) const char * encoding CODE: - RETVAL = g_mime_part_encoding_from_string(encoding); +#ifdef GMIME24 + RETVAL = g_mime_content_encoding_from_string (encoding); +#else + RETVAL = g_mime_part_encoding_from_string (encoding); +#endif OUTPUT: RETVAL @@ -111,14 +122,22 @@ rspamd_part_add_content_disposition_parameter (mime_part, name, value) const char * name const char * value CODE: +#ifdef GMIME24 + g_mime_object_add_content_disposition_parameter (GMIME_OBJECT (mime_part), name, value); +#else g_mime_part_add_content_disposition_parameter (mime_part, name, value); +#endif const char * rspamd_part_get_content_disposition_parameter (mime_part, name) Mail::Rspamd::Part mime_part const char * name CODE: +#ifdef GMIME24 + RETVAL = g_mime_object_get_content_disposition_parameter (GMIME_OBJECT (mime_part), name); +#else RETVAL = g_mime_part_get_content_disposition_parameter (mime_part, name); +#endif OUTPUT: RETVAL @@ -140,20 +159,39 @@ SV * rspamd_part_get_content(mime_part) Mail::Rspamd::Part mime_part PREINIT: +#ifdef GMIME24 + GMimeDataWrapper *wrapper; + GMimeStream *part_stream; + GByteArray *part_content; +#else guint len; const char * content_char; +#endif SV * content; CODE: ST(0) = &PL_sv_undef; +#ifdef GMIME24 + if (!(mime_part->content) || !(mime_part->content->stream) || + (wrapper = g_mime_part_get_content_object (mime_part)) == NULL) { +#else if (!(mime_part->content) || !(mime_part->content->stream) || - (content_char = g_mime_part_get_content(mime_part, &len)) == NULL) { + (content_char = g_mime_part_get_content (mime_part, &len)) == NULL) { +#endif return; } content = sv_newmortal (); SvUPGRADE (content, SVt_PV); SvREADONLY_on (content); +#ifdef GMIME24 + part_stream = g_mime_stream_mem_new (); + g_mime_data_wrapper_write_to_stream (wrapper, part_stream); + part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (part_stream)); + SvPVX(content) = (char *) (part_content->data); + SvCUR_set (content, part_content->len); +#else SvPVX(content) = (char *) (content_char); SvCUR_set (content, len); +#endif SvLEN_set (content, 0); SvPOK_only (content); ST(0) = content; diff --git a/src/filter.c b/src/filter.c index 49f239f27..56d7d9945 100644 --- a/src/filter.c +++ b/src/filter.c @@ -529,7 +529,11 @@ insert_metric_header (gpointer metric_name, gpointer metric_value, gpointer data cur = g_list_next (cur); } g_list_free (symbols); +#ifdef GMIME24 + g_mime_object_append_header (GMIME_OBJECT (task->message), header_name, outbuf); +#else g_mime_message_add_header (task->message, header_name, outbuf); +#endif } diff --git a/src/message.c b/src/message.c index 8978ea827..bce54c992 100644 --- a/src/message.c +++ b/src/message.c @@ -232,8 +232,13 @@ free_byte_array_callback (void *pointer) g_byte_array_free (arr, TRUE); } +#ifdef GMIME24 +static void +mime_foreach_callback (GMimeObject *parent, GMimeObject *part, gpointer user_data) +#else static void mime_foreach_callback (GMimeObject *part, gpointer user_data) +#endif { struct worker_task *task = (struct worker_task *)user_data; struct mime_part *mime_part; @@ -257,7 +262,11 @@ mime_foreach_callback (GMimeObject *part, gpointer user_data) g_mime_message_foreach_part() again here. */ message = g_mime_message_part_get_message ((GMimeMessagePart *) part); +#ifdef GMIME24 + g_mime_message_foreach (message, mime_foreach_callback, task); +#else g_mime_message_foreach_part (message, mime_foreach_callback, task); +#endif g_object_unref (message); } else if (GMIME_IS_MESSAGE_PARTIAL (part)) { /* message/partial */ @@ -274,7 +283,11 @@ mime_foreach_callback (GMimeObject *part, gpointer user_data) /* we'll get to finding out if this is a signed/encrypted multipart later... */ } else if (GMIME_IS_PART (part)) { /* a normal leaf part, could be text/plain or image/jpeg etc */ +#ifdef GMIME24 + type = (GMimeContentType *)g_mime_object_get_content_type (GMIME_OBJECT (part)); +#else type = (GMimeContentType *)g_mime_part_get_content_type (GMIME_PART (part)); +#endif if (type == NULL) { msg_warn ("mime_foreach_callback: type of part is unknown, assume text/plain"); type = g_mime_content_type_new ("text", "plain"); @@ -328,7 +341,11 @@ process_message (struct worker_task *task) task->message = message; memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_object_unref, task->message); +#ifdef GMIME24 + g_mime_message_foreach (message, mime_foreach_callback, task); +#else g_mime_message_foreach_part (message, mime_foreach_callback, task); +#endif msg_info ("process_message: found %d parts in message", task->parts_count); @@ -341,8 +358,13 @@ process_message (struct worker_task *task) return 0; } +#ifdef GMIME24 +static void +mime_learn_foreach_callback (GMimeObject *parent, GMimeObject *part, gpointer user_data) +#else static void mime_learn_foreach_callback (GMimeObject *part, gpointer user_data) +#endif { struct controller_session *session = (struct controller_session *)user_data; struct mime_part *mime_part; @@ -362,9 +384,12 @@ mime_learn_foreach_callback (GMimeObject *part, gpointer user_data) child message parts, so if we want to count any subparts of this child message, we'll have to call g_mime_message_foreach_part() again here. */ - message = g_mime_message_part_get_message ((GMimeMessagePart *) part); +#ifdef GMIME24 + g_mime_message_foreach (message, mime_learn_foreach_callback, session); +#else g_mime_message_foreach_part (message, mime_learn_foreach_callback, session); +#endif g_object_unref (message); } else if (GMIME_IS_MESSAGE_PARTIAL (part)) { /* message/partial */ @@ -386,7 +411,11 @@ mime_learn_foreach_callback (GMimeObject *part, gpointer user_data) part_stream = g_mime_stream_mem_new (); if (g_mime_data_wrapper_write_to_stream (wrapper, part_stream) != -1) { part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (part_stream)); +#ifdef GMIME24 + type = (GMimeContentType *)g_mime_object_get_content_type (GMIME_OBJECT (part)); +#else type = (GMimeContentType *)g_mime_part_get_content_type (GMIME_PART (part)); +#endif mime_part = memory_pool_alloc (session->session_pool, sizeof (struct mime_part)); mime_part->type = type; mime_part->content = part_content; @@ -420,7 +449,11 @@ process_learn (struct controller_session *session) /* free the parser (and the stream) */ g_object_unref (parser); +#ifdef GMIME24 + g_mime_message_foreach (message, mime_learn_foreach_callback, session); +#else g_mime_message_foreach_part (message, mime_learn_foreach_callback, session); +#endif return 0; } diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 9cc37ea7e..8606be77c 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -150,7 +150,11 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task) return 0; } msg_debug ("process_regexp: checking header regexp: %s = /%s/", re->header, re->regexp_text); +#ifdef GMIME24 + headerv = (char *)g_mime_object_get_header (GMIME_OBJECT (task->message), re->header); +#else headerv = (char *)g_mime_message_get_header (task->message, re->header); +#endif if (headerv == NULL) { return 0; } diff --git a/utils/url_extracter.c b/utils/url_extracter.c index 75dd5c1d3..8e16a689f 100644 --- a/utils/url_extracter.c +++ b/utils/url_extracter.c @@ -26,8 +26,13 @@ #include "../src/url.h" #include "../src/message.h" +#ifdef GMIME24 +static void +mime_foreach_callback (GMimeObject *parent, GMimeObject *part, gpointer user_data) +#else static void mime_foreach_callback (GMimeObject *part, gpointer user_data) +#endif { struct worker_task *task = (struct worker_task *)user_data; struct mime_part *mime_part; @@ -50,7 +55,11 @@ mime_foreach_callback (GMimeObject *part, gpointer user_data) g_mime_message_foreach_part() again here. */ message = g_mime_message_part_get_message ((GMimeMessagePart *) part); +#ifdef GMIME24 + g_mime_message_foreach (message, mime_foreach_callback, task); +#else g_mime_message_foreach_part (message, mime_foreach_callback, task); +#endif g_object_unref (message); } else if (GMIME_IS_MESSAGE_PARTIAL (part)) { /* message/partial */ @@ -76,7 +85,11 @@ mime_foreach_callback (GMimeObject *part, gpointer user_data) if (g_mime_data_wrapper_write_to_stream (wrapper, part_stream) != -1) { printf ("Write wrapper to stream\n"); part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (part_stream)); +#ifdef GMIME24 + type = (GMimeContentType *)g_mime_object_get_content_type (GMIME_OBJECT (part)); +#else type = (GMimeContentType *)g_mime_part_get_content_type (GMIME_PART (part)); +#endif mime_part = g_malloc (sizeof (struct mime_part)); mime_part->type = type; mime_part->content = part_content; @@ -141,7 +154,11 @@ main (int argc, char **argv) /* free the parser (and the stream) */ g_object_unref (parser); +#ifdef GMIME24 + g_mime_message_foreach (message, mime_foreach_callback, &task); +#else g_mime_message_foreach_part (message, mime_foreach_callback, &task); +#endif TAILQ_FOREACH (url, &task.urls, next) { printf ("Found url: %s, hostname: %s, data: %s\n", struri (url), url->host, url->data); |