$(GTK_INCLUDEDIR)
libcamel_la_SOURCES = \
+ camel.c \
camel-log.c \
camel-data-wrapper.c \
camel-simple-data-wrapper.c \
camel-folder.c \
+ camel-mime-body-part.c \
camel-mime-message.c \
camel-mime-part.c \
+ camel-multipart.c \
camel-provider.c \
camel-service.c \
camel-session.c \
camel-store.c \
camel-stream.c \
camel-stream-fs.c \
+ data-wrapper-repository.c \
gmime-content-field.c \
gmime-utils.c \
gstring-util.c \
+ string-utils.c \
url-util.c
libcamelinclude_HEADERS = \
+ camel.h \
camel-log.h \
camel-data-wrapper.h \
camel-simple-data-wrapper.h \
camel-folder.h \
+ camel-mime-body-part.h \
camel-mime-message.h \
camel-mime-part.h \
+ camel-multipart.h \
camel-provider.h \
camel-service.h \
camel-session.h \
camel-store.h \
camel-stream.h \
camel-stream-fs.h \
+ data-wrapper-repository.h \
gmime-content-field.h \
gmime-utils.h \
gstring-util.h \
+ string-utils.h \
url-util.h
/*
*
- * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> .
+ * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> .
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
*/
#include <config.h>
#include "camel-data-wrapper.h"
+#include "camel-log.h"
static GtkObjectClass *parent_class=NULL;
static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
static void _set_mime_type (CamelDataWrapper *data_wrapper, gchar *mime_type);
static gchar *_get_mime_type (CamelDataWrapper *data_wrapper);
+static GMimeContentField *_get_mime_type_field (CamelDataWrapper *data_wrapper);
+static void _set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type);
+
static void
camel_data_wrapper_class_init (CamelDataWrapperClass *camel_data_wrapper_class)
camel_data_wrapper_class->construct_from_stream = _construct_from_stream;
camel_data_wrapper_class->set_mime_type = _set_mime_type;
camel_data_wrapper_class->get_mime_type = _get_mime_type;
-
+ camel_data_wrapper_class->get_mime_type_field = _get_mime_type_field;
+ camel_data_wrapper_class->set_mime_type_field = _set_mime_type_field;
/* virtual method overload */
}
{
CamelDataWrapper *camel_data_wrapper = CAMEL_DATA_WRAPPER (object);
+ CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_init:: Entering\n");
camel_data_wrapper->mime_type = gmime_content_field_new (NULL, NULL);
+ CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_init:: Leaving\n");
}
/**
* camel_data_wrapper_write_to_stream: write data in a stream
- * @data_wrapper: the data wrapper object
+ * @data_wrappewr: the data wrapper object
* @stream: byte stream where data will be written
*
* Write data content in a stream. Data is stored in a machine
void
camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
+ CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_write_to_stream:: Entering\n");
CDW_CLASS(data_wrapper)->write_to_stream (data_wrapper, stream);
+ CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_write_to_stream:: Leaving\n");
}
void
camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
+ CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_construct_from_stream:: Entering\n");
CDW_CLASS(data_wrapper)->construct_from_stream (data_wrapper, stream);
+ CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_construct_from_stream:: Leaving\n");
}
static void
_set_mime_type (CamelDataWrapper *data_wrapper, gchar *mime_type)
{
+ CAMEL_LOG_FULL_DEBUG ( "CamelDataWrapper::set_mime_type Entering\n");
g_assert (mime_type);
gmime_content_field_construct_from_string (data_wrapper->mime_type, mime_type);
+ CAMEL_LOG_FULL_DEBUG ( "CamelDataWrapper::set_mime_type Leaving\n");
}
void
return mime_type;
}
-static gchar *
+gchar *
camel_data_wrapper_get_mime_type (CamelDataWrapper *data_wrapper)
{
+ CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_get_mime_type:: Entering before returning\n");
return CDW_CLASS(data_wrapper)->get_mime_type (data_wrapper);
}
+
+
+static GMimeContentField *
+_get_mime_type_field (CamelDataWrapper *data_wrapper)
+{
+ return data_wrapper->mime_type;
+}
+
+GMimeContentField *
+camel_data_wrapper_get_mime_type_field (CamelDataWrapper *data_wrapper)
+{
+ return CDW_CLASS(data_wrapper)->get_mime_type_field (data_wrapper);
+}
+
+
+static void
+_set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type)
+{
+ if (data_wrapper->mime_type) gmime_content_field_free (data_wrapper->mime_type);
+ data_wrapper->mime_type = mime_type;
+}
+
+void
+camel_data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type)
+{
+ CDW_CLASS(data_wrapper)->set_mime_type_field (data_wrapper, mime_type);
+}
+
+
/* Virtual methods */
void (*write_to_stream) (CamelDataWrapper *data_wrapper, CamelStream *stream);
void (*construct_from_stream) (CamelDataWrapper *data_wrapper, CamelStream *stream);
- void (*set_mime_type) (CamelDataWrapper *data_wrapper, gchar *content_type);
+ void (*set_mime_type) (CamelDataWrapper *data_wrapper, gchar * mime_type);
gchar * (*get_mime_type) (CamelDataWrapper *data_wrapper);
-
+ GMimeContentField * (*get_mime_type_field) (CamelDataWrapper *data_wrapper);
+ void (*set_mime_type_field) (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type_field);
} CamelDataWrapperClass;
void camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
void camel_data_wrapper_set_mime_type (CamelDataWrapper *data_wrapper, gchar *mime_type);
static gchar *camel_data_wrapper_get_mime_type (CamelDataWrapper *data_wrapper);
+GMimeContentField *camel_data_wrapper_get_mime_type_field (CamelDataWrapper *data_wrapper);
+void camel_data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type);
#ifdef __cplusplus
}
*/
#include <config.h>
#include "camel-folder.h"
-#include "gstring-util.h"
+#include "string-utils.h"
static GtkObjectClass *parent_class=NULL;
static void _init_with_store (CamelFolder *folder, CamelStore *parent_store);
static void _open (CamelFolder *folder, CamelFolderOpenMode mode);
static void _close (CamelFolder *folder, gboolean expunge);
-static void _set_name (CamelFolder *folder, GString *name_);
-static void _set_full_name (CamelFolder *folder, GString *name);
-static GString *_get_name (CamelFolder *folder);
-static GString *_get_full_name (CamelFolder *folder);
+static void _set_name (CamelFolder *folder, const gchar *name);
+static void _set_full_name (CamelFolder *folder, const gchar *name);
+static const gchar *_get_name (CamelFolder *folder);
+static const gchar *_get_full_name (CamelFolder *folder);
static gboolean _can_hold_folders (CamelFolder *folder);
static gboolean _can_hold_messages(CamelFolder *folder);
static gboolean _exists (CamelFolder *folder);
static gboolean _is_open (CamelFolder *folder);
-static CamelFolder *_get_folder (CamelFolder *folder, GString *folder_name);
+static CamelFolder *_get_folder (CamelFolder *folder, const gchar *folder_name);
static gboolean _create (CamelFolder *folder);
static gboolean _delete (CamelFolder *folder, gboolean recurse);
static gboolean _delete_messages (CamelFolder *folder);
*
**/
static void
-_init_with_store(CamelFolder *folder, CamelStore *parent_store)
+_init_with_store (CamelFolder *folder, CamelStore *parent_store)
{
g_assert(folder);
g_assert(parent_store);
/**
* _open: Open a folder
- * @folder:
+ * @folder: The folder object
* @mode: open mode (R/W/RW ?)
*
+ *
**/
static void
-_open(CamelFolder *folder, CamelFolderOpenMode mode)
+_open( CamelFolder *folder, CamelFolderOpenMode mode)
{
folder->open_state = FOLDER_OPEN;
folder->open_mode = mode;
* expunge the flagged messages.
**/
static void
-_close(CamelFolder *folder, gboolean expunge)
+_close (CamelFolder *folder, gboolean expunge)
{
if (expunge) CF_CLASS(folder)->expunge(folder);
folder->open_state = FOLDER_CLOSE;
* @name: new name of the folder
*
* set the name of the folder.
- * The old name object is freed.
+ *
*
**/
static void
-_set_name(CamelFolder *folder, GString *name)
+_set_name(CamelFolder *folder, const gchar *name)
{
- if (folder->name) g_string_free(folder->name, 0);;
- folder->name = name;
+ if (folder->name) g_free(folder->name);
+ folder->name = g_strdup (name);
}
* @name: new name of the folder
*
* set the name of the folder.
- * The old name object is freed.
*
**/
static void
-_set_full_name(CamelFolder *folder, GString *name)
+_set_full_name (CamelFolder *folder, const gchar *name)
{
- if (folder->full_name) g_string_free(folder->full_name, 0);;
- folder->full_name = name;
+ if (folder->full_name) g_free(folder->full_name);
+ folder->full_name = g_strdup (name);
}
*
* Return value: name of the folder
**/
-static GString *
-_get_name(CamelFolder *folder)
+static const gchar *
+_get_name (CamelFolder *folder)
{
return folder->name;
}
*
* Return value: full name of the folder
**/
-static GString *
-_get_full_name(CamelFolder *folder)
+static const gchar *
+_get_full_name (CamelFolder *folder)
{
return folder->full_name;
}
/**
* _can_hold_folders: tests if the folder can contain other folders
- * @folder:
- *
+ * @folder: The folder object
*
+ * Tests if a folder can contain other folder
+ * (as for example MH folders)
*
* Return value:
**/
static gboolean
-_can_hold_folders(CamelFolder *folder)
+_can_hold_folders (CamelFolder *folder)
{
return folder->can_hold_folders;
}
/**
* _can_hold_messages: tests if the folder can contain messages
- * @folder:
+ * @folder: The folder object
*
+ * Tests if a folder object can contain messages.
+ * In the case it can not, it most surely can only
+ * contain folders (rare).
*
- *
- * Return value:
+ * Return value: true if it can contain messages false otherwise
**/
static gboolean
-_can_hold_messages(CamelFolder *folder)
+_can_hold_messages (CamelFolder *folder)
{
return folder->can_hold_messages;
}
/**
- * _exists: tests if the folder object exists on the store.
- * @folder:
+ * _exists: tests if the folder object exists in its parent store.
+ * @folder: folder object
*
+ * Test if a folder exists on a store. A folder can be
+ * created without physically on a store. In that case,
+ * use CamelFolder::create to create it
*
- *
- * Return value:
+ * Return value: true if the folder exists on the store false otherwise
**/
static gboolean
-_exists(CamelFolder *folder)
+_exists (CamelFolder *folder)
{
return folder->exists_on_store;
}
/**
- * _is_open:
- * @folder:
- *
+ * _is_open: test if the folder is open
+ * @folder: The folder object
*
+ * Tests if a folder is open. If not open it can be opened
+ * CamelFolder::open
*
- * Return value:
+ * Return value: true if the folder exists, false otherwise
**/
static gboolean
-_is_open(CamelFolder *folder)
+_is_open (CamelFolder *folder)
{
return (folder->open_state==FOLDER_OPEN);
-}
+}
/**
- * _get_folder: return the (sub)folder object that
- * is specified.
+ * _get_folder: return the (sub)folder object that is specified.
+ *
+ * @folder : the folder
+ * @folder_name: subfolder path.
*
* This method returns a folder objects. This folder
* is necessarily a subfolder of the current folder.
* It is an error to ask a folder begining with the
* folder separator character.
*
- * @folder : the folder
- * @folderName: subfolder path. NULL if the subfolder object
- * could not be created
+ *
+ * Return value: Required folder. NULL if the subfolder object
+ * could not be obtained
**/
static CamelFolder *
-_get_folder(CamelFolder *folder, GString *folder_name)
+_get_folder (CamelFolder *folder, const gchar *folder_name)
{
g_warning("getFolder called on the abstract CamelFolder class\n");
return NULL;
}
/**
- * camel_folder_get_folder: return the (sub)folder object that
- * is specified.
+ * _get_folder: return the (sub)folder object that is specified.
+ *
+ * @folder : the folder
+ * @folder_name: subfolder path.
*
* This method returns a folder objects. This folder
* is necessarily a subfolder of the current folder.
* It is an error to ask a folder begining with the
* folder separator character.
*
- * @folder : the folder
- * @folderName: subfolder path. NULL if the subfolder object
- * could not be created
+ * Return value: Required folder. NULL if the subfolder object
+ * could not be obtained
**/
CamelFolder *
-camel_folder_get_folder(CamelFolder *folder, GString *folder_name)
+camel_folder_get_folder(CamelFolder *folder, gchar *folder_name)
{
return (CF_CLASS(folder)->get_folder(folder,folder_name));
}
static gboolean
_create(CamelFolder *folder)
{
- GString *prefix;
+ gchar *prefix;
gchar dich_result;
CamelFolder *parent;
gchar sep;
g_assert(folder->parent_store);
g_assert(folder->name);
- if (CF_CLASS(folder)->exists(folder))
+ if (CF_CLASS(folder)->exists (folder))
return TRUE;
- sep = camel_store_get_separator(folder->parent_store);
+ sep = camel_store_get_separator (folder->parent_store);
if (folder->parent_folder)
- camel_folder_create(folder->parent_folder);
+ camel_folder_create (folder->parent_folder);
else {
if (folder->full_name) {
- dich_result = g_string_dichotomy(
+ dich_result = string_dichotomy (
folder->full_name, sep, &prefix, NULL,
- GSTRING_DICHOTOMY_STRIP_TRAILING | GSTRING_DICHOTOMY_RIGHT_DIR);
+ STRING_DICHOTOMY_STRIP_TRAILING | STRING_DICHOTOMY_RIGHT_DIR);
if (dich_result!='o') {
g_warning("I have to handle the case where the path is not OK\n");
return FALSE;
} else {
- parent = camel_store_get_folder(folder->parent_store, prefix);
- camel_folder_create(parent);
- gtk_object_unref (GTK_OBJECT(parent));
+ parent = camel_store_get_folder (folder->parent_store, prefix);
+ camel_folder_create (parent);
+ gtk_object_unref (GTK_OBJECT (parent));
}
}
}
* Return value: list of subfolders
**/
GList *
-camel_folder_list_subfolders(CamelFolder *folder)
+camel_folder_list_subfolders (CamelFolder *folder)
{
return CF_CLASS(folder)->list_subfolders(folder);
}
static GList *
-_expunge(CamelFolder *folder)
+_expunge (CamelFolder *folder)
{
return NULL;
}
* Return value: list of expunged message objects.
**/
GList *
-camel_folder_expunge(CamelFolder *folder)
+camel_folder_expunge (CamelFolder *folder)
{
- return CF_CLASS(folder)->expunge(folder);
+ return CF_CLASS (folder)->expunge (folder);
}
gboolean exists_on_store;
CamelFolderOpenMode open_mode;
CamelFolderState open_state;
- GString *name;
- GString *full_name;
+ gchar *name;
+ gchar *full_name;
CamelStore *parent_store;
CamelFolder *parent_folder;
void (*init_with_store) (CamelFolder *folder, CamelStore *parent_store);
void (*open) (CamelFolder *object, CamelFolderOpenMode mode);
void (*close) (CamelFolder *folder, gboolean expunge);
- void (*set_name) (CamelFolder *folder, GString *name);
- void (*set_full_name) (CamelFolder *folder, GString *name);
- GString * (*get_name) (CamelFolder *folder);
- GString * (*get_full_name) (CamelFolder *folder);
+ void (*set_name) (CamelFolder *folder, const gchar *name);
+ void (*set_full_name) (CamelFolder *folder, const gchar *name);
+ const gchar * (*get_name) (CamelFolder *folder);
+ const gchar * (*get_full_name) (CamelFolder *folder);
gboolean (*can_hold_folders) (CamelFolder *folder);
gboolean (*can_hold_messages) (CamelFolder *folder);
gboolean (*exists) (CamelFolder *folder);
gboolean (*is_open) (CamelFolder *folder);
- CamelFolder * (*get_folder) (CamelFolder *folder, GString *folder_name);
+ CamelFolder * (*get_folder) (CamelFolder *folder, const gchar *folder_name);
gboolean (*create) (CamelFolder *folder);
gboolean (*delete) (CamelFolder *folder, gboolean recurse);
gboolean (*delete_messages) (CamelFolder *folder);
/* public methods */
-CamelFolder *camel_folder_get_folder(CamelFolder *folder, GString *folder_name);
+CamelFolder *camel_folder_get_folder(CamelFolder *folder, gchar *folder_name);
gboolean camel_folder_create(CamelFolder *folder);
gboolean camel_folder_delete (CamelFolder *folder, gboolean recurse);
gboolean camel_folder_delete_messages (CamelFolder *folder);
#include <config.h>
#include "camel-log.h"
-int camel_debug_level = 10;
+int camel_debug_level = CAMEL_LOG_LEVEL_FULL_DEBUG;
FILE *camel_log_file_descriptor = NULL;
void
-camel_log(CamelLogLevel level, const gchar *format, ... )
+camel_log(guint level, const gchar *format, ... )
{
va_list args;
- if (camel_log_file_descriptor == NULL)
- camel_log_file_descriptor = stderr;
-
+ if (camel_log_file_descriptor == NULL)
+ camel_log_file_descriptor = stdout;
+
if (level<=camel_debug_level)
{
va_start(args, format);
extern int camel_debug_level;
extern FILE *camel_log_file_descriptor;
-typedef enum {
- NO_LOG = 0,
- STRANGE = 5,
- WARNING = 6,
- TRACE = 8,
- FULL_DEBUG = 10
-} CamelLogLevel;
+#define CAMEL_LOG_LEVEL_NO_LOG 0
+#define CAMEL_LOG_LEVEL_STRANGE 5
+#define CAMEL_LOG_LEVEL_WARNING 6
+#define CAMEL_LOG_LEVEL_TRACE 8
+#define CAMEL_LOG_LEVEL_FULL_DEBUG 10
-#define HARD_LOG_LEVEL TRACE
+/* #define CAMEL_HARD_LOG_LEVEL CAMEL_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
-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 */
+runtime (with camel_debug_level) */
+#if CAMEL_HARD_LOG_LEVEL>=CAMEL_LOG_LEVEL_STRANGE
+#define CAMEL_LOG_STRANGE(args...) camel_log(CAMEL_LOG_LEVEL_STRANGE, ##args)
+#else /* CAMEL_LOG_LEVEL_STRANGE */
+#define CAMEL_LOG_STRANGE(args...)
+#endif /* CAMEL_LOG_LEVEL_STRANGE */
-#define CAMEL_LOG(level, args...) camel_log(level,##args)
+#if CAMEL_HARD_LOG_LEVEL>=CAMEL_LOG_LEVEL_WARNING
+#define CAMEL_LOG_WARNING(args...) camel_log(CAMEL_LOG_LEVEL_WARNING, ##args)
+#else /* CAMEL_LOG_LEVEL_WARNING */
+#define CAMEL_LOG_WARNING(args...)
+#endif /* CAMEL_LOG_LEVEL_WARNING */
-extern void camel_log(CamelLogLevel level, const gchar *format, ... );
+#if CAMEL_HARD_LOG_LEVEL>=CAMEL_LOG_LEVEL_TRACE
+#define CAMEL_LOG_TRACE(args...) camel_log(CAMEL_LOG_LEVEL_TRACE, ##args)
+#else /* CAMEL_LOG_LEVEL_TRACE */
+#define CAMEL_LOG_TRACE(args...)
+#endif /* CAMEL_LOG_LEVEL_TRACE */
+
+#if CAMEL_HARD_LOG_LEVEL>=CAMEL_LOG_LEVEL_FULL_DEBUG
+#define CAMEL_LOG_FULL_DEBUG(args...) camel_log(CAMEL_LOG_LEVEL_FULL_DEBUG, ##args)
+#else /* CAMEL_LOG_LEVEL_FULL_DEBUG */
+#define CAMEL_LOG_FULL_DEBUG(args...)
+#endif /* CAMEL_LOG_LEVEL_FULL_DEBUG */
+
+
+
+
+extern void camel_log(guint level, const gchar *format, ... );
#endif /* CAMEL_LOG_H */
#include "camel-mime-message.h"
#include <stdio.h>
#include "gmime-content-field.h"
-#include "gstring-util.h"
+#include "string-utils.h"
#include "camel-log.h"
#include "gmime-utils.h"
static CamelMimePartClass *parent_class=NULL;
-static GString *received_date_str;
-static GString *sent_date_str;
-static GString *reply_to_str;
-static GString *subject_str;
-static GString *from_str;
-
-static void _set_received_date (CamelMimeMessage *mime_message, GString *received_date);
-static GString *_get_received_date (CamelMimeMessage *mime_message);
-static GString *_get_sent_date (CamelMimeMessage *mime_message);
-static void _set_reply_to (CamelMimeMessage *mime_message, GString *reply_to);
-static GString *_get_reply_to (CamelMimeMessage *mime_message);
-static void _set_subject (CamelMimeMessage *mime_message, GString *subject);
-static GString *_get_subject (CamelMimeMessage *mime_message);
-static void _set_from (CamelMimeMessage *mime_message, GString *from);
-static GString *_get_from (CamelMimeMessage *mime_message);
-
-static void _add_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString *recipient);
-static void _remove_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString *recipient);
-static GList *_get_recipients (CamelMimeMessage *mime_message, GString *recipient_type);
-
-static void _set_flag (CamelMimeMessage *mime_message, GString *flag, gboolean value);
-static gboolean _get_flag (CamelMimeMessage *mime_message, GString *flag);
+static gchar *received_date_str;
+static gchar *sent_date_str;
+static gchar *reply_to_str;
+static gchar *subject_str;
+static gchar *from_str;
+
+static void _set_received_date (CamelMimeMessage *mime_message, gchar *received_date);
+static const gchar *_get_received_date (CamelMimeMessage *mime_message);
+static const gchar *_get_sent_date (CamelMimeMessage *mime_message);
+static void _set_reply_to (CamelMimeMessage *mime_message, gchar *reply_to);
+static const gchar *_get_reply_to (CamelMimeMessage *mime_message);
+static void _set_subject (CamelMimeMessage *mime_message, gchar *subject);
+static const gchar *_get_subject (CamelMimeMessage *mime_message);
+static void _set_from (CamelMimeMessage *mime_message, gchar *from);
+static const gchar *_get_from (CamelMimeMessage *mime_message);
+
+static void _add_recipient (CamelMimeMessage *mime_message, gchar *recipient_type, gchar *recipient);
+static void _remove_recipient (CamelMimeMessage *mime_message, const gchar *recipient_type, const gchar *recipient);
+static const GList *_get_recipients (CamelMimeMessage *mime_message, const gchar *recipient_type);
+
+static void _set_flag (CamelMimeMessage *mime_message, gchar *flag, gboolean value);
+static gboolean _get_flag (CamelMimeMessage *mime_message, gchar *flag);
static void _set_message_number (CamelMimeMessage *mime_message, guint number);
static guint _get_message_number (CamelMimeMessage *mime_message);
static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
-static gboolean _parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *header_value);
+static gboolean _parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_value);
/* Returns the class for a CamelMimeMessage */
#define CMM_CLASS(so) CAMEL_MIME_MESSAGE_CLASS (GTK_OBJECT(so)->klass)
static void
_init_header_name_table()
{
- header_name_table = g_hash_table_new (g_string_hash, g_string_equal_for_hash);
- g_hash_table_insert (header_name_table, g_string_new ("From"), (gpointer)HEADER_FROM);
- g_hash_table_insert (header_name_table, g_string_new ("Reply-To"), (gpointer)HEADER_REPLY_TO);
- g_hash_table_insert (header_name_table, g_string_new ("Subject"), (gpointer)HEADER_SUBJECT);
- g_hash_table_insert (header_name_table, g_string_new ("To"), (gpointer)HEADER_TO);
- g_hash_table_insert (header_name_table, g_string_new ("Cc"), (gpointer)HEADER_CC);
- g_hash_table_insert (header_name_table, g_string_new ("Bcc"), (gpointer)HEADER_BCC);
+ header_name_table = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_insert (header_name_table, "From", (gpointer)HEADER_FROM);
+ g_hash_table_insert (header_name_table, "Reply-To", (gpointer)HEADER_REPLY_TO);
+ g_hash_table_insert (header_name_table, "Subject", (gpointer)HEADER_SUBJECT);
+ g_hash_table_insert (header_name_table, "To", (gpointer)HEADER_TO);
+ g_hash_table_insert (header_name_table, "Cc", (gpointer)HEADER_CC);
+ g_hash_table_insert (header_name_table, "Bcc", (gpointer)HEADER_BCC);
}
parent_class = gtk_type_class (camel_mime_part_get_type ());
_init_header_name_table();
- received_date_str = g_string_new("");
- sent_date_str = g_string_new("");
- reply_to_str = g_string_new("Reply-To");
- subject_str = g_string_new("Subject");
- from_str = g_string_new("From");
+ received_date_str = "";
+ sent_date_str = "";
+ reply_to_str = "Reply-To";
+ subject_str = "Subject";
+ from_str = "From";
/* virtual method definition */
camel_mime_message_class->set_received_date = _set_received_date;
static void
-camel_mime_message_init (gpointer object, gpointer klass)
+camel_mime_message_init (gpointer object, gpointer klass)
{
CamelMimeMessage *camel_mime_message = CAMEL_MIME_MESSAGE (object);
- camel_mime_message->recipients = g_hash_table_new(g_string_hash, g_string_equal_for_hash);
- camel_mime_message->flags = g_hash_table_new(g_string_hash, g_string_equal_for_hash);
-
+ camel_mime_message->recipients = g_hash_table_new(g_str_hash, g_str_equal);
+ camel_mime_message->flags = g_hash_table_new(g_str_hash, g_str_equal);
}
-
-
-
-
GtkType
camel_mime_message_get_type (void)
{
}
-
CamelMimeMessage *
camel_mime_message_new_with_session (CamelSession *session)
{
}
-
-
/* two utils func */
static void
-_set_field (CamelMimeMessage *mime_message, GString *name, GString *value, GString **variable)
+_set_field (CamelMimeMessage *mime_message, gchar *name, gchar *value, gchar **variable)
{
if (variable) {
- if (*variable) g_string_free (*variable, FALSE);
+ if (*variable) g_free (*variable);
*variable = value;
}
}
-static GString *
-_get_field (CamelMimeMessage *mime_message, GString *name, GString *variable)
+/* for future use */
+/* for the moment, only @variable is used */
+static gchar *
+_get_field (CamelMimeMessage *mime_message, gchar *name, gchar *variable)
{
return variable;
}
-
-
-
+/* * */
static void
-_set_received_date (CamelMimeMessage *mime_message, GString *received_date)
+_set_received_date (CamelMimeMessage *mime_message, gchar *received_date)
{
_set_field (mime_message, received_date_str, received_date, &(mime_message->received_date));
}
void
-camel_mime_message_set_received_date (CamelMimeMessage *mime_message, GString *received_date)
+camel_mime_message_set_received_date (CamelMimeMessage *mime_message, gchar *received_date)
{
CMM_CLASS (mime_message)->set_received_date (mime_message, received_date);
}
-static GString *
+static const gchar *
_get_received_date (CamelMimeMessage *mime_message)
{
return _get_field (mime_message, received_date_str, mime_message->received_date);
}
-GString *
+const gchar *
camel_mime_message_get_received_date (CamelMimeMessage *mime_message)
{
return CMM_CLASS (mime_message)->get_received_date (mime_message);
}
-
-
-
-
-static GString *
+static const gchar *
_get_sent_date (CamelMimeMessage *mime_message)
{
return _get_field (mime_message, sent_date_str, mime_message->sent_date);
}
-GString *
+const gchar *
camel_mime_message_get_sent_date (CamelMimeMessage *mime_message)
{
return CMM_CLASS (mime_message)->get_sent_date (mime_message);
}
-
-
-
static void
-_set_reply_to (CamelMimeMessage *mime_message, GString *reply_to)
+_set_reply_to (CamelMimeMessage *mime_message, gchar *reply_to)
{
_set_field (mime_message, reply_to_str, reply_to, &(mime_message->reply_to));
}
void
-camel_mime_message_set_reply_to (CamelMimeMessage *mime_message, GString *reply_to)
+camel_mime_message_set_reply_to (CamelMimeMessage *mime_message, gchar *reply_to)
{
CMM_CLASS (mime_message)->set_reply_to (mime_message, reply_to);
}
-static GString *
+static const gchar *
_get_reply_to (CamelMimeMessage *mime_message)
{
return _get_field (mime_message, reply_to_str, mime_message->reply_to);
}
-GString *
+const gchar *
camel_mime_message_get_reply_to (CamelMimeMessage *mime_message)
{
return CMM_CLASS (mime_message)->get_reply_to (mime_message);
static void
-_set_subject (CamelMimeMessage *mime_message, GString *subject)
+_set_subject (CamelMimeMessage *mime_message, gchar *subject)
{
_set_field (mime_message, subject_str, subject, &(mime_message->subject));
}
void
-camel_mime_message_set_subject (CamelMimeMessage *mime_message, GString *subject)
+camel_mime_message_set_subject (CamelMimeMessage *mime_message, gchar *subject)
{
CMM_CLASS (mime_message)->set_subject (mime_message, subject);
}
-static GString *
+static const gchar *
_get_subject (CamelMimeMessage *mime_message)
{
return _get_field (mime_message, subject_str, mime_message->subject);
}
-GString *
+const gchar *
camel_mime_message_get_subject (CamelMimeMessage *mime_message)
{
return CMM_CLASS (mime_message)->get_subject (mime_message);
static void
-_set_from (CamelMimeMessage *mime_message, GString *from)
+_set_from (CamelMimeMessage *mime_message, gchar *from)
{
_set_field (mime_message, from_str, from, &(mime_message->from));
}
void
-camel_mime_message_set_from (CamelMimeMessage *mime_message, GString *from)
+camel_mime_message_set_from (CamelMimeMessage *mime_message, gchar *from)
{
CMM_CLASS (mime_message)->set_from (mime_message, from);
}
-static GString *
+static const gchar *
_get_from (CamelMimeMessage *mime_message)
{
return _get_field (mime_message, from_str, mime_message->from);
}
-GString *
+const gchar *
camel_mime_message_get_from (CamelMimeMessage *mime_message)
{
return CMM_CLASS (mime_message)->get_from (mime_message);
static void
-_add_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString *recipient)
+_add_recipient (CamelMimeMessage *mime_message, gchar *recipient_type, gchar *recipient)
{
/* be careful, recipient_type and recipient may be freed within this func */
GList *recipients_list;
existent_list = (GList *)g_hash_table_lookup (mime_message->recipients, recipient_type);
/* if the recipient is already in this list, do nothing */
- if ( existent_list && g_list_find_custom (existent_list, (gpointer)recipient, g_string_equal_for_glist) ) {
- g_string_free (recipient_type, FALSE);
- g_string_free (recipient, FALSE);
+ if ( existent_list && g_list_find_custom (existent_list, (gpointer)recipient, string_equal_for_glist) ) {
+ g_free (recipient_type);
+ g_free (recipient);
return;
}
/* append the new recipient to the recipient list
if (!existent_list) /* if there was no recipient of this type create the section */
g_hash_table_insert (mime_message->recipients, recipient_type, recipients_list);
else
- g_string_free (recipient_type, FALSE);
+ g_free (recipient_type);
}
* @recipient may be freed within this func
**/
void
-camel_mime_message_add_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString *recipient)
+camel_mime_message_add_recipient (CamelMimeMessage *mime_message, gchar *recipient_type, gchar *recipient)
{
CMM_CLASS (mime_message)->add_recipient (mime_message, recipient_type, recipient);
}
* them just after remove_recipient returns.
**/
static void
-_remove_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString *recipient)
+_remove_recipient (CamelMimeMessage *mime_message, const gchar *recipient_type, const gchar *recipient)
{
GList *recipients_list;
GList *new_recipients_list;
GList *old_element;
- GString *old_recipient_type;
+ gchar *old_recipient_type;
/* if the recipient type section does not exist, do nothing */
if (! g_hash_table_lookup_extended (mime_message->recipients,
) return;
/* look for the recipient to remove */
- old_element = g_list_find_custom (recipients_list, recipient, g_string_equal_for_hash);
+ /* g_list_find_custom does use "const" for recipient, is it a mistake ? */
+ old_element = g_list_find_custom (recipients_list, recipient, g_str_equal);
if (old_element) {
/* if recipient exists, remove it */
new_recipients_list = g_list_remove_link (recipients_list, old_element);
if (new_recipients_list != recipients_list)
g_hash_table_insert (mime_message->recipients, old_recipient_type, new_recipients_list);
- g_string_free( (GString *)(old_element->data), FALSE);
- g_list_free_1(old_element);
+ g_free( (gchar *)(old_element->data));
+ g_list_free_1 (old_element);
}
}
void
-camel_mime_message_remove_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString *recipient)
+camel_mime_message_remove_recipient (CamelMimeMessage *mime_message, const gchar *recipient_type, const gchar *recipient)
{
CMM_CLASS (mime_message)->remove_recipient (mime_message, recipient_type, recipient);
}
-
-
-static GList *
-_get_recipients (CamelMimeMessage *mime_message, GString *recipient_type)
+static const GList *
+_get_recipients (CamelMimeMessage *mime_message, const gchar *recipient_type)
{
return (GList *)g_hash_table_lookup (mime_message->recipients, recipient_type);
}
-GList *
-camel_mime_message_get_recipients (CamelMimeMessage *mime_message, GString *recipient_type)
+const GList *
+camel_mime_message_get_recipients (CamelMimeMessage *mime_message, const gchar *recipient_type)
{
return CMM_CLASS (mime_message)->get_recipients (mime_message, recipient_type);
}
-
-
static void
-_set_flag (CamelMimeMessage *mime_message, GString *flag, gboolean value)
+_set_flag (CamelMimeMessage *mime_message, gchar *flag, gboolean value)
{
- GString old_flags;
+ gchar old_flags;
gboolean *ptr_value;
if (! g_hash_table_lookup_extended (mime_message->flags,
flag,
ptr_value = g_new (gboolean, 1);
g_hash_table_insert (mime_message->flags, flag, ptr_value);
} else {
- g_string_free (flag, FALSE);
+ g_free (flag);
}
*ptr_value = value;
}
void
-camel_mime_message_set_flag (CamelMimeMessage *mime_message, GString *flag, gboolean value)
+camel_mime_message_set_flag (CamelMimeMessage *mime_message, gchar *flag, gboolean value)
{
CMM_CLASS (mime_message)->set_flag (mime_message, flag, value);
}
static gboolean
-_get_flag (CamelMimeMessage *mime_message, GString *flag)
+_get_flag (CamelMimeMessage *mime_message, gchar *flag)
{
gboolean *value;
value = (gboolean *)g_hash_table_lookup (mime_message->flags, flag);
}
gboolean
-camel_mime_message_get_flag (CamelMimeMessage *mime_message, GString *flag)
+camel_mime_message_get_flag (CamelMimeMessage *mime_message, gchar *flag)
{
return CMM_CLASS (mime_message)->get_flag (mime_message, flag);
}
static void
_write_one_recipient_to_stream (gpointer key, gpointer value, gpointer user_data)
{
- GString *recipient_type = (GString *)key;
+ gchar *recipient_type = (gchar *)key;
GList *recipients = (GList *)value;
- // GString *current;
+ // gchar *current;
CamelStream *stream = (CamelStream *)user_data;
- if ( (recipient_type) && (recipient_type->str) )
- write_header_with_glist_to_stream (stream, recipient_type->str, recipients, ", ");
+ if (recipient_type)
+ write_header_with_glist_to_stream (stream, recipient_type, recipients, ", ");
}
static void
_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
CamelMimeMessage *mm = CAMEL_MIME_MESSAGE (data_wrapper);
- CAMEL_LOG (FULL_DEBUG, "CamelMimeMessage::write_to_stream\n");
- CAMEL_LOG (FULL_DEBUG, "Writing \"From\"\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage::write_to_stream\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage:: Writing \"From\"\n");
WHPT (stream, "From", mm->from);
- CAMEL_LOG (FULL_DEBUG, "Writing \"Reply-To\"\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage:: Writing \"Reply-To\"\n");
WHPT (stream, "Reply-To", mm->reply_to);
- CAMEL_LOG (FULL_DEBUG, "Writing recipients\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage:: Writing recipients\n");
_write_recipients_to_stream (mm, stream);
- CAMEL_LOG (FULL_DEBUG, "Writing \"Date\"\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage:: Writing \"Date\"\n");
WHPT (stream, "Date", mm->received_date);
- CAMEL_LOG (FULL_DEBUG, "Writing \"Subject\"\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage:: Writing \"Subject\"\n");
WHPT (stream, "Subject", mm->subject);
CAMEL_DATA_WRAPPER_CLASS (parent_class)->write_to_stream (data_wrapper, stream);
/* mime message header parsing */
static void
-_set_recipient_list_from_string (CamelMimeMessage *message, GString *recipient_type, GString *recipients_string)
+_set_recipient_list_from_string (CamelMimeMessage *message, gchar *recipient_type, gchar *recipients_string)
{
GList *recipients_list;
- CAMEL_LOG (FULL_DEBUG,"CamelMimeMessage::_set_recipient_list_from_string parsing ##%s##\n", recipients_string->str);
- recipients_list = g_string_split (
+ CAMEL_LOG_FULL_DEBUG ("CamelMimeMessage::_set_recipient_list_from_string parsing ##%s##\n", recipients_string);
+ recipients_list = string_split (
recipients_string, ',', "\t ",
- GSTRING_TRIM_STRIP_TRAILING | GSTRING_TRIM_STRIP_LEADING);
+ STRING_TRIM_STRIP_TRAILING | STRING_TRIM_STRIP_LEADING);
g_hash_table_insert (message->recipients, recipient_type, recipients_list);
}
static gboolean
-_parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *header_value)
+_parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_value)
{
CamelHeaderType header_type;
CamelMimeMessage *message = CAMEL_MIME_MESSAGE (mime_part);
switch (header_type) {
case HEADER_FROM:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimeMessage::parse_header_pair found HEADER_FROM : %s\n",
- header_value->str );
+ header_value );
camel_mime_message_set_from (message, header_value);
header_handled = TRUE;
break;
case HEADER_REPLY_TO:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimeMessage::parse_header_pair found HEADER_REPLY_YO : %s\n",
- header_value->str );
+ header_value );
camel_mime_message_set_reply_to (message, header_value);
header_handled = TRUE;
break;
case HEADER_SUBJECT:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimeMessage::parse_header_pair found HEADER_SUBJECT : %s\n",
- header_value->str );
+ header_value );
camel_mime_message_set_subject (message, header_value);
header_handled = TRUE;
break;
case HEADER_TO:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimeMessage::parse_header_pair found HEADER_TO : %s\n",
- header_value->str );
+ header_value );
- _set_recipient_list_from_string (message, g_string_new ("To"), header_value);
- g_string_free (header_value, TRUE);
+ _set_recipient_list_from_string (message, "To", header_value);
+ g_free (header_value);
header_handled = TRUE;
break;
case HEADER_CC:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimeMessage::parse_header_pair found HEADER_CC : %s\n",
- header_value->str );
+ header_value );
- _set_recipient_list_from_string (message, g_string_new ("Cc"), header_value);
- g_string_free (header_value, TRUE);
+ _set_recipient_list_from_string (message, "Cc", header_value);
+ g_free (header_value);
header_handled = TRUE;
break;
case HEADER_BCC:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimeMessage::parse_header_pair found HEADER_BCC : %s\n",
- header_value->str );
+ header_value );
- _set_recipient_list_from_string (message, g_string_new ("Bcc"), header_value);
- g_string_free (header_value, TRUE);
+ _set_recipient_list_from_string (message, "Bcc", header_value);
+ g_free (header_value);
header_handled = TRUE;
break;
}
if (header_handled) {
- g_string_free (header_name, TRUE);
+ g_free (header_name);
return TRUE;
} else
return parent_class->parse_header_pair (mime_part, header_name, header_value);
CamelMimePart parent_object;
/* header fields */
- GString *received_date;
- GString *sent_date;
+ gchar *received_date;
+ gchar *sent_date;
- GString *subject;
- GString *reply_to;
+ gchar *subject;
+ gchar *reply_to;
- GString *from;
+ gchar *from;
GHashTable *recipients;
/* -> each value is a GList of address strings */
/* each key is a recipient type string in lower-case */
CamelMimePartClass parent_class;
/* Virtual methods */
- void (*set_received_date) (CamelMimeMessage *mime_message,
- GString *received_date);
- GString * (*get_received_date) (CamelMimeMessage *mime_message);
- GString * (*get_sent_date) (CamelMimeMessage *mime_message);
- void (*set_reply_to) (CamelMimeMessage *mime_message,
- GString *reply_to);
- GString * (*get_reply_to) (CamelMimeMessage *mime_message);
- void (*set_subject) (CamelMimeMessage *mime_message,
- GString *subject);
- GString * (*get_subject) (CamelMimeMessage *mime_message);
- void (*set_from) (CamelMimeMessage *mime_message,
- GString *from);
- GString * (*get_from) (CamelMimeMessage *mime_message);
- void (*add_recipient) (CamelMimeMessage *mime_message,
- GString *recipient_type,
- GString *recipient);
- void (*remove_recipient) (CamelMimeMessage *mime_message,
- GString *recipient_type,
- GString *recipient);
- GList * (*get_recipients) (CamelMimeMessage *mime_message,
- GString *recipient_type);
- void (*set_flag) (CamelMimeMessage *mime_message,
- GString *flag, gboolean value);
- gboolean (*get_flag) (CamelMimeMessage *mime_message,
- GString *flag);
-
- void (*set_message_number)(CamelMimeMessage *mime_message,
- guint number);
- guint (*get_message_number)(CamelMimeMessage *mime_message);
+ void (*set_received_date) (CamelMimeMessage *mime_message, gchar *received_date);
+ const gchar * (*get_received_date) (CamelMimeMessage *mime_message);
+ const gchar * (*get_sent_date) (CamelMimeMessage *mime_message);
+ void (*set_reply_to) (CamelMimeMessage *mime_message, gchar *reply_to);
+ const gchar * (*get_reply_to) (CamelMimeMessage *mime_message);
+ void (*set_subject) (CamelMimeMessage *mime_message, gchar *subject);
+ const gchar * (*get_subject) (CamelMimeMessage *mime_message);
+ void (*set_from) (CamelMimeMessage *mime_message, gchar *from);
+ const gchar * (*get_from) (CamelMimeMessage *mime_message);
+ void (*add_recipient) (CamelMimeMessage *mime_message, gchar *recipient_type, gchar *recipient);
+ void (*remove_recipient) (CamelMimeMessage *mime_message, const gchar *recipient_type, const gchar *recipient);
+ const GList * (*get_recipients) (CamelMimeMessage *mime_message, const gchar *recipient_type);
+ void (*set_flag) (CamelMimeMessage *mime_message, gchar *flag, gboolean value);
+ gboolean (*get_flag) (CamelMimeMessage *mime_message, gchar *flag);
+
+ void (*set_message_number)(CamelMimeMessage *mime_message, guint number);
+ guint (*get_message_number)(CamelMimeMessage *mime_message);
} CamelMimeMessageClass;
CamelMimeMessage *camel_mime_message_new_with_session (CamelSession *session);
-void camel_mime_message_set_received_date (CamelMimeMessage *mime_message,
- GString *received_date);
-GString *camel_mime_message_get_received_date (CamelMimeMessage *mime_message);
-GString *camel_mime_message_get_sent_date (CamelMimeMessage *mime_message);
-void camel_mime_message_set_reply_to (CamelMimeMessage *mime_message,
- GString *reply_to);
-GString *camel_mime_message_get_reply_to (CamelMimeMessage *mime_message);
-void camel_mime_message_set_subject (CamelMimeMessage *mime_message,
- GString *subject);
-GString *camel_mime_message_get_subject (CamelMimeMessage *mime_message);
-void camel_mime_message_set_from (CamelMimeMessage *mime_message, GString *from);
-GString *camel_mime_message_get_from (CamelMimeMessage *mime_message);
-
-void camel_mime_message_add_recipient (CamelMimeMessage *mime_message,
- GString *recipient_type,
- GString *recipient);
-void camel_mime_message_remove_recipient (CamelMimeMessage *mime_message,
- GString *recipient_type,
- GString *recipient);
-GList *camel_mime_message_get_recipients (CamelMimeMessage *mime_message,
- GString *recipient_type);
-
-void camel_mime_message_set_flag (CamelMimeMessage *mime_message,
- GString *flag, gboolean value);
-gboolean camel_mime_message_get_flag (CamelMimeMessage *mime_message,
- GString *flag);
-
-guint camel_mime_message_get_message_number (CamelMimeMessage *mime_message);
+void camel_mime_message_set_received_date (CamelMimeMessage *mime_message, gchar *received_date);
+const gchar *camel_mime_message_get_received_date (CamelMimeMessage *mime_message);
+const gchar *camel_mime_message_get_sent_date (CamelMimeMessage *mime_message);
+void camel_mime_message_set_reply_to (CamelMimeMessage *mime_message, gchar *reply_to);
+const gchar *camel_mime_message_get_reply_to (CamelMimeMessage *mime_message);
+void camel_mime_message_set_subject (CamelMimeMessage *mime_message, gchar *subject);
+const gchar *camel_mime_message_get_subject (CamelMimeMessage *mime_message);
+void camel_mime_message_set_from (CamelMimeMessage *mime_message, gchar *from);
+const gchar *camel_mime_message_get_from (CamelMimeMessage *mime_message);
+
+void camel_mime_message_add_recipient (CamelMimeMessage *mime_message, gchar *recipient_type, gchar *recipient);
+void camel_mime_message_remove_recipient (CamelMimeMessage *mime_message, const gchar *recipient_type, const gchar *recipient);
+const GList *camel_mime_message_get_recipients (CamelMimeMessage *mime_message, const gchar *recipient_type);
+
+void camel_mime_message_set_flag (CamelMimeMessage *mime_message, gchar *flag, gboolean value);
+gboolean camel_mime_message_get_flag (CamelMimeMessage *mime_message, gchar *flag);
+
+guint camel_mime_message_get_message_number (CamelMimeMessage *mime_message);
#ifdef __cplusplus
}
#include "camel-mime-part.h"
#include <stdio.h>
#include "gmime-content-field.h"
-#include "gstring-util.h"
+#include "string-utils.h"
#include "camel-log.h"
#include "gmime-utils.h"
+#include "camel-simple-data-wrapper.h"
typedef enum {
/* Returns the class for a CamelMimePart */
#define CMP_CLASS(so) CAMEL_MIME_PART_CLASS (GTK_OBJECT(so)->klass)
-static void _add_header (CamelMimePart *mime_part, GString *header_name, GString *header_value);
-static void _remove_header (CamelMimePart *mime_part, GString *header_name);
-static GString *_get_header (CamelMimePart *mime_part, GString *header_name);
-static void _set_description (CamelMimePart *mime_part, GString *description);
-static GString *_get_description (CamelMimePart *mime_part);
-static void _set_disposition (CamelMimePart *mime_part, GString *disposition);
-static GString *_get_disposition (CamelMimePart *mime_part);
-static void _set_filename (CamelMimePart *mime_part, GString *filename);
-static GString *_get_filename (CamelMimePart *mime_part);
-static void _set_content_id (CamelMimePart *mime_part, GString *content_id);
-static GString *_get_content_id (CamelMimePart *mime_part);
-static void _set_content_MD5 (CamelMimePart *mime_part, GString *content_MD5);
-static GString *_get_content_MD5 (CamelMimePart *mime_part);
-static void _set_encoding (CamelMimePart *mime_part, GString *encoding);
-static GString *_get_encoding (CamelMimePart *mime_part);
+static void _add_header (CamelMimePart *mime_part, gchar *header_name, gchar *header_value);
+static void _remove_header (CamelMimePart *mime_part, const gchar *header_name);
+static const gchar *_get_header (CamelMimePart *mime_part, const gchar *header_name);
+static void _set_description (CamelMimePart *mime_part, gchar *description);
+static const gchar *_get_description (CamelMimePart *mime_part);
+static void _set_disposition (CamelMimePart *mime_part, gchar *disposition);
+static const gchar *_get_disposition (CamelMimePart *mime_part);
+static void _set_filename (CamelMimePart *mime_part, gchar *filename);
+static const gchar *_get_filename (CamelMimePart *mime_part);
+static void _set_content_id (CamelMimePart *mime_part, gchar *content_id);
+static const gchar *_get_content_id (CamelMimePart *mime_part);
+static void _set_content_MD5 (CamelMimePart *mime_part, gchar *content_MD5);
+static const gchar *_get_content_MD5 (CamelMimePart *mime_part);
+static void _set_encoding (CamelMimePart *mime_part, gchar *encoding);
+static const gchar *_get_encoding (CamelMimePart *mime_part);
static void _set_content_languages (CamelMimePart *mime_part, GList *content_languages);
-static GList *_get_content_languages (CamelMimePart *mime_part);
+static const 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 const GList *_get_header_lines (CamelMimePart *mime_part);
+static void _set_content_type (CamelMimePart *mime_part, const gchar *content_type);
+static GMimeContentField *_get_content_type (CamelMimePart *mime_part);
-static CamelDataWrapper *_get_content_object(CamelMimePart *mime_part);
-static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
+static const CamelDataWrapper *_get_content_object(CamelMimePart *mime_part);
+static void _set_content_object(CamelMimePart *mime_part, CamelDataWrapper *content);
-static gboolean _parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *header_value);
+static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
+static gboolean _parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_value);
void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
static void
_init_header_name_table()
{
- header_name_table = g_hash_table_new (g_string_hash, g_string_equal_for_hash);
- g_hash_table_insert (header_name_table, g_string_new ("Content-Description"), (gpointer)HEADER_DESCRIPTION);
- g_hash_table_insert (header_name_table, g_string_new ("Content-Disposition"), (gpointer)HEADER_DISPOSITION);
- g_hash_table_insert (header_name_table, g_string_new ("Content-id"), (gpointer)HEADER_CONTENT_ID);
- g_hash_table_insert (header_name_table, g_string_new ("Content-Transfer-Encoding"), (gpointer)HEADER_ENCODING);
- g_hash_table_insert (header_name_table, g_string_new ("Content-MD5"), (gpointer)HEADER_CONTENT_MD5);
- g_hash_table_insert (header_name_table, g_string_new ("Content-Type"), (gpointer)HEADER_CONTENT_TYPE);
-
+ header_name_table = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_insert (header_name_table, "Content-Description", (gpointer)HEADER_DESCRIPTION);
+ g_hash_table_insert (header_name_table, "Content-Disposition", (gpointer)HEADER_DISPOSITION);
+ g_hash_table_insert (header_name_table, "Content-id", (gpointer)HEADER_CONTENT_ID);
+ g_hash_table_insert (header_name_table, "Content-Transfer-Encoding", (gpointer)HEADER_ENCODING);
+ g_hash_table_insert (header_name_table, "Content-MD5", (gpointer)HEADER_CONTENT_MD5);
+ g_hash_table_insert (header_name_table, "Content-Type", (gpointer)HEADER_CONTENT_TYPE);
+
}
static void
camel_mime_part_class->get_header_lines =_get_header_lines;
camel_mime_part_class->set_content_type = _set_content_type;
camel_mime_part_class->get_content_type = _get_content_type;
-
+
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_object = _set_content_object;
+
/* virtual method overload */
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->headers = g_hash_table_new (g_str_hash, g_str_equal);
camel_mime_part->content_type = gmime_content_field_new (NULL, NULL);
}
static void
-_add_header (CamelMimePart *mime_part, GString *header_name, GString *header_value)
+_add_header (CamelMimePart *mime_part, gchar *header_name, gchar *header_value)
{
gboolean header_exists;
- GString *old_header_name;
- GString *old_header_value;
-
+ gchar *old_header_name;
+ gchar *old_header_value;
+
/* Try to parse the header pair. If it corresponds to something */
/* known, the job is done in the parsing routine. If not, */
/* we simply add the header in a raw fashion */
(gpointer *) &old_header_name,
(gpointer *) &old_header_value);
if (header_exists) {
- g_string_free (old_header_name, TRUE);
- g_string_free (old_header_value, TRUE);
+ g_free (old_header_name);
+ g_free (old_header_value);
}
g_hash_table_insert (mime_part->headers, header_name, header_value);
void
-camel_mime_part_add_header (CamelMimePart *mime_part, GString *header_name, GString *header_value)
+camel_mime_part_add_header (CamelMimePart *mime_part, gchar *header_name, gchar *header_value)
{
CMP_CLASS(mime_part)->add_header(mime_part, header_name, header_value);
}
static void
-_remove_header (CamelMimePart *mime_part, GString *header_name)
+_remove_header (CamelMimePart *mime_part, const gchar *header_name)
{
gboolean header_exists;
- GString *old_header_name;
- GString *old_header_value;
-
+ gchar *old_header_name;
+ gchar *old_header_value;
+
header_exists = g_hash_table_lookup_extended (mime_part->headers, header_name,
(gpointer *) &old_header_name,
(gpointer *) &old_header_value);
if (header_exists) {
- g_string_free (old_header_name, TRUE);
- g_string_free (old_header_value, TRUE);
+ g_free (old_header_name);
+ g_free (old_header_value);
}
g_hash_table_remove (mime_part->headers, header_name);
}
void
-camel_mime_part_remove_header (CamelMimePart *mime_part, GString *header_name)
+camel_mime_part_remove_header (CamelMimePart *mime_part, const gchar *header_name)
{
CMP_CLASS(mime_part)->remove_header(mime_part, header_name);
}
-static GString *
-_get_header (CamelMimePart *mime_part, GString *header_name)
+static const gchar *
+_get_header (CamelMimePart *mime_part, const gchar *header_name)
{
- GString *old_header_name;
- GString *old_header_value;
- GString *header_value;
-
- header_value = (GString *)g_hash_table_lookup (mime_part->headers, header_name);
+ gchar *old_header_name;
+ gchar *old_header_value;
+ gchar *header_value;
+
+ header_value = (gchar *)g_hash_table_lookup (mime_part->headers, header_name);
return header_value;
}
-GString *
-camel_mime_part_get_header (CamelMimePart *mime_part, GString *header_name)
+const gchar *
+camel_mime_part_get_header (CamelMimePart *mime_part, const gchar *header_name)
{
return CMP_CLASS(mime_part)->get_header (mime_part, header_name);
}
static void
-_set_description (CamelMimePart *mime_part, GString *description)
+_set_description (CamelMimePart *mime_part, gchar *description)
{
- if (mime_part->description) g_free(mime_part->description);
+ if (mime_part->description) g_free (mime_part->description);
mime_part->description = description;
}
void
-camel_mime_part_set_description (CamelMimePart *mime_part, GString *description)
+camel_mime_part_set_description (CamelMimePart *mime_part, gchar *description)
{
CMP_CLASS(mime_part)->set_description (mime_part, description);
}
-static GString *
+static const gchar *
_get_description (CamelMimePart *mime_part)
{
return mime_part->description;
}
-GString *
+const gchar *
camel_mime_part_get_description (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_description (mime_part);
static void
-_set_disposition (CamelMimePart *mime_part, GString *disposition)
+_set_disposition (CamelMimePart *mime_part, gchar *disposition)
{
+#warning Do not use MimeContentfield here !!!
//if (mime_part->disposition) g_free(mime_part->disposition);
if (!mime_part->disposition)
mime_part->disposition = g_new (GMimeContentField,1);
void
-camel_mime_part_set_disposition (CamelMimePart *mime_part, GString *disposition)
+camel_mime_part_set_disposition (CamelMimePart *mime_part, gchar *disposition)
{
CMP_CLASS(mime_part)->set_disposition (mime_part, disposition);
}
-static GString *
+static const gchar *
_get_disposition (CamelMimePart *mime_part)
{
if (!mime_part->disposition) return NULL;
}
-GString *
+const gchar *
camel_mime_part_get_disposition (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_disposition (mime_part);
static void
-_set_filename (CamelMimePart *mime_part, GString *filename)
+_set_filename (CamelMimePart *mime_part, gchar *filename)
{
if (mime_part->filename) g_free(mime_part->filename);
mime_part->filename = filename;
void
-camel_mime_part_set_filename (CamelMimePart *mime_part, GString *filename)
+camel_mime_part_set_filename (CamelMimePart *mime_part, gchar *filename)
{
CMP_CLASS(mime_part)->set_filename (mime_part, filename);
}
-static GString *
+static const gchar *
_get_filename (CamelMimePart *mime_part)
{
return mime_part->filename;
}
-GString *
+const gchar *
camel_mime_part_get_filename (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_filename (mime_part);
/* this routine must not be public */
static void
-_set_content_id (CamelMimePart *mime_part, GString *content_id)
+_set_content_id (CamelMimePart *mime_part, gchar *content_id)
{
if (mime_part->content_id) g_free(mime_part->content_id);
mime_part->content_id = content_id;
}
-static GString *
+static const gchar *
_get_content_id (CamelMimePart *mime_part)
{
return mime_part->content_id;
}
-GString *
+const gchar *
camel_mime_part_get_content_id (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_content_id (mime_part);
/* this routine must not be public */
static void
-_set_content_MD5 (CamelMimePart *mime_part, GString *content_MD5)
+_set_content_MD5 (CamelMimePart *mime_part, gchar *content_MD5)
{
if (mime_part->content_MD5) g_free(mime_part->content_MD5);
mime_part->content_MD5 = content_MD5;
}
-static GString *
+static const gchar *
_get_content_MD5 (CamelMimePart *mime_part)
{
return mime_part->content_MD5;
}
-GString *
+const gchar *
camel_mime_part_get_content_MD5 (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_content_MD5 (mime_part);
static void
-_set_encoding (CamelMimePart *mime_part, GString *encoding)
+_set_encoding (CamelMimePart *mime_part, gchar *encoding)
{
if (mime_part->encoding) g_free(mime_part->encoding);
mime_part->encoding = encoding;
}
void
-camel_mime_part_set_encoding (CamelMimePart *mime_part, GString *encoding)
+camel_mime_part_set_encoding (CamelMimePart *mime_part, gchar *encoding)
{
CMP_CLASS(mime_part)->set_encoding (mime_part, encoding);
}
-static GString *
+static const gchar *
_get_encoding (CamelMimePart *mime_part)
{
return mime_part->encoding;
}
-GString *
+const gchar *
camel_mime_part_get_encoding (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_encoding (mime_part);
static void
_set_content_languages (CamelMimePart *mime_part, GList *content_languages)
{
- if (mime_part->content_languages) g_string_list_free(mime_part->content_languages);
+ if (mime_part->content_languages) string_list_free (mime_part->content_languages);
mime_part->content_languages = content_languages;
}
-static GList *
+static const GList *
_get_content_languages (CamelMimePart *mime_part)
{
return mime_part->content_languages;
}
-GList *
+const GList *
camel_mime_part_get_content_languages (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_content_languages (mime_part);
static void
_set_header_lines (CamelMimePart *mime_part, GList *header_lines)
{
- if (mime_part->header_lines) g_string_list_free(mime_part->header_lines);
+ if (mime_part->header_lines) string_list_free (mime_part->header_lines);
mime_part->header_lines = header_lines;
}
-static GList *
+static const GList *
_get_header_lines (CamelMimePart *mime_part)
{
return mime_part->header_lines;
-GList *
+const GList *
camel_mime_part_get_header_lines (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_header_lines (mime_part);
/*********/
static void
-_set_content_type (CamelMimePart *mime_part, GString *content_type)
+_set_content_type (CamelMimePart *mime_part, const gchar *content_type)
{
g_assert (content_type);
gmime_content_field_construct_from_string (mime_part->content_type, content_type);
}
void
-camel_mime_part_set_mime_type (CamelMimePart *mime_part, GString *content_type)
+camel_mime_part_set_content_type (CamelMimePart *mime_part, gchar *content_type)
{
CMP_CLASS(mime_part)->set_content_type (mime_part, content_type);
}
-static GString *
+static GMimeContentField *
_get_content_type (CamelMimePart *mime_part)
{
- GString *mime_type;
-
- mime_type = gmime_content_field_get_mime_type (mime_part->content_type);
- return mime_type;
+ return mime_part->content_type;
}
-static GString *
+GMimeContentField *
camel_mime_part_get_content_type (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_content_type (mime_part);
}
+
/*********/
-static CamelDataWrapper *
+static const CamelDataWrapper *
_get_content_object(CamelMimePart *mime_part)
{
return mime_part->content;
-
+
}
-CamelDataWrapper *
+const CamelDataWrapper *
camel_mime_part_get_content_object(CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_content_object (mime_part);
}
+static void
+_set_content_object(CamelMimePart *mime_part, CamelDataWrapper *content)
+{
+ CAMEL_LOG_FULL_DEBUG ("Entering CamelMimePart::set_content_object\n");
+ if (mime_part->content) {
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::set_content_object unreferencing old content object\n");
+ gtk_object_unref (GTK_OBJECT (mime_part->content));
+ }
+ gtk_object_ref (GTK_OBJECT (content));
+ mime_part->content = content;
+ if (mime_part->content_type) gmime_content_field_free (mime_part->content_type);
+ mime_part->content_type = camel_data_wrapper_get_mime_type_field (content);
+ CAMEL_LOG_FULL_DEBUG ("Leaving CamelMimePart::set_content_object\n");
+
+}
+
+void
+camel_mime_part_set_content_object(CamelMimePart *mime_part, CamelDataWrapper *content)
+{
+ CMP_CLASS(mime_part)->set_content_object (mime_part, content);
+}
+
+
/**********************************************************************/
#define WHPT gmime_write_header_pair_to_stream
-/* This is not used for the moment */
static void
_write_content_to_stream (CamelMimePart *mime_part, CamelStream *stream)
{
gchar *encoded_buffer;
CamelDataWrapper *content = mime_part->content;
+ CAMEL_LOG_FULL_DEBUG ( "Entering CamelMimePart::_write_content_to_stream\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::_write_content_to_stream, content=%p\n", content);
+ if (!content) return;
// buffer_size = camel_data_wrapper_size (content);
- buffer = g_malloc (buffer_size);
+ //buffer = g_malloc (buffer_size);
camel_data_wrapper_write_to_stream (content, stream);
- if (mime_part->encoding) {
+ //if (mime_part->encoding) {
// encoded_buffer_size = gmime_encoded_size(buffer, buffer_size, encoding);
// encoded_buffer = g_malloc (encoded_buffer_size);
// gmime_encode_buffer (buffer, encoded_buffer, encoding);
// camel_stream_write (stream, encoded_buffer, encoded_buffer_size);
// g_free (encoded_buffer);
- } else
+ //} else
//fwrite (buffer, buffer_size, 1, file);
- camel_stream_write (stream, buffer, buffer_size);
- g_free (buffer);
+ //camel_stream_write (stream, buffer, buffer_size);
+ //g_free (buffer);
+ CAMEL_LOG_FULL_DEBUG ( "Leaving CamelMimePart::_write_content_to_stream\n");
}
{
CamelMimePart *mp = CAMEL_MIME_PART (data_wrapper);
- CAMEL_LOG (FULL_DEBUG, "Entering CamelMimePart::write_to_stream\n");
-
- CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-disposition\n");
+ CAMEL_LOG_FULL_DEBUG ( "Entering CamelMimePart::write_to_stream\n");
+
+ 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");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-transfer-encoding\n");
WHPT (stream, "Content-Transfer-Encoding", mp->encoding);
- CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-description\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-description\n");
WHPT (stream, "Content-Description", mp->description);
- CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-MD5\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-MD5\n");
WHPT (stream, "Content-MD5", mp->content_MD5);
- CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-id\n");
+ 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");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-languages\n");
write_header_with_glist_to_stream (stream, "Content-Language", mp->content_languages,", ");
-
- CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing other headers\n");
+
+ 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");
+
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-type\n");
gmime_content_field_write_to_stream(mp->content_type, stream);
-
+
camel_stream_write_string(stream,"\n");
- if (mp->content) camel_data_wrapper_write_to_stream (mp->content, stream);
+ _write_content_to_stream (mp, stream);
}
/* mime part parsing */
static gboolean
-_parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *header_value)
+_parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_value)
{
CamelHeaderType header_type;
gboolean header_handled = FALSE;
-
-
+
+
header_type = (CamelHeaderType) g_hash_table_lookup (header_name_table, header_name);
switch (header_type) {
-
+
case HEADER_DESCRIPTION:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimePart::parse_header_pair found HEADER_DESCRIPTION: %s\n",
- header_value->str );
+ header_value );
camel_mime_part_set_description (mime_part, header_value);
header_handled = TRUE;
break;
-
+
case HEADER_DISPOSITION:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimePart::parse_header_pair found HEADER_DISPOSITION: %s\n",
- header_value->str );
+ header_value);
camel_mime_part_set_disposition (mime_part, header_value);
header_handled = TRUE;
break;
-
+
case HEADER_CONTENT_ID:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimePart::parse_header_pair found HEADER_CONTENT_ID: %s\n",
- header_value->str );
+ header_value);
CMP_CLASS(mime_part)->set_content_id (mime_part, header_value);
header_handled = TRUE;
break;
case HEADER_ENCODING:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimePart::parse_header_pair found HEADER_ENCODING: %s\n",
- header_value->str );
+ header_value);
camel_mime_part_set_encoding (mime_part, header_value);
header_handled = TRUE;
break;
case HEADER_CONTENT_MD5:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimePart::parse_header_pair found HEADER_CONTENT_MD5: %s\n",
- header_value->str );
-
+ header_value );
+
CMP_CLASS(mime_part)->set_content_MD5 (mime_part, header_value);
header_handled = TRUE;
break;
case HEADER_CONTENT_TYPE:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimePart::parse_header_pair found HEADER_CONTENT_TYPE: %s\n",
- header_value->str );
+ header_value );
gmime_content_field_construct_from_string (mime_part->content_type, header_value);
header_handled = TRUE;
}
-
-
+
+
if (header_handled) {
- g_string_free (header_name, TRUE);
+ g_free (header_name);
return TRUE;
} else return FALSE;
-
+
}
/* calls _parse_header_pair, but can be called
void
_parse_hash_table_pair (gpointer key, gpointer value, gpointer user_data)
{
- GString *header_name = (GString *)key;
- GString *header_value = (GString *)value;
+ gchar *header_name = (gchar *)key;
+ gchar *header_value = (gchar *)value;
CamelMimePart *mime_part = (CamelMimePart *) user_data;
-
-
- CAMEL_LOG (FULL_DEBUG,"\n--------- New Header ----------\n");
- if ((header_name) && (header_name->str))
- CAMEL_LOG (FULL_DEBUG, "header name :%s\n", header_name->str);
- if ((header_value) && (header_value->str))
- CAMEL_LOG (FULL_DEBUG, "header value :%s\n", header_value->str);
-
+
+
+ CAMEL_LOG_FULL_DEBUG ("\n--------- New Header ----------\n");
+ if (header_name)
+ CAMEL_LOG_FULL_DEBUG ( "header name :%s\n", header_name);
+ if (header_value)
+ CAMEL_LOG_FULL_DEBUG ( "header value :%s\n", header_value);
+
camel_mime_part_add_header (mime_part, header_name, header_value);
- CAMEL_LOG (FULL_DEBUG, "--------- End -----------------\n");
+ CAMEL_LOG_FULL_DEBUG ( "--------- End -----------------\n");
}
void
{
GHashTable *header_table;
CamelMimePart *mime_part = CAMEL_MIME_PART (data_wrapper);
-
+ GMimeContentField *content_type;
+ gchar *mime_type;
+ GtkType content_object_type;
+ CamelDataWrapper *content_object;
+
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Entering _construct_from_stream\n");
+ g_assert (stream);
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream parsing headers\n");
+ /* parse all header lines */
header_table = get_header_table_from_stream (stream);
if (header_table) {
g_hash_table_foreach (header_table, _parse_hash_table_pair, (gpointer)mime_part);
}
g_hash_table_destroy (header_table);
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream headers parsed \n");
+
+ /* now parse the content */
+ /* find its mime type */
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream parsing content\n");
+ content_type = camel_mime_part_get_content_type (mime_part);
+ mime_type = gmime_content_field_get_mime_type (content_type);
+ if (mime_type) {
+ content_object_type = data_wrapper_get_data_wrapper_type (mime_type);
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream content type object type used: %s\n", gtk_type_name (content_object_type));
+ g_free (mime_type);
+ content_object = CAMEL_DATA_WRAPPER (gtk_type_new (content_object_type));
+ camel_mime_part_set_content_object (mime_part, content_object);
+ camel_data_wrapper_construct_from_stream (content_object, stream);
+
+ } else
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream content type field not found\n");
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream content parsed\n");
+
+
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Leaving _construct_from_stream\n");
+}
+
+
+/******************************/
+/** Misc utility functions **/
+
+
+/**
+ * camel_mime_part_set_text: set the content to be some text
+ * @camel_mime_part: Mime part
+ * @text: the text
+ *
+ * Utility function used to set the content of a mime part object to
+ * be a text string. When @text is NULL, this routine can be used as
+ * a way to remove old text content.
+ *
+ **/
+void
+camel_mime_part_set_text (CamelMimePart *camel_mime_part, gchar *text)
+{
+ CamelSimpleDataWrapper *simple_data_wrapper;
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Entering set_text\n");
+ CAMEL_LOG_TRACE ("CamelMimePart::set_text, setting text as a mime part content\n");
+ if (camel_mime_part->content) {
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::set_text unreferencing old content object\n");
+ gtk_object_unref (GTK_OBJECT (camel_mime_part->content));
+ }
+ if (text) {
+ simple_data_wrapper = camel_simple_data_wrapper_new ();
+ camel_mime_part->content = CAMEL_DATA_WRAPPER (simple_data_wrapper);
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::set_text calling CamelSimpleDataWrapper:set_text with %d chars\n", strlen (text));
+ camel_simple_data_wrapper_set_text ( simple_data_wrapper, text);
+ } else camel_mime_part->content = NULL;
+
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Leaving camel_mime_part_set_text\n");
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camelMimePart.h : class for a mime part */
+/* camel-mime-part.h : class for a mime part */
/*
*
#include "camel-stream.h"
-
#define CAMEL_MIME_PART_TYPE (camel_mime_part_get_type ())
#define CAMEL_MIME_PART(obj) (GTK_CHECK_CAST((obj), CAMEL_MIME_PART_TYPE, CamelMimePart))
#define CAMEL_MIME_PART_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_MIME_PART_TYPE, CamelMimePartClass))
CamelDataWrapper parent_object;
GHashTable *headers;
- GString *description;
+ gchar *description;
GMimeContentField *disposition;
- GString *content_id;
- GString *content_MD5;
+ gchar *content_id;
+ gchar *content_MD5;
GList *content_languages;
- GString *encoding;
- GString *filename;
+ gchar *encoding;
+ gchar *filename;
GList *header_lines;
GMimeContentField *content_type;
CamelDataWrapper *content; /* part real content */
-
+
} CamelMimePart;
CamelDataWrapperClass parent_class;
/* Virtual methods */
- void (*add_header) (CamelMimePart *mime_part, GString *header_name, GString *header_value);
- void (*remove_header) (CamelMimePart *mime_part, GString *header_name);
- GString * (*get_header) (CamelMimePart *mime_part, GString *header_name);
- void (*set_description) (CamelMimePart *mime_part, GString *description);
- GString * (*get_description) (CamelMimePart *mime_part);
- void (*set_disposition) (CamelMimePart *mime_part, GString *disposition);
- GString * (*get_disposition) (CamelMimePart *mime_part);
- void (*set_filename) (CamelMimePart *mime_part, GString *filename);
- GString * (*get_filename) (CamelMimePart *mime_part);
- void (*set_content_id) (CamelMimePart *mime_part, GString *content_id);
- GString * (*get_content_id) (CamelMimePart *mime_part);
- void (*set_content_MD5) (CamelMimePart *mime_part, GString *content_MD5);
- GString * (*get_content_MD5) (CamelMimePart *mime_part);
- void (*set_encoding) (CamelMimePart *mime_part, GString *encoding);
- GString * (*get_encoding) (CamelMimePart *mime_part);
+ void (*add_header) (CamelMimePart *mime_part, gchar *header_name, gchar *header_value);
+ void (*remove_header) (CamelMimePart *mime_part, const gchar *header_name);
+ const gchar * (*get_header) (CamelMimePart *mime_part, const gchar *header_name);
+ void (*set_description) (CamelMimePart *mime_part, gchar *description);
+ const gchar * (*get_description) (CamelMimePart *mime_part);
+ void (*set_disposition) (CamelMimePart *mime_part, gchar *disposition);
+ const gchar * (*get_disposition) (CamelMimePart *mime_part);
+ void (*set_filename) (CamelMimePart *mime_part, gchar *filename);
+ const gchar * (*get_filename) (CamelMimePart *mime_part);
+ void (*set_content_id) (CamelMimePart *mime_part, gchar *content_id);
+ const gchar * (*get_content_id) (CamelMimePart *mime_part);
+ void (*set_content_MD5) (CamelMimePart *mime_part, gchar *content_MD5);
+ const gchar * (*get_content_MD5) (CamelMimePart *mime_part);
+ void (*set_encoding) (CamelMimePart *mime_part, gchar *encoding);
+ const gchar * (*get_encoding) (CamelMimePart *mime_part);
void (*set_content_languages) (CamelMimePart *mime_part, GList *content_languages);
- GList * (*get_content_languages) (CamelMimePart *mime_part);
+ const 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);
+ const GList * (*get_header_lines) (CamelMimePart *mime_part);
+ void (*set_content_type) (CamelMimePart *mime_part, const gchar *content_type);
+ GMimeContentField * (*get_content_type) (CamelMimePart *mime_part);
- CamelDataWrapper * (*get_content_object) (CamelMimePart *mime_part);
+ gboolean (*parse_header_pair) (CamelMimePart *mime_part, gchar *header_name, gchar *header_value);
+
+ const CamelDataWrapper * (*get_content_object) (CamelMimePart *mime_part);
+ void (*set_content_object) (CamelMimePart *mime_part, CamelDataWrapper *content);
+
} CamelMimePartClass;
/* public methods */
-void camel_mime_part_add_header (CamelMimePart *mime_part,
- GString *header_name,
- GString *header_value);
-void camel_mime_part_remove_header (CamelMimePart *mime_part,
- GString *header_name);
-GString *camel_mime_part_get_header (CamelMimePart *mime_part,
- GString *header_name);
-void camel_mime_part_set_description (CamelMimePart *mime_part,
- GString *description);
-GString *camel_mime_part_get_description (CamelMimePart *mime_part);
-void camel_mime_part_set_disposition (CamelMimePart *mime_part,
- GString *disposition);
-GString *camel_mime_part_get_disposition (CamelMimePart *mime_part);
-void camel_mime_part_set_filename (CamelMimePart *mime_part,
- GString *filename);
-GString *camel_mime_part_get_filename (CamelMimePart *mime_part);
-GString *camel_mime_part_get_content_id (CamelMimePart *mime_part);
-GString *camel_mime_part_get_content_MD5 (CamelMimePart *mime_part);
-void camel_mime_part_set_encoding (CamelMimePart *mime_part,
- GString *encoding);
-GString *camel_mime_part_get_encoding (CamelMimePart *mime_part);
-void camel_mime_part_set_content_languages (CamelMimePart *mime_part,
- GList *content_languages);
-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_add_header (CamelMimePart *mime_part, gchar *header_name, gchar *header_value);
+void camel_mime_part_remove_header (CamelMimePart *mime_part, const gchar *header_name);
+const gchar *camel_mime_part_get_header (CamelMimePart *mime_part, const gchar *header_name);
+void camel_mime_part_set_description (CamelMimePart *mime_part, gchar *description);
+const gchar *camel_mime_part_get_description (CamelMimePart *mime_part);
+void camel_mime_part_set_disposition (CamelMimePart *mime_part, gchar *disposition);
+const gchar *camel_mime_part_get_disposition (CamelMimePart *mime_part);
+void camel_mime_part_set_filename (CamelMimePart *mime_part, gchar *filename);
+const gchar *camel_mime_part_get_filename (CamelMimePart *mime_part);
+const gchar *camel_mime_part_get_content_id (CamelMimePart *mime_part);
+const gchar *camel_mime_part_get_content_MD5 (CamelMimePart *mime_part);
+void camel_mime_part_set_encoding (CamelMimePart *mime_part, gchar *encoding);
+const gchar *camel_mime_part_get_encoding (CamelMimePart *mime_part);
+void camel_mime_part_set_content_languages (CamelMimePart *mime_part, GList *content_languages);
+const GList *camel_mime_part_get_content_languages (CamelMimePart *mime_part);
+void camel_mime_part_set_header_lines (CamelMimePart *mime_part, GList *header_lines);
+const GList *camel_mime_part_get_header_lines (CamelMimePart *mime_part);
+
+const CamelDataWrapper *camel_mime_part_get_content_object (CamelMimePart *mime_part);
+void camel_mime_part_set_content_object (CamelMimePart *mime_part, CamelDataWrapper *content);
+
+
+/* utility functions */
+void camel_mime_part_set_text (CamelMimePart *camel_mime_part, gchar *text);
+
+
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* CAMEL_MIME_PART_H */
+
#define CSERV_CLASS(so) CAMEL_SERVICE_CLASS (GTK_OBJECT(so)->klass)
static void _connect(CamelService *service);
-static void _connect_to_with_login_passwd(CamelService *service, GString *host, GString *login, GString *passwd);
-static void _connect_to_with_login_passwd_port(CamelService *service, GString *host, GString *login, GString *passwd, guint port);
-static gboolean _is_connected(CamelService *service);
-static void _set_connected(CamelService *service, gboolean state);
-static GString *_get_url(CamelService *service);
+static void _connect_to_with_login_passwd (CamelService *service, gchar *host, gchar *login, gchar *passwd);
+static void _connect_to_with_login_passwd_port (CamelService *service, gchar *host, gchar *login, gchar *passwd, guint port);
+static gboolean _is_connected (CamelService *service);
+static void _set_connected (CamelService *service, gboolean state);
+static const gchar *_get_url (CamelService *service);
static void
camel_service_class_init (CamelServiceClass *camel_service_class)
* @service: object to connect
**/
static void
-_connect(CamelService *service)
+_connect (CamelService *service)
{
CSERV_CLASS(service)->set_connected(service, TRUE);
}
* @service: object to connect to
**/
void
-camel_service_connect(CamelService *service)
+camel_service_connect (CamelService *service)
{
CSERV_CLASS(service)->connect(service);
}
* @passwd: password used to log in
**/
static void
-_connect_to_with_login_passwd(CamelService *service, GString *host, GString *login, GString *passwd)
+_connect_to_with_login_passwd (CamelService *service, gchar *host, gchar *login, gchar *passwd)
{
CSERV_CLASS(service)->set_connected(service, TRUE);
}
*
**/
void
-camel_service_connect_to_with_login_passwd(CamelService *service, GString *host, GString *login, GString *passwd)
+camel_service_connect_to_with_login_passwd (CamelService *service, gchar *host, gchar *login, gchar *passwd)
{
CSERV_CLASS(service)->connect_to_with_login_passwd (service, host, login, passwd);
}
*
**/
static void
-_connect_to_with_login_passwd_port(CamelService *service, GString *host, GString *login, GString *passwd, guint port)
+_connect_to_with_login_passwd_port(CamelService *service, gchar *host, gchar *login, gchar *passwd, guint port)
{
CSERV_CLASS(service)->set_connected(service, TRUE);
}
*
**/
void
-camel_service_connect_to_with_login_passwd_port(CamelService *service, GString *host, GString *login, GString *passwd, guint port)
+camel_service_connect_to_with_login_passwd_port (CamelService *service, gchar *host, gchar *login, gchar *passwd, guint port)
{
CSERV_CLASS(service)->connect_to_with_login_passwd_port (service, host, login, passwd, port);
}
*
**/
static gboolean
-_is_connected(CamelService *service)
+_is_connected (CamelService *service)
{
return service->connected;
}
* Return value: TRUE is the service is connected
**/
gboolean
-camel_service_is_connected(CamelService *service)
+camel_service_is_connected (CamelService *service)
{
return CSERV_CLASS(service)->is_connected(service);
}
*
**/
static void
-_set_connected(CamelService *service, gboolean state)
+_set_connected (CamelService *service, gboolean state)
{
service->connected = state;
}
*
* Return value:
**/
-static GString *
-_get_url(CamelService *service)
+static const gchar *
+_get_url (CamelService *service)
{
return service->url;
}
*
* Return value: the url name
**/
-GString *
-camel_service_get_url(CamelService *service)
+const gchar *
+camel_service_get_url (CamelService *service)
{
return CSERV_CLASS(service)->get_url(service);
}
GtkObject parent_object;
gboolean connected;
- GString *url; /* This may be a full object ? */
+ gchar *url; /* This may be a full object ? */
} CamelService;
GtkObjectClass parent_class;
void (*connect) (CamelService *service);
- void (*connect_to_with_login_passwd) (CamelService *service, GString *host, GString *login, GString *passwd);
- void (*connect_to_with_login_passwd_port) (CamelService *service, GString *host, GString *login, GString *passwd, guint port);
+ void (*connect_to_with_login_passwd) (CamelService *service, gchar *host, gchar *login, gchar *passwd);
+ void (*connect_to_with_login_passwd_port) (CamelService *service, gchar *host, gchar *login, gchar *passwd, guint port);
gboolean (*is_connected) (CamelService *service);
void (*set_connected) (CamelService *service, gboolean state);
- GString * (*get_url) (CamelService *service);
+ const gchar * (*get_url) (CamelService *service);
} CamelServiceClass;
/* public methods */
void camel_service_connect (CamelService *service);
gboolean camel_service_is_connected (CamelService *service);
-void camel_service_connect_to_with_login_passwd (CamelService *service, GString *host, GString *login, GString *passwd);
-void camel_service_connect_to_with_login_passwd_port (CamelService *service, GString *host, GString *login, GString *passwd, guint port);
-GString *camel_service_get_url(CamelService *service);
+void camel_service_connect_to_with_login_passwd (CamelService *service, gchar *host, gchar *login, gchar *passwd);
+void camel_service_connect_to_with_login_passwd_port (CamelService *service, gchar *host, gchar *login, gchar *passwd, guint port);
+const gchar *camel_service_get_url (CamelService *service);
/* Standard Gtk function */
GtkType camel_service_get_type (void);
*/
#include <config.h>
#include "camel-session.h"
-#include "gstring-util.h"
static GtkObjectClass *parent_class=NULL;
*/
#include <config.h>
#include "camel-simple-data-wrapper.h"
+#include "camel-log.h"
static CamelDataWrapperClass *parent_class=NULL;
/* Returns the class for a CamelDataWrapper */
#define CSDW_CLASS(so) CAMEL_SIMPLE_DATA_WRAPPER_CLASS (GTK_OBJECT(so)->klass)
-static void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream, guint size);
+static void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
static void
if (!camel_simple_data_wrapper_type) {
GtkTypeInfo camel_simple_data_wrapper_info =
{
- "CamelDataWrapper",
- sizeof (CamelDataWrapper),
- sizeof (CamelDataWrapperClass),
+ "CamelSimpleDataWrapper",
+ sizeof (CamelSimpleDataWrapper),
+ sizeof (CamelSimpleDataWrapperClass),
(GtkClassInitFunc) camel_simple_data_wrapper_class_init,
(GtkObjectInitFunc) NULL,
/* reserved_1 */ NULL,
+/**
+ * camel_simple_data_wrapper_new: create a new CamelSimpleDataWrapper object
+ *
+ *
+ *
+ * Return value:
+ **/
+CamelSimpleDataWrapper *
+camel_simple_data_wrapper_new ()
+{
+ CamelSimpleDataWrapper *simple_data_wrapper;
+ CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering new()\n");
+
+ simple_data_wrapper = (CamelSimpleDataWrapper *)gtk_type_new (CAMEL_SIMPLE_DATA_WRAPPER_TYPE);
+ CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Leaving new()\n");
+ return simple_data_wrapper;
+}
+
+
+
static void
_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
CamelSimpleDataWrapper *simple_data_wrapper = CAMEL_SIMPLE_DATA_WRAPPER (data_wrapper);
GByteArray *array;
+ CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering _write_to_stream\n");
g_assert (data_wrapper);
g_assert (stream);
g_assert (simple_data_wrapper->byte_array);
-
array = simple_data_wrapper->byte_array;
if (array->len)
camel_stream_write (stream, (gchar *)array->data, array->len);
- return;
+ CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Leaving _write_to_stream\n");
}
#define _CMSDW_TMP_BUF_SIZE 100
static void
-_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream, guint size)
+_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
CamelSimpleDataWrapper *simple_data_wrapper = CAMEL_SIMPLE_DATA_WRAPPER (data_wrapper);
guint current_index;
guint nb_bytes_left;
static gchar *tmp_buf;
GByteArray *array;
-
+ CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering _construct_from_stream\n");
g_assert (data_wrapper);
g_assert (stream);
- if (!size) return;
if (!tmp_buf) tmp_buf = g_new (gchar, _CMSDW_TMP_BUF_SIZE);
array = simple_data_wrapper->byte_array;
g_byte_array_free (array, FALSE);
array = g_byte_array_new();
- nb_bytes_left = size;
+ simple_data_wrapper->byte_array = array;
do {
-
- nb_bytes_read = camel_stream_read (stream, tmp_buf,
- MIN (_CMSDW_TMP_BUF_SIZE, nb_bytes_left));
- nb_bytes_left -= nb_bytes_read;
- if (nb_bytes_read) g_byte_array_append (array, tmp_buf, nb_bytes_read);
-
- } while (nb_bytes_read && (nb_bytes_left>0));
+ nb_bytes_read = camel_stream_read (stream, tmp_buf, _CMSDW_TMP_BUF_SIZE);
+ if (nb_bytes_read) g_byte_array_append (array, tmp_buf, nb_bytes_read);
+ } while (nb_bytes_read);
+
+ CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Leaving _construct_from_stream\n");
+}
+
+
+
+
+/**
+ * camel_simple_data_wrapper_set_text: set some text as data wrapper content
+ * @simple_data_wrapper: SimpleDataWrapper object
+ * @text: the text to use
+ *
+ * Utility routine used to set up the content of a SimpleDataWrapper object
+ * to be a character string.
+ **/
+void
+camel_simple_data_wrapper_set_text (CamelSimpleDataWrapper *simple_data_wrapper, const gchar *text)
+{
+ GByteArray *array;
+ CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering set_text\n");
+
+ array = simple_data_wrapper->byte_array;
+ if (array) {
+ CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper::set_text freeing old byte array\n");
+ g_byte_array_free (array, FALSE);
+ }
+ array = g_byte_array_new ();
+ simple_data_wrapper->byte_array = array;
+
+ g_byte_array_append (array, text, strlen (text));
+
+ CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering set_text\n");
}
+
/* public methods */
+CamelSimpleDataWrapper *camel_simple_data_wrapper_new ();
+void camel_simple_data_wrapper_set_text (CamelSimpleDataWrapper *simple_data_wrapper, const gchar *text);
#ifdef __cplusplus
}
static void _set_separator(CamelStore *store, gchar sep);
static CamelFolder *_get_root_folder(CamelStore *store);
static CamelFolder *_get_default_folder(CamelStore *store);
-static void _init(CamelStore *store, CamelSession *session, GString *url_name);
+static void _init(CamelStore *store, CamelSession *session, gchar *url_name);
*
**/
void
-camel_store_init(CamelStore *store, CamelSession *session, GString *url_name)
+camel_store_init(CamelStore *store, CamelSession *session, gchar *url_name)
{
g_assert(store);
- CS_CLASS(store)->init(store, session, url_name);
+ CS_CLASS(store)->init (store, session, url_name);
}
* @url_name: URL defining the store
*
* This routine is called by the session object from which this
- * store is created.
+ * store is created. Be careful, @url_name is used as a private field
+ * of the store object.
*
**/
static void
-_init(CamelStore *store, CamelSession *session, GString *url_name)
+_init (CamelStore *store, CamelSession *session, gchar *url_name)
{
*
**/
static void
-_set_separator(CamelStore *store, gchar sep)
+_set_separator (CamelStore *store, gchar sep)
{
store->separator = sep;
}
*
**/
gchar
-camel_store_get_separator(CamelStore *store)
+camel_store_get_separator (CamelStore *store)
{
g_assert(store);
return store->separator;
* Return value: the folder
**/
CamelFolder *
-camel_store_get_folder(CamelStore *store, GString *folder_name)
+camel_store_get_folder (CamelStore *store, gchar *folder_name)
{
#warning fill this part in.
* @Return value: the tolevel folder.
**/
static CamelFolder *
-_get_root_folder(CamelStore *store)
+_get_root_folder (CamelStore *store)
{
return NULL;
}
* @Return value: the default folder.
**/
static CamelFolder *
-_get_default_folder(CamelStore *store)
+_get_default_folder (CamelStore *store)
{
return NULL;
}
CamelService parent_object;
CamelSession *session;
- GString *url_name;
+ gchar *url_name;
gchar separator;
};
typedef struct {
CamelServiceClass parent_class;
- void (*init) (CamelStore *store, CamelSession *session, GString *url_name);
+ void (*init) (CamelStore *store, CamelSession *session, gchar *url_name);
void (*set_separator) (CamelStore *store, gchar sep);
gchar (*get_separator) (CamelStore *store);
- CamelFolder * (*get_folder) (CamelStore *store, GString *folder_name);
+ CamelFolder * (*get_folder) (CamelStore *store, gchar *folder_name);
CamelFolder * (*get_root_folder) (CamelStore *store);
CamelFolder * (*get_default_folder) (CamelStore *store);
/* Standard Gtk function */
GtkType camel_store_get_type (void);
-void camel_store_init(CamelStore *store, CamelSession *session, GString *url_name);
-CamelFolder *camel_store_get_folder(CamelStore *store, GString *folder_name);
+void camel_store_init(CamelStore *store, CamelSession *session, gchar *url_name);
+CamelFolder *camel_store_get_folder(CamelStore *store, gchar *folder_name);
gchar camel_store_get_separator(CamelStore *store);
#ifdef __cplusplus
#define CS_CLASS(so) CAMEL_STREAM_FS_CLASS (GTK_OBJECT(so)->klass)
static gint _read (CamelStream *stream, gchar *buffer, gint n);
-static gint _write (CamelStream *stream, gchar *buffer, gint n);
+static gint _write (CamelStream *stream, const gchar *buffer, gint n);
static void _flush (CamelStream *stream);
static gint _available (CamelStream *stream);
static gboolean _eos (CamelStream *stream);
CamelStream *
-camel_stream_fs_new_with_name (GString *name, CamelStreamFsMode mode)
+camel_stream_fs_new_with_name (gchar *name, CamelStreamFsMode mode)
{
struct stat s;
int v, fd;
CamelStreamFs *stream_fs;
g_assert (name);
- g_assert (name->str);
- CAMEL_LOG (FULL_DEBUG, "Entering CamelStream::new_with_name, name=\"%s\", mode=%d\n", name->str, mode);
- v = stat (name->str, &s);
+ CAMEL_LOG_FULL_DEBUG ( "Entering CamelStream::new_with_name, name=\"%s\", mode=%d\n", name, mode);
+ v = stat (name, &s);
if (mode & CAMEL_STREAM_FS_READ){
if (mode & CAMEL_STREAM_FS_WRITE)
if ( (mode & CAMEL_STREAM_FS_READ) && !(mode & CAMEL_STREAM_FS_WRITE) )
if (v == -1) return NULL;
- fd = open (name->str, flags, 0600);
+ fd = open (name, flags, 0600);
if (fd==-1) {
- CAMEL_LOG (FULL_DEBUG, "CamelStreamFs::new_with_name can not obtain fd for file \"%s\"\n", name->str);
- CAMEL_LOG (FULL_DEBUG, " Full error text is : %s\n", strerror(errno));
+ CAMEL_LOG_FULL_DEBUG ( "CamelStreamFs::new_with_name can not obtain fd for file \"%s\"\n", name);
+ CAMEL_LOG_FULL_DEBUG ( " Full error text is : %s\n", strerror(errno));
return NULL;
}
{
CamelStreamFs *stream_fs;
- CAMEL_LOG (FULL_DEBUG, "Entering CamelStream::new_with_fd fd=%d\n",fd);
+ CAMEL_LOG_FULL_DEBUG ( "Entering CamelStream::new_with_fd fd=%d\n",fd);
stream_fs = gtk_type_new (camel_stream_fs_get_type ());
stream_fs->fd = fd;
return CAMEL_STREAM (stream_fs);
_read (CamelStream *stream, gchar *buffer, gint n)
{
int v;
-
do {
v = read ( (CAMEL_STREAM_FS (stream))->fd, buffer, n);
} while (v == -1 && errno == EINTR);
-
return v;
}
* in the stream.
**/
static gint
-_write (CamelStream *stream, gchar *buffer, gint n)
+_write (CamelStream *stream, const gchar *buffer, gint n)
{
int v;
g_assert (stream);
g_assert ((CAMEL_STREAM_FS (stream))->fd);
- CAMEL_LOG (FULL_DEBUG, "CamelStreamFs:: entering write. n=%d\n", n);
+ CAMEL_LOG_FULL_DEBUG ( "CamelStreamFs:: entering write. n=%d\n", n);
do {
v = write ( (CAMEL_STREAM_FS (stream))->fd, buffer, n);
} while (v == -1 && errno == EINTR);
#if HARD_LOG_LEVEL >= FULL_DEBUG
if (v==-1) {
perror("");
- CAMEL_LOG (FULL_DEBUG, "CamelStreamFs::write could not write bytes in stream\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelStreamFs::write could not write bytes in stream\n");
}
#endif
return v;
typedef struct
{
CamelStream parent_object;
- GString *name;
+ gchar *name;
int fd;
} CamelStreamFs;
/* public methods */
-CamelStream *camel_stream_fs_new_with_name (GString *name, CamelStreamFsMode mode);
+CamelStream *camel_stream_fs_new_with_name (gchar *name, CamelStreamFsMode mode);
CamelStream *camel_stream_fs_new_with_fd (int fd);
#ifdef __cplusplus
* in the stream.
**/
gint
-camel_stream_write (CamelStream *stream, gchar *buffer, gint n)
+camel_stream_write (CamelStream *stream, const gchar *buffer, gint n)
{
return CS_CLASS (stream)->write (stream, buffer, n);
}
*
* Return value: the number of bytes available.
**/
-static gint
+gint
camel_stream_available (CamelStream *stream)
{
return CS_CLASS (stream)->available (stream);
}
/**
- * camle_stream_eos:
+ * camel_stream_eos:
* @stream: a CamelStream object
*
* Test if there are bytes left to read on the @stream object.
* Return value: %TRUE if all the contents on the stream has been read, or
* %FALSE if information is still available.
**/
-static gboolean
+gboolean
camel_stream_eos (CamelStream *stream)
{
return CS_CLASS (stream)->eos (stream);
camel_stream_write_strings (CamelStream *stream, ... )
{
va_list args;
- char *string;
+ const char *string;
va_start(args, stream);
- string = va_arg (args, char *);
+ string = va_arg (args, const char *);
while (string) {
camel_stream_write_string (stream, string);
/* Virtual methods */
gint (*read) (CamelStream *stream, gchar *buffer, gint n);
- gint (*write) (CamelStream *stream, gchar *buffer, gint n);
+ gint (*write) (CamelStream *stream, const gchar *buffer, gint n);
void (*flush) (CamelStream *stream);
gint (*available) (CamelStream *stream);
gboolean (*eos) (CamelStream *stream);
/* public methods */
gint camel_stream_read (CamelStream *stream, gchar *buffer, gint n);
-gint camel_stream_write (CamelStream *stream, gchar *buffer, gint n);
+gint camel_stream_write (CamelStream *stream, const gchar *buffer, gint n);
void camel_stream_flush (CamelStream *stream);
gint camel_stream_available (CamelStream *stream);
gboolean camel_stream_eos (CamelStream *stream);
#include <config.h>
#include "gmime-content-field.h"
-/* #include "-util.h" */
+#include "string-utils.h"
#include "camel-log.h"
-/
+
/**
* gmime_content_field_new: Creates a new GMimeContentField object
*
* Return value: The newly created GMimeContentField object
**/
-void
+GMimeContentField *
gmime_content_field_new (const gchar *type, const gchar *subtype)
{
GMimeContentField *ctf;
ctf = g_new (GMimeContentField, 1);
- ctf->type = type;
- ctf->subtype = subtype;
+ ctf->type = g_strdup (type);
+ ctf->subtype = g_strdup (subtype);
ctf->parameters = g_hash_table_new (g_str_hash, g_str_equal);
return ctf;
gboolean attribute_exists;
gchar *old_attribute;
gchar *old_value;
-
+ CAMEL_LOG_FULL_DEBUG ("GMimeContentField:: Entering set_parameter\n");
+ CAMEL_LOG_FULL_DEBUG ("GMimeContentField:: set_parameter content_field=%p name=%s, value=%s\n", content_field, attribute, value);
attribute_exists = g_hash_table_lookup_extended (content_field->parameters,
attribute,
(gpointer *) &old_attribute,
(gpointer *) &old_value);
- /** CHECK THAT **/
+ /** CHECK THAT : is normal to free pointers before insertion ? **/
if (attribute_exists) {
- g_string_free (old_value, TRUE);
- g_string_free (old_attribute, TRUE);
+ g_free (old_value);
+ g_free (old_attribute);
}
- g_hash_table_insert (content_field->parameters, attribute, value);
+ g_hash_table_insert (content_field->parameters, g_strdup (attribute), g_strdup (value));
+ CAMEL_LOG_FULL_DEBUG ("GMimeContentField:: Leaving set_parameter\n");
}
}
/**
- * gmime_content_field_write_to: write a mime content type to a stream
+ * gmime_content_field_write_to_stream: write a mime content type to a stream
* @content_field: content type object
* @stream: the stream
*
gmime_content_field_write_to_stream (GMimeContentField *content_field, CamelStream *stream)
{
if (!content_field) return;
- if ((content_field->type) && ((content_field->type)->str)) {
+
+ g_assert (stream);
+ if (content_field->type) {
camel_stream_write_strings (stream, "Content-Type: ", content_field->type, NULL);
if (content_field->subtype) {
camel_stream_write_strings (stream, "/", content_field->subtype, NULL);
/* print all parameters */
g_hash_table_foreach (content_field->parameters, _print_parameter, stream);
camel_stream_write_string (stream, "\n");
- }
+ }
}
+/**
+ * gmime_content_field_get_mime_type: return the mime type of the content field object
+ * @content_field: content field object
+ *
+ * A RFC 2045 content type field contains the mime type in the
+ * form "type/subtype" (example : "application/postscript") and some
+ * parameters (attribute/value pairs). This routine returns the mime type
+ * in a gchar object.
+ *
+ * Return value: the mime type in the form "type/subtype" or NULL if not defined.
+ **/
gchar *
gmime_content_field_get_mime_type (GMimeContentField *content_field)
{
gchar *mime_type;
if (!content_field->type) return NULL;
- mime_type = g_strdup (content_field->type);
- if (content_field->subtype) {
- g_string_append_c (mime_type, '/');
- g_string_append_g_string (mime_type, content_field->subtype);
- }
+
+ if (content_field->subtype)
+ mime_type = g_strdup_printf ("%s/%s", content_field->type, content_field->subtype);
+ else
+ mime_type = g_strdup (content_field->type);
return mime_type;
}
+static void
+___debug_print_parameter (gpointer name, gpointer value, gpointer user_data)
+{
+
+ printf ("****** parameter \"%s\"=\"%s\"\n", (gchar *)name, (gchar *)value);
+
+}
+
+/**
+ * gmime_content_field_get_parameter: return the value of a mime type parameter
+ * @content_field: content field object
+ * @name: name of the parameter
+ *
+ * Returns the value of a parameter contained in the content field
+ * object. The content type is formed of a mime type, a mime subtype,
+ * and a parameter list. Each parameter is a name/value pair. This
+ * routine returns the value assiciated to a given name.
+ * When the parameter does not exist, NULL is returned.
+ *
+ * Return value: parameter value, or NULL if not found.
+ **/
+const gchar *
+gmime_content_field_get_parameter (GMimeContentField *content_field, const gchar *name)
+{
+ const gchar *parameter;
+ const gchar *old_name;
+ gboolean parameter_exists;
+
+ CAMEL_LOG_FULL_DEBUG ("Entering GMimeContentField::get_parameter content_field =%p\n", content_field);
+ g_assert (content_field->parameters);
+ g_assert (name);
+ CAMEL_LOG_FULL_DEBUG ("GMimeContentField::get_parameter looking for parameter \"%s\"\n", name);
+ //parameter = (const gchar *)g_hash_table_lookup (content_field->parameters, name);
+ parameter_exists = g_hash_table_lookup_extended (content_field->parameters,
+ name,
+ (gpointer *) &old_name,
+ (gpointer *) ¶meter);
+ if (!parameter_exists) {
+ CAMEL_LOG_FULL_DEBUG ("GMimeContentField::get_parameter, parameter not found\n");
+ g_hash_table_foreach (content_field->parameters, ___debug_print_parameter, NULL);
+ return NULL;
+ }
+ CAMEL_LOG_FULL_DEBUG ("Leaving GMimeContentField::get_parameter\n");
+ return parameter;
+}
+
+
+
+/**
+ * gmime_content_field_construct_from_string: construct a ContentType object
+ * by parsing a string.
+ *
+ * @content_field: content type object to construct
+ * @string: string containing the content type field
+ *
+ * Parse a string containing a content type field as defined in
+ * RFC 2045, and construct the corresponding ContentType object.
+ * The string is not modified and not used in the ContentType
+ * object. It can and must be freed by the calling part.
+ **/
void
-gmime_content_field_construct_from_string (GMimeContentField *content_field, gchar *string)
+gmime_content_field_construct_from_string (GMimeContentField *content_field, const gchar *string)
{
gint first, len;
gchar *str;
gchar *param_name, *param_value;
gboolean param_end;
- CAMEL_LOG (TRACE, "Entering gmime_content_field_construct_from_string\n");
+ CAMEL_LOG_TRACE ( "GMimeContentField::construct_from_string, entering\n");
g_assert (string);
- g_assert (string->str);
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);
+ CAMEL_LOG_FULL_DEBUG ( "GMimeContentField::construct_from_string, Freeing old mime type string\n");
+ g_free (content_field->type);
}
if (content_field->subtype) {
- CAMEL_LOG (FULL_DEBUG, "Freeing old mime type substring\n");
- g_string_free (content_field->subtype, FALSE);
+ CAMEL_LOG_FULL_DEBUG ( "GMimeContentField::construct_from_string, Freeing old mime type substring\n");
+ g_free (content_field->subtype);
}
- str = string->str;
first = 0;
- len = string->len;
+ len = strlen (string);
if (!len) return;
- CAMEL_LOG (TRACE, "All checks done\n");
+ CAMEL_LOG_FULL_DEBUG ("GMimeContentField::construct_from_string, All checks done\n");
/* find the type */
- while ( (i<len) && (!strchr ("/;", str[i])) ) i++;
+ while ( (i<len) && (!strchr ("/;", string[i])) ) i++;
if (i == 0) return;
- type = g_string_new (g_strndup (str, i));
+ type = g_strndup (string, i);
+ string_trim (type, " \t", STRING_TRIM_STRIP_TRAILING | STRING_TRIM_STRIP_LEADING);
content_field->type = type;
- CAMEL_LOG (TRACE, "Found mime type : %s\n", type->str);
- if (i == len) {
+ CAMEL_LOG_TRACE ( "GMimeContentField::construct_from_string, Found mime type : \"%s\"\n", type);
+ if (i >= len-1) {
content_field->subtype = NULL;
return;
}
first = i+1;
/* find the subtype, if any */
- if (str[i++] == '/') {
- while ( (i<len) && (str[i] != ';') ) i++;
+ if (string[i++] == '/') {
+ while ( (i<len) && (string[i] != ';') ) i++;
if (i != first) {
- subtype = g_string_new (g_strndup (str+first, i-first));
+ subtype = g_strndup (string+first, i-first);
+ string_trim (subtype, " \t", STRING_TRIM_STRIP_TRAILING | STRING_TRIM_STRIP_LEADING);
content_field->subtype = subtype;
- if (i == len) return;
+ CAMEL_LOG_TRACE ( "GMimeContentField::construct_from_string, Found mime subtype: \"%s\"\n", subtype);
+ if (i >= len-1) return;
}
}
first = i+1;
/* parse parameters list */
param_end = FALSE;
do {
- while ( (i<len) && (str[i] != '=') ) i++;
+ while ( (i<len) && (string[i] != '=') ) i++;
if ((i == len) || (i==first)) param_end = TRUE;
else {
/* we have found parameter name */
- param_name = g_string_new (g_strndup (str+first, i-first));
+ param_name = g_strndup (string+first, i-first);
+ string_trim (param_name, " ", STRING_TRIM_STRIP_TRAILING | STRING_TRIM_STRIP_LEADING);
i++;
first = i;
/* Let's find parameter value */
- while ( (i<len) && (str[i] != ';') ) i++;
- if (i != first) param_value = g_string_new (g_strndup (str+first, i-first));
- else param_value = g_string_new ("");
+ while ( (i<len) && (string[i] != ';') ) i++;
+ if (i != first) param_value = g_strndup (string+first, i-first);
+ else param_value = g_strdup ("");
+ CAMEL_LOG_TRACE ( "GMimeContentField::construct_from_string, Found mime parameter \"%s\"=\"%s\"\n", param_name, param_value);
+ string_trim (param_value, " \t", STRING_TRIM_STRIP_TRAILING | STRING_TRIM_STRIP_LEADING);
gmime_content_field_set_parameter (content_field, param_name, param_value);
i++;
first = i;
static void
_free_parameter (gpointer name, gpointer value, gpointer user_data)
{
- g_string_free (name, FALSE);
- g_string_free (value, FALSE);
+ g_free (name);
+ g_free (value);
}
void
gmime_content_field_free (GMimeContentField *content_field)
{
g_hash_table_foreach (content_field->parameters, _free_parameter, NULL);
- g_string_free (content_field->type, FALSE);
- g_string_free (content_field->subtype, FALSE);
+ g_free (content_field->type);
+ g_free (content_field->subtype);
g_hash_table_destroy (content_field->parameters);
g_free (content_field);
}
GMimeContentField *gmime_content_field_new (const gchar *type, const gchar *subtype);
void gmime_content_field_set_parameter (GMimeContentField *content_field, const gchar *attribute, const gchar *value);
void gmime_content_field_write_to_stream (GMimeContentField *content_field, CamelStream *stream);
-void gmime_content_field_construct_from_string (GMimeContentField *content_field, gchar *string);
+void gmime_content_field_construct_from_string (GMimeContentField *content_field, const gchar *string);
void gmime_content_field_free (GMimeContentField *content_field);
gchar * gmime_content_field_get_mime_type (GMimeContentField *content_field);
+const gchar *gmime_content_field_get_parameter (GMimeContentField *content_field, const gchar *name);
#ifdef __cplusplus
#include <config.h>
#include "gmime-utils.h"
-#include "gstring-util.h"
+#include "string-utils.h"
#include "camel-log.h"
#include "camel-stream.h"
void
-gmime_write_header_pair_to_stream (CamelStream *stream, gchar* name, GString *value)
+gmime_write_header_pair_to_stream (CamelStream *stream, const gchar* name, const gchar *value)
{
- GString *strtmp;
+ gchar *strtmp;
guint len;
-
+ CAMEL_LOG_FULL_DEBUG ( "gmime_write_header_pair_to_stream:: Entering\n");
g_assert(name);
-
- if (!value || !(value->str)) return;
- len = strlen (name) + strlen (value->str) +3;
+#warning use g_strdup_printf instead
+
+ if (!value) return;
+ len = strlen (name) + strlen (value) +3;
/* 3 is for ": " and "\n" */
- strtmp = g_string_sized_new (len);
+ strtmp = g_new (gchar, len);
- sprintf(strtmp->str, "%s: %s\n", name, value->str);
- camel_stream_write (stream, strtmp->str, len);
- CAMEL_LOG (FULL_DEBUG, "gmime_write_header_pair_to_stream:\n writing %s\n", strtmp->str);
- g_string_free (strtmp, FALSE);
+ sprintf (strtmp, "%s: %s\n", name, value);
+ camel_stream_write (stream, strtmp, len);
+ CAMEL_LOG_FULL_DEBUG ( "gmime_write_header_pair_to_stream:\n writing %s\n", strtmp);
+ g_free (strtmp);
+ CAMEL_LOG_FULL_DEBUG ( "gmime_write_header_pair_to_stream:: Leaving\n");
+
}
static void
_write_one_header_to_stream (gpointer key, gpointer value, gpointer user_data)
{
- GString *header_name = (GString *)key;
- GString *header_value = (GString *)value;
+ gchar *header_name = (gchar *)key;
+ gchar *header_value = (gchar *)value;
CamelStream *stream = (CamelStream *)user_data;
- if ( (header_name) && (header_name->str) &&
- (header_value) && (header_value->str) )
- gmime_write_header_pair_to_stream (stream, header_name->str, header_value);
+ CAMEL_LOG_FULL_DEBUG ( "_write_one_header_to_stream:: Entering\n");
+ if ((header_name) && (header_value))
+ gmime_write_header_pair_to_stream (stream, header_name, header_value);
+ CAMEL_LOG_FULL_DEBUG ( "_write_one_header_to_stream:: Leaving\n");
}
void
write_header_table_to_stream (CamelStream *stream, GHashTable *header_table)
{
+ CAMEL_LOG_FULL_DEBUG ( "write_header_table_to_stream:: Entering\n");
g_hash_table_foreach (header_table,
_write_one_header_to_stream,
(gpointer)stream);
+ CAMEL_LOG_FULL_DEBUG ( "write_header_table_to_stream:: Leaving\n");
}
void
-write_header_with_glist_to_stream (CamelStream *stream, gchar *header_name, GList *header_values, gchar *separator)
+write_header_with_glist_to_stream (CamelStream *stream, const gchar *header_name, GList *header_values, const gchar *separator)
{
- GString *current;
-
+ gchar *current;
+
+ CAMEL_LOG_FULL_DEBUG ( "write_header_with_glist_to_stream:: entering\n");
if ( (header_name) && (header_values) )
{
gboolean first;
camel_stream_write (stream, ": ", 2);
first = TRUE;
while (header_values) {
- current = (GString *)header_values->data;
- if ( (current) && (current->str) ) {
+ current = (gchar *)header_values->data;
+ if (current) {
if (!first) camel_stream_write_string (stream, separator);
else first = FALSE;
- camel_stream_write (stream, current->str, strlen (current->str));
+ camel_stream_write (stream, current, strlen (current));
}
header_values = g_list_next(header_values);
}
camel_stream_write (stream, "\n", 1);
}
+ CAMEL_LOG_FULL_DEBUG ( "write_header_with_glist_to_stream:: leaving\n");
}
/* scanning functions */
static void
-_store_header_pair_from_gstring (GHashTable *header_table, GString *header_line)
+_store_header_pair_from_string (GHashTable *header_table, gchar *header_line)
{
gchar dich_result;
- GString *header_name, *header_value;
+ gchar *header_name, *header_value;
+ CAMEL_LOG_FULL_DEBUG ( "_store_header_pair_from_string:: Entering\n");
g_assert (header_table);
- if ( (header_line) && (header_line->str) ) {
- dich_result = g_string_dichotomy (
- header_line, ':', &header_name, &header_value,
- GSTRING_DICHOTOMY_NONE);
+ g_assert (header_line);
+ if (header_line) {
+ dich_result = string_dichotomy ( header_line, ':',
+ &header_name, &header_value,
+ STRING_DICHOTOMY_NONE);
if (dich_result != 'o')
- camel_log(WARNING,
- "store_header_pair_from_gstring : dichotomy result is %c"
- "header line is :\n--\n%s\n--\n");
-
+ CAMEL_LOG_WARNING (
+ "store_header_pair_from_string : dichotomy result is %c"
+ "header line is :\n--\n%s\n--\n");
else {
- g_string_trim (
- header_value, " \t",
- GSTRING_TRIM_STRIP_LEADING | GSTRING_TRIM_STRIP_TRAILING);
+ string_trim (header_value, " \t",
+ STRING_TRIM_STRIP_LEADING | STRING_TRIM_STRIP_TRAILING);
g_hash_table_insert (header_table, header_name, header_value);
}
}
-
+ CAMEL_LOG_FULL_DEBUG ( "_store_header_pair_from_string:: Leaving\n");
+
}
GHashTable *
get_header_table_from_stream (CamelStream *stream)
{
+#warning Correct Lazy Implementation
+ /* should not use GString. */
+ /* should read the header line by line */
+ /* and not char by char */
gchar next_char;
gboolean crlf = FALSE;
gboolean end_of_headers = FALSE;
gboolean end_of_file = FALSE;
GString *header_line=NULL;
+ gchar *str_header_line;
GHashTable *header_table;
-
- header_table = g_hash_table_new (g_string_hash, g_string_equal_for_hash);
+#warning Correct a bug here. Should use return value of camel_stream_read instead of looking for next_char!=-1
+ CAMEL_LOG_FULL_DEBUG ( "gmime-utils:: Entering get_header_table_from_stream\n");
+ header_table = g_hash_table_new (g_str_hash, g_str_equal);
camel_stream_read (stream, &next_char, 1);
do {
- header_line = g_string_new("");
+ header_line = g_string_new ("");
end_of_header_line = FALSE;
crlf = FALSE;
if (!end_of_header_line) camel_stream_read (stream, &next_char, 1);
} while ( !end_of_header_line );
- if ( strlen(header_line->str) )
- _store_header_pair_from_gstring (header_table, header_line);
+ if ( strlen(header_line->str) ) {
+ str_header_line = g_strdup (header_line->str);
+ _store_header_pair_from_string (header_table, str_header_line);
+ }
g_string_free (header_line, FALSE);
} while ( (!end_of_headers) && (!end_of_file) );
-
+
+ CAMEL_LOG_FULL_DEBUG ( "gmime-utils:: Leaving get_header_table_from_stream\n");
return header_table;
}
+gchar *
+gmime_read_line_from_stream (CamelStream *stream)
+{
+ GString *new_line;
+ gchar *result;
+ gchar next_char;
+ gboolean end_of_line = FALSE;
+ gboolean end_of_stream = FALSE;
+ gint nb_char_read;
+
+ new_line = g_string_new ("");
+ do {
+ nb_char_read = camel_stream_read (stream, &next_char, 1);
+ if (nb_char_read>0) {
+ switch (next_char) {
+ case '\n':
+ end_of_line = TRUE;
+ /* g_string_append_c (new_line, next_char); */
+ break;
+ default:
+ g_string_append_c (new_line, next_char);
+ }
+ } else end_of_stream = TRUE;
+ } while (!end_of_line && !end_of_stream);
+
+ if ( (new_line->str[0]) != '\0')
+ result = g_strdup (new_line->str);
+ else result=NULL;
+ g_string_free (new_line, TRUE);
+ return result;
+}
#include <stdio.h>
#include <camel-stream.h>
-void gmime_write_header_pair_to_stream (CamelStream *stream, gchar* name, GString *value);
+void gmime_write_header_pair_to_stream (CamelStream *stream, const gchar* name, const gchar *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, gchar *separator);
+void write_header_with_glist_to_stream (CamelStream *stream, const gchar *header_name, GList *header_values, const gchar *separator);
GHashTable *get_header_table_from_stream (CamelStream *stream);
+gchar *gmime_read_line_from_stream (CamelStream *stream);
gchar *str, *tmp;
gint pos, len, first;
- CAMEL_LOG(FULL_DEBUG,\
+ CAMEL_LOG_FULL_DEBUG (\
"Entering string_dichotomy: \n\tseparator=%c \n\tprefix=%p \n\tsuffix=%p \n\toptions=%ld\n",\
sep, prefix, suffix, options);
g_assert( tmp=string->str );
*prefix=NULL;
if (suffix)
*suffix=NULL;
- CAMEL_LOG(FULL_DEBUG,"string_dichotomy: string is empty\n");
+ CAMEL_LOG_FULL_DEBUG ("string_dichotomy: string is empty\n");
return 'n';
}
first = 0;
if (first==len) {
if (prefix) *prefix=NULL;
if (suffix) *suffix=NULL;
- CAMEL_LOG(FULL_DEBUG,"string_dichotomy: after stripping, string is empty\n");
+ CAMEL_LOG_FULL_DEBUG ("string_dichotomy: after stripping, string is empty\n");
return 'n';
}
{
if (suffix) *suffix=NULL;
if (prefix) *prefix=NULL;
- CAMEL_LOG(FULL_DEBUG,"string_dichotomy: separator not found\n");
+ CAMEL_LOG_FULL_DEBUG ("string_dichotomy: separator not found\n");
return 'n';
}
{
if (suffix) *suffix=NULL;
if (prefix) *prefix=NULL;
- CAMEL_LOG(FULL_DEBUG,"string_dichotomy: separator is last character\n");
+ CAMEL_LOG_FULL_DEBUG ("string_dichotomy: separator is last character\n");
return 'l';
}
/* if we have stripped leading separators, we should */
{
if (suffix) *suffix=NULL;
if (prefix) *prefix=NULL;
- CAMEL_LOG(FULL_DEBUG,"string_dichotomy: separator is first character\n");
+ CAMEL_LOG_FULL_DEBUG ("string_dichotomy: separator is first character\n");
return 'l';
}
last--;
- CAMEL_LOG(FULL_DEBUG,"g_string_split:: trim options: %d\n", trim_options);
+ CAMEL_LOG_FULL_DEBUG ("g_string_split:: trim options: %d\n", trim_options);
while (first<=last) {
pos = first;
guint length;
gchar *str;
- CAMEL_LOG(FULL_DEBUG,"**\nentering g_string_trim::\n");
+ CAMEL_LOG_FULL_DEBUG ("**\nentering g_string_trim::\n");
if ((!string) || (!string->str))
return;
first_ok = 0;
last_ok = length - 1;
- CAMEL_LOG (FULL_DEBUG,"g_string_trim:: trim_options:%d\n", options);
+ CAMEL_LOG_FULL_DEBUG ("g_string_trim:: trim_options:%d\n", options);
if (options & GSTRING_TRIM_STRIP_LEADING)
while ( (first_ok <= last_ok) && (strchr (chars, str[first_ok])) )
first_ok++;
if (options & GSTRING_TRIM_STRIP_TRAILING)
while ( (first_ok <= last_ok) && (strchr (chars, str[last_ok])) )
last_ok++;
- CAMEL_LOG (FULL_DEBUG,"g_string_trim::\n\t\"%s\":first ok:%d last_ok:%d\n",
+ CAMEL_LOG_FULL_DEBUG ("g_string_trim::\n\t\"%s\":first ok:%d last_ok:%d\n",
string->str, first_ok, last_ok);
if (first_ok > 0)