aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/mbox
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2000-04-02 05:58:27 +0800
committerDan Winship <danw@src.gnome.org>2000-04-02 05:58:27 +0800
commit9e7dabfa8274777916da364b50284cfa51ac9a6f (patch)
tree579b255f6178357a1c2d9e697a423636fb65d619 /camel/providers/mbox
parent98690e9f75e909483f857f23bae0f903ee1ed84a (diff)
downloadgsoc2013-evolution-9e7dabfa8274777916da364b50284cfa51ac9a6f.tar
gsoc2013-evolution-9e7dabfa8274777916da364b50284cfa51ac9a6f.tar.gz
gsoc2013-evolution-9e7dabfa8274777916da364b50284cfa51ac9a6f.tar.bz2
gsoc2013-evolution-9e7dabfa8274777916da364b50284cfa51ac9a6f.tar.lz
gsoc2013-evolution-9e7dabfa8274777916da364b50284cfa51ac9a6f.tar.xz
gsoc2013-evolution-9e7dabfa8274777916da364b50284cfa51ac9a6f.tar.zst
gsoc2013-evolution-9e7dabfa8274777916da364b50284cfa51ac9a6f.zip
Compare mbox_file_size and mbox_modtime to the results of stat()ing the
* providers/mbox/camel-mbox-folder.c (_check_get_or_maybe_generate_summary_file): Compare mbox_file_size and mbox_modtime to the results of stat()ing the mbox file, not the summary file. Duh. (_close): Update the summary's mbox_file_size and mbox_modtime before writing it to disk. * providers/mbox/camel-mbox-summary.c (camel_mbox_summary_save, camel_mbox_summary_load): Wow. I must have been tired when I wrote this code. First, the comparison bug above. Second, it was using ntohs and htons instead of ntohl and htonl. Third, I was reading the status flag byte in two different places and thus getting out of sync. Fourth, it was writing out field_length bytes of each header field after having converted field_length to network byte order, resulting in lots of random crap being appended, and the summary files being huge. (Fortunately, since the size/modtime comparison was biffed, the garbage summary read from disk was always immediately discarded.) * providers/mbox/camel-mbox-parser.c (camel_mbox_parse_file): fix an off-by-one error that caused the last-used UID to be reused if the summary file was regenerated. (That one wasn't my fault. :-) svn path=/trunk/; revision=2279
Diffstat (limited to 'camel/providers/mbox')
-rw-r--r--camel/providers/mbox/camel-mbox-folder.c15
-rw-r--r--camel/providers/mbox/camel-mbox-parser.c31
-rw-r--r--camel/providers/mbox/camel-mbox-summary.c75
3 files changed, 71 insertions, 50 deletions
diff --git a/camel/providers/mbox/camel-mbox-folder.c b/camel/providers/mbox/camel-mbox-folder.c
index b376f67fbd..8e1fe00402 100644
--- a/camel/providers/mbox/camel-mbox-folder.c
+++ b/camel/providers/mbox/camel-mbox-folder.c
@@ -221,11 +221,12 @@ _check_get_or_maybe_generate_summary_file (CamelMboxFolder *mbox_folder,
folder->summary = NULL;
/* Test for the existence and up-to-dateness of the summary file. */
- if (stat (mbox_folder->summary_file_path, &st) == 0) {
+ if (access (mbox_folder->summary_file_path, F_OK) == 0) {
summ = camel_mbox_summary_load (mbox_folder->summary_file_path,
ex);
if (summ) {
- if (summ->mbox_file_size == st.st_size &&
+ if (stat (mbox_folder->folder_file_path, &st) == 0 &&
+ summ->mbox_file_size == st.st_size &&
summ->mbox_modtime == st.st_mtime)
folder->summary = CAMEL_FOLDER_SUMMARY (summ);
else
@@ -318,6 +319,8 @@ static void
_close (CamelFolder *folder, gboolean expunge, CamelException *ex)
{
CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder);
+ CamelMboxSummary *mbox_summary = CAMEL_MBOX_SUMMARY (folder->summary);
+ struct stat st;
/* call parent implementation */
parent_class->close (folder, expunge, ex);
@@ -327,8 +330,12 @@ _close (CamelFolder *folder, gboolean expunge, CamelException *ex)
ibex_close(mbox_folder->index);
}
- /* save the folder summary on disk */
- camel_mbox_summary_save (CAMEL_MBOX_SUMMARY (folder->summary),
+ /* Update the summary and save it to disk */
+ if (stat (mbox_folder->folder_file_path, &st) == 0) {
+ mbox_summary->mbox_file_size = st.st_size;
+ mbox_summary->mbox_modtime = st.st_mtime;
+ }
+ camel_mbox_summary_save (mbox_summary,
mbox_folder->summary_file_path, ex);
}
diff --git a/camel/providers/mbox/camel-mbox-parser.c b/camel/providers/mbox/camel-mbox-parser.c
index 7c0eec5379..c03639133f 100644
--- a/camel/providers/mbox/camel-mbox-parser.c
+++ b/camel/providers/mbox/camel-mbox-parser.c
@@ -584,20 +584,29 @@ read_message_begining (CamelMboxPreParser *parser, gchar **message_summary)
/**
* camel_mbox_parse_file: read an mbox file and parse it.
* @fd: file descriptor opened on the mbox file.
- * @message_delimiter: character string delimiting the beginig of a new message
- * @start_position: poition in the file where to start the parsing.
- * @get_message_summary: should the parser retrieve the begining of the messages
- * @status_callback: function to call peridically to indicate the progress of the parser
- * @status_interval: floating value between 0 and 1 indicate how often to call @status_callback.
+ * @message_delimiter: character string delimiting the beginig of a
+ * new message
+ * @start_position: position in the file where to start the parsing.
+ * @file_size: on output, the size in bytes of the file
+ * @next_uid: on output, the next uid available for use
+ * @get_message_summary: should the parser retrieve the begining of
+ * the messages
+ * @status_callback: function to call peridically to indicate the
+ * progress of the parser
+ * @status_interval: floating value between 0 and 1 indicate how often
+ * to call @status_callback.
* @user_data: user data that will be passed to the callback function
*
- * This routine parses an mbox file and retreives both the message starting positions and
- * some of the informations contained in the message. Those informations are mainly
- * some RFC822 headers values but also (optionally) the first characters of the mail
- * body. The @get_message_summary parameter allows to enable or disable this option.
+ * This routine parses an mbox file and retreives both the message
+ * starting positions and some of the informations contained in the
+ * message. Those informations are mainly some RFC822 headers values
+ * but also (optionally) the first characters of the mail body. The
+ * @get_message_summary parameter allows to enable or disable this
+ * option.
*
*
- * Return value: An array of CamelMboxParserMessageInfo containing the informations on each message parsed in the file
+ * Return value: An array of CamelMboxParserMessageInfo containing the
+ * informations on each message parsed in the file
**/
GArray *
camel_mbox_parse_file (int fd,
@@ -766,7 +775,7 @@ camel_mbox_parse_file (int fd,
G_STRUCT_OFFSET (CamelMboxPreParser, current_message_info) +
G_STRUCT_OFFSET (CamelMboxParserMessageInfo, status)));
g_free (x_ev_header_content);
- next_available_uid = MAX (next_available_uid, parser->current_message_info.uid);
+ next_available_uid = MAX (next_available_uid, parser->current_message_info.uid + 1);
newline = TRUE;
continue;
diff --git a/camel/providers/mbox/camel-mbox-summary.c b/camel/providers/mbox/camel-mbox-summary.c
index a6561d60f0..69c720b091 100644
--- a/camel/providers/mbox/camel-mbox-summary.c
+++ b/camel/providers/mbox/camel-mbox-summary.c
@@ -174,6 +174,7 @@ camel_mbox_summary_save (CamelMboxSummary *summary, const gchar *filename,
gint fd;
gint write_result; /* XXX use this */
guint32 data;
+ struct stat st;
CAMEL_LOG_FULL_DEBUG ("CamelMboxFolder::save_summary entering \n");
@@ -192,16 +193,16 @@ camel_mbox_summary_save (CamelMboxSummary *summary, const gchar *filename,
* that makes sense, but because it's easy.
*/
- data = htons (CAMEL_MBOX_SUMMARY_VERSION);
+ data = htonl (CAMEL_MBOX_SUMMARY_VERSION);
write (fd, &data, sizeof (data));
- data = htons (summary->nb_message);
+ data = htonl (summary->nb_message);
write (fd, &data, sizeof (data));
- data = htons (summary->next_uid);
+ data = htonl (summary->next_uid);
write (fd, &data, sizeof (data));
- data = htons (summary->mbox_file_size);
+ data = htonl (summary->mbox_file_size);
write (fd, &data, sizeof (data));
- data = htons (summary->mbox_modtime);
+ data = htonl (summary->mbox_modtime);
write (fd, &data, sizeof (data));
for (cur_msg = 0; cur_msg < summary->nb_message; cur_msg++) {
@@ -209,62 +210,67 @@ camel_mbox_summary_save (CamelMboxSummary *summary, const gchar *filename,
(summary->message_info->data) + cur_msg;
/* Write meta-info. */
- data = htons (msg_info->position);
+ data = htonl (msg_info->position);
write (fd, &data, sizeof (data));
- data = htons (msg_info->size);
+ data = htonl (msg_info->size);
write (fd, &data, sizeof (data));
- data = htons (msg_info->x_evolution_offset);
+ data = htonl (msg_info->x_evolution_offset);
write (fd, &data, sizeof (data));
- data = htons (msg_info->uid);
+ data = htonl (msg_info->uid);
write (fd, &data, sizeof (data));
write (fd, &msg_info->status, 1);
/* Write subject. */
if (msg_info->headers.subject)
- field_length = htons (strlen (msg_info->headers.subject));
+ field_length = strlen (msg_info->headers.subject);
else
field_length = 0;
- write (fd, &field_length, sizeof (field_length));
+ data = htonl (field_length);
+ write (fd, &data, sizeof (data));
if (msg_info->headers.subject)
write (fd, msg_info->headers.subject, field_length);
/* Write sender. */
if (msg_info->headers.sender)
- field_length = htons (strlen (msg_info->headers.sender));
+ field_length = strlen (msg_info->headers.sender);
else
field_length = 0;
- write (fd, &field_length, sizeof (field_length));
+ data = htonl (field_length);
+ write (fd, &data, sizeof (data));
if (msg_info->headers.sender)
write (fd, msg_info->headers.sender, field_length);
/* Write to. */
if (msg_info->headers.to)
- field_length = htons (strlen (msg_info->headers.to));
+ field_length = strlen (msg_info->headers.to);
else
field_length = 0;
- write (fd, &field_length, sizeof (field_length));
+ data = htonl (field_length);
+ write (fd, &data, sizeof (data));
if (msg_info->headers.to)
write (fd, msg_info->headers.to, field_length);
/* Write sent date. */
if (msg_info->headers.sent_date)
- field_length = htons (strlen (msg_info->headers.sent_date));
+ field_length = strlen (msg_info->headers.sent_date);
else
field_length = 0;
- write (fd, &field_length, sizeof (field_length));
+ data = htonl (field_length);
+ write (fd, &data, sizeof (data));
if (msg_info->headers.sent_date)
write (fd, msg_info->headers.sent_date, field_length);
/* Write received date. */
if (msg_info->headers.received_date)
- field_length = htons (strlen (msg_info->headers.received_date));
+ field_length = strlen (msg_info->headers.received_date);
else
field_length = 0;
- write (fd, &field_length, sizeof (field_length));
+ data = htonl (field_length);
+ write (fd, &data, sizeof (data));
if (msg_info->headers.received_date)
write (fd, msg_info->headers.received_date, field_length);
}
-
+
close (fd);
CAMEL_LOG_FULL_DEBUG ("CamelMboxFolder::save_summary leaving \n");
@@ -305,7 +311,7 @@ camel_mbox_summary_load (const gchar *filename, CamelException *ex)
/* Verify version number. */
read (fd, &data, sizeof(data));
- data = ntohs (data);
+ data = ntohl (data);
if (data != CAMEL_MBOX_SUMMARY_VERSION) {
camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_SUMMARY_INVALID,
@@ -319,13 +325,13 @@ camel_mbox_summary_load (const gchar *filename, CamelException *ex)
summary = CAMEL_MBOX_SUMMARY (gtk_object_new (camel_mbox_summary_get_type (), NULL));
read (fd, &data, sizeof(data));
- summary->nb_message = ntohs (data);
+ summary->nb_message = ntohl (data);
read (fd, &data, sizeof(data));
- summary->next_uid = ntohs (data);
+ summary->next_uid = ntohl (data);
read (fd, &data, sizeof(data));
- summary->mbox_file_size = ntohs (data);
+ summary->mbox_file_size = ntohl (data);
read (fd, &data, sizeof(data));
- summary->mbox_modtime = ntohs (data);
+ summary->mbox_modtime = ntohl (data);
summary->message_info =
g_array_new (FALSE, FALSE,
@@ -338,20 +344,19 @@ camel_mbox_summary_load (const gchar *filename, CamelException *ex)
/* Read the meta-info. */
read (fd, &data, sizeof(data));
- msg_info->position = ntohs (data);
+ msg_info->position = ntohl (data);
read (fd, &data, sizeof(data));
- msg_info->size = ntohs (data);
+ msg_info->size = ntohl (data);
read (fd, &data, sizeof(data));
- msg_info->x_evolution_offset = ntohs (data);
- read (fd, &(msg_info->status), 1);
+ msg_info->x_evolution_offset = ntohl (data);
read (fd, &data, sizeof(data));
- msg_info->uid = ntohs (data);
+ msg_info->uid = ntohl (data);
msg_info->headers.uid = g_strdup_printf ("%d", msg_info->uid);
read (fd, &msg_info->status, 1);
/* Read the subject. */
read (fd, &field_length, sizeof (field_length));
- field_length = ntohs (field_length);
+ field_length = ntohl (field_length);
if (field_length > 0) {
msg_info->headers.subject =
g_new0 (gchar, field_length + 1);
@@ -361,7 +366,7 @@ camel_mbox_summary_load (const gchar *filename, CamelException *ex)
/* Read the sender. */
read (fd, &field_length, sizeof (field_length));
- field_length = ntohs (field_length);
+ field_length = ntohl (field_length);
if (field_length > 0) {
msg_info->headers.sender =
g_new0 (gchar, field_length + 1);
@@ -371,7 +376,7 @@ camel_mbox_summary_load (const gchar *filename, CamelException *ex)
/* Read the "to" field. */
read (fd, &field_length, sizeof (field_length));
- field_length = ntohs (field_length);
+ field_length = ntohl (field_length);
if (field_length > 0) {
msg_info->headers.to =
g_new0 (gchar, field_length + 1);
@@ -381,7 +386,7 @@ camel_mbox_summary_load (const gchar *filename, CamelException *ex)
/* Read the sent date field. */
read (fd, &field_length, sizeof (field_length));
- field_length = ntohs (field_length);
+ field_length = ntohl (field_length);
if (field_length > 0) {
msg_info->headers.sent_date =
g_new0 (gchar, field_length + 1);
@@ -391,7 +396,7 @@ camel_mbox_summary_load (const gchar *filename, CamelException *ex)
/* Read the received date field. */
read (fd, &field_length, sizeof (field_length));
- field_length = ntohs (field_length);
+ field_length = ntohl (field_length);
if (field_length > 0) {
msg_info->headers.received_date =
g_new0 (gchar, field_length + 1);