tests for summary and parsing process of mbox files.

2000-01-18  bertrand  <bertrand@helixcode.com>

	* tests/test9.c:
	tests for summary and parsing process of mbox files.

	* camel/providers/mbox/camel-mbox-parser.c (camel_mbox_parse_file): do
	not use case insensitive comp to detect message separators. Kill
	some nasty bugs in netscape file parsing,

	* camel/providers/mbox/camel-mbox-utils.c (parsed_information_to_mbox_summary):
	don't use g_array_append but write directly inside the
	array data instead. Better performance and bug fix.

	* camel/providers/mbox/camel-mbox-summary.c (camel_mbox_load_summary):
	fix the name and bugs.

	* camel/camel-folder-summary.h: update the class
	method definition to match the public defs.

svn path=/trunk/; revision=1592
This commit is contained in:
bertrand
2000-01-19 04:33:14 +00:00
committed by Bertrand Guiheneuf
parent bd4e64bd78
commit d44875ac5f
8 changed files with 79 additions and 26 deletions

View File

@ -1,5 +1,22 @@
2000-01-18 bertrand <bertrand@helixcode.com>
* tests/test9.c:
tests for summary and parsing process of mbox files.
* camel/providers/mbox/camel-mbox-parser.c (camel_mbox_parse_file): do
not use case insensitive comp to detect message separators. Kill
some nasty bugs in netscape file parsing,
* camel/providers/mbox/camel-mbox-utils.c (parsed_information_to_mbox_summary):
don't use g_array_append but write directly inside the
array data instead. Better performance and bug fix.
* camel/providers/mbox/camel-mbox-summary.c (camel_mbox_load_summary):
fix the name and bugs.
* camel/camel-folder-summary.h: update the class
method definition to match the public defs.
* camel/providers/mbox/camel-mbox-summary.c (camel_mbox_save_summary):
(mbox_load_summary): summary file read/write routines.

View File

