aboutsummaryrefslogtreecommitdiffstats
path: root/perl/Rspamd
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-03-02 13:09:33 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-03-02 13:09:33 +0300
commitdef8d3d1a9135748a9c3223107edea592067cad4 (patch)
treed38bd6841f5b3b280643619e3bf47d3e300a90e4 /perl/Rspamd
parentdb656e70f8d5a2e5522ef90d0b5127c8efe192ec (diff)
downloadrspamd-def8d3d1a9135748a9c3223107edea592067cad4.tar.gz
rspamd-def8d3d1a9135748a9c3223107edea592067cad4.zip
* Add compatibility with gmime24
Diffstat (limited to 'perl/Rspamd')
-rw-r--r--perl/Rspamd/Hash.xs34
-rw-r--r--perl/Rspamd/InternetAddress.xs52
-rw-r--r--perl/Rspamd/Message.xs68
-rw-r--r--perl/Rspamd/Object.xs16
-rw-r--r--perl/Rspamd/Part.xs46
5 files changed, 205 insertions, 11 deletions
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;