diff options
Diffstat (limited to 'camel')
-rw-r--r-- | camel/camel-data-wrapper.c | 49 | ||||
-rw-r--r-- | camel/camel-data-wrapper.h | 4 | ||||
-rw-r--r-- | camel/camel-log.h | 6 | ||||
-rw-r--r-- | camel/camel-mime-part.c | 44 | ||||
-rw-r--r-- | camel/camel-mime-part.h | 5 | ||||
-rw-r--r-- | camel/gmime-content-field.c | 30 | ||||
-rw-r--r-- | camel/gmime-utils.c | 4 | ||||
-rw-r--r-- | camel/gmime-utils.h | 2 | ||||
-rw-r--r-- | camel/gstring-util.c | 2 |
9 files changed, 84 insertions, 62 deletions
diff --git a/camel/camel-data-wrapper.c b/camel/camel-data-wrapper.c index c7793403b4..f885e8a0a6 100644 --- a/camel/camel-data-wrapper.c +++ b/camel/camel-data-wrapper.c @@ -29,10 +29,12 @@ static GtkObjectClass *parent_class=NULL; /* Returns the class for a CamelDataWrapper */ -#define CDH_CLASS(so) CAMEL_DATA_WRAPPER_CLASS (GTK_OBJECT(so)->klass) +#define CDW_CLASS(so) CAMEL_DATA_WRAPPER_CLASS (GTK_OBJECT(so)->klass) static void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream, guint size); static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream); +static void _set_content_type (CamelDataWrapper *data_wrapper, GString *content_type); +static GString *_get_content_type (CamelDataWrapper *data_wrapper); static void camel_data_wrapper_class_init (CamelDataWrapperClass *camel_data_wrapper_class) @@ -42,6 +44,8 @@ camel_data_wrapper_class_init (CamelDataWrapperClass *camel_data_wrapper_class) /* virtual method definition */ camel_data_wrapper_class->write_to_stream = _write_to_stream; camel_data_wrapper_class->construct_from_stream = _construct_from_stream; + camel_data_wrapper_class->set_content_type = _set_content_type; + camel_data_wrapper_class->get_content_type = _get_content_type; /* virtual method overload */ } @@ -50,6 +54,14 @@ camel_data_wrapper_class_init (CamelDataWrapperClass *camel_data_wrapper_class) +static void +camel_data_wrapper_init (gpointer object, gpointer klass) +{ + CamelDataWrapper *camel_data_wrapper = CAMEL_DATA_WRAPPER (object); + + camel_data_wrapper->content_type = gmime_content_field_new (NULL, NULL); +} + GtkType @@ -64,7 +76,7 @@ camel_data_wrapper_get_type (void) sizeof (CamelDataWrapper), sizeof (CamelDataWrapperClass), (GtkClassInitFunc) camel_data_wrapper_class_init, - (GtkObjectInitFunc) NULL, + (GtkObjectInitFunc) camel_data_wrapper_init, /* reserved_1 */ NULL, /* reserved_2 */ NULL, (GtkClassInitFunc) NULL, @@ -78,7 +90,6 @@ camel_data_wrapper_get_type (void) - /** * _write_to_stream: write data content in a byte stream * @data_wrapper: the data wrapper object @@ -113,7 +124,7 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) void camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { - CDH_CLASS(data_wrapper)->write_to_stream (data_wrapper, stream); + CDW_CLASS(data_wrapper)->write_to_stream (data_wrapper, stream); } @@ -130,7 +141,35 @@ _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream, gui void camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream, guint size) { - CDH_CLASS(data_wrapper)->construct_from_stream (data_wrapper, stream, size); + CDW_CLASS(data_wrapper)->construct_from_stream (data_wrapper, stream, size); } + +static void +_set_content_type (CamelDataWrapper *data_wrapper, GString *content_type) +{ + g_assert (content_type); + gmime_content_field_construct_from_string (data_wrapper->content_type, content_type); +} + +void +camel_data_wrapper_set_content_type (CamelDataWrapper *data_wrapper, GString *content_type) +{ + CDW_CLASS(data_wrapper)->set_content_type (data_wrapper, content_type); +} + +static GString * +_get_content_type (CamelDataWrapper *data_wrapper) +{ + GString *mime_type; + + mime_type = gmime_content_field_get_mime_type (data_wrapper->content_type); + return mime_type; +} + +static GString * +camel_data_wrapper_get_content_type (CamelDataWrapper *data_wrapper) +{ + return CDW_CLASS(data_wrapper)->get_content_type (data_wrapper); +} diff --git a/camel/camel-data-wrapper.h b/camel/camel-data-wrapper.h index a7b9dbbff1..a0bb859f3b 100644 --- a/camel/camel-data-wrapper.h +++ b/camel/camel-data-wrapper.h @@ -60,6 +60,8 @@ typedef struct { /* Virtual methods */ void (*write_to_stream) (CamelDataWrapper *data_wrapper, CamelStream *stream); void (*construct_from_stream) (CamelDataWrapper *data_wrapper, CamelStream *stream, guint size); + void (*set_content_type) (CamelDataWrapper *data_wrapper, GString *content_type); + GString * (*get_content_type) (CamelDataWrapper *data_wrapper); } CamelDataWrapperClass; @@ -73,6 +75,8 @@ GtkType camel_data_wrapper_get_type (void); void camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream); void camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream, guint size); +void camel_data_wrapper_set_content_type (CamelDataWrapper *data_wrapper, GString *content_type); +static GString *camel_data_wrapper_get_content_type (CamelDataWrapper *data_wrapper); #ifdef __cplusplus } diff --git a/camel/camel-log.h b/camel/camel-log.h index dfe023cc3c..5ab9f8f405 100644 --- a/camel/camel-log.h +++ b/camel/camel-log.h @@ -34,11 +34,12 @@ extern FILE *camel_log_file_descriptor; typedef enum { NO_LOG = 0, STRANGE = 5, - WARNING = 7, + WARNING = 6, + TRACE = 8, FULL_DEBUG = 10 } CamelLogLevel; -#define HARD_LOG_LEVEL FULL_DEBUG +#define HARD_LOG_LEVEL TRACE /* the idea here is to be able to have a hard maximum log level, given at compilation time, and a soft one, given at @@ -46,6 +47,7 @@ runtime (with camel_debug_level). For the moment, only soft level is implmented, but one day, when performance become important, I will set the hard one too */ + #define CAMEL_LOG(level, args...) camel_log(level,##args) extern void camel_log(CamelLogLevel level, const gchar *format, ... ); diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c index 489e6d0d27..8e187a8eac 100644 --- a/camel/camel-mime-part.c +++ b/camel/camel-mime-part.c @@ -68,8 +68,6 @@ static void _set_content_languages (CamelMimePart *mime_part, GList *content_lan static GList *_get_content_languages (CamelMimePart *mime_part); static void _set_header_lines (CamelMimePart *mime_part, GList *header_lines); static GList *_get_header_lines (CamelMimePart *mime_part); -static void _set_content_type (CamelMimePart *mime_part, GString *content_type); -static GString *_get_content_type (CamelMimePart *mime_part); static CamelDataWrapper *_get_content_object(CamelMimePart *mime_part); static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream); @@ -122,8 +120,6 @@ camel_mime_part_class_init (CamelMimePartClass *camel_mime_part_class) camel_mime_part_class->get_header_lines=_get_header_lines; camel_mime_part_class->parse_header_pair = _parse_header_pair; camel_mime_part_class->get_content_object = _get_content_object; - camel_mime_part_class->set_content_type = _set_content_type; - camel_mime_part_class->get_content_type = _get_content_type; @@ -137,7 +133,6 @@ camel_mime_part_init (gpointer object, gpointer klass) CamelMimePart *camel_mime_part = CAMEL_MIME_PART (object); camel_mime_part->headers = g_hash_table_new (g_string_hash, g_string_equal_for_hash); - camel_mime_part->content_type_field = gmime_content_field_new (NULL, NULL); } @@ -497,34 +492,6 @@ camel_mime_part_get_content_object(CamelMimePart *mime_part) } -static void -_set_content_type (CamelMimePart *mime_part, GString *content_type) -{ - g_assert (content_type); - gmime_content_field_construct_from_string (mime_part->content_type_field, content_type); -} - -void -camel_mime_part_set_content_type (CamelMimePart *mime_part, GString *content_type) -{ - CMP_CLASS(mime_part)->set_content_type (mime_part, content_type); -} - -static GString * -_get_content_type (CamelMimePart *mime_part) -{ - GString *mime_type; - - mime_type = gmime_content_field_get_mime_type (mime_part->content_type_field); - return mime_type; -} - -static GString * -camel_mime_part_get_content_type (CamelMimePart *mime_part) -{ - return CMP_CLASS(mime_part)->get_content_type (mime_part); -} - /**********************************************************************/ @@ -570,8 +537,6 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) CAMEL_LOG (FULL_DEBUG, "Entering CamelMimePart::write_to_stream\n"); - CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-type\n"); - gmime_content_field_write_to_stream(data_wrapper->content_type, stream); CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-disposition\n"); gmime_content_field_write_to_stream(mp->disposition, stream); CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-transfer-encoding\n"); @@ -583,9 +548,14 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-id\n"); WHPT (stream, "Content-id", mp->content_id); CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-languages\n"); - write_header_with_glist_to_stream (stream, "Content-Language", mp->content_languages); + write_header_with_glist_to_stream (stream, "Content-Language", mp->content_languages,", "); + CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing other headers\n"); write_header_table_to_stream (stream, mp->headers); + + CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-type\n"); + gmime_content_field_write_to_stream(data_wrapper->content_type, stream); + camel_stream_write_string(stream,"\n"); if (mp->content) camel_data_wrapper_write_to_stream (mp->content, stream); @@ -656,7 +626,7 @@ _parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *hea "CamelMimePart::parse_header_pair found HEADER_CONTENT_TYPE: %s\n", header_value->str ); - /* CMP_CLASS(mime_part)->set_content_MD5 (mime_part, header_value); */ + gmime_content_field_construct_from_string (CAMEL_DATA_WRAPPER(mime_part)->content_type, header_value); header_handled = TRUE; break; diff --git a/camel/camel-mime-part.h b/camel/camel-mime-part.h index 8ab5fc152c..eadf65ce68 100644 --- a/camel/camel-mime-part.h +++ b/camel/camel-mime-part.h @@ -58,7 +58,6 @@ typedef struct GString *encoding; GString *filename; GList *header_lines; - GMimeContentField *content_type_field; CamelDataWrapper *content; /* part real content */ @@ -89,8 +88,6 @@ typedef struct { GList * (*get_content_languages) (CamelMimePart *mime_part); void (*set_header_lines) (CamelMimePart *mime_part, GList *header_lines); GList * (*get_header_lines) (CamelMimePart *mime_part); - void (*set_content_type) (CamelMimePart *mime_part, GString *content_type); - GString * (*get_content_type) (CamelMimePart *mime_part); gboolean (*parse_header_pair) (CamelMimePart *mime_part, GString *header_name, GString *header_value); @@ -121,8 +118,6 @@ void camel_mime_part_set_content_languages (CamelMimePart *mime_part, GList *con GList *camel_mime_part_get_content_languages (CamelMimePart *mime_part); void camel_mime_part_set_header_lines (CamelMimePart *mime_part, GList *header_lines); GList *camel_mime_part_get_header_lines (CamelMimePart *mime_part); -void camel_mime_part_set_content_type (CamelMimePart *mime_part, GString *content_type); -static GString *camel_mime_part_get_content_type (CamelMimePart *mime_part); #ifdef __cplusplus } diff --git a/camel/gmime-content-field.c b/camel/gmime-content-field.c index a22bbe2979..06e4384437 100644 --- a/camel/gmime-content-field.c +++ b/camel/gmime-content-field.c @@ -26,18 +26,20 @@ #include "gmime-content-field.h" #include "gstring-util.h" +#include "camel-log.h" GMimeContentField * gmime_content_field_new (GString *type, GString *subtype) { - GMimeContentField *ct; + GMimeContentField *ctf; - ct = g_new (GMimeContentField,1); - ct->type = type; - ct->subtype = subtype; - ct->parameters = g_hash_table_new(g_string_hash, g_string_equal_for_hash); + ctf = g_new (GMimeContentField,1); + ctf->type = type; + ctf->subtype = subtype; + ctf->parameters = g_hash_table_new(g_string_hash, g_string_equal_for_hash); + return ctf; } @@ -122,16 +124,25 @@ gmime_content_field_construct_from_string (GMimeContentField *content_field, GSt GString *param_name, *param_value; gboolean param_end; + CAMEL_LOG (TRACE, "Entering gmime_content_field_construct_from_string\n"); g_assert (string); g_assert (string->str); - - if (content_field->type) g_string_free (content_field->type, FALSE); - if (content_field->subtype) g_string_free (content_field->subtype, FALSE); + g_assert (content_field); + + if (content_field->type) { + CAMEL_LOG (FULL_DEBUG, "Freeing old mime type string\n"); + g_string_free (content_field->type, FALSE); + } + if (content_field->subtype) { + CAMEL_LOG (FULL_DEBUG, "Freeing old mime type substring\n"); + g_string_free (content_field->subtype, FALSE); + } str = string->str; first = 0; len = string->len; if (!len) return; + CAMEL_LOG (TRACE, "All checks done\n"); /* find the type */ while ( (i<len) && (!strchr ("/;", str[i])) ) i++; @@ -140,7 +151,7 @@ gmime_content_field_construct_from_string (GMimeContentField *content_field, GSt type = g_string_new (g_strndup (str, i)); content_field->type = type; - + CAMEL_LOG (TRACE, "Found mime type : %s\n", type->str); if (i == len) { content_field->subtype = NULL; return; @@ -178,6 +189,7 @@ gmime_content_field_construct_from_string (GMimeContentField *content_field, GSt } } while ((!param_end) && (first < len)); + } diff --git a/camel/gmime-utils.c b/camel/gmime-utils.c index 917c426801..1555d27e7b 100644 --- a/camel/gmime-utils.c +++ b/camel/gmime-utils.c @@ -71,7 +71,7 @@ write_header_table_to_stream (CamelStream *stream, GHashTable *header_table) void -write_header_with_glist_to_stream (CamelStream *stream, gchar *header_name, GList *header_values) +write_header_with_glist_to_stream (CamelStream *stream, gchar *header_name, GList *header_values, gchar *separator) { GString *current; @@ -86,7 +86,7 @@ write_header_with_glist_to_stream (CamelStream *stream, gchar *header_name, GLis while (header_values) { current = (GString *)header_values->data; if ( (current) && (current->str) ) { - if (!first) camel_stream_write (stream, ", ", 2); + if (!first) camel_stream_write_string (stream, separator); else first = FALSE; camel_stream_write (stream, current->str, strlen (current->str)); } diff --git a/camel/gmime-utils.h b/camel/gmime-utils.h index 6ed47b816c..a8ff6094e9 100644 --- a/camel/gmime-utils.h +++ b/camel/gmime-utils.h @@ -37,7 +37,7 @@ extern "C" { void gmime_write_header_pair_to_stream (CamelStream *stream, gchar* name, GString *value); void write_header_table_to_stream (CamelStream *stream, GHashTable *header_table); -void write_header_with_glist_to_stream (CamelStream *stream, gchar *header_name, GList *header_values); +void write_header_with_glist_to_stream (CamelStream *stream, gchar *header_name, GList *header_values, gchar *separator); GHashTable *get_header_table_from_stream (CamelStream *stream); diff --git a/camel/gstring-util.c b/camel/gstring-util.c index b8a92ce10f..c48a98d410 100644 --- a/camel/gstring-util.c +++ b/camel/gstring-util.c @@ -318,7 +318,7 @@ g_string_trim (GString *string, gchar *chars, TrimOption options) CAMEL_LOG (FULL_DEBUG,"g_string_trim:: trim_options:%d\n", options); if (options & TRIM_STRIP_LEADING) - while ( (first_ok <= last_ok) && (strchr (chars, str[first_ok]) != NULL) ) + while ( (first_ok <= last_ok) && (strchr (chars, str[first_ok])) ) first_ok++; if (options & TRIM_STRIP_TRAILING) |