@ -65,8 +65,8 @@ camel_folder_summary_init (gpointer object, gpointer klass)
CamelFolderSummary *summary = CAMEL_FOLDER_SUMMARY (object);
CAMEL_LOG_FULL_DEBUG ( "camel_folder_summary_init:: Entering\n");
summary->subfolder_info_list = g_array_new (FALSE, FALSE, sizeof (CamelFolderInfo);
summary->message_info_list = g_array_new (FALSE, FALSE, sizeof (CamelMessageInfo);
summary->subfolder_info_list = g_array_new (FALSE, FALSE, sizeof (CamelFolderInfo));
summary->message_info_list = g_array_new (FALSE, FALSE, sizeof (CamelMessageInfo));
CAMEL_LOG_FULL_DEBUG ( "camel_folder_summary_init:: Leaving\n");
}

View File

@ -85,8 +85,8 @@ typedef struct {
GtkObjectClass parent_class;
/* Virtual methods */
const GList * (*get_subfolder_info_list) (CamelFolderSummary *summary);
const GList * (*get_message_info_list) (CamelFolderSummary *summary);
const GArray * (*get_subfolder_info_list) (CamelFolderSummary *summary);
const GArray * (*get_message_info_list) (CamelFolderSummary *summary);
} CamelFolderSummaryClass;

View File

@ -620,7 +620,7 @@ camel_mbox_parse_file (int fd,
}
/* is the next part a message delimiter ? */
if (g_strncasecmp (parser->buffer + parser->current_position,
if (strncmp (parser->buffer + parser->current_position,
parser->message_delimiter,
parser->message_delimiter_length) == 0) {

View File

@ -63,12 +63,13 @@ 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);
//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);
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;
@ -79,6 +80,7 @@ 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));
@ -116,7 +118,7 @@ camel_mbox_save_summary (CamelMboxSummary *summary, const gchar *filename, Camel
CamelMboxSummary *
mbox_load_summary (const gchar *filename, CamelException *ex)
camel_mbox_load_summary (const gchar *filename, CamelException *ex)
{
CamelMboxSummaryInformation *msg_info;
guint cur_msg;
@ -200,3 +202,13 @@ mbox_load_summary (const gchar *filename, CamelException *ex)
}

View File

@ -55,10 +55,10 @@ typedef struct {
void
camel_mbox_save_summary (CamelMboxSummary *, const gchar *filename, CamelException *ex);
camel_mbox_save_summary (CamelMboxSummary *summary, const gchar *filename, CamelException *ex);
CamelMboxSummary *
mbox_load_summary (const gchar *filename, CamelException *ex);
camel_mbox_load_summary (const gchar *filename, CamelException *ex);

View File

@ -259,7 +259,7 @@ camel_mbox_write_xev (gchar *mbox_file_name,
cur_pos = cur_msg_info->message_position
+ cur_msg_info->end_of_headers_offset;
copy_file_chunk (fd1, fd2, bytes_to_copy, ex);
if (camel_exception_get_id (ex)) {
close (fd1);
@ -280,7 +280,8 @@ camel_mbox_write_xev (gchar *mbox_file_name,
}
cur_msg_info->message_position += cur_offset;
}
bytes_to_copy = end_of_last_message - cur_pos;
copy_file_chunk (fd1, fd2, bytes_to_copy, ex);
@ -342,7 +343,7 @@ parsed_information_to_mbox_summary (GArray *parsed_information)
guint cur_msg;
CamelMboxParserMessageInfo *cur_msg_info;
GArray *mbox_summary;
CamelMboxSummaryInformation cur_sum_info;
CamelMboxSummaryInformation *cur_sum_info;
mbox_summary = g_array_new (FALSE, FALSE, sizeof (CamelMboxSummaryInformation));
mbox_summary = g_array_set_size (mbox_summary, parsed_information->len);
@ -350,25 +351,24 @@ parsed_information_to_mbox_summary (GArray *parsed_information)
for (cur_msg = 0; cur_msg < parsed_information->len; cur_msg++) {
cur_msg_info = (CamelMboxParserMessageInfo *)(parsed_information->data) + cur_msg;
cur_sum_info = (CamelMboxSummaryInformation *)(mbox_summary->data) + cur_msg;
cur_sum_info.position = cur_msg_info->message_position;
cur_sum_info->position = cur_msg_info->message_position;
cur_sum_info.x_evolution_offset = cur_msg_info->x_evolution_offset;
cur_sum_info->x_evolution_offset = cur_msg_info->x_evolution_offset;
cur_sum_info.uid = cur_msg_info->uid;
cur_sum_info->uid = cur_msg_info->uid;
cur_sum_info.status = cur_msg_info->status;
cur_sum_info->status = cur_msg_info->status;
cur_sum_info.subject = cur_msg_info->subject;
cur_sum_info->subject = cur_msg_info->subject;
cur_msg_info->subject = NULL;
cur_sum_info.sender = cur_msg_info->from;
cur_sum_info->sender = cur_msg_info->from;
cur_msg_info->from = NULL;
cur_sum_info.to = cur_msg_info->to;
cur_msg_info->to = NULL;
g_array_append_vals (mbox_summary, &cur_sum_info, 1);
cur_sum_info->to = cur_msg_info->to;
cur_msg_info->to = NULL;
}

View File

@ -4,9 +4,10 @@
#include "camel-mbox-folder.h"
#include "camel-mbox-parser.h"
#include "camel-mbox-utils.h"
#include "camel.h"
#include "camel-mbox-summary.h"
#include "camel-log.h"
#include "camel-exception.h"
#include "md5-utils.h"
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
@ -21,6 +22,10 @@ main (int argc, char**argv)
GArray *message_info_array;
gint test_file_fd;
CamelException *ex;
CamelMboxSummary *sum1, *sum2;
GArray *mbox_summary_info;
CamelMboxSummaryInformation *msg_info;
int i;
camel_debug_level = CAMEL_LOG_LEVEL_FULL_DEBUG;
@ -38,14 +43,33 @@ main (int argc, char**argv)
ex);
close (test_file_fd);
camel_mbox_write_xev (argv[1], message_info_array, 0, ex);
camel_mbox_write_xev (argv[1], message_info_array, 1, ex);
if (camel_exception_get_id (ex)) {
printf ("Exception caught in camel_mbox_write_xev : %s\n", camel_exception_get_description (ex));
}
mbox_summary_info =
parsed_information_to_mbox_summary (message_info_array);
sum1 = g_new (CamelMboxSummary, 1);
md5_get_digest_from_file (argv[1], sum1->md5_digest);
sum1->nb_message = mbox_summary_info->len;
sum1->message_info = mbox_summary_info;
camel_mbox_save_summary (sum1, "ev-summary.mbox", ex);
sum2 = camel_mbox_load_summary ("ev-summary.mbox", ex);
for (i=0; i<sum1->nb_message; i++) {
msg_info = (CamelMboxSummaryInformation *)(sum1->message_info->data) + i;
printf ("Message %d :\n"
" From : %s\n", i, msg_info->sender);
}
return 1;
}