aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2010-05-31 19:45:13 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2010-05-31 19:45:13 +0400
commitab222b29d811745683c55f3c743870526f2da432 (patch)
tree895307b4de4f57b0bdd3cebf6b954bd29dd4fe7c /src
parent0612e84b3cec508c3d62d38c4e2682c85cc808bb (diff)
downloadrspamd-ab222b29d811745683c55f3c743870526f2da432.tar.gz
rspamd-ab222b29d811745683c55f3c743870526f2da432.zip
* Fix more gmime2.4 issues
Diffstat (limited to 'src')
-rw-r--r--src/expressions.c51
-rw-r--r--src/message.c39
-rw-r--r--src/spf.c1
3 files changed, 57 insertions, 34 deletions
diff --git a/src/expressions.c b/src/expressions.c
index a8d639325..5f5213dd3 100644
--- a/src/expressions.c
+++ b/src/expressions.c
@@ -987,7 +987,9 @@ rspamd_content_type_compare_param (struct worker_task * task, GList * args, void
part = g_mime_message_get_mime_part (task->message);
if (part) {
ct = g_mime_object_get_content_type (part);
+#ifndef GMIME24
g_object_unref (part);
+#endif
if ((param_data = g_mime_content_type_get_parameter ((GMimeContentType *)ct, param_name)) == NULL) {
return FALSE;
@@ -1043,7 +1045,9 @@ rspamd_content_type_has_param (struct worker_task * task, GList * args, void *un
part = g_mime_message_get_mime_part (task->message);
if (part) {
ct = g_mime_object_get_content_type (part);
+#ifndef GMIME24
g_object_unref (part);
+#endif
debug_task ("checking %s param", param_name);
@@ -1055,15 +1059,6 @@ rspamd_content_type_has_param (struct worker_task * task, GList * args, void *un
return TRUE;
}
-/* In gmime24 this function is opaque, so define it here to avoid errors when compiling with gmime24 */
-typedef struct {
- char *type;
- char *subtype;
-
- GMimeParam *params;
- GHashTable *param_hash;
-} localContentType;
-
gboolean
rspamd_content_type_is_subtype (struct worker_task *task, GList * args, void *unused)
{
@@ -1071,7 +1066,7 @@ rspamd_content_type_is_subtype (struct worker_task *task, GList * args, void *un
struct rspamd_regexp *re;
struct expression_argument *arg;
GMimeObject *part;
- const localContentType *ct;
+ GMimeContentType *ct;
int r;
if (args == NULL) {
@@ -1083,10 +1078,12 @@ rspamd_content_type_is_subtype (struct worker_task *task, GList * args, void *un
param_pattern = arg->data;
part = g_mime_message_get_mime_part (task->message);
if (part) {
- ct = (const localContentType *)g_mime_object_get_content_type (part);
+ ct = g_mime_object_get_content_type (part);
+#ifndef GMIME24
g_object_unref (part);
+#endif
- if (ct == NULL) {
+ if (ct == NULL ) {
return FALSE;
}
@@ -1113,7 +1110,7 @@ rspamd_content_type_is_subtype (struct worker_task *task, GList * args, void *un
}
else {
/* Just do strcasecmp */
- if (g_ascii_strcasecmp (ct->subtype, param_pattern) == 0) {
+ if (ct->subtype && g_ascii_strcasecmp (ct->subtype, param_pattern) == 0) {
return TRUE;
}
}
@@ -1128,7 +1125,7 @@ rspamd_content_type_is_type (struct worker_task * task, GList * args, void *unus
char *param_pattern;
struct rspamd_regexp *re;
GMimeObject *part;
- const localContentType *ct;
+ GMimeContentType *ct;
struct expression_argument *arg;
int r;
@@ -1142,8 +1139,10 @@ rspamd_content_type_is_type (struct worker_task * task, GList * args, void *unus
part = g_mime_message_get_mime_part (task->message);
if (part) {
- ct = (const localContentType *)g_mime_object_get_content_type (part);
+ ct = g_mime_object_get_content_type (part);
+#ifndef GMIME24
g_object_unref (part);
+#endif
if (ct == NULL) {
return FALSE;
@@ -1172,7 +1171,7 @@ rspamd_content_type_is_type (struct worker_task * task, GList * args, void *unus
}
else {
/* Just do strcasecmp */
- if (g_ascii_strcasecmp (ct->type, param_pattern) == 0) {
+ if (ct->type && g_ascii_strcasecmp (ct->type, param_pattern) == 0) {
return TRUE;
}
}
@@ -1312,7 +1311,7 @@ is_recipient_list_sorted (const InternetAddressList * ia)
addr = internet_address_list_get_address ((InternetAddressList *)cur, i);
current.addr = (char *)internet_address_get_name (addr);
if (previous.addr != NULL) {
- if (g_ascii_strcasecmp (current.addr, previous.addr) < 0) {
+ if (current.addr && g_ascii_strcasecmp (current.addr, previous.addr) < 0) {
res = FALSE;
break;
}
@@ -1325,7 +1324,7 @@ is_recipient_list_sorted (const InternetAddressList * ia)
addr = internet_address_list_get_address (cur);
current.addr = internet_address_get_addr (addr);
if (previous.addr != NULL) {
- if (g_ascii_strcasecmp (current.addr, previous.addr) < 0) {
+ if (current_addr && g_ascii_strcasecmp (current.addr, previous.addr) < 0) {
res = FALSE;
break;
}
@@ -1356,7 +1355,7 @@ rspamd_is_recipients_sorted (struct worker_task * task, GList * args, void *unus
}
static inline gboolean
-compare_subtype (struct worker_task *task, const localContentType * ct, char *subtype)
+compare_subtype (struct worker_task *task, GMimeContentType * ct, char *subtype)
{
struct rspamd_regexp *re;
int r;
@@ -1384,7 +1383,7 @@ compare_subtype (struct worker_task *task, const localContentType * ct, char *su
}
else {
/* Just do strcasecmp */
- if (g_ascii_strcasecmp (ct->subtype, subtype) == 0) {
+ if (ct->subtype && g_ascii_strcasecmp (ct->subtype, subtype) == 0) {
return TRUE;
}
}
@@ -1416,13 +1415,13 @@ common_has_content_part (struct worker_task * task, char *param_type, char *para
struct rspamd_regexp *re;
struct mime_part *part;
GList *cur;
- const localContentType *ct;
+ GMimeContentType *ct;
int r;
cur = g_list_first (task->parts);
while (cur) {
part = cur->data;
- ct = (localContentType *) part->type;
+ ct = part->type;
if (ct == NULL) {
cur = g_list_next (cur);
continue;
@@ -1440,7 +1439,7 @@ common_has_content_part (struct worker_task * task, char *param_type, char *para
re_cache_add (param_type, re, task->cfg->cfg_pool);
}
if ((r = task_cache_check (task, re)) == -1) {
- if (g_regex_match (re->regexp, ct->type, 0, NULL) == TRUE) {
+ if (ct->type && g_regex_match (re->regexp, ct->type, 0, NULL) == TRUE) {
if (param_subtype) {
if (compare_subtype (task, ct, param_subtype)) {
if (compare_len (part, min_len, max_len)) {
@@ -1471,7 +1470,7 @@ common_has_content_part (struct worker_task * task, char *param_type, char *para
}
else {
/* Just do strcasecmp */
- if (g_ascii_strcasecmp (ct->type, param_type) == 0) {
+ if (ct->type && g_ascii_strcasecmp (ct->type, param_type) == 0) {
if (param_subtype) {
if (compare_subtype (task, ct, param_subtype)) {
if (compare_len (part, min_len, max_len)) {
@@ -1595,11 +1594,15 @@ rspamd_compare_transfer_encoding (struct worker_task * task, GList * args, void
debug_task ("got encoding in part: %d and compare with %d", (int)part_enc, (int)enc_req);
+#ifndef GMIME24
g_object_unref (part);
+#endif
return part_enc == enc_req;
}
+#ifndef GMIME24
g_object_unref (part);
+#endif
}
return FALSE;
diff --git a/src/message.c b/src/message.c
index 07838391d..ef3cc02e6 100644
--- a/src/message.c
+++ b/src/message.c
@@ -645,7 +645,8 @@ mime_foreach_callback (GMimeObject * part, gpointer user_data)
}
else if (GMIME_IS_MULTIPART (part)) {
/* multipart/mixed, multipart/alternative, multipart/related, multipart/signed, multipart/encrypted, etc... */
-
+#ifndef GMIME24
+ debug_task ("detected multipart part");
/* we'll get to finding out if this is a signed/encrypted multipart later... */
if (task->parser_recursion++ < RECURSION_LIMIT) {
g_mime_multipart_foreach ((GMimeMultipart *) part, mime_foreach_callback, task);
@@ -654,6 +655,8 @@ mime_foreach_callback (GMimeObject * part, gpointer user_data)
msg_err ("endless recursion detected: %d", task->parser_recursion);
return;
}
+#endif
+ /* XXX: do nothing with multiparts in gmime 2.4 */
}
else if (GMIME_IS_PART (part)) {
/* a normal leaf part, could be text/plain or image/jpeg etc */
@@ -672,7 +675,11 @@ mime_foreach_callback (GMimeObject * part, gpointer user_data)
#endif
}
wrapper = g_mime_part_get_content_object (GMIME_PART (part));
+#ifdef GMIME24
+ if (wrapper != NULL && GMIME_IS_DATA_WRAPPER (wrapper)) {
+#else
if (wrapper != NULL) {
+#endif
part_stream = g_mime_stream_mem_new ();
if (g_mime_data_wrapper_write_to_stream (wrapper, part_stream) != -1) {
g_mime_stream_mem_set_owner (GMIME_STREAM_MEM (part_stream), FALSE);
@@ -735,7 +742,7 @@ process_message (struct worker_task *task)
if (task->is_mime) {
- debug_task ("construct mime parser from string length %ld", (long int)task->msg->len);
+ debug_task ("construct mime parser from string length %d", (int)task->msg->len);
/* create a new parser object to parse the stream */
parser = g_mime_parser_new_with_stream (stream);
g_object_unref (stream);
@@ -905,7 +912,13 @@ header_iterate (memory_pool_t * pool, GMimeHeaderList * ls, GList ** ret, const
GMimeHeaderIter *iter;
const char *name;
- if (g_mime_header_list_get_iter (ls, iter)) {
+ if (ls == NULL) {
+ *ret = NULL;
+ return;
+ }
+
+ iter = g_mime_header_iter_new ();
+ if (g_mime_header_list_get_iter (ls, iter) && g_mime_header_iter_first (iter)) {
while (g_mime_header_iter_is_valid (iter)) {
name = g_mime_header_iter_get_name (iter);
if (!g_strncasecmp (field, name, strlen (name))) {
@@ -921,6 +934,7 @@ header_iterate (memory_pool_t * pool, GMimeHeaderList * ls, GList ** ret, const
}
}
}
+ g_mime_header_iter_free (iter);
}
#endif
@@ -943,14 +957,16 @@ multipart_iterate (GMimeObject * part, gpointer user_data)
#endif
{
struct multipart_cb_data *data = user_data;
+#ifndef GMIME24
struct raw_header *h;
+#endif
GList *l = NULL;
- if (data->try_search && GMIME_IS_PART (part)) {
+ if (data->try_search && part != NULL && GMIME_IS_PART (part)) {
#ifdef GMIME24
GMimeHeaderList *ls;
- ls = GMIME_OBJECT (part)->headers;
+ ls = g_mime_object_get_header_list (GMIME_OBJECT (part));
header_iterate (data->pool, ls, &l, data->field);
#else
h = part->headers->headers;
@@ -1013,7 +1029,9 @@ local_message_get_header (memory_pool_t * pool, GMimeMessage * message, const ch
gret = cb.ret;
}
}
+#ifndef GMIME24
g_object_unref (part);
+#endif
}
}
@@ -1027,7 +1045,7 @@ local_message_get_header (memory_pool_t * pool, GMimeMessage * message, const ch
/* Try to iterate with mime part headers */
part = g_mime_message_get_mime_part (message);
if (part) {
- ls = part->headers;
+ ls = g_mime_object_get_header_list (GMIME_OBJECT (part));
header_iterate (pool, ls, &gret, field);
if (gret == NULL && GMIME_IS_MULTIPART (part)) {
g_mime_multipart_foreach (GMIME_MULTIPART (part), multipart_iterate, &cb);
@@ -1035,7 +1053,9 @@ local_message_get_header (memory_pool_t * pool, GMimeMessage * message, const ch
gret = cb.ret;
}
}
+#ifndef GMIME24
g_object_unref (part);
+#endif
}
}
@@ -1196,7 +1216,7 @@ local_message_get_recipients_##type (GMimeMessage *message, const char *unused)
"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},
+ "Date", (GetFunc)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}, {
@@ -1206,7 +1226,7 @@ local_message_get_recipients_##type (GMimeMessage *message, const char *unused)
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}
+ NULL, NULL, NULL, local_message_get_header, NULL, (SetListFunc)g_mime_object_append_header, FUNC_LIST}
#endif
};
@@ -1278,13 +1298,12 @@ message_get_header (memory_pool_t * pool, GMimeMessage * message, const char *fi
}
#else
i = internet_address_list_length (ia);
- while (i > 0) {
+ while (--i >= 0) {
ia_string = internet_address_to_string (internet_address_list_get_address (ia, i), FALSE);
if (pool != NULL) {
memory_pool_add_destructor (pool, (pool_destruct_func) g_free, ia_string);
}
gret = g_list_prepend (gret, ia_string);
- --i;
}
#endif
break;
diff --git a/src/spf.c b/src/spf.c
index 0ff92303c..0d2e28c64 100644
--- a/src/spf.c
+++ b/src/spf.c
@@ -121,6 +121,7 @@ parse_spf_ipmask (const char *begin, struct spf_addr *addr)
bzero (ip_buf, sizeof (ip_buf));
bzero (mask_buf, sizeof (mask_buf));
pos = begin;
+ p = ip_buf;
while (*pos) {
switch (state) {