diff options
author | bertrand <Bertrand.Guiheneuf@aful.org> | 1999-09-07 23:45:57 +0800 |
---|---|---|
committer | Bertrand Guiheneuf <bertrand@src.gnome.org> | 1999-09-07 23:45:57 +0800 |
commit | 598dc5e5564a6a04c0714ab480651261fe9f3c9a (patch) | |
tree | 45de64ab131517768562c3a89be2721d32db22c0 | |
parent | 9043c1aa7a31915129d14f913c9126557ca49402 (diff) | |
download | gsoc2013-evolution-598dc5e5564a6a04c0714ab480651261fe9f3c9a.tar gsoc2013-evolution-598dc5e5564a6a04c0714ab480651261fe9f3c9a.tar.gz gsoc2013-evolution-598dc5e5564a6a04c0714ab480651261fe9f3c9a.tar.bz2 gsoc2013-evolution-598dc5e5564a6a04c0714ab480651261fe9f3c9a.tar.lz gsoc2013-evolution-598dc5e5564a6a04c0714ab480651261fe9f3c9a.tar.xz gsoc2013-evolution-598dc5e5564a6a04c0714ab480651261fe9f3c9a.tar.zst gsoc2013-evolution-598dc5e5564a6a04c0714ab480651261fe9f3c9a.zip |
correct parameter decl (const)
1999-09-07 bertrand <Bertrand.Guiheneuf@aful.org>
* camel/md5-utils.c (md5_get_digest_from_file):
correct parameter decl (const)
* camel/md5-utils.h: typo.
* camel/providers/MH/mh-uid.c
More work on UID stuff for MH.
(mh_save_uid_list):
(mh_load_uid_list):
(mh_generate_uid_list):
new funcs. Manage on-disk uid list.
* camel/providers/MH/mh-utils.c (mh_is_a_message_file):
Util routines live here now.
svn path=/trunk/; revision=1190
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | camel/md5-utils.c | 2 | ||||
-rw-r--r-- | camel/md5-utils.h | 2 | ||||
-rw-r--r-- | camel/providers/MH/Makefile.am | 8 | ||||
-rw-r--r-- | camel/providers/MH/camel-mh-folder.c | 53 | ||||
-rw-r--r-- | camel/providers/MH/camel-mh-folder.h | 1 | ||||
-rw-r--r-- | camel/providers/MH/mh-uid.c | 133 | ||||
-rw-r--r-- | camel/providers/MH/mh-uid.h | 12 |
8 files changed, 188 insertions, 38 deletions
@@ -1,5 +1,20 @@ 1999-09-07 bertrand <Bertrand.Guiheneuf@aful.org> + * camel/md5-utils.c (md5_get_digest_from_file): + correct parameter decl (const) + + * camel/md5-utils.h: typo. + + * camel/providers/MH/mh-uid.c + More work on UID stuff for MH. + (mh_save_uid_list): + (mh_load_uid_list): + (mh_generate_uid_list): + new funcs. Manage on-disk uid list. + + * camel/providers/MH/mh-utils.c (mh_is_a_message_file): + Util routines live here now. + * camel/md5-utils.c Documented all funcs. diff --git a/camel/md5-utils.c b/camel/md5-utils.c index 4696905176..53f3373bb5 100644 --- a/camel/md5-utils.c +++ b/camel/md5-utils.c @@ -358,7 +358,7 @@ md5_get_digest_from_stream (CamelStream *stream, guchar digest[16]) * the 16 bytes buffer @digest . **/ void -md5_get_digest_from_file (gchar *filename, guchar digest[16]) +md5_get_digest_from_file (const gchar *filename, guchar digest[16]) { MD5Context ctx; guchar tmp_buf[1024]; diff --git a/camel/md5-utils.h b/camel/md5-utils.h index da5accbd5b..a2552d21b2 100644 --- a/camel/md5-utils.h +++ b/camel/md5-utils.h @@ -43,7 +43,7 @@ void md5_get_digest_from_stream (CamelStream *stream, guchar digest[16]); /* use this one when speed is needed */ /* for use in provider code only */ -void md5_get_digest_from_file (gchar *filename, gint buffer_size, guchar digest[16]); +void md5_get_digest_from_file (const gchar *filename, guchar digest[16]); /* raw routines */ void md5_init (MD5Context *ctx); diff --git a/camel/providers/MH/Makefile.am b/camel/providers/MH/Makefile.am index 6ebdc765b3..2442be6912 100644 --- a/camel/providers/MH/Makefile.am +++ b/camel/providers/MH/Makefile.am @@ -15,12 +15,14 @@ libcamelmh_la_SOURCES = \ camel-mh-folder.c \ camel-mh-provider.c \ camel-mh-store.c \ - mh-uid.c + mh-uid.c \ + mh-utils.c libcamelmhinclude_HEADERS = \ camel-mh-folder.h \ - camel-mh-store.h\ - mh-uid.h + camel-mh-store.h \ + mh-uid.h \ + mh-utils.h libcamelmh_la_LDFLAGS = -version-info 0:0:0 -rpath $(libdir) diff --git a/camel/providers/MH/camel-mh-folder.c b/camel/providers/MH/camel-mh-folder.c index fa6661c722..272090fa0e 100644 --- a/camel/providers/MH/camel-mh-folder.c +++ b/camel/providers/MH/camel-mh-folder.c @@ -38,6 +38,7 @@ #include "camel-stream-buffered-fs.h" #include "camel-folder-summary.h" #include "gmime-utils.h" +#include "mh-utils.h" static CamelFolderClass *parent_class=NULL; @@ -65,7 +66,6 @@ static void _open (CamelFolder *folder, CamelFolderOpenMode mode); /* some utility functions */ static int copy_reg (const char *src_path, const char *dst_path); -static gboolean _is_a_message_file (const gchar *file_name, const gchar *file_path); static void camel_mh_folder_class_init (CamelMhFolderClass *camel_mh_folder_class) @@ -221,7 +221,7 @@ _open (CamelFolder *folder, CamelFolderOpenMode mode) 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, mh_folder->directory_path)) + if (mh_is_a_message_file (dir_entry->d_name, mh_folder->directory_path)) /* add the file name to the list */ mh_folder->file_name_list = g_list_insert_sorted (mh_folder->file_name_list, g_strdup (dir_entry->d_name), @@ -233,8 +233,30 @@ _open (CamelFolder *folder, CamelFolderOpenMode mode) closedir (dir_handle); _create_summary (folder); + + /* get (or create) uid list */ + if (!mh_load_uid_list (mh_folder)) + mh_generate_uid_list (mh_folder); +} + + + +static void +_close (CamelFolder *folder, gboolean expunge) +{ + CamelMhFolder *mh_folder = CAMEL_MH_FOLDER (folder); + + if (mh_folder->uid_array) + mh_save_uid_list (mh_folder); + + /* call parent implementation */ + parent_class->close (folder, expunge); } + + + + /** * camel_mh_folder_set_name: set the name of an MH folder * @folder: the folder to set the name @@ -479,29 +501,6 @@ _list_subfolders (CamelFolder *folder) -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 void _filename_free (gpointer data) @@ -583,7 +582,7 @@ _get_message_count (CamelFolder *folder) 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)) + if (mh_is_a_message_file (dir_entry->d_name, directory_path)) message_count++; /* read next entry */ dir_entry = readdir (dir_handle); @@ -619,7 +618,7 @@ _find_next_free_message_file (CamelFolder *folder, gint *new_msg_number, gchar * 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)) { + if (mh_is_a_message_file (dir_entry->d_name, directory_path)) { /* see if the message number is the biggest found */ current_message_number = atoi (dir_entry->d_name); if (current_message_number > last_max_message_number) diff --git a/camel/providers/MH/camel-mh-folder.h b/camel/providers/MH/camel-mh-folder.h index e1c2e86900..40800375eb 100644 --- a/camel/providers/MH/camel-mh-folder.h +++ b/camel/providers/MH/camel-mh-folder.h @@ -46,6 +46,7 @@ typedef struct { gchar *directory_path; GList *file_name_list; + GArray *uid_array; } CamelMhFolder; diff --git a/camel/providers/MH/mh-uid.c b/camel/providers/MH/mh-uid.c index 8c777accaa..b112caa003 100644 --- a/camel/providers/MH/mh-uid.c +++ b/camel/providers/MH/mh-uid.c @@ -20,22 +20,34 @@ * USA */ + +#include <config.h> + #include "mh-uid.h" #include "camel-stream.h" #include "camel-stream-fs.h" #include "camel-stream-buffered-fs.h" #include "gmime-utils.h" #include "md5-utils.h" +#include "mh-utils.h" + +#include <sys/stat.h> +#include <unistd.h> +#include <sys/types.h> +#include <fcntl.h> +#include <dirent.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> -guchar * -mh_uid_get_for_file (gchar *filename) +void +mh_uid_get_for_file (gchar *filename, guchar uid[16]) { CamelStream *message_stream; GArray *header_array; Rfc822Header *cur_header; int i; MD5Context ctx; - guchar *md5_digest_uid; message_stream = camel_stream_buffered_fs_new_with_name (filename, @@ -61,10 +73,119 @@ mh_uid_get_for_file (gchar *filename) g_array_free (header_array, TRUE); - md5_digest_uid = g_new0 (guchar, 16); - md5_final (md5_digest_uid, &ctx); + md5_final (uid, &ctx); +} + + + + +void +mh_save_uid_list (CamelMhFolder *mh_folder) +{ + GArray *uid_array; + MhUidCouple *first_uid_couple; + gchar *directory_path = mh_folder->directory_path; + gchar *uidfile_path; + int fd; + int i; + + uidfile_path = g_strdup_printf ("%s/%s", directory_path, ".camel-uid-list"); + fd = open (uidfile_path, O_WRONLY | O_CREAT ); + g_free (uidfile_path); + if (!fd) return; + + uid_array = mh_folder->uid_array; + first_uid_couple = (MhUidCouple *)uid_array->data; + + /* write the number of uid contained in the file */ + write (fd, &(uid_array->len), sizeof (uid_array->len)); + + /* now write the array of uid self */ + write (fd, first_uid_couple, sizeof (first_uid_couple) * uid_array->len); + + close (fd); +} + + +gint +mh_load_uid_list (CamelMhFolder *mh_folder) +{ + GArray *new_uid_array; + MhUidCouple *first_uid_couple; + gchar *directory_path = mh_folder->directory_path; + gchar *uidfile_path; + int fd; + guint uid_nb; + + uidfile_path = g_strdup_printf ("%s/%s", directory_path, ".camel-uid-list"); + fd = open (uidfile_path, O_RDONLY); + g_free (uidfile_path); + if (!fd) return -1; + + if (mh_folder->uid_array) g_array_free (mh_folder->uid_array, FALSE); + + read (fd, &uid_nb, sizeof (uid_nb)); + + new_uid_array = g_array_new (FALSE, FALSE, sizeof (MhUidCouple)); + new_uid_array = g_array_set_size (new_uid_array, uid_nb); + first_uid_couple = (MhUidCouple *)new_uid_array->data; + + /* read the number of uids in the file */ + read (fd, first_uid_couple, sizeof (first_uid_couple) * uid_nb); + + mh_folder->uid_array = new_uid_array; - return md5_digest_uid; + return 1; } +gint +mh_generate_uid_list (CamelMhFolder *mh_folder) +{ + GArray *new_uid_array; + const gchar *directory_path; + struct dirent *dir_entry; + DIR *dir_handle; + gchar *msg_path; + guint msg_count; + MhUidCouple *uid_couple; + guint file_number; + + g_assert(mh_folder); + + directory_path = mh_folder->directory_path; + if (!directory_path) return -1; + + msg_count = camel_folder_get_message_count (CAMEL_FOLDER (mh_folder)); + if (!msg_count) return -1; + + new_uid_array = g_array_new (FALSE, FALSE, sizeof (MhUidCouple)); + new_uid_array = g_array_set_size (new_uid_array, msg_count); + uid_couple = (MhUidCouple *)new_uid_array->data; + + 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 (mh_is_a_message_file (dir_entry->d_name, directory_path)) { + + /* get the uid for this message */ + msg_path = g_strdup_printf ("%s/%s", directory_path, dir_entry->d_name); + mh_uid_get_for_file (msg_path, uid_couple->uid); + g_free (msg_path); + + /* convert filename into file number */ + uid_couple->file_number = atoi (dir_entry->d_name); + uid_couple++; + } + + /* read next entry */ + dir_entry = readdir (dir_handle); + } + + closedir (dir_handle); + +} diff --git a/camel/providers/MH/mh-uid.h b/camel/providers/MH/mh-uid.h index 32fe138a53..63dfe5b159 100644 --- a/camel/providers/MH/mh-uid.h +++ b/camel/providers/MH/mh-uid.h @@ -24,5 +24,17 @@ #define MH_UID_H 1 #include <glib.h> +#include "camel-mh-folder.h" + + +typedef struct { + gchar uid[16]; + guint file_number; +} MhUidCouple; + +void mh_uid_get_for_file (gchar *filename, guchar uid[16]); +void mh_save_uid_list (CamelMhFolder *mh_folder); +gint mh_load_uid_list (CamelMhFolder *mh_folder); +gint mh_generate_uid_list (CamelMhFolder *mh_folder); #endif /* MH_UID_H */ |