diff options
author | bertrand <Bertrand.Guiheneuf@aful.org> | 1999-08-09 04:02:02 +0800 |
---|---|---|
committer | Bertrand Guiheneuf <bertrand@src.gnome.org> | 1999-08-09 04:02:02 +0800 |
commit | 4c3eb877493c9f4ae656788cde2eacc6b7ca5d0e (patch) | |
tree | 44abba2c15f35822470aacc4bf546c578191247a | |
parent | e5d44122b8457faa0a18877c5c45be516035e138 (diff) | |
download | gsoc2013-evolution-4c3eb877493c9f4ae656788cde2eacc6b7ca5d0e.tar gsoc2013-evolution-4c3eb877493c9f4ae656788cde2eacc6b7ca5d0e.tar.gz gsoc2013-evolution-4c3eb877493c9f4ae656788cde2eacc6b7ca5d0e.tar.bz2 gsoc2013-evolution-4c3eb877493c9f4ae656788cde2eacc6b7ca5d0e.tar.lz gsoc2013-evolution-4c3eb877493c9f4ae656788cde2eacc6b7ca5d0e.tar.xz gsoc2013-evolution-4c3eb877493c9f4ae656788cde2eacc6b7ca5d0e.tar.zst gsoc2013-evolution-4c3eb877493c9f4ae656788cde2eacc6b7ca5d0e.zip |
fix. In MH, message number is not related to message position in folder.
1999-08-08 bertrand <Bertrand.Guiheneuf@aful.org>
* camel/providers/MH/camel-mh-folder.c (_get_message):
fix. In MH, message number is not related to
message position in folder.
svn path=/trunk/; revision=1097
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | camel/providers/MH/camel-mh-folder.c | 118 | ||||
-rw-r--r-- | camel/string-utils.c | 4 | ||||
-rw-r--r-- | tests/test4.c | 4 |
4 files changed, 77 insertions, 53 deletions
@@ -1,5 +1,9 @@ 1999-08-08 bertrand <Bertrand.Guiheneuf@aful.org> + * camel/providers/MH/camel-mh-folder.c (_get_message): + fix. In MH, message number is not related to + message position in folder. + * camel/providers/MH/camel-mh-folder.c (_is_a_message_file): util func. (_get_message_count): implemented. diff --git a/camel/providers/MH/camel-mh-folder.c b/camel/providers/MH/camel-mh-folder.c index 0254b003f4..2e19349e67 100644 --- a/camel/providers/MH/camel-mh-folder.c +++ b/camel/providers/MH/camel-mh-folder.c @@ -356,50 +356,6 @@ _list_subfolders(CamelFolder *folder) - - -static CamelMimeMessage * -_get_message (CamelFolder *folder, gint number) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - gchar *directory_path; - gchar *message_file_name; - struct stat stat_buf; - gint stat_error = 0; - CamelStream *input_stream; - CamelMimeMessage *message; - - g_assert(folder); - - /* call default implementation */ - parent_class->delete_messages (folder); - - directory_path = mh_folder->directory_path; - if (!directory_path) return NULL; - - if (!camel_folder_exists (folder)) return NULL; - - message_file_name = g_strdup_printf ("%s/%d", directory_path, number); - stat_error = stat (message_file_name, &stat_buf); - - if ((stat_error == -1) || (!S_ISREG (stat_buf.st_mode))) { - g_free (message_file_name); - return NULL; - } else { - input_stream = camel_stream_fs_new_with_name (message_file_name, CAMEL_STREAM_FS_READ); - g_free (message_file_name); - if (!input_stream) return NULL; -#warning use session field here - message = camel_mime_message_new_with_session ( (CamelSession *)NULL); - camel_data_wrapper_construct_from_stream ( CAMEL_DATA_WRAPPER (message), input_stream); - gtk_object_unref (GTK_OBJECT (input_stream)); - - } - - return message; -} - - static gboolean _is_a_message_file (const gchar *file_name, const gchar *file_path) { @@ -409,30 +365,93 @@ _is_a_message_file (const gchar *file_name, const gchar *file_path) gchar *full_file_name; int i; - - - /* test if the name is a number */ i=0; while ((file_name[i] != '\0') && (file_name[i] >= '0') && (file_name[i] <= '9')) i++; if ((i==0) || (file_name[i] != '\0')) return FALSE; - /* is it a regular file ? */ full_file_name = g_strdup_printf ("%s/%s", file_path, file_name); stat_error = stat (full_file_name, &stat_buf); g_free (full_file_name); return ((stat_error != -1) && S_ISREG (stat_buf.st_mode)); +} + + +static gint +_message_name_compare (gconstpointer a, gconstpointer b) +{ + gchar *m1 = (gchar *)a; + gchar *m2 = (gchar *)b; + gint len_diff; + + return (atoi (m1) - atoi (m2)); +} + +/* slow routine, may be optimixed, or we should use + caches if users complain */ +static CamelMimeMessage * +_get_message (CamelFolder *folder, gint number) +{ + CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); + const gchar *directory_path; + gchar *message_name; + gchar *message_file_name; + struct dirent *dir_entry; + DIR *dir_handle; + CamelStream *input_stream = NULL; + CamelMimeMessage *message = NULL; + GList *message_list = NULL; + + g_assert(folder); + + directory_path = mh_folder->directory_path; + if (!directory_path) return NULL; + if (!camel_folder_exists (folder)) return NULL; + + /* read the whole folder and sort message names */ + dir_handle = opendir (directory_path); + /* read first entry in the directory */ + dir_entry = readdir (dir_handle); + while (dir_entry != NULL) { + /* tests if the entry correspond to a message file */ + if (_is_a_message_file (dir_entry->d_name, directory_path)) + message_list = g_list_insert_sorted (message_list, g_strdup (dir_entry->d_name), _message_name_compare); + /* read next entry */ + dir_entry = readdir (dir_handle); + } + + closedir (dir_handle); + + + message_name = g_list_nth_data (message_list, number); + if (message_name != NULL) { + CAMEL_LOG_FULL_DEBUG ("CanelMhFolder::get_message message number = %d, name = %s\n", number, message_name); + message_file_name = g_strdup_printf ("%s/%s", directory_path, message_name); + input_stream = camel_stream_fs_new_with_name (message_file_name, CAMEL_STREAM_FS_READ); + g_free (message_file_name); + if (input_stream != NULL) { +#warning use session field here + message = camel_mime_message_new_with_session ( (CamelSession *)NULL); + camel_data_wrapper_construct_from_stream ( CAMEL_DATA_WRAPPER (message), input_stream); + gtk_object_unref (GTK_OBJECT (input_stream)); + } + } else + CAMEL_LOG_FULL_DEBUG ("CanelMhFolder::get_message message number = %d, not found\n", number); + string_list_free (message_list); + + return message; } + static gint _get_message_count (CamelFolder *folder) { - + CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); const gchar *directory_path; struct dirent *dir_entry; @@ -461,4 +480,3 @@ _get_message_count (CamelFolder *folder) closedir (dir_handle); return message_count; } - diff --git a/camel/string-utils.c b/camel/string-utils.c index 7cfd07e6d8..e53c41308e 100644 --- a/camel/string-utils.c +++ b/camel/string-utils.c @@ -156,13 +156,15 @@ static void __string_list_free_string (gpointer data, gpointer user_data) { gchar *string = (gchar *)data; - g_free(string); + g_free (string); } void string_list_free (GList *string_list) { + if (string_list == NULL) return; + g_list_foreach (string_list, __string_list_free_string, NULL); g_list_free (string_list); } diff --git a/tests/test4.c b/tests/test4.c index b199c7c912..1b46f72e65 100644 --- a/tests/test4.c +++ b/tests/test4.c @@ -57,8 +57,8 @@ main (int argc, char**argv) } printf ("\n Inbox folder contains %d messages\n", camel_folder_get_message_count (inbox_folder)); - printf ("\n------------- Gettting message numer 1 in inbox --------\n"); - message_1 = camel_folder_get_message (inbox_folder, 1); + printf ("\n------------- Gettting message numer 3 in inbox --------\n"); + message_1 = camel_folder_get_message (inbox_folder, 3); printf ("--------------------------------------------------------\n\n"); |