From fbcdf475521aaf13049ddc7c9f96bb0c9ed9b870 Mon Sep 17 00:00:00 2001 From: bertrand Date: Sun, 23 Jan 2000 01:45:49 +0000 Subject: use the real summary file path instead of a stupid hardcoded one. Fixes 2000-01-22 bertrand * camel/providers/mbox/camel-mbox-folder.c (_check_get_or_maybe_generate_summary_file): use the real summary file path instead of a stupid hardcoded one. Fixes yet another bug. * camel/providers/mbox/camel-mbox-utils.c (parsed_information_to_mbox_summary): don't forget to copy the date too. Fix a very annoying bug. * camel/providers/mbox/camel-mbox-folder.c (_append_message): implemented. A lot of fixes too. Works now. (_get_uid_list): implemented. svn path=/trunk/; revision=1609 --- ChangeLog | 9 ++++++- camel/providers/mbox/camel-mbox-folder.c | 39 +++++++++++++++++++++---------- camel/providers/mbox/camel-mbox-parser.c | 2 -- camel/providers/mbox/camel-mbox-summary.c | 22 +++++++++++++---- camel/providers/mbox/camel-mbox-summary.h | 2 ++ camel/providers/mbox/camel-mbox-utils.c | 5 +++- tests/test10.c | 23 ++++++++++++++++-- 7 files changed, 79 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index fb43e39c3e..6e5a90ca6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,15 @@ 2000-01-22 bertrand + * camel/providers/mbox/camel-mbox-folder.c (_check_get_or_maybe_generate_summary_file): + use the real summary file path instead of a + stupid hardcoded one. Fixes yet another bug. + + * camel/providers/mbox/camel-mbox-utils.c (parsed_information_to_mbox_summary): + don't forget to copy the date too. Fix a very annoying bug. + * camel/providers/mbox/camel-mbox-folder.c (_append_message): implemented. A lot of fixes too. Works now. - + (_get_uid_list): implemented. 2000-01-21 bertrand diff --git a/camel/providers/mbox/camel-mbox-folder.c b/camel/providers/mbox/camel-mbox-folder.c index 3bd02a7739..54f38e1210 100644 --- a/camel/providers/mbox/camel-mbox-folder.c +++ b/camel/providers/mbox/camel-mbox-folder.c @@ -102,12 +102,12 @@ camel_mbox_folder_class_init (CamelMboxFolderClass *camel_mbox_folder_class) /* camel_folder_class->get_message_by_number = _get_message_by_number; */ camel_folder_class->get_message_count = _get_message_count; camel_folder_class->append_message = _append_message; + camel_folder_class->get_uid_list = _get_uid_list; #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; camel_folder_class->get_message_by_uid = _get_message_by_uid; - camel_folder_class->get_uid_list = _get_uid_list; #endif gtk_object_class->finalize = _finalize; @@ -175,7 +175,6 @@ _init_with_store (CamelFolder *folder, CamelStore *parent_store, CamelException parent_class->init_with_store (folder, parent_store, ex); if (camel_exception_get_id (ex)) return; - printf ("%d\n", folder->open_mode); /* we assume that the parent init_with_store method checks for the existance of @folder */ @@ -212,7 +211,6 @@ _check_get_or_maybe_generate_summary_file (CamelMboxFolder *mbox_folder, CamelEx guint32 next_uid; guint32 file_size; - /* test for the existence of the summary file */ summary_file_exists = (access (mbox_folder->summary_file_path, F_OK) == 0); @@ -276,14 +274,13 @@ _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; } else { /* every thing seems ok, just read the summary file from disk */ - mbox_folder->summary = camel_mbox_load_summary ("ev-summary.mbox", ex); + mbox_folder->summary = camel_mbox_load_summary (mbox_folder->summary_file_path, ex); } } @@ -356,7 +353,7 @@ _set_name (CamelFolder *folder, const gchar *name, CamelException *ex) CAMEL_LOG_FULL_DEBUG ("CamelMboxFolder::separator is %c\n", separator); mbox_folder->folder_file_path = g_strdup_printf ("%s%c%s", root_dir_path, separator, folder->full_name); - mbox_folder->summary_file_path = g_strdup_printf ("%s%c.%s-ev-summary", root_dir_path, separator, folder->full_name); + mbox_folder->summary_file_path = g_strdup_printf ("%s%c%s-ev-summary", root_dir_path, separator, folder->full_name); mbox_folder->folder_dir_path = g_strdup_printf ("%s%c%s.sdb", root_dir_path, separator, folder->full_name); @@ -954,21 +951,18 @@ _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException 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; - 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); + camel_summary_append_entries (mbox_folder->summary, mbox_summary_info); - g_array_free (mbox_summary_info, TRUE); + g_array_free (mbox_summary_info, TRUE); /* append the temporary file message to the mbox file */ @@ -992,6 +986,9 @@ _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException close (fd1); close (fd2); + /* remove the temporary file */ + unlink (tmp_message_filename); + /* generate the folder md5 signature */ md5_get_digest_from_file (mbox_folder->folder_file_path, mbox_folder->summary->md5_digest); @@ -1008,7 +1005,25 @@ _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException static GList * _get_uid_list (CamelFolder *folder, CamelException *ex) { + CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER(folder); + GArray *message_info_array; + CamelMboxSummaryInformation *message_info; + GList *uid_list = NULL; + int i; + + CAMEL_LOG_FULL_DEBUG ("Entering CamelMboxFolder::get_uid_list\n"); + + message_info_array = mbox_folder->summary->message_info; + + for (i=0; ilen; i++) { + + message_info = (CamelMboxSummaryInformation *)(message_info_array->data) + i; + uid_list = g_list_prepend (uid_list, g_strdup_printf ("%u", message_info->uid)); + } + + CAMEL_LOG_FULL_DEBUG ("Leaving CamelMboxFolder::get_uid_list\n"); + return uid_list; } diff --git a/camel/providers/mbox/camel-mbox-parser.c b/camel/providers/mbox/camel-mbox-parser.c index db6f5bff44..905214811e 100644 --- a/camel/providers/mbox/camel-mbox-parser.c +++ b/camel/providers/mbox/camel-mbox-parser.c @@ -228,7 +228,6 @@ initialize_buffer (CamelMboxPreParser *parser, /* fill the end of the buffer with 0\ */ memset (parser->buffer + buf_nb_read + parser->left_chunk_size, '\0', MIN (parser->left_chunk_size, MBOX_PARSER_BUF_SIZE - buf_nb_read - parser->left_chunk_size)); - printf ("I am memsetting with 0\n"); }; parser->last_position = MIN (buf_nb_read + parser->left_chunk_size + 1, @@ -802,7 +801,6 @@ camel_mbox_parse_file (int fd, if (parser->is_pending_message) { parser->current_message_info.size = parser->real_position - parser->current_message_info.message_position; - printf ("the postion of the last message : %ld\nthe size of the last message is : %ld\n", parser->current_message_info.message_position, parser->current_message_info.size); g_array_append_vals (parser->preparsed_messages, (gchar *)parser + G_STRUCT_OFFSET (CamelMboxPreParser, current_message_info), 1); } diff --git a/camel/providers/mbox/camel-mbox-summary.c b/camel/providers/mbox/camel-mbox-summary.c index f35ca16a16..2cbb481700 100644 --- a/camel/providers/mbox/camel-mbox-summary.c +++ b/camel/providers/mbox/camel-mbox-summary.c @@ -47,6 +47,7 @@ camel_mbox_save_summary (CamelMboxSummary *summary, const gchar *filename, Camel guint cur_msg; guint field_lgth; gint fd; + gint write_result; CAMEL_LOG_FULL_DEBUG ("CamelMboxFolder::save_summary entering \n"); @@ -67,8 +68,8 @@ camel_mbox_save_summary (CamelMboxSummary *summary, const gchar *filename, Camel /* write the number of messages + the md5 signatures + next UID + mbox file size */ - write (fd, summary, sizeof (guint) + sizeof (guchar) * 16 + 2 * sizeof (guint32)); - + write_result = write (fd, summary, G_STRUCT_OFFSET (CamelMboxSummary, message_info)); + for (cur_msg=0; cur_msg < summary->nb_message; cur_msg++) { @@ -85,7 +86,6 @@ camel_mbox_save_summary (CamelMboxSummary *summary, const gchar *filename, Camel write (fd, &field_lgth, sizeof (guint)); if (field_lgth) write (fd, msg_info->subject, field_lgth); - /* write sender */ field_lgth = msg_info->sender ? strlen (msg_info->sender) : 0; write (fd, &field_lgth, sizeof (gint)); @@ -124,7 +124,7 @@ camel_mbox_load_summary (const gchar *filename, CamelException *ex) guint field_lgth; gint fd; CamelMboxSummary *summary; - + gint read_result; CAMEL_LOG_FULL_DEBUG ("CamelMboxFolder::save_summary entering \n"); @@ -143,7 +143,8 @@ camel_mbox_load_summary (const gchar *filename, CamelException *ex) /* read the message number, the md5 signature and the next available UID + mbox file size */ - read (fd, summary, sizeof (guint) + sizeof (guchar) * 16 + 2 * sizeof (guint32)); + read_result = read (fd, summary, G_STRUCT_OFFSET (CamelMboxSummary, message_info)); + summary->message_info = g_array_new (FALSE, FALSE, sizeof (CamelMboxSummaryInformation)); summary->message_info = g_array_set_size (summary->message_info, summary->nb_message); @@ -249,3 +250,14 @@ camel_mbox_check_summary_sync (gchar *summary_filename, return (strncmp (real_md5, summary_md5, 16) == 0); } + + + + +void +camel_summary_append_entries (CamelMboxSummary *summary, GArray *entries) +{ + + summary->message_info = g_array_append_vals (summary->message_info, entries->data, entries->len); + +} diff --git a/camel/providers/mbox/camel-mbox-summary.h b/camel/providers/mbox/camel-mbox-summary.h index bb7450d5e7..cdfb88d63a 100644 --- a/camel/providers/mbox/camel-mbox-summary.h +++ b/camel/providers/mbox/camel-mbox-summary.h @@ -66,6 +66,8 @@ camel_mbox_check_summary_sync (gchar *summary_filename, gchar *mbox_filename, CamelException *ex); +void +camel_summary_append_entries (CamelMboxSummary *summary, GArray *entries); #endif /* MH_SUMMARY_H */ diff --git a/camel/providers/mbox/camel-mbox-utils.c b/camel/providers/mbox/camel-mbox-utils.c index b8b11495ea..52de0d526e 100644 --- a/camel/providers/mbox/camel-mbox-utils.c +++ b/camel/providers/mbox/camel-mbox-utils.c @@ -250,7 +250,7 @@ camel_mbox_write_xev (gchar *mbox_file_name, cur_msg_info = (CamelMboxParserMessageInfo *)(summary_information->data) + cur_msg; end_of_last_message = cur_msg_info->message_position + cur_msg_info->size; - printf ("End of last message : %ld\n", end_of_last_message); + if (cur_msg_info->uid == 0) { bytes_to_copy = cur_msg_info->message_position @@ -370,6 +370,9 @@ parsed_information_to_mbox_summary (GArray *parsed_information) cur_sum_info->to = cur_msg_info->to; cur_msg_info->to = NULL; + + cur_sum_info->date = cur_msg_info->date; + cur_msg_info->date = NULL; } diff --git a/tests/test10.c b/tests/test10.c index 07f0fdf81e..b223efb8ef 100644 --- a/tests/test10.c +++ b/tests/test10.c @@ -72,7 +72,7 @@ main (int argc, char**argv) gchar *store_url = "mbox:///tmp/evmail"; CamelFolder *folder; CamelMimeMessage *message; - + GList *uid_list; camel_debug_level = 10; gtk_init (&argc, &argv); @@ -88,11 +88,30 @@ main (int argc, char**argv) if (camel_exception_get_id (ex)) { printf ("Exception caught in camel_store_get_folder" "Full description : %s\n", camel_exception_get_description (ex)); + return -1; } + camel_folder_open (folder, FOLDER_OPEN_RW, ex); - + if (camel_exception_get_id (ex)) { + printf ("Exception caught when trying to open the folder" + "Full description : %s\n", camel_exception_get_description (ex)); + return -1; + } + message = create_sample_mime_message (); camel_folder_append_message (folder, message, ex); + if (camel_exception_get_id (ex)) { + printf ("Exception caught when trying to append a message to the folder" + "Full description : %s\n", camel_exception_get_description (ex)); + return -1; + } + + uid_list = camel_folder_get_uid_list (folder, ex); + while (uid_list) { + printf ("UID : %s\n", (gchar *)uid_list->data); + uid_list = uid_list->next; + } + camel_folder_close (folder, FALSE, ex); return 1; -- cgit