From de8e7223eac6c40b10d2a095210d2120aa97fa55 Mon Sep 17 00:00:00 2001 From: bertrand Date: Thu, 20 Jan 2000 03:02:13 +0000 Subject: implemented. 2000-01-19 bertrand * camel/providers/mbox/camel-mbox-folder.c (_get_message_count): implemented. * camel/providers/mbox/camel-mbox-summary.c (camel_mbox_save_summary): (camel_mbox_load_summary): save/load the next uid. * camel/providers/mbox/camel-mbox-parser.c (camel_mbox_parse_file): Compute the next available uid. * camel/providers/mbox/camel-mbox-folder.c (_create): (_check_get_or_maybe_generate_summary_file): Set and use the next_uid field properly. * camel/providers/mbox/camel-mbox-summary.h: added an extra field to store the next available uid. * camel/providers/mbox/camel-mbox-folder.c (_check_get_or_maybe_generate_summary_file): routine called when the folder is opened. Reads or creates the summary file. (_create): initialize the internal summary structure. (_close): save the summary file on closing. (_init_with_store): initialize mbox specific folder members. svn path=/trunk/; revision=1597 --- camel/providers/mbox/camel-mbox-summary.c | 49 +++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 6 deletions(-) (limited to 'camel/providers/mbox/camel-mbox-summary.c') diff --git a/camel/providers/mbox/camel-mbox-summary.c b/camel/providers/mbox/camel-mbox-summary.c index 6915cd4a9b..c8ba96fe2f 100644 --- a/camel/providers/mbox/camel-mbox-summary.c +++ b/camel/providers/mbox/camel-mbox-summary.c @@ -65,11 +65,11 @@ camel_mbox_save_summary (CamelMboxSummary *summary, const gchar *filename, Camel /* compute and write the mbox file md5 signature */ //md5_get_digest_from_file (filename, summary->md5_digest); - /* write the number of messages + the md5 signatures */ - write (fd, summary, sizeof (guint) + sizeof (guchar) * 16); + /* write the number of messages + the md5 signatures + + next UID */ + write (fd, summary, sizeof (guint) + sizeof (guchar) * 16 + sizeof (guint32)); - printf ("%d %d\n", summary->nb_message, summary->message_info->len); for (cur_msg=0; cur_msg < summary->nb_message; cur_msg++) { msg_info = (CamelMboxSummaryInformation *)(summary->message_info->data) + cur_msg; @@ -80,7 +80,6 @@ camel_mbox_save_summary (CamelMboxSummary *summary, const gchar *filename, Camel sizeof (guint32) + sizeof (guint) + sizeof (guint32) + sizeof (guchar)); - //printf ("IN iewr subject = %s\n", msg_info->subject); /* write subject */ field_lgth = msg_info->subject ? strlen (msg_info->subject) : 0; write (fd, &field_lgth, sizeof (guint)); @@ -142,8 +141,9 @@ camel_mbox_load_summary (const gchar *filename, CamelException *ex) } summary = g_new0 (CamelMboxSummary, 1); - /* read the message number as well as the md5 signature */ - read (fd, summary, sizeof (guint) + sizeof (guchar) * 16); + /* read the message number, the md5 signature + and the next available UID */ + read (fd, summary, sizeof (guint) + sizeof (guchar) * 16 + sizeof (guint32)); summary->message_info = g_array_new (FALSE, FALSE, sizeof (CamelMboxSummaryInformation)); summary->message_info = g_array_set_size (summary->message_info, summary->nb_message); @@ -209,6 +209,43 @@ camel_mbox_load_summary (const gchar *filename, CamelException *ex) +gboolean +camel_mbox_check_summary_sync (gchar *summary_filename, + gchar *mbox_filename, + CamelException *ex) +{ + gint fd; + guchar summary_md5[16]; + guchar real_md5[16]; + + + CAMEL_LOG_FULL_DEBUG ("CamelMboxFolder::save_summary entering \n"); + fd = open (summary_filename, O_RDONLY); + if (fd == -1) { + camel_exception_setv (ex, + CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, + "could not open the mbox summary file\n" + "\t%s\n" + "Full error is : %s\n", + summary_filename, + strerror (errno)); + return FALSE; + } + + /* skip the message number field */ + lseek (fd, sizeof (guint), SEEK_SET); + + /* read the md5 signature stored in the summary file */ + read (fd, summary_md5, + sizeof (guchar) * 16); + close (fd); + /* ** FIXME : check for exception in all these operations */ + + /* compute the actual md5 signature on the + mbox file */ + md5_get_digest_from_file (mbox_filename, real_md5); + + return (strncmp (real_md5, summary_md5, 16) == 0); +} -- cgit v1.2.3