aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--camel/camel-folder.c1
-rw-r--r--camel/providers/mbox/camel-mbox-folder.c96
-rw-r--r--camel/providers/mbox/camel-mbox-summary.c2
-rw-r--r--camel/providers/mbox/camel-mbox-utils.c17
-rw-r--r--camel/providers/mbox/camel-mbox-utils.h6
-rw-r--r--tests/test1.c4
-rw-r--r--tests/test10.c52
8 files changed, 148 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index 025a751a0b..fb43e39c3e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2000-01-22 bertrand <bertrand@helixcode.com>
+
+ * camel/providers/mbox/camel-mbox-folder.c (_append_message):
+ implemented. A lot of fixes too. Works now.
+
+
2000-01-21 bertrand <bertrand@helixcode.com>
* tests/test10.c:
diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index 69e1df9694..0930550cbf 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -200,7 +200,6 @@ static void
_finalize (GtkObject *object)
{
CamelFolder *camel_folder = CAMEL_FOLDER (object);
- GList *message_node;
CAMEL_LOG_FULL_DEBUG ("Entering CamelFolder::finalize\n");
diff --git a/camel/providers/mbox/camel-mbox-folder.c b/camel/providers/mbox/camel-mbox-folder.c
index 1a01462fd6..3bd02a7739 100644
--- a/camel/providers/mbox/camel-mbox-folder.c
+++ b/camel/providers/mbox/camel-mbox-folder.c
@@ -69,12 +69,12 @@ static GList *_list_subfolders (CamelFolder *folder, CamelException *ex);
/* static CamelMimeMessage *_get_message_by_number (CamelFolder *folder, gint number, CamelException *ex);*/
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);
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);
-static CamelMimeMessage *_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex);
-static GList *_get_uid_list (CamelFolder *folder, CamelException *ex);
#endif
static void _finalize (GtkObject *object);
@@ -101,8 +101,8 @@ camel_mbox_folder_class_init (CamelMboxFolderClass *camel_mbox_folder_class)
camel_folder_class->list_subfolders = _list_subfolders;
/* camel_folder_class->get_message_by_number = _get_message_by_number; */
camel_folder_class->get_message_count = _get_message_count;
-#if 0
camel_folder_class->append_message = _append_message;
+#if 0
camel_folder_class->expunge = _expunge;
camel_folder_class->copy_message_to = _copy_message_to;
camel_folder_class->get_message_uid = _get_message_uid;
@@ -276,6 +276,7 @@ _check_get_or_maybe_generate_summary_file (CamelMboxFolder *mbox_folder, CamelEx
/* store the number of messages as well as the summary array */
mbox_folder->summary->nb_message = mbox_summary_info->len;
+ printf ("Next UID : %ld\n", next_uid);
mbox_folder->summary->next_uid = next_uid;
mbox_folder->summary->mbox_file_size = file_size;
mbox_folder->summary->message_info = mbox_summary_info;
@@ -886,26 +887,29 @@ _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException
CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER(folder);
//guint new_msg_number;
CamelStream *output_stream;
- guint32 file_size;
+ guint32 tmp_file_size;
guint32 next_uid;
- gint mbox_file_fd;
+ gint tmp_file_fd;
GArray *message_info_array;
GArray *mbox_summary_info;
+ gchar *tmp_message_filename;
+ gint fd1, fd2;
+
CAMEL_LOG_FULL_DEBUG ("Entering CamelMboxFolder::append_message\n");
+ tmp_message_filename = g_strdup_printf ("%s.tmp", mbox_folder->folder_file_path);
/* write the message itself */
- output_stream = camel_stream_fs_new_with_name (mbox_folder->folder_file_path, CAMEL_STREAM_FS_WRITE);
+ output_stream = camel_stream_fs_new_with_name (tmp_message_filename, CAMEL_STREAM_FS_WRITE);
if (output_stream != NULL) {
- camel_stream_seek (output_stream, mbox_folder->summary->mbox_file_size, CAMEL_STREAM_SET);
camel_stream_write_string (output_stream, "From - \n");
camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), output_stream);
}
camel_stream_close (output_stream);
- /* at this point we have only added the message to
- the file, but now, we have to add the x-evolution
- field and also update the summary */
+ /* at this point we have saved the message to a
+ temporary file, now, we have to add the x-evolution
+ field and also update the main summary summary */
/*
First : parse the mbox file, but only from the
@@ -915,26 +919,31 @@ _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException
This position is still stored in the summary
for the moment
*/
- mbox_file_fd = open (mbox_folder->folder_file_path, O_RDONLY);
- message_info_array = camel_mbox_parse_file (mbox_file_fd,
+ next_uid = mbox_folder->summary->next_uid;
+ tmp_file_fd = open (tmp_message_filename, O_RDONLY);
+ message_info_array = camel_mbox_parse_file (tmp_file_fd,
"From - ",
- mbox_folder->summary->mbox_file_size,
- &file_size,
+ 0,
+ &tmp_file_size,
&next_uid,
TRUE,
NULL,
0,
ex);
- close (mbox_file_fd);
+ close (tmp_file_fd);
+
+ /* get the value of the last available UID
+ as saved in the summary file */
+ next_uid = mbox_folder->summary->next_uid;
/*
OK, this is not very efficient, we should not use the same
method as for parsing an entire mail file,
but I have no time to write a simpler parser
*/
- next_uid = camel_mbox_write_xev (mbox_folder->folder_file_path,
- message_info_array, &file_size, next_uid, ex);
+ next_uid = camel_mbox_write_xev (tmp_message_filename,
+ message_info_array, &tmp_file_size, next_uid, ex);
if (camel_exception_get_id (ex)) {
/* ** FIXME : free the preparsed information */
@@ -944,19 +953,50 @@ _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException
mbox_summary_info =
parsed_information_to_mbox_summary (message_info_array);
+
/* generate the folder md5 signature */
md5_get_digest_from_file (mbox_folder->folder_file_path, mbox_folder->summary->md5_digest);
-
+
+
/* store the number of messages as well as the summary array */
mbox_folder->summary->nb_message += 1;
- mbox_folder->summary->next_uid = next_uid;
- mbox_folder->summary->mbox_file_size = file_size;
-
+ mbox_folder->summary->next_uid = next_uid;
+ printf ("Next UID = %ld\n", next_uid);
+ ((CamelMboxSummaryInformation *)(mbox_summary_info->data))->position += mbox_folder->summary->mbox_file_size;
+ mbox_folder->summary->mbox_file_size += tmp_file_size;
+
mbox_folder->summary->message_info =
g_array_append_val (mbox_folder->summary->message_info, mbox_summary_info->data);
g_array_free (mbox_summary_info, TRUE);
+
+ /* append the temporary file message to the mbox file */
+ fd1 = open (tmp_message_filename, O_RDONLY);
+ fd2 = open (mbox_folder->folder_file_path, O_WRONLY | O_CREAT | O_APPEND);
+ if (fd2 == -1) {
+ camel_exception_setv (ex,
+ CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION,
+ "could not open the mbox folder file for appending the message\n"
+ "\t%s\n"
+ "Full error is : %s\n",
+ mbox_folder->folder_file_path,
+ strerror (errno));
+ return -1;
+ }
+
+ camel_mbox_copy_file_chunk (fd1,
+ fd2,
+ tmp_file_size,
+ ex);
+ close (fd1);
+ close (fd2);
+
+ /* generate the folder md5 signature */
+ md5_get_digest_from_file (mbox_folder->folder_file_path, mbox_folder->summary->md5_digest);
+
+
+ g_free (tmp_message_filename);
CAMEL_LOG_FULL_DEBUG ("Leaving CamelMboxFolder::append_message\n");
return -1;
@@ -965,6 +1005,20 @@ _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException
+static GList *
+_get_uid_list (CamelFolder *folder, CamelException *ex)
+{
+
+}
+
+
+
+
+
+
+
+
+
diff --git a/camel/providers/mbox/camel-mbox-summary.c b/camel/providers/mbox/camel-mbox-summary.c
index 685d375fa7..f35ca16a16 100644
--- a/camel/providers/mbox/camel-mbox-summary.c
+++ b/camel/providers/mbox/camel-mbox-summary.c
@@ -238,7 +238,7 @@ camel_mbox_check_summary_sync (gchar *summary_filename,
lseek (fd, sizeof (guint), SEEK_SET);
/* read the md5 signature stored in the summary file */
- read (fd, summary_md5, + sizeof (guchar) * 16);
+ read (fd, summary_md5, sizeof (guchar) * 16);
close (fd);
/* ** FIXME : check for exception in all these operations */
diff --git a/camel/providers/mbox/camel-mbox-utils.c b/camel/providers/mbox/camel-mbox-utils.c
index 5d901b4d7c..b8b11495ea 100644
--- a/camel/providers/mbox/camel-mbox-utils.c
+++ b/camel/providers/mbox/camel-mbox-utils.c
@@ -32,7 +32,7 @@
* ...
*
*
- * The evolution line ha10s the following format :
+ * The evolution line has the following format :
*
* X-Evolution:XXXXX-X
* \___/ \/
@@ -160,17 +160,16 @@ camel_mbox_xev_write_header_content (gchar header_content[6],
-static void
-copy_file_chunk (gint fd_src,
- gint fd_dest,
- glong nb_bytes,
- CamelException *ex)
+void
+camel_mbox_copy_file_chunk (gint fd_src,
+ gint fd_dest,
+ glong nb_bytes,
+ CamelException *ex)
{
gchar buffer [1000];
glong nb_to_read;
glong nb_read, v;
- printf ("Write %ld bytes\n", nb_bytes);
nb_to_read = nb_bytes;
while (nb_to_read > 0) {
@@ -261,7 +260,7 @@ camel_mbox_write_xev (gchar *mbox_file_name,
cur_pos = cur_msg_info->message_position
+ cur_msg_info->end_of_headers_offset;
- copy_file_chunk (fd1, fd2, bytes_to_copy, ex);
+ camel_mbox_copy_file_chunk (fd1, fd2, bytes_to_copy, ex);
if (camel_exception_get_id (ex)) {
close (fd1);
close (fd2);
@@ -285,7 +284,7 @@ camel_mbox_write_xev (gchar *mbox_file_name,
bytes_to_copy = end_of_last_message - cur_pos;
- copy_file_chunk (fd1, fd2, bytes_to_copy, ex);
+ camel_mbox_copy_file_chunk (fd1, fd2, bytes_to_copy, ex);
/* close the original file as well as the
diff --git a/camel/providers/mbox/camel-mbox-utils.h b/camel/providers/mbox/camel-mbox-utils.h
index 10a8a68e24..062a284b03 100644
--- a/camel/providers/mbox/camel-mbox-utils.h
+++ b/camel/providers/mbox/camel-mbox-utils.h
@@ -56,6 +56,12 @@ camel_mbox_write_xev (gchar *mbox_file_name,
GArray *
parsed_information_to_mbox_summary (GArray *parsed_information);
+void
+camel_mbox_copy_file_chunk (gint fd_src,
+ gint fd_dest,
+ glong nb_bytes,
+ CamelException *ex);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/tests/test1.c b/tests/test1.c
index 5caac29c74..048b36e1ec 100644
--- a/tests/test1.c
+++ b/tests/test1.c
@@ -62,9 +62,9 @@ main (int argc, char**argv)
camel_mime_message_add_recipient (message, CAMEL_RECIPIENT_TYPE_TO,
g_strdup ("mc@alseve.fr"));
camel_mime_message_add_recipient (message, CAMEL_RECIPIENT_TYPE_TO,
- g_strdup ("richard.lengagne@aful.org"));
+ g_strdup ("richard.lengagne@inria.fr"));
camel_mime_message_add_recipient (message, CAMEL_RECIPIENT_TYPE_CC,
- g_strdup ("Francois.fleuret@aful.org"));
+ g_strdup ("Francois.fleuret@inria.fr"));
camel_mime_message_add_recipient (message, CAMEL_RECIPIENT_TYPE_CC,
g_strdup ("maury@justmagic.com"));
camel_mime_message_add_recipient (message, CAMEL_RECIPIENT_TYPE_BCC,
diff --git a/tests/test10.c b/tests/test10.c
index deeed0b0ac..07f0fdf81e 100644
--- a/tests/test10.c
+++ b/tests/test10.c
@@ -17,6 +17,52 @@
#include <fcntl.h>
#include <glib.h>
+
+static CamelMimeMessage *
+create_sample_mime_message ()
+{
+ CamelMimeMessage *message;
+ CamelMimeBodyPart *body_part;
+ CamelMultipart *multipart;
+
+
+ message = camel_mime_message_new_with_session ((CamelSession *)NULL);
+
+ camel_mime_part_set_description (CAMEL_MIME_PART (message), "a test");
+
+ camel_medium_add_header (CAMEL_MEDIUM (message), "X-test1", "the value of a test");
+ camel_medium_add_header (CAMEL_MEDIUM (message), "X-test2", "the value of another test");
+
+ camel_mime_message_set_received_date (message, g_strdup ("Thu, 20 May 1999, 10:39:14 +0200"));
+ camel_mime_message_set_subject (message, g_strdup ("A test message"));
+ camel_mime_message_set_reply_to (message, g_strdup ("toto@toto.com"));
+ camel_mime_message_set_from (message, g_strdup ("Bertrand.Guiheneuf@aful.org"));
+
+ camel_mime_message_add_recipient (message, CAMEL_RECIPIENT_TYPE_TO,
+ g_strdup ("franck.dechamps@alseve.fr"));
+ camel_mime_message_add_recipient (message, CAMEL_RECIPIENT_TYPE_TO,
+ g_strdup ("mc@alseve.fr"));
+ camel_mime_message_add_recipient (message, CAMEL_RECIPIENT_TYPE_TO,
+ g_strdup ("richard.lengagne@inria.fr"));
+ camel_mime_message_add_recipient (message, CAMEL_RECIPIENT_TYPE_CC,
+ g_strdup ("Francois.fleuret@inria.fr"));
+ camel_mime_message_add_recipient (message, CAMEL_RECIPIENT_TYPE_CC,
+ g_strdup ("maury@justmagic.com"));
+ camel_mime_message_add_recipient (message, CAMEL_RECIPIENT_TYPE_BCC,
+ g_strdup ("Bertrand.Guiheneuf@aful.org"));
+
+ multipart = camel_multipart_new ();
+ body_part = camel_mime_body_part_new ();
+ camel_mime_part_set_text (CAMEL_MIME_PART (body_part), "This is a test.\nThis is only a test.\n");
+ camel_multipart_add_part (multipart, body_part);
+ camel_medium_set_content_object (CAMEL_MEDIUM (message), CAMEL_DATA_WRAPPER (multipart));
+
+ return message;
+}
+
+
+
+
int
main (int argc, char**argv)
{
@@ -25,7 +71,7 @@ main (int argc, char**argv)
CamelStore *store;
gchar *store_url = "mbox:///tmp/evmail";
CamelFolder *folder;
-
+ CamelMimeMessage *message;
camel_debug_level = 10;
@@ -40,11 +86,13 @@ main (int argc, char**argv)
folder = camel_store_get_folder (store, "Inbox", ex);
if (camel_exception_get_id (ex)) {
- printf ("Exception caughy in camel_store_get_folder"
+ printf ("Exception caught in camel_store_get_folder"
"Full description : %s\n", camel_exception_get_description (ex));
}
camel_folder_open (folder, FOLDER_OPEN_RW, ex);
+ message = create_sample_mime_message ();
+ camel_folder_append_message (folder, message, ex);
camel_folder_close (folder, FALSE, ex);
return 1;