diff options
author | bertrand <Bertrand.Guiheneuf@aful.org> | 1999-08-09 03:10:05 +0800 |
---|---|---|
committer | Bertrand Guiheneuf <bertrand@src.gnome.org> | 1999-08-09 03:10:05 +0800 |
commit | e5d44122b8457faa0a18877c5c45be516035e138 (patch) | |
tree | 7cb75afd2e2614c342d8598d22ff9aaea30de3f8 | |
parent | b9f1b5ebf004e48d96ecccf1e99a388ac3bce1b3 (diff) | |
download | gsoc2013-evolution-e5d44122b8457faa0a18877c5c45be516035e138.tar.gz gsoc2013-evolution-e5d44122b8457faa0a18877c5c45be516035e138.tar.zst gsoc2013-evolution-e5d44122b8457faa0a18877c5c45be516035e138.zip |
util func. (_get_message_count): implemented.
1999-08-08 bertrand <Bertrand.Guiheneuf@aful.org>
* camel/providers/MH/camel-mh-folder.c (_is_a_message_file):
util func.
(_get_message_count): implemented.
svn path=/trunk/; revision=1096
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | camel/providers/MH/camel-mh-folder.c | 67 | ||||
-rw-r--r-- | tests/test4.c | 2 |
3 files changed, 73 insertions, 2 deletions
@@ -1,3 +1,9 @@ +1999-08-08 bertrand <Bertrand.Guiheneuf@aful.org> + + * camel/providers/MH/camel-mh-folder.c (_is_a_message_file): + util func. + (_get_message_count): implemented. + 1999-08-06 bertrand <Bertrand.Guiheneuf@aful.org> * devel-docs/camel/: diff --git a/camel/providers/MH/camel-mh-folder.c b/camel/providers/MH/camel-mh-folder.c index 53554585c3..0254b003f4 100644 --- a/camel/providers/MH/camel-mh-folder.c +++ b/camel/providers/MH/camel-mh-folder.c @@ -50,6 +50,7 @@ static gboolean _delete (CamelFolder *folder, gboolean recurse); static gboolean _delete_messages (CamelFolder *folder); static GList *_list_subfolders (CamelFolder *folder); static CamelMimeMessage *_get_message (CamelFolder *folder, gint number); +static gint _get_message_count (CamelFolder *folder); static void camel_mh_folder_class_init (CamelMhFolderClass *camel_mh_folder_class) @@ -67,6 +68,7 @@ camel_mh_folder_class_init (CamelMhFolderClass *camel_mh_folder_class) camel_folder_class->delete_messages = _delete_messages; camel_folder_class->list_subfolders = _list_subfolders; camel_folder_class->get_message = _get_message; + camel_folder_class->get_message_count = _get_message_count; } @@ -249,7 +251,6 @@ _delete_messages (CamelFolder *folder) const gchar *directory_path; struct stat stat_buf; gint stat_error = 0; - GList *file_list; gchar *entry_name; struct dirent *dir_entry; gint unlink_error = 0; @@ -397,3 +398,67 @@ _get_message (CamelFolder *folder, gint number) return message; } + + +static gboolean +_is_a_message_file (const gchar *file_name, const gchar *file_path) +{ + struct stat stat_buf; + gint stat_error = 0; + gboolean ok; + 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 +_get_message_count (CamelFolder *folder) +{ + + CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); + const gchar *directory_path; + struct dirent *dir_entry; + DIR *dir_handle; + guint message_count = 0; + + g_assert(folder); + + directory_path = mh_folder->directory_path; + if (!directory_path) return -1; + + if (!camel_folder_exists (folder)) return 0; + + 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_count++; + /* read next entry */ + dir_entry = readdir (dir_handle); + } + + closedir (dir_handle); + return message_count; +} + diff --git a/tests/test4.c b/tests/test4.c index bd333974a0..b199c7c912 100644 --- a/tests/test4.c +++ b/tests/test4.c @@ -55,8 +55,8 @@ main (int argc, char**argv) printf ("MH folder inbox does not exist. Stopping \n"); return; } - + 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\n"); |