CAMEL_EXCEPTION_FOLDER_NON_UID,
CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION,
CAMEL_EXCEPTION_FOLDER_INVALID_PATH,
+CAMEL_EXCEPTION_FOLDER_INVALID_UID,
+/* CamelStoreException */
+CAMEL_EXCEPTION_STORE_NULL,
\ No newline at end of file
static void
_write_recipients_to_stream (CamelMimeMessage *mime_message, CamelStream *stream)
{
- camel_recipient_foreach_recipient_type (mime_message->recipients,
- _write_one_recipient_to_stream,
- (gpointer)stream);
+ camel_recipient_foreach_recipient_type (mime_message->recipients,
+ _write_one_recipient_to_stream,
+ (gpointer)stream);
}
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 ( "CamelMimeMessage:: Writing \"From\"\n");
WHPT (stream, "From", mm->from);
+
CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage:: Writing \"Reply-To\"\n");
WHPT (stream, "Reply-To", mm->reply_to);
+
CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage:: Writing recipients\n");
_write_recipients_to_stream (mm, stream);
+
CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage:: Writing \"Date\"\n");
WHPT (stream, "Date", mm->received_date);
+
CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage:: Writing \"Subject\"\n");
WHPT (stream, "Subject", mm->subject);
_set_recipient_list_from_string (CamelMimeMessage *message, gchar *recipient_type, gchar *recipients_string)
{
GList *recipients_list;
+ GList *tmp;
+
CAMEL_LOG_FULL_DEBUG ("CamelMimeMessage::_set_recipient_list_from_string parsing ##%s##\n", recipients_string);
recipients_list = string_split (
recipients_string, ',', "\t ",
STRING_TRIM_STRIP_TRAILING | STRING_TRIM_STRIP_LEADING);
+
camel_recipient_table_add_list (message->recipients, recipient_type, recipients_list);
}
/* see if there is already a list for this recipient type */
existent_list = (GList *)g_hash_table_lookup (recipient_table->recipient_hash_table, recipient_type);
-
/* append the new recipient to the recipient list
if the existent_list is NULL, then a new GList is
automagically created */
const gchar *recipient_type,
GList *recipient_list)
{
- GList *recipients_list;
GList *existent_list;
-
+
/* see if there is already a list for this recipient type */
existent_list = (GList *)g_hash_table_lookup (recipient_table->recipient_hash_table, recipient_type);
-
-
+
if (existent_list)
g_list_concat (existent_list, recipient_list);
else
- g_hash_table_insert (recipient_table->recipient_hash_table, g_strdup (recipient_type), recipients_list);
+ g_hash_table_insert (recipient_table->recipient_hash_table, g_strdup (recipient_type), recipient_list);
+
}
}
+CamelSession *
+camel_store_get_session (CamelStore *store, CamelException *ex)
+{
+ if (!store) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_STORE_NULL,
+ "Store is NULL");
+ return NULL;
+ }
+
+ return store->session;
+}
void camel_store_init (CamelStore *store, CamelSession *session, const gchar *url_name, CamelException *ex);
CamelFolder *camel_store_get_folder (CamelStore *store, const gchar *folder_name, CamelException *ex);
gchar camel_store_get_separator (CamelStore *store, CamelException *ex);
+CamelSession *camel_store_get_session (CamelStore *store, CamelException *ex);
#ifdef __cplusplus
}
*/
#include <config.h>
#include "camel-stream-fs.h"
+#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
static void _destroy (GtkObject *object);
static void _init_with_fd (CamelStreamFs *stream_fs, int fd);
+static void _init_with_fd_and_bounds (CamelStreamFs *stream_fs, int fd, guint32 inf_bound, gint64 sup_bound);
static void _init_with_name (CamelStreamFs *stream_fs, const gchar *name, CamelStreamFsMode mode);
+static void _init_with_name_and_bounds (CamelStreamFs *stream_fs, const gchar *name, CamelStreamFsMode mode,
+ guint32 inf_bound, gint64 sup_bound);
static void
camel_stream_fs_class_init (CamelStreamFsClass *camel_stream_fs_class)
/* virtual method definition */
camel_stream_fs_class->init_with_fd = _init_with_fd;
+ camel_stream_fs_class->init_with_fd_and_bounds = _init_with_fd_and_bounds;
camel_stream_fs_class->init_with_name = _init_with_name;
-
+ camel_stream_fs_class->init_with_name_and_bounds = _init_with_name_and_bounds;
+
/* virtual method overload */
camel_stream_class->read = _read;
camel_stream_class->write = _write;
CAMEL_LOG_FULL_DEBUG ("Leaving CamelStreamFs::finalize\n");
}
+
+
+static void
+_set_bounds (CamelStreamFs *stream_fs, guint32 inf_bound, gint64 sup_bound)
+{
+ /* store the bounds */
+ stream_fs->inf_bound = inf_bound;
+ stream_fs->sup_bound = sup_bound;
+
+ /* go to the first position */
+ lseek ((CAMEL_STREAM_FS (stream_fs))->fd, inf_bound, SEEK_SET);
+
+ stream_fs->cur_pos = inf_bound;
+}
+
+
+
+
static void
_init_with_fd (CamelStreamFs *stream_fs, int fd)
{
+ /* no bounds by default */
+ _set_bounds (stream_fs, 0, -1);
+
stream_fs->fd = fd;
}
+
+
+
+static void
+_init_with_fd_and_bounds (CamelStreamFs *stream_fs, int fd, guint32 inf_bound, gint64 sup_bound)
+{
+
+ CSFS_CLASS (stream_fs)->init_with_fd (stream_fs, fd);
+ _set_bounds (stream_fs, inf_bound, sup_bound);
+
+}
+
+
+
static void
_init_with_name (CamelStreamFs *stream_fs, const gchar *name, CamelStreamFsMode mode)
{
struct stat s;
int v, fd;
int flags;
-
+
g_assert (name);
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){
else
return;
}
+
if ( (mode & CAMEL_STREAM_FS_READ) && !(mode & CAMEL_STREAM_FS_WRITE) )
if (v == -1) return;
stream_fs->name = g_strdup (name);
CSFS_CLASS (stream_fs)->init_with_fd (stream_fs, fd);
-
+ /* no bounds by default */
+ _set_bounds (stream_fs, 0, -1);
+
+
+}
+
+
+static void
+_init_with_name_and_bounds (CamelStreamFs *stream_fs, const gchar *name, CamelStreamFsMode mode,
+ guint32 inf_bound, gint64 sup_bound)
+{
+ CSFS_CLASS (stream_fs)->init_with_name (stream_fs, name, mode);
+ _set_bounds (stream_fs, inf_bound, sup_bound);
}
+
+
CamelStream *
camel_stream_fs_new_with_name (const gchar *name, CamelStreamFsMode mode)
{
return CAMEL_STREAM (stream_fs);
}
+
+
+CamelStream *
+camel_stream_fs_new_with_name_and_bounds (const gchar *name, CamelStreamFsMode mode,
+ guint32 inf_bound, gint64 sup_bound)
+{
+ CamelStreamFs *stream_fs;
+ stream_fs = gtk_type_new (camel_stream_fs_get_type ());
+ CSFS_CLASS (stream_fs)->init_with_name_and_bounds (stream_fs, name, mode, inf_bound, sup_bound);
+
+ return CAMEL_STREAM (stream_fs);
+
+}
+
+
+
+
+
CamelStream *
camel_stream_fs_new_with_fd (int fd)
return CAMEL_STREAM (stream_fs);
}
+
+
+CamelStream *
+camel_stream_fs_new_with_fd_and_bounds (int fd, guint32 inf_bound, gint64 sup_bound)
+{
+ CamelStreamFs *stream_fs;
+
+ CAMEL_LOG_FULL_DEBUG ( "Entering CamelStream::new_with_fd fd=%d\n",fd);
+ stream_fs = gtk_type_new (camel_stream_fs_get_type ());
+ CSFS_CLASS (stream_fs)->init_with_fd_and_bounds (stream_fs, fd, inf_bound, sup_bound);
+
+ return CAMEL_STREAM (stream_fs);
+}
+
+
+
/**
* _read: read bytes from a stream
* @stream: stream
static gint
_read (CamelStream *stream, gchar *buffer, gint n)
{
+ CamelStreamFs *stream_fs = CAMEL_STREAM_FS (stream);
gint v;
+ gint nb_to_read;
+
+ if (stream_fs->sup_bound != -1)
+ nb_to_read = stream_fs->sup_bound - stream_fs->cur_pos;
+ else
+ nb_to_read = n;
+
do {
- v = read ( (CAMEL_STREAM_FS (stream))->fd, buffer, n);
+ v = read ( (CAMEL_STREAM_FS (stream))->fd, buffer, nb_to_read);
} while (v == -1 && errno == EINTR);
if (v<0)
CAMEL_LOG_FULL_DEBUG ("CamelStreamFs::read v=%d\n", v);
+ else
+ stream_fs->cur_pos += v;
+
return v;
}
/**
- * _write: read bytes to a stream
+ * _write: write bytes to a stream
* @stream: the stream
* @buffer: byte buffer
* @n: number of bytes to write
static gint
_write (CamelStream *stream, const gchar *buffer, gint n)
{
+ CamelStreamFs *stream_fs = CAMEL_STREAM_FS (stream);
int v;
+ gint nb_to_write;
+
g_assert (stream);
- g_assert ((CAMEL_STREAM_FS (stream))->fd);
+ g_assert (stream_fs->fd);
CAMEL_LOG_FULL_DEBUG ( "CamelStreamFs:: entering write. n=%d\n", n);
+
+ if (stream_fs->sup_bound != -1)
+ nb_to_write = stream_fs->sup_bound - stream_fs->cur_pos;
+ else
+ nb_to_write = n;
+
do {
- v = write ( (CAMEL_STREAM_FS (stream))->fd, buffer, n);
+ v = write ( stream_fs->fd, buffer, nb_to_write);
} while (v == -1 && errno == EINTR);
#if HARD_LOG_LEVEL >= FULL_DEBUG
CAMEL_LOG_FULL_DEBUG ( "CamelStreamFs::write could not write bytes in stream\n");
}
#endif
+
+ if (v>0)
+ stream_fs->cur_pos += v;
+
return v;
}
_seek (CamelStream *stream, gint offset, CamelStreamSeekPolicy policy)
{
int whence;
+ gint return_position;
+ gint real_offset;
+ CamelStreamFs *stream_fs = CAMEL_STREAM_FS (stream);
+
switch (policy) {
case CAMEL_STREAM_SET:
- whence = SEEK_SET;
+ real_offset = MAX (stream_fs->inf_bound + offset, stream_fs->inf_bound);
+ if (stream_fs->sup_bound > 0)
+ real_offset = MIN (real_offset, stream_fs->sup_bound);
+ whence = SEEK_SET;
break;
+
case CAMEL_STREAM_CUR:
- whence = SEEK_CUR;
+ if ((stream_fs->sup_bound == -1) && ((stream_fs->cur_pos + offset) > stream_fs->sup_bound)) {
+ real_offset = stream_fs->sup_bound;
+ whence = SEEK_SET;
+ } else if ((stream_fs->cur_pos + offset) < stream_fs->inf_bound) {
+ real_offset = stream_fs->inf_bound;
+ whence = SEEK_SET;
+ } else
+ {
+ real_offset = offset;
+ whence = SEEK_CUR;
+ }
break;
+
case CAMEL_STREAM_END:
- whence = SEEK_END;
+ if (stream_fs->sup_bound != -1) {
+ real_offset = stream_fs->sup_bound - offset;
+ whence = SEEK_SET;
+ } else {
+ real_offset = offset;
+ whence = SEEK_END;
+ }
+
+
break;
default:
return -1;
}
+
- return lseek ((CAMEL_STREAM_FS (stream))->fd, offset, whence);
+ return_position = lseek (stream_fs->fd, real_offset, whence) - stream_fs->inf_bound;
+ stream_fs->cur_pos = return_position;
+
+ return return_position;
}
+
+
+
+
+
+
+
+
+
+
+
typedef struct
{
+
CamelStream parent_object;
- gchar *name;
- int fd;
+ gchar *name; /* name of the underlying file */
+ gint fd; /* file descriptor on the underlying file */
+ guint32 cur_pos; /* current postion in the stream */
+ guint32 inf_bound; /* first valid position */
+ gint64 sup_bound; /* last valid position, -1 means, no sup bound */
+
} CamelStreamFs;
/* Virtual methods */
void (*init_with_fd) (CamelStreamFs *stream_fs, int fd);
+ void (*init_with_fd_and_bounds) (CamelStreamFs *stream_fs, int fd, guint32 inf_bound, gint64 sup_bound);
void (*init_with_name) (CamelStreamFs *stream_fs, const gchar *name, CamelStreamFsMode mode);
+ void (*init_with_name_and_bounds) (CamelStreamFs *stream_fs, const gchar *name,
+ CamelStreamFsMode mode, guint32 inf_bound, gint64 sup_bound);
} CamelStreamFsClass;
/* public methods */
CamelStream *camel_stream_fs_new_with_name (const gchar *name, CamelStreamFsMode mode);
+CamelStream *camel_stream_fs_new_with_name_and_bounds (const gchar *name, CamelStreamFsMode mode,
+ guint32 inf_bound, gint64 sup_bound);
CamelStream *camel_stream_fs_new_with_fd (int fd);
+CamelStream *camel_stream_fs_new_with_fd_and_bounds (int fd,
+ guint32 inf_bound, gint64 sup_bound);
#ifdef __cplusplus
}
#ifdef G_THREADS_ENABLED
g_thread_init (NULL);
#else /* G_THREADS_ENABLED */
- printf ("Threads are not supported by glib\n");
+ printf ("Threads are not supported by your version of glib\n");
#endif /* G_THREADS_ENABLED */
- /* return data_wrapper_repository_init (); */
+ return data_wrapper_repository_init ();
}
gchar *current;
CAMEL_LOG_FULL_DEBUG ( "write_header_with_glist_to_stream:: entering\n");
+ CAMEL_LOG_FULL_DEBUG ( "\theader name : %s\n", header_name);
if ( (header_name) && (header_values) )
{
gboolean first;
first = TRUE;
while (header_values) {
current = (gchar *)header_values->data;
+ CAMEL_LOG_FULL_DEBUG ( "write_header_with_glist_to_stream:: writing value : %s\n", current);
if (current) {
if (!first) camel_stream_write_string (stream, separator);
else first = FALSE;
#include <config.h>
+#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
static gint _get_message_count (CamelFolder *folder, CamelException *ex);
static gint _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex);
static GList *_get_uid_list (CamelFolder *folder, CamelException *ex);
-#if 0
static CamelMimeMessage *_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex);
+#if 0
static void _expunge (CamelFolder *folder, CamelException *ex);
static void _copy_message_to (CamelFolder *folder, CamelMimeMessage *message, CamelFolder *dest_folder, CamelException *ex);
static const gchar *_get_message_uid (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex);
#endif
+
static void _finalize (GtkObject *object);
static void
camel_folder_class->expunge = _expunge;
camel_folder_class->copy_message_to = _copy_message_to;
camel_folder_class->get_message_uid = _get_message_uid;
- camel_folder_class->get_message_by_uid = _get_message_by_uid;
#endif
+ camel_folder_class->get_message_by_uid = _get_message_by_uid;
+
gtk_object_class->finalize = _finalize;
}
+static CamelMimeMessage *
+_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex)
+{
+
+ CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER(folder);
+ GArray *message_info_array;
+ CamelMboxSummaryInformation *message_info;
+ guint32 searched_uid;
+ int i;
+ gboolean uid_found;
+ CamelStreamFs *message_stream;
+ CamelMimeMessage *message = NULL;
+ CamelStore *parent_store;
+
+ CAMEL_LOG_FULL_DEBUG ("Entering CamelMboxFolder::get_uid_list\n");
+
+ searched_uid = strtoul(uid, (char **)NULL, 10);
+
+ message_info_array = mbox_folder->summary->message_info;
+ i=0;
+ uid_found = FALSE;
+
+ /* first, look for the message that has the searched uid */
+ while ((i<message_info_array->len) && (!uid_found)) {
+ message_info = (CamelMboxSummaryInformation *)(message_info_array->data) + i;
+ uid_found = (message_info->uid == searched_uid);
+ i++;
+ }
+
+ /* if the uid was not found, raise an exception and return */
+ if (!uid_found) {
+ camel_exception_setv (ex,
+ CAMEL_EXCEPTION_FOLDER_INVALID_UID,
+ "uid %s not found in the folder",
+ uid);
+ CAMEL_LOG_FULL_DEBUG ("Leaving CamelMboxFolder::get_uid_list\n");
+ return NULL;
+ }
+
+ /* at this point, the message_info structure
+ contains the informations concerning the
+ message that was searched for */
+
+ /* create a stream bound to the message */
+ message_stream = camel_stream_fs_new_with_name_and_bounds (mbox_folder->folder_file_path,
+ CAMEL_STREAM_FS_READ,
+ message_info->position,
+ message_info->position + message_info->size);
+
+
+ /* get the parent store */
+ parent_store = camel_folder_get_parent_store (folder, ex);
+ if (camel_exception_get_id (ex)) {
+ gtk_object_unref (GTK_OBJECT (message_stream));
+ return NULL;
+ }
+
+
+ message = camel_mime_message_new_with_session (camel_store_get_session (parent_store, ex));
+ camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (message), CAMEL_STREAM (message_stream));
+
+
+
+
+ CAMEL_LOG_FULL_DEBUG ("Leaving CamelMboxFolder::get_uid_list\n");
+ return message;
+}
msg_info = (CamelMboxSummaryInformation *)(summary->message_info->data) + cur_msg;
- /* write message position + x-evolution offset
- + uid + status */
+ /* write message position + message size
+ + x-evolution offset + uid + status */
write (fd, (gchar *)msg_info,
- sizeof (guint32) + sizeof (guint) +
+ sizeof (guint32) + 2 * sizeof (guint) +
sizeof (guint32) + sizeof (guchar));
/* write subject */
msg_info = (CamelMboxSummaryInformation *)(summary->message_info->data) + cur_msg;
- /* read message position + x-evolution offset
- + uid + status */
+ /* read message position + message size
+ + x-evolution offset + uid + status */
read (fd, (gchar *)msg_info,
- sizeof (guint32) + sizeof (guint) +
+ sizeof (guint32) + 2 * sizeof (guint) +
sizeof (guint32) + sizeof (guchar));
*
* Author : Bertrand Guiheneuf <bertrand@helixcode.com>
*
- * Copyright (C) 1999 Helix Code .
+ * Copyright (C) 1999 Helix Code (http://www.helixcode.com).
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
typedef struct {
guint32 position;
+ guint size;
guint x_evolution_offset;
guint32 uid;
guchar status;
cur_sum_info->position = cur_msg_info->message_position;
+ cur_sum_info->size = cur_msg_info->size;
+
cur_sum_info->x_evolution_offset = cur_msg_info->x_evolution_offset;
cur_sum_info->uid = cur_msg_info->uid;