aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorbertrand <bertrand@helixcode.com>2000-01-17 16:40:11 +0800
committerBertrand Guiheneuf <bertrand@src.gnome.org>2000-01-17 16:40:11 +0800
commit3bdd857a4a69e83841c2fbae83d96101912ebf69 (patch)
tree96287828f9f04604e529a52b11a0f07206d04744 /camel
parent8c55e9f58b86483aa64c75a9324cd04e3ae79b2b (diff)
downloadgsoc2013-evolution-3bdd857a4a69e83841c2fbae83d96101912ebf69.tar
gsoc2013-evolution-3bdd857a4a69e83841c2fbae83d96101912ebf69.tar.gz
gsoc2013-evolution-3bdd857a4a69e83841c2fbae83d96101912ebf69.tar.bz2
gsoc2013-evolution-3bdd857a4a69e83841c2fbae83d96101912ebf69.tar.lz
gsoc2013-evolution-3bdd857a4a69e83841c2fbae83d96101912ebf69.tar.xz
gsoc2013-evolution-3bdd857a4a69e83841c2fbae83d96101912ebf69.tar.zst
gsoc2013-evolution-3bdd857a4a69e83841c2fbae83d96101912ebf69.zip
test for the mbox utils. (copy_file_chunk): fixed a nasty bug.
2000-01-17 bertrand <bertrand@helixcode.com> * 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
Diffstat (limited to 'camel')
-rw-r--r--camel/providers/mbox/camel-mbox-folder.c2
-rw-r--r--camel/providers/mbox/camel-mbox-parser.c2
-rw-r--r--camel/providers/mbox/camel-mbox-utils.c52
3 files changed, 40 insertions, 16 deletions
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 <stdio.h>
#include <unistd.h>
#include <errno.h>
+#include <string.h>
#include <glib.h>
@@ -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);