From 3bdd857a4a69e83841c2fbae83d96101912ebf69 Mon Sep 17 00:00:00 2001 From: bertrand Date: Mon, 17 Jan 2000 08:40:11 +0000 Subject: test for the mbox utils. (copy_file_chunk): fixed a nasty bug. 2000-01-17 bertrand * tests/test9.c (main): test for the mbox utils. (copy_file_chunk): fixed a nasty bug. (camel_mbox_write_xev): create the copy file descriptor with the proper arguments. Exceptions implememnted. (camel_mbox_write_xev): changed the way bytes are counted. No more uses the message size cause it did not take into account the message separators characters. (camel_mbox_write_xev): hopefully fixed the last bugs. works ok now. Summary information / X-Evolution header generation should all work ok now. svn path=/trunk/; revision=1579 --- ChangeLog | 14 ++++++++- camel/providers/mbox/camel-mbox-folder.c | 2 +- camel/providers/mbox/camel-mbox-parser.c | 2 +- camel/providers/mbox/camel-mbox-utils.c | 52 +++++++++++++++++++++++--------- tests/Makefile.am | 12 ++++++-- tests/test9.c | 51 +++++++++++++++++++++++++++++++ 6 files changed, 114 insertions(+), 19 deletions(-) create mode 100644 tests/test9.c diff --git a/ChangeLog b/ChangeLog index 7744d78ff0..c6dccaf76f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2000-01-17 bertrand + + * tests/test9.c (main): test for the mbox utils. + 2000-01-17 Federico Mena Quintero * configure.in: Add the gnomecanvaspixbuf argument to gnome-config @@ -8,13 +12,21 @@ * camel/providers/mbox/camel-mbox-utils.c (camel_mbox_write_xev): (copy_file_chunk): (camel_mbox_xev_write_header_content): - (camel_mbox_xev_parse_header_content): (string_to_flag): (flag_to_string): (string_to_uid): (uid_to_string): A bunch of new funcs to handle x-evolution private header field. + (copy_file_chunk): fixed a nasty bug. + (camel_mbox_write_xev): create the copy file descriptor + with the proper arguments. Exceptions implememnted. + (camel_mbox_write_xev): changed the way bytes are counted. + No more uses the message size cause it did not take into + account the message separators characters. + (camel_mbox_write_xev): hopefully fixed the last bugs. + works ok now. + 2000-01-15 bertrand diff --git a/camel/providers/mbox/camel-mbox-folder.c b/camel/providers/mbox/camel-mbox-folder.c index c502a190fd..82e5bc15b3 100644 --- a/camel/providers/mbox/camel-mbox-folder.c +++ b/camel/providers/mbox/camel-mbox-folder.c @@ -340,7 +340,7 @@ _exists (CamelFolder *folder, CamelException *ex) return FALSE; } - exists = S_REG (stat_buf.st_mode); + exists = S_ISREG (stat_buf.st_mode); /* we should check the rights here */ CAMEL_LOG_FULL_DEBUG ("Leaving CamelMboxFolder::exists\n"); diff --git a/camel/providers/mbox/camel-mbox-parser.c b/camel/providers/mbox/camel-mbox-parser.c index 87752be417..eee41b83db 100644 --- a/camel/providers/mbox/camel-mbox-parser.c +++ b/camel/providers/mbox/camel-mbox-parser.c @@ -35,7 +35,7 @@ -#define MBOX_PARSER_BUF_SIZE 1000 +#define MBOX_PARSER_BUF_SIZE 10000 #define MBOX_PARSER_FROM_KW "from:" #define MBOX_PARSER_FROM_KW_SZ 5 diff --git a/camel/providers/mbox/camel-mbox-utils.c b/camel/providers/mbox/camel-mbox-utils.c index 9eb4bd1f0d..f4cbe34899 100644 --- a/camel/providers/mbox/camel-mbox-utils.c +++ b/camel/providers/mbox/camel-mbox-utils.c @@ -51,6 +51,7 @@ #include #include #include +#include #include @@ -172,7 +173,7 @@ copy_file_chunk (gint fd_src, while (nb_to_read > 0) { do { - nb_read = read (fd_src, buffer, MAX (1000, nb_to_read)); + nb_read = read (fd_src, buffer, MIN (1000, nb_to_read)); } while (nb_read == -1 && errno == EINTR); if (nb_read == -1) { @@ -190,9 +191,11 @@ copy_file_chunk (gint fd_src, } while (v == -1 && errno == EINTR); if (v == -1) { - camel_exception_set (ex, + camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, - "could write to the mbox copy file"); + "could not write to the mbox copy file\n" + "Full error is : %s\n", + strerror (errno)); return; } @@ -214,6 +217,9 @@ camel_mbox_write_xev (gchar *mbox_file_name, CamelMboxParserMessageInfo *cur_msg_info; gint fd1, fd2; guint bytes_to_copy = 0; + glong cur_pos = 0; + glong cur_offset = 0; + glong end_of_last_message; glong next_free_uid; gchar xev_header[20] = "X-Evolution:XXXX-X\n"; gchar *tmp_file_name; @@ -221,40 +227,58 @@ camel_mbox_write_xev (gchar *mbox_file_name, gint rename_result; gint unlink_result; - tmp_file_name = g_strdup_printf ("__%s__.ev_tmp", mbox_file_name); - tmp_file_name_secure = g_strdup_printf ("__%s__.ev_tmp_secure", mbox_file_name); + tmp_file_name = g_strdup_printf ("%s__.ev_tmp", mbox_file_name); + tmp_file_name_secure = g_strdup_printf ("%s__.ev_tmp_secure", mbox_file_name); fd1 = open (mbox_file_name, O_RDONLY); - fd2 = open (tmp_file_name, O_RDWR); + fd2 = open (tmp_file_name, O_WRONLY | O_CREAT | O_TRUNC ); + if (fd2 == -1) { + camel_exception_setv (ex, + CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, + "could not create the temporary mbox copy file\n" + "\t%s\n" + "Full error is : %s\n", + tmp_file_name, + strerror (errno)); + return next_uid; + } next_free_uid = next_uid; for (cur_msg = 0; cur_msg < summary_information->len; cur_msg++) { cur_msg_info = (CamelMboxParserMessageInfo *)(summary_information->data) + cur_msg; - if (cur_msg_info->x_evolution) { + end_of_last_message = cur_msg_info->message_position + cur_msg_info->size; - bytes_to_copy += cur_msg_info->size; - } else { + if ( !cur_msg_info->x_evolution) { - bytes_to_copy += cur_msg_info->end_of_headers_offset; + bytes_to_copy = cur_msg_info->message_position + + cur_msg_info->end_of_headers_offset + - cur_pos; + + 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); close (fd2); goto end; } - + + printf ("Writing the x-ev header\n"); + printf ("Current message number : %d\n", cur_msg); camel_mbox_xev_write_header_content (xev_header + 12, next_free_uid++, 0); write (fd2, xev_header, 19); - bytes_to_copy = cur_msg_info->size - cur_msg_info->end_of_headers_offset; + cur_offset += 19; cur_msg_info->size += 19; cur_msg_info->x_evolution_offset = cur_msg_info->end_of_headers_offset; cur_msg_info->x_evolution = g_strdup_printf ("%.6s", xev_header + 12); cur_msg_info->end_of_headers_offset += 19; - } + } + cur_msg_info->message_position += cur_offset; } - if (bytes_to_copy > 0) + bytes_to_copy = end_of_last_message - cur_pos; copy_file_chunk (fd1, fd2, bytes_to_copy, ex); diff --git a/tests/Makefile.am b/tests/Makefile.am index 432c39a953..a7f0cb1883 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,7 +1,8 @@ # process this file with automake to create Makefile.in INCLUDES = -I$(top_srcdir)/intl -I$(top_srcdir) -I$(top_srcdir)/camel \ - -I$(includedir) -I$(top_srcdir)/camel/providers/MH + -I$(includedir) -I$(top_srcdir)/camel/providers/MH \ + -I$(top_srcdir)/camel/providers/mbox LDADD = \ $(top_builddir)/camel/libcamel.la \ $(GNOME_LIBDIR) \ @@ -17,10 +18,17 @@ LDADD = \ # $(GNOME_LIBDIR) \ # $(GNOMEUI_LIBS) $(INTLLIBS) $(PTHREAD_LIB) +test9_LDADD = \ + $(top_builddir)/camel/libcamel.la \ + $(top_builddir)/camel/providers/mbox/libcamelmbox.la \ + $(GNOME_LIBDIR) \ + $(GNOMEUI_LIBS) $(INTLLIBS) $(PTHREAD_LIB) $(EXTRA_GNOME_LIBS_THREADS) + noinst_PROGRAMS = \ test1 \ test2 \ test3 \ test7 \ - test8 + test8 \ + test9 diff --git a/tests/test9.c b/tests/test9.c new file mode 100644 index 0000000000..6356bad41f --- /dev/null +++ b/tests/test9.c @@ -0,0 +1,51 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + + +#include "camel-mbox-folder.h" +#include "camel-mbox-parser.h" +#include "camel-mbox-utils.h" +#include "camel.h" +#include "camel-log.h" +#include "camel-exception.h" +#include +#include +#include +#include +#include +#include +#include + +int +main (int argc, char**argv) +{ + GArray *message_info_array; + gint test_file_fd; + CamelException *ex; + + camel_debug_level = CAMEL_LOG_LEVEL_FULL_DEBUG; + + gtk_init (&argc, &argv); + camel_init (); + + ex = camel_exception_new (); + test_file_fd = open (argv[1], O_RDONLY); + message_info_array = camel_mbox_parse_file (test_file_fd, + "From ", + 0, + TRUE, + NULL, + 0, + ex); + + close (test_file_fd); + camel_mbox_write_xev (argv[1], message_info_array, 0, ex); + if (camel_exception_get_id (ex)) { + printf ("Exception caught in camel_mbox_write_xev : %s\n", camel_exception_get_description (ex)); + } + + + +} + + + -- cgit v1.2.3