diff options
Diffstat (limited to 'perl/Rspamd')
-rw-r--r-- | perl/Rspamd/Config.xs | 141 | ||||
-rw-r--r-- | perl/Rspamd/ContentType.xs | 87 | ||||
-rw-r--r-- | perl/Rspamd/Hash.xs | 258 | ||||
-rw-r--r-- | perl/Rspamd/InternetAddress.xs | 124 | ||||
-rw-r--r-- | perl/Rspamd/Message.xs | 264 | ||||
-rw-r--r-- | perl/Rspamd/Object.xs | 152 | ||||
-rw-r--r-- | perl/Rspamd/Part.xs | 160 | ||||
-rw-r--r-- | perl/Rspamd/Task.xs | 83 |
8 files changed, 1269 insertions, 0 deletions
diff --git a/perl/Rspamd/Config.xs b/perl/Rspamd/Config.xs new file mode 100644 index 000000000..49b26db2f --- /dev/null +++ b/perl/Rspamd/Config.xs @@ -0,0 +1,141 @@ +MODULE = Mail::Rspamd PACKAGE = Mail::Rspamd::Config PREFIX = rspamd_config_ +PROTOTYPES: DISABLE + +SV * +rspamd_config_get_scalar (cfg, param) + Mail::Rspamd::Config cfg + const char *param + CODE: + struct config_scalar *sc; + int val; + + sc = g_hash_table_lookup (cfg->cfg_params, param); + if (sc == NULL) { + XSRETURN_UNDEF; + } + else { + switch (sc->type) { + case SCALAR_TYPE_SIZE: + RETVAL = newSViv ((int)(*(size_t *)sc->pointer)); + break; + case SCALAR_TYPE_INT: + case SCALAR_TYPE_UINT: + RETVAL = newSViv (*(int *)sc->pointer); + break; + case SCALAR_TYPE_STR: + RETVAL = newSVpv ((char *)sc->pointer, 0); + break; + } + } + + +void +rspamd_config_set_scalar (cfg, param, value) + Mail::Rspamd::Config cfg + const char *param + SV* value + CODE: + char *param, *charval; + int intval; + + sc = g_hash_table_lookup (cfg->cfg_params, param); + if (sc == NULL) { + XSRETURN_UNDEF; + } + else { + switch (sc->type) { + case SCALAR_TYPE_SIZE: + intval = (int)SvIV (value); + *((size_t *)sc->pointer) = intval; + break; + case SCALAR_TYPE_INT: + case SCALAR_TYPE_UINT: + intval = (int)SvIV (value); + *((int *)sc->pointer) = intval; + break; + case SCALAR_TYPE_STR: + charval = (char *)SvPVX (value); + *((char **)sc->pointer) = charval; + break; + } + } + +HV * +rspamd_config_get_metric (r, name) + Mail::Rspamd::Config cfg + const char *name + CODE: + struct metric *val; + + val = g_hash_table_lookup (r->metrics, name); + if (val == NULL) { + XSRETURN_UNDEF; + } + else { + RETVAL = newHV(); + + (void)hv_store_ent (RETVAL, + newSVpv ("name", sizeof ("name") - 1), + newSVpv (val->name, strlen (val->name)), 0); + (void)hv_store_ent (RETVAL, + newSVpv ("func_name", sizeof ("func_name") - 1), + newSVpv (val->func_name, strlen (val->func_name)), 0); + (void)hv_store_ent (RETVAL, + newSVpv ("required_score", sizeof ("required_score") - 1), + newSVnv (val->required_score), 0); + sv_2mortal((SV*)RETVAL); + } + OUTPUT: + RETVAL + +HV * +rspamd_config_get_statfile (r, name) + Mail::Rspamd::Config cfg + const char *name + CODE: + struct statfile *val; + char *name; + + val = g_hash_table_lookup (r->statfiles, name); + if (val == NULL) { + XSRETURN_UNDEF; + } + else { + RETVAL = newHV(); + + (void)hv_store_ent (RETVAL, + newSVpv ("alias", sizeof ("alias") - 1), + newSVpv (val->alias, strlen (val->alias)), 0); + (void)hv_store_ent (RETVAL, + newSVpv ("pattern", sizeof ("pattern") - 1), + newSVpv (val->pattern, strlen (val->pattern)), 0); + (void)hv_store_ent (RETVAL, + newSVpv ("metric", sizeof ("metric") - 1), + newSVpv (val->metric, strlen (val->metric)), 0); + (void)hv_store_ent (RETVAL, + newSVpv ("weight", sizeof ("weight") - 1), + newSVnv (val->weight), 0); + (void)hv_store_ent (RETVAL, + newSVpv ("size", sizeof ("size") - 1), + newSViv (val->size), 0); + sv_2mortal((SV*)RETVAL); + } + OUTPUT: + RETVAL + +SV* +rspamd_config_get_module_param (r, modulename, paramname) + Mail::Rspamd::Config cfg + const char *modulename + const char *paramname + CODE: + char *value; + + value = get_module_opt (r, modulename, paramname); + if (value == NULL) { + XSRETURN_UNDEF; + } + RETVAL = newSVpv (value, 0); + OUTPUT: + RETVAL + diff --git a/perl/Rspamd/ContentType.xs b/perl/Rspamd/ContentType.xs new file mode 100644 index 000000000..dae8a35ad --- /dev/null +++ b/perl/Rspamd/ContentType.xs @@ -0,0 +1,87 @@ +MODULE = Mail::Rspamd PACKAGE = Mail::Rspamd::ContentType PREFIX = rspamd_content_type_ + +Mail::Rspamd::ContentType +rspamd_content_type_new (Class = "Mail::Rspamd::ContentType", name = 0, subname = 0) + CASE: items == 2 + char * Class; + const char * name; + CODE: + RETVAL = g_mime_content_type_new_from_string (name); + plist = g_list_prepend (plist, RETVAL); + OUTPUT: + RETVAL + CASE: items == 3 + char * Class; + const char * name; + const char * subname; + CODE: + RETVAL = g_mime_content_type_new (name, subname); + plist = g_list_prepend (plist, RETVAL); + OUTPUT: + RETVAL + +void +DESTROY (mime_type) + Mail::Rspamd::ContentType mime_type + CODE: + if (g_list_find(plist,mime_type)) { + g_mime_content_type_destroy(mime_type); + plist = g_list_remove(plist, mime_type); + } + +SV * +rspamd_content_type_to_string (mime_type) + Mail::Rspamd::ContentType mime_type + PREINIT: + char * type; + CODE: + type = g_mime_content_type_to_string (mime_type); + if (!type) + XSRETURN_UNDEF; + RETVAL = newSVpv(type, 0); + g_free (type); + OUTPUT: + RETVAL + +gboolean +rspamd_content_type_is_type (mime_type, type, subtype) + Mail::Rspamd::ContentType mime_type + const char * type + const char * subtype + CODE: + RETVAL = g_mime_content_type_is_type (mime_type, type, subtype); + OUTPUT: + RETVAL + +void +rspamd_content_type_set_parameter (mime_type, attribute, value) + Mail::Rspamd::ContentType mime_type + const char * attribute + const char * value + CODE: + g_mime_content_type_set_parameter (mime_type, attribute, value); + +const char * +rspamd_content_type_get_parameter (mime_type, attribute) + Mail::Rspamd::ContentType mime_type + const char * attribute + CODE: + RETVAL = g_mime_content_type_get_parameter (mime_type, attribute); + OUTPUT: + RETVAL + +char * +rspamd_content_type_type (ctype) + Mail::Rspamd::ContentType ctype + CODE: + RETVAL = ctype->type; + OUTPUT: + RETVAL + +char * +rspamd_content_type_subtype (ctype) + Mail::Rspamd::ContentType ctype + CODE: + RETVAL = ctype->subtype; + OUTPUT: + RETVAL diff --git a/perl/Rspamd/Hash.xs b/perl/Rspamd/Hash.xs new file mode 100644 index 000000000..b61cebc39 --- /dev/null +++ b/perl/Rspamd/Hash.xs @@ -0,0 +1,258 @@ +MODULE = Mail::Rspamd PACKAGE = Mail::Rspamd::Hash::Header PREFIX=hash_ + +Mail::Rspamd::Hash::Header +hash_TIEHASH (Class, objptr) + char * Class + Mail::Rspamd::Message objptr + PREINIT: + hash_header * hash; + CODE: + hash = g_malloc (sizeof (hash_header)); + hash->keyindex = 0; + hash->objptr = objptr; + hash->fetchvalue = NULL; + RETVAL = hash; + OUTPUT: + RETVAL + +void +hash_DESTROY (obj) + Mail::Rspamd::Hash::Header obj + CODE: + obj->objptr = NULL; + g_free (obj); + +void +hash_FETCH (obj, key) + Mail::Rspamd::Hash::Header obj + const char * key + PREINIT: + Mail__Rspamd__Message msg; + GList *gret = NULL, *item; + AV * retav; + I32 gimme = GIMME_V; + PPCODE: + msg = obj->objptr; + + /* THE HACK - FETCH method would get value indirectly from NEXTKEY */ + if (obj->keyindex != -1 && obj->fetchvalue != NULL) { + XPUSHs (sv_2mortal (newSVpv (obj->fetchvalue, 0))); + obj->fetchvalue == NULL; + XSRETURN(1); + } + + obj->fetchvalue = NULL; + + gret = message_get_header (msg, key); + + if (!gret || gret->data == NULL) { + if (gret) { + g_list_free(gret); + } + + XSRETURN(0); + } else { + if (gret->next == NULL) { // one value + XPUSHs (sv_2mortal (newSVpv ((char *)(gret->data), 0))); + } else { + if (gimme == G_ARRAY) { + item = gret; + while (item && item->data) { + XPUSHs (sv_2mortal (newSVpv ((char *)(item->data), 0))); + item = item->next; + } + } else if (gimme == G_SCALAR) { + retav = newAV(); + item = gret; + while (item && item->data) { + av_push (retav, newSVpv ((char *)g_strdup ((item->data)), 0)); + item = item->next; + } + XPUSHs (newRV_noinc ((SV *)retav)); + } + } + } + if (gret) { + item = gret; + while (item) { + if (item->data) { + g_free((char *)(item->data)); + } + item = item->next; + } + g_list_free(gret); + } + +void +hash_STORE (obj, key, svmixed) + Mail::Rspamd::Hash::Header obj + const char * key + SV * svmixed + PREINIT: + Mail__Rspamd__Message msg; + char * value; + SV * svvalue; + svtype svvaltype; + STRLEN vallen; + CODE: + /* only one value can be stored - no arrays allowed by perl */ + msg = obj->objptr; + + svvalue = svmixed; + if (SvROK (svmixed)) { + svvalue = SvRV(svmixed); + } + svvaltype = SvTYPE (svvalue); + + if (SvGMAGICAL(svvalue)) { + mg_get(svvalue); + } + + /* delete header for the first array item */ + g_mime_object_remove_header (GMIME_OBJECT(msg), key); + + if (svvaltype == SVt_PVAV) { + AV * avvalue; + I32 i, avlen; + SV * svtmp; + + /* set header */ + avvalue = (AV *)svvalue; + avlen = av_len(avvalue); + for (i=avlen; i>=0; --i) { + svtmp = (SV *)(*(av_fetch (avvalue, i, 0))); + + if (SvGMAGICAL(svtmp)) { + mg_get(svtmp); + } + + if (svtmp && SvPOKp(svtmp)) { + value = (char *)SvPV(svtmp, vallen); + message_set_header (msg, key, value); + } + } + } else if (SvPOK(svvalue) || SvIOK(svvalue) || SvNOK(svvalue)) { + value = (char *)SvPV (svvalue, vallen); + message_set_header (msg, key, value); + } else { /* assume scalar value */ + /* undefined value -> remove header */ + if (!(SvOK(svvalue))) { + g_mime_object_remove_header (GMIME_OBJECT(msg), key); + } + } + +gboolean +hash_EXISTS (obj, key) + Mail::Rspamd::Hash::Header obj + const char * key + PREINIT: + Mail__Rspamd__Message msg; + GList *gret, *item; + CODE: + msg = obj->objptr; + gret = message_get_header (msg, key); + RETVAL = (gret != NULL && gret->data != NULL); + if (gret) { + item = gret; + while (item) { + if (item->data) { + g_free((char *)(item->data)); + } + item = item->next; + } + g_list_free(gret); + } + OUTPUT: + RETVAL + +void +hash_DELETE(obj, key) + Mail::Rspamd::Hash::Header obj + const char * key + CODE: + g_mime_object_remove_header (GMIME_OBJECT(obj->objptr), key); + +void +hash_NEXTKEY(obj, lastkey = NULL) + Mail::Rspamd::Hash::Header obj + const char * lastkey + ALIAS: + Mail::Rspamd::Hash::Header::FIRSTKEY = 1 + PREINIT: + char * key = NULL; + char * value = NULL; + Mail__Rspamd__Message msg; + I32 gimme = GIMME_V; + gint i, j, found; + local_GMimeHeader * header; + struct raw_header *h; + INIT: + if (ix == 1) { + obj->keyindex = -1; + } + PPCODE: + msg = obj->objptr; + ++obj->keyindex; + i = obj->keyindex; + header = GMIME_OBJECT(msg)->headers; + + h = header->headers; + j = 0; + found = 0; + while (h) { + if (j >= i) { + key = h->name; + value = h->value; + found = 1; + break; + } + j++; + h = h->next; + } + + if (!found && key == NULL) { + obj->keyindex = -1; + } + + /* THE HACK - FETCH method would get value indirectly */ + obj->fetchvalue = NULL; + + if (key) { + XPUSHs (sv_2mortal (newSVpv (key, 0))); + if (gimme != G_SCALAR && value) { + XPUSHs (sv_2mortal (newSVpv (value, 0))); + } + /* THE HACK - FETCH method would get value indirectly */ + obj->fetchvalue = value; + } + +void +hash_CLEAR(obj) + Mail::Rspamd::Hash::Header obj + PREINIT: + Mail__Rspamd__Message message; + local_GMimeHeader *header; + CODE: + message = obj->objptr; + + g_free (message->from); + message->from = NULL; + + g_free (message->reply_to); + message->reply_to = NULL; + + /* destroy all recipients */ + g_hash_table_foreach_remove (message->recipients, recipients_destroy, NULL); + + g_free (message->subject); + message->subject = NULL; + + g_free (message->message_id); + message->message_id = NULL; + + /* free all the headers */ + header = GMIME_OBJECT(message)->headers; + g_mime_header_destroy (header); + GMIME_OBJECT(message)->headers = g_mime_header_new (); + + diff --git a/perl/Rspamd/InternetAddress.xs b/perl/Rspamd/InternetAddress.xs new file mode 100644 index 000000000..834117bbe --- /dev/null +++ b/perl/Rspamd/InternetAddress.xs @@ -0,0 +1,124 @@ +MODULE = Mail::Rspamd PACKAGE = Mail::Rspamd::InternetAddress PREFIX = rspamd_internet_address_ + +Mail::Rspamd::InternetAddress +rspamd_internet_address_new (Class, name, address) + CASE: items <= 1 + char * Class + CODE: + RETVAL = internet_address_new (); + plist = g_list_prepend (plist, RETVAL); + OUTPUT: + RETVAL + CASE: items == 2 + char * Class + char * name + CODE: + RETVAL = internet_address_new_group (name); + plist = g_list_prepend (plist, RETVAL); + OUTPUT: + RETVAL + CASE: items == 3 + char * Class + char * name + char * address + CODE: + RETVAL = internet_address_new_name (name, address); + plist = g_list_prepend (plist, RETVAL); + OUTPUT: + RETVAL + +void +DESTROY(ia) + Mail::Rspamd::InternetAddress ia + CODE: + if (g_list_find (plist,ia)) { + internet_address_unref (ia); + plist = g_list_remove (plist, ia); + } + +AV * +rspamd_internet_address_parse_string (str) + const char * str + PREINIT: + InternetAddressList * addrlist; + AV * retav; + CODE: + addrlist = internet_address_parse_string (str); + retav = newAV (); + 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; + } + RETVAL = retav; + OUTPUT: + RETVAL + +void +interface_ia_set (ia, value) + Mail::Rspamd::InternetAddress ia + char * value + INTERFACE_MACRO: + XSINTERFACE_FUNC + XSINTERFACE_FUNC_RSPAMD_IA_SET + INTERFACE: + set_name + set_addr + +SV * +rspamd_internet_address_to_string (ia, encode = TRUE) + Mail::Rspamd::InternetAddress ia + gboolean encode + PREINIT: + char * textdata; + CODE: + textdata = internet_address_to_string (ia, encode); + if (textdata == NULL) { + XSRETURN_UNDEF; + } + RETVAL = newSVpv (textdata, 0); + OUTPUT: + RETVAL + +void +rspamd_internet_address_set_group (ia, ...) + Mail::Rspamd::InternetAddress ia + PREINIT: + Mail__Rspamd__InternetAddress addr; + InternetAddressList * addrlist = NULL; + int i; + CODE: + if (items < 2) { + XSRETURN_UNDEF; + } + for (i = items - 1; i > 0; --i) { + /* retrieve each address from the perl array */ + if (sv_derived_from (ST (items - i), "Mail::Rspamd::InternetAddress")) { + IV tmp = SvIV ((SV*)SvRV (ST (items - i))); + addr = INT2PTR (Mail__Rspamd__InternetAddress, tmp); + } + if (addr) { + internet_address_list_append (addrlist, addr); + } + } + if (addrlist) { + internet_address_set_group (ia, addrlist); + } + +void +rspamd_internet_address_add_member (ia, member) + Mail::Rspamd::InternetAddress ia + Mail::Rspamd::InternetAddress member + CODE: + internet_address_add_memeber (ia, member); + +Mail::Rspamd::InternetAddressType +rspamd_internet_address_type (ia) + Mail::Rspamd::InternetAddress ia + CODE: + RETVAL = ia->type; + OUTPUT: + RETVAL + + diff --git a/perl/Rspamd/Message.xs b/perl/Rspamd/Message.xs new file mode 100644 index 000000000..6e3a16d8b --- /dev/null +++ b/perl/Rspamd/Message.xs @@ -0,0 +1,264 @@ +MODULE = Mail::Rspamd PACKAGE = Mail::Rspamd::Message PREFIX = rspamd_message_ + +Mail::Rspamd::Message +rspamd_message_new(Class, pretty_headers = FALSE) + char * Class + gboolean pretty_headers + CODE: + RETVAL = g_mime_message_new (pretty_headers); + plist = g_list_prepend(plist, RETVAL); + OUTPUT: + RETVAL + +void +DESTROY(message) + Mail::Rspamd::Message message + CODE: + if (g_list_find(plist,message)) { + g_mime_object_unref (GMIME_OBJECT (message)); + plist = g_list_remove(plist, message); + } + +void +rspamd_message_add_recipient(message, type, name, address) + Mail::Rspamd::Message message + char * type + const char * name + const char * address + CODE: + g_mime_message_add_recipient (message, type, name, address); + +void +rspamd_message_add_recipients_from_string(message, type, recipients) + Mail::Rspamd::Message message + char * type + const char * recipients + CODE: + g_mime_message_add_recipients_from_string (message, type, recipients); + +AV * +rspamd_message_get_recipients(message, type) + Mail::Rspamd::Message message + const char * type + PREINIT: + const InternetAddressList * rcpt; + AV * retav; + CODE: + retav = newAV(); + rcpt = g_mime_message_get_recipients (message, type); + while (rcpt) { + SV * address = newSViv(0); + sv_setref_pv(address, "Mail::Rspamd::InternetAddress", (Mail__Rspamd__InternetAddress)(rcpt->address)); + av_push(retav, address); + rcpt = rcpt->next; + } + RETVAL = retav; + OUTPUT: + RETVAL + + +void +interface_m_set (message, value) + Mail::Rspamd::Message message + char * value + INTERFACE_MACRO: + XSINTERFACE_FUNC + XSINTERFACE_FUNC_RSPAMD_MESSAGE_SET + INTERFACE: + set_subject + set_message_id + set_reply_to + set_sender + +const char * +interface_m_get (message) + Mail::Rspamd::Message message + INTERFACE_MACRO: + XSINTERFACE_FUNC + XSINTERFACE_FUNC_RSPAMD_MESSAGE_SET + INTERFACE: + get_subject + get_message_id + get_reply_to + get_sender + + # date +void +rspamd_message_set_date (message, date, gmt_offset) + Mail::Rspamd::Message message + time_t date + int gmt_offset + CODE: + g_mime_message_set_date (message, date, gmt_offset); + +void +rspamd_message_set_date_from_string (message, str) + Mail::Rspamd::Message message + const char * str + PREINIT: + time_t date; + int offset = 0; + CODE: + date = g_mime_utils_header_decode_date (str, &offset); + g_mime_message_set_date (message, date, offset); + + +void +rspamd_message_get_date (message) + Mail::Rspamd::Message message + PREINIT: + time_t date; + int gmt_offset; + I32 gimme = GIMME_V; + char * str; + PPCODE: + if (gimme == G_SCALAR) { + str = g_mime_message_get_date_string (message); + if (str) { + XPUSHs (sv_2mortal (newSVpv (str,0))); + g_free (str); + } + } else if (gimme == G_ARRAY) { + g_mime_message_get_date (message, &date, &gmt_offset); + XPUSHs (sv_2mortal (newSVnv (date))); + XPUSHs (sv_2mortal (newSViv (gmt_offset))); + } + +void +rspamd_message_set_header (message, field, value) + Mail::Rspamd::Message message + const char * field + const char * value + CODE: + g_mime_message_set_header (message, field, value); + +void +rspamd_message_remove_header (message, field) + Mail::Rspamd::Message message + const char * field + CODE: + g_mime_object_remove_header (GMIME_OBJECT (message), field); + +void +rspamd_message_add_header (message, field, value) + Mail::Rspamd::Message message + const char * field + const char * value + CODE: + g_mime_message_set_header (message, field, value); + +const char * +rspamd_message_get_header (message, field) + Mail::Rspamd::Message message + const char * field + CODE: + RETVAL = g_mime_message_get_header (message, field); + OUTPUT: + RETVAL + +void +rspamd_message_set_mime_part (message, mime_part) + Mail::Rspamd::Message message + Mail::Rspamd::Object mime_part + CODE: + g_mime_message_set_mime_part (message, GMIME_OBJECT (mime_part)); + plist = g_list_remove (plist, mime_part); + +SV * +rspamd_message_get_body (message, want_plain = 1, is_html = 0) + CASE: items == 1 + Mail::Rspamd::Message message + PREINIT: + gboolean want_plain = 1; + gboolean is_html; + char * textdata; + CODE: + textdata = g_mime_message_get_body (message, want_plain, &is_html); + if (textdata == NULL) + XSRETURN_UNDEF; + RETVAL = newSVpv (textdata, 0); + g_free (textdata); + OUTPUT: + RETVAL + CASE: items == 2 + Mail::Rspamd::Message message + gboolean want_plain + PREINIT: + gboolean is_html; + char * textdata; + CODE: + textdata = g_mime_message_get_body (message, want_plain, &is_html); + if (textdata == NULL) + XSRETURN_UNDEF; + RETVAL = newSVpv (textdata, 0); + g_free (textdata); + OUTPUT: + RETVAL + CASE: items == 3 + Mail::Rspamd::Message message + gboolean want_plain + gboolean &is_html + PREINIT: + char * textdata; + CODE: + textdata = g_mime_message_get_body (message, want_plain, &is_html); + if (textdata == NULL) { + RETVAL = &PL_sv_undef; + } + RETVAL = newSVpv (textdata, 0); + g_free (textdata); + OUTPUT: + is_html + RETVAL + +SV * +rspamd_message_get_headers(message) + Mail::Rspamd::Message message + PREINIT: + char * textdata; + CODE: + textdata = g_mime_message_get_headers (message); + if (textdata == NULL) { + RETVAL = &PL_sv_undef; + } + RETVAL = newSVpv (textdata, 0); + g_free (textdata); + OUTPUT: + RETVAL + +void +rspamd_message_foreach_part (message, callback, svdata) + Mail::Rspamd::Message message + SV * callback + SV * svdata + PREINIT: + struct _user_data_sv *data; + + CODE: + data = g_new0 (struct _user_data_sv, 1); + data->svuser_data = newSVsv (svdata); + data->svfunc = newSVsv (callback); + g_mime_message_foreach_part (message, call_sub_foreach, data); + g_free (data); + +SV * +get_mime_part(message) + Mail::Rspamd::Message message + PREINIT: + GMimeObject * mime_object; + CODE: + if (message->mime_part != NULL) { + RETVAL = newSViv(4); + mime_object = GMIME_OBJECT (message->mime_part); + if (GMIME_IS_PART(mime_object)) { + sv_setref_pv(RETVAL, "Mail::Rspamd::Part", (Mail__Rspamd__Part)mime_object); + } else { + plist = g_list_prepend(plist, RETVAL); + } + g_mime_object_ref( mime_object ); + } else { + RETVAL = &PL_sv_undef; + } + OUTPUT: + RETVAL + diff --git a/perl/Rspamd/Object.xs b/perl/Rspamd/Object.xs new file mode 100644 index 000000000..89bc09bf8 --- /dev/null +++ b/perl/Rspamd/Object.xs @@ -0,0 +1,152 @@ +MODULE = Mail::Rspamd PACKAGE = Mail::Rspamd::Object PREFIX = rspamd_object_ + +void +rspamd_object_set_content_type (mime_object, content_type) + Mail::Rspamd::Object mime_object + Mail::Rspamd::ContentType content_type + CODE: + g_mime_object_set_content_type (mime_object, content_type); + plist = g_list_remove (plist, content_type); + +Mail::Rspamd::ContentType +rspamd_object_get_content_type (mime_object) + Mail::Rspamd::Object mime_object + PREINIT: + char * textdata; + const GMimeContentType *ct; + CODE: + ct = g_mime_object_get_content_type (mime_object); + textdata = g_mime_content_type_to_string (ct); + RETVAL = g_mime_content_type_new_from_string (textdata); + plist = g_list_prepend (plist, RETVAL); + g_free (textdata); + OUTPUT: + RETVAL + +void +rspamd_object_set_content_type_parameter (mime_object, name, value) + Mail::Rspamd::Object mime_object + const char * name + const char * value + CODE: + gmime_object_set_content_type_parameter (mime_object, name, value); + +const char * +rspamd_object_get_content_type_parameter (mime_object, name) + Mail::Rspamd::Object mime_object + const char * name + CODE: + RETVAL = g_mime_object_get_content_type_parameter (mime_object, name); + OUTPUT: + RETVAL + +void +rspamd_object_set_content_id (mime_object, content_id) + Mail::Rspamd::Object mime_object + const char * content_id + CODE: + g_mime_object_set_content_id (mime_object, content_id); + +const char * +rspamd_object_get_content_id(mime_object) + Mail::Rspamd::Object mime_object + CODE: + RETVAL = g_mime_object_get_content_id (mime_object); + OUTPUT: + RETVAL + + +void +rspamd_object_add_header (mime_object, field, value) + Mail::Rspamd::Object mime_object + const char * field + const char * value + CODE: + g_mime_object_add_header (mime_object, field, value); + +void +rspamd_object_set_header (mime_object, field, value) + Mail::Rspamd::Object mime_object + const char * field + const char * value + CODE: + g_mime_object_set_header (mime_object, field, value); + +const char * +rspamd_object_get_header (mime_object, field) + Mail::Rspamd::Object mime_object + const char * field + CODE: + RETVAL = g_mime_object_get_header (mime_object, field); + OUTPUT: + RETVAL + +void +rspamd_object_remove_header (mime_object, field) + Mail::Rspamd::Object mime_object + const char * field + CODE: + g_mime_object_remove_header (mime_object, field); + +SV * +rspamd_object_get_headers(mime_object) + Mail::Rspamd::Object mime_object + PREINIT: + char * textdata; + CODE: + textdata = g_mime_object_get_headers(mime_object); + if (textdata == NULL) { + XSRETURN_UNDEF; + } + RETVAL = newSVpv (textdata, 0); + g_free (textdata); + OUTPUT: + RETVAL + +SV * +rspamd_object_to_string(mime_object) + Mail::Rspamd::Object mime_object + PREINIT: + char * textdata; + CODE: + textdata = g_mime_object_to_string (mime_object); + if (textdata) { + RETVAL = newSVpv (textdata, 0); + g_free (textdata); + } else { + XSRETURN_UNDEF; + } + OUTPUT: + RETVAL + +guint +rspamd_object_get_content_length(mime_object) + Mail::Rspamd::Object mime_object + PREINIT: + guint lsize = 0; + GMimePart * mime_part; + CODE: + if (mime_object) { + if (GMIME_IS_PART(mime_object)) { // also MESSAGE_PARTIAL + mime_part = GMIME_PART(mime_object); + lsize = (mime_part->content && mime_part->content->stream) ? + g_mime_stream_length (mime_part->content->stream) : 0; + if (lsize) { + GMimePartEncodingType enc; + + enc = g_mime_part_get_encoding (mime_part); + switch (enc) { + case GMIME_PART_ENCODING_BASE64: + lsize = BASE64_ENCODE_LEN (lsize); + break; + case GMIME_PART_ENCODING_QUOTEDPRINTABLE: + lsize = QP_ENCODE_LEN (lsize); + break; + } + } + } + } + RETVAL = lsize; + OUTPUT: + RETVAL + diff --git a/perl/Rspamd/Part.xs b/perl/Rspamd/Part.xs new file mode 100644 index 000000000..b95a5fc99 --- /dev/null +++ b/perl/Rspamd/Part.xs @@ -0,0 +1,160 @@ +MODULE = Mail::Rspamd PACKAGE = Mail::Rspamd::Part PREFIX = rspamd_part + +Mail::Rspamd::Part +g_mime_part_new (Class = "Mail::Rspamd::Part", type = "text", subtype = "plain") + char * Class; + const char * type; + const char * subtype; + CODE: + RETVAL = g_mime_part_new_with_type (type, subtype); + plist = g_list_prepend (plist, RETVAL); + OUTPUT: + RETVAL + +void +DESTROY (mime_part) + Mail::Rspamd::Part mime_part + CODE: + if (g_list_find (plist,mime_part)) { + g_object_unref (G_OBJECT (mime_part)); + plist = g_list_remove (plist, mime_part); + } + +void +interface_p_set(mime_part, value) + Mail::Rspamd::Part mime_part + char * value + INTERFACE_MACRO: + XSINTERFACE_FUNC + XSINTERFACE_FUNC_RSPAMD_PART_SET + INTERFACE: + set_content_description + set_content_md5 + set_content_location + set_content_disposition + set_filename + + +const char * +interface_p_get(mime_part) + Mail::Rspamd::Part mime_part + INTERFACE_MACRO: + XSINTERFACE_FUNC + XSINTERFACE_FUNC_RSPAMD_PART_SET + INTERFACE: + get_content_description + get_content_md5 + get_content_location + get_content_disposition + get_filename + +void +rspamd_part_set_content_header (mime_part, field, value) + Mail::Rspamd::Part mime_part + const char * field + const char * value + CODE: + g_mime_part_set_content_header (mime_part, field, value); + +const char * +rspamd_part_get_content_header (mime_part, field) + Mail::Rspamd::Part mime_part + const char * field + CODE: + RETVAL = g_mime_part_get_content_header (mime_part, field); + OUTPUT: + RETVAL + +void +rspamd_part_set_content_type (mime_part, content_type) + Mail::Rspamd::Part mime_part + Mail::Rspamd::ContentType content_type + CODE: + g_mime_part_set_content_type (mime_part, content_type); + plist = g_list_remove (plist, content_type); + + +void +rspamd_part_set_encoding (mime_part, encoding) + Mail::Rspamd::Part mime_part + Mail::Rspamd::PartEncodingType encoding + CODE: + g_mime_part_set_encoding (mime_part, encoding); + +Mail::Rspamd::PartEncodingType +rspamd_part_get_encoding (mime_part) + Mail::Rspamd::Part mime_part + CODE: + RETVAL = g_mime_part_get_encoding (mime_part); + OUTPUT: + RETVAL + +const char * +rspamd_part_encoding_to_string (encoding) + Mail::Rspamd::PartEncodingType encoding + CODE: + RETVAL = g_mime_part_encoding_to_string (encoding); + OUTPUT: + RETVAL + +Mail::Rspamd::PartEncodingType +rspamd_part_encoding_from_string (encoding) + const char * encoding + CODE: + RETVAL = g_mime_part_encoding_from_string(encoding); + OUTPUT: + RETVAL + +void +rspamd_part_add_content_disposition_parameter (mime_part, name, value) + Mail::Rspamd::Part mime_part + const char * name + const char * value + CODE: + g_mime_part_add_content_disposition_parameter (mime_part, name, value); + +const char * +rspamd_part_get_content_disposition_parameter (mime_part, name) + Mail::Rspamd::Part mime_part + const char * name + CODE: + RETVAL = g_mime_part_get_content_disposition_parameter (mime_part, name); + OUTPUT: + RETVAL + + +void +rspamd_part_set_pre_encoded_content(mime_part, content, encoding) + Mail::Rspamd::Part mime_part + SV * content + Mail::Rspamd::PartEncodingType encoding + PREINIT: + char * data; + STRLEN len; + CODE: + data = SvPV (content, len); + g_mime_part_set_pre_encoded_content (mime_part, data, len, encoding); + + +SV * +rspamd_part_get_content(mime_part) + Mail::Rspamd::Part mime_part + PREINIT: + guint len; + const char * content_char; + SV * content; + CODE: + ST(0) = &PL_sv_undef; + if (!(mime_part->content) || !(mime_part->content->stream) || + (content_char = g_mime_part_get_content(mime_part, &len)) == NULL) { + return; + } + content = sv_newmortal (); + SvUPGRADE (content, SVt_PV); + SvREADONLY_on (content); + SvPVX(content) = (char *) (content_char); + SvCUR_set (content, len); + SvLEN_set (content, 0); + SvPOK_only (content); + ST(0) = content; + diff --git a/perl/Rspamd/Task.xs b/perl/Rspamd/Task.xs new file mode 100644 index 000000000..dec521660 --- /dev/null +++ b/perl/Rspamd/Task.xs @@ -0,0 +1,83 @@ + +MODULE = Mail::Rspamd PACKAGE = Mail::Rspamd::Task PREFIX = rspamd_task_ +PROTOTYPES: DISABLE + +Mail::Rspamd::Message +rspamd_task_get_message (task) + Mail::Rspamd::Task task + CODE: + RETVAL = task->message; + OUTPUT: + RETVAL + +void +rspamd_task_set_message (message) + Mail::Rspamd::Message message + CODE: + g_object_unref (G_OBJECT(task->message)); + task->message = message; + +SV* +rspamd_task_ip (task) + Mail::Rspamd::Task task + CODE: + RETVAL = newSVpv (inet_ntoa (task->from_addr), 0); + OUTPUT: + RETVAL + +SV* +rspamd_task_from (task) + Mail::Rspamd::Task task + CODE: + if (task->from == NULL) { + XSRETURN_UNDEF; + } + RETVAL = newSVpv (task->from, 0); + OUTPUT: + RETVAL + +void +rspamd_task_save_point (task) + Mail::Rspamd::Task task + CODE: + task->save.saved = 1; + +void +rspamd_task_recall_filter (task) + Mail::Rspamd::Task task + CODE: + process_filters (task); + +void +rspamd_task_insert_result (task, metric, symbol, flag) + Mail::Rspamd::Task task + const char *metric + const char *symbol + double flag + CODE: + insert_result (task, metric, symbol, flag); + +Mail::Rspamd::Conf +rspamd_task_get_conf (task) + Mail::Rspamd::Task task + CODE: + RETVAL = task->cfg; + OUTPUT: + RETVAL + +AV* +rspamd_task_get_urls (task) + Mail::Rspamd::Task task + PREINIT: + AV* retav; + struct uri *url; + CODE: + retav = newAV (); + TAILQ_FOREACH (url, &task.urls, next) { + av_push (retav, newSVpv ((char *)g_strdup (struri (url)), 0)); + } + + RETVAL = retav; + OUTPUT: + RETVAL + |