diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-02 13:09:33 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-02 13:09:33 +0300 |
commit | def8d3d1a9135748a9c3223107edea592067cad4 (patch) | |
tree | d38bd6841f5b3b280643619e3bf47d3e300a90e4 /perl | |
parent | db656e70f8d5a2e5522ef90d0b5127c8efe192ec (diff) | |
download | rspamd-def8d3d1a9135748a9c3223107edea592067cad4.tar.gz rspamd-def8d3d1a9135748a9c3223107edea592067cad4.zip |
* Add compatibility with gmime24
Diffstat (limited to 'perl')
-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 |
6 files changed, 291 insertions, 16 deletions
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; |