IMPORTANT devel fixes



Hello,

There are 2 problems:

1. The devel cvs version of gmime has a problem finding the endboundery of  
multipart messages, resulting in failed message copying. gmime-bugfixes. 
patch fixes this.

2. If your using mailboxes in MBox format you could corrupt signed  
messages. Changing flags, such as read/unread, or copying to a mbox  
mailbox currently rewrites the message. This is done in using gmime and it  
writes in a default format. See also the bug report at:
http://bugzilla.gnome.org/show_bug.cgi?id=116200
This is fixed using gmime-mbox-fix.patch and balsa-mbox-fix.patch

In point 2 i use the g_object_set_data because this probably isn't the  
right way to do it. But i want to avoid corrupting more messages and this  
will work for now. There is still the problem with rechecking signed  
messages, but that is not fatal.

Bart
--
When a guy says "the last thing I'd wanna do is hurt you" it just means
he's gotta do other things first.
Fingerprint = CD4D 5601 287D F075 6F96  6157 99F9 E56A 4B08 6D06
Index: gmime-parser.c
===================================================================
RCS file: /cvs/gnome/gmime/gmime/gmime-parser.c,v
retrieving revision 1.75
diff -u -b -B -w -p -r1.75 gmime-parser.c
--- gmime-parser.c	9 Aug 2003 07:45:37 -0000	1.75
+++ gmime-parser.c	12 Sep 2003 11:52:21 -0000
@@ -1337,6 +1337,7 @@ parser_construct_message (GMimeParser *p
 	GMimeMessage *message;
 	GMimeObject *object;
 	int found;
+	off_t start, end;
 	
 	/* get the headers (and, optionally, the from-line) */
 	while (parser_step (parser) != GMIME_PARSER_STATE_HEADERS_END)
@@ -1356,6 +1357,10 @@ parser_construct_message (GMimeParser *p
 	if (!content_type)
 		content_type = g_mime_content_type_new ("text", "plain");
 	
+	/* skip header/body seperator */
+	if (priv->persist_stream && priv->seekable)
+		start = parser_offset (parser, NULL) + 1;
+
 	parser_unstep (parser);
 	if (content_type && g_mime_content_type_is_type (content_type, "multipart", "*")) {
 		object = parser_construct_multipart (parser, content_type, &found);
@@ -1363,6 +1368,14 @@ parser_construct_message (GMimeParser *p
 		object = parser_construct_leaf_part (parser, content_type, &found);
 	}
 	
+	if (priv->persist_stream && priv->seekable) {
+		GMimeStream *stream;
+		end = parser_offset (parser, NULL);
+		stream = g_mime_stream_substream (priv->stream, start, end);
+		g_object_set_data_full(G_OBJECT(message), "body-stream",
+				       stream, g_object_unref);
+	}
+
 	g_mime_message_set_mime_part (message, object);
 	g_mime_object_unref (object);
 	
--- libbalsa/mailbox_mbox.c	2003-09-10 12:07:17.000000000 +0200
+++ /tmp/balsa/devel/libbalsa/mailbox_mbox.c	2003-09-12 13:51:21.000000000 +0200
@@ -487,6 +487,34 @@
     return TRUE;
 }
 
+static int write_message(GMimeStream *stream, GMimeMessage *msg)
+{
+    GMimeStream *body_stream;
+    
+    body_stream = (GMimeStream*)g_object_get_data(G_OBJECT(msg), "body-stream");
+    if (body_stream) {
+	char *headers;
+	headers = g_mime_message_get_headers(msg);
+	if (!headers)
+	    return -1;
+	if (g_mime_stream_write_string(stream, headers) == -1) {
+	    g_free(headers);
+	    return -1;
+	}
+	g_free(headers);
+	if (g_mime_stream_write(stream, "\n", 1) == -1)
+	    return -1;
+	if (g_mime_stream_write_to_stream(body_stream, stream) == -1)
+	    return -1;
+    } else {
+	if (g_mime_message_write_to_stream(msg, stream) == -1)
+	    return -1;
+	if (g_mime_stream_write(stream, "\n", 1) == -1)
+	    return -1;
+    }
+    return 1;
+}
+
 static gboolean libbalsa_mailbox_mbox_sync(LibBalsaMailbox * mailbox)
 {
     int fd;
@@ -613,9 +641,8 @@
 		if (g_mime_stream_write_string(temp_stream,
 					       msg_info->from) == -1
 		    || g_mime_stream_write_string(temp_stream, "\n") == -1
-		    || g_mime_message_write_to_stream(msg_info->mime_message,
-						      temp_stream) == -1
-		    || g_mime_stream_write_string(temp_stream, "\n") == -1)
+		    || write_message(temp_stream, msg_info->mime_message) == -1
+		   )
 		{
 		    g_mime_stream_unref(temp_stream);
 		    unlink(tempfile);
@@ -876,7 +903,8 @@
     const char *path;
     int fd;
     GMimeStream* append_stream;
-    GMimeStreamIOVector iovector[6];
+    GMimeStreamIOVector iovector[4];
+    int ret;
 
     g_return_val_if_fail(LIBBALSA_IS_MAILBOX_MBOX(mailbox), FALSE);
 
@@ -887,11 +915,6 @@
     msg = g_mime_parser_construct_message(gmime_parser);
     g_object_unref(G_OBJECT(gmime_parser));
 
-    update_message_status_headers(msg, flags);
-    iovector[4].data=g_mime_message_to_string(msg);
-    iovector[4].len=strlen(iovector[4].data);
-
-
     g_mime_message_get_date(msg, &date, NULL);
     ctime_r(&date, date_string);
     iovector[3].data=date_string;
@@ -901,14 +924,12 @@
     internet_address_list = internet_address_parse_string(sender);
     if (internet_address_list == NULL) {
 	g_mime_object_unref(GMIME_OBJECT(msg));
-	g_free(iovector[4].data);
 	UNLOCK_MAILBOX(mailbox);
 	return -1;
     }
     internet_address = internet_address_list->address;
     if (internet_address == NULL) {
 	g_mime_object_unref(GMIME_OBJECT(msg));
-	g_free(iovector[4].data);
 	internet_address_list_destroy(internet_address_list);
 	UNLOCK_MAILBOX(mailbox);
 	return -1;
@@ -918,7 +939,6 @@
     } else {
 	address = "none";
     }
-    g_mime_object_unref(GMIME_OBJECT(msg));
     iovector[1].data=(char*)address;
     iovector[1].len=strlen(address);
 
@@ -928,7 +948,6 @@
     /* open in read-write mode */
     fd = open(path, O_RDWR);
     if (fd == -1) {
-	g_free(iovector[4].data);
 	internet_address_list_destroy(internet_address_list);
 	UNLOCK_MAILBOX(mailbox);
 	return -1;
@@ -938,7 +957,6 @@
     mbox_lock(mailbox, append_stream);
     if (g_mime_stream_seek(append_stream, 0, GMIME_STREAM_SEEK_END) == -1)
     {
-	g_free(iovector[4].data);
 	internet_address_list_destroy(internet_address_list);
 	g_mime_stream_flush(append_stream);
 	mbox_unlock(mailbox, append_stream);
@@ -950,11 +968,8 @@
     iovector[0].len=5;
     iovector[2].data=" ";
     iovector[2].len=1;
-    iovector[5].data="\n";
-    iovector[5].len=1;
-    if (g_mime_stream_writev(append_stream, iovector, 6) == -1)
+    if (g_mime_stream_writev(append_stream, iovector, 4) == -1)
     {
-	g_free(iovector[4].data);
 	internet_address_list_destroy(internet_address_list);
 	g_mime_stream_flush(append_stream);
 	mbox_unlock(mailbox, append_stream);
@@ -962,14 +977,17 @@
 	UNLOCK_MAILBOX(mailbox);
 	return -1;
     }
-    g_free(iovector[4].data);
+    update_message_status_headers(msg, flags);
+    ret = write_message(append_stream, msg);
+
+    g_mime_object_unref(GMIME_OBJECT(msg));
     internet_address_list_destroy(internet_address_list);
     g_mime_stream_flush(append_stream);
     mbox_unlock(mailbox, append_stream);
     g_mime_stream_unref(append_stream);
     UNLOCK_MAILBOX(mailbox);
 
-    return 1;
+    return ret;
 }
 
 static void
Index: gmime-parser.c
===================================================================
RCS file: /cvs/gnome/gmime/gmime/gmime-parser.c,v
retrieving revision 1.75
diff -u -b -B -w -p -r1.75 gmime-parser.c
--- gmime-parser.c	9 Aug 2003 07:45:37 -0000	1.75
+++ gmime-parser.c	12 Sep 2003 10:20:46 -0000
@@ -137,7 +137,7 @@ parser_push_boundary (GMimeParser *parse
 	} else {
 		s->boundary = g_strdup_printf ("--%s--", boundary);
 		s->boundarylen = strlen (boundary) + 2;
-		s->boundarylenfinal = s->boundarylen + 4;
+		s->boundarylenfinal = s->boundarylen + 2;
 	}
 	
 	s->boundarylenmax = MAX (s->boundarylenfinal, max);
Index: gmime-stream-mem.c
===================================================================
RCS file: /cvs/gnome/gmime/gmime/gmime-stream-mem.c,v
retrieving revision 1.23
diff -u -b -B -w -p -r1.23 gmime-stream-mem.c
--- gmime-stream-mem.c	6 Aug 2003 04:52:51 -0000	1.23
+++ gmime-stream-mem.c	12 Sep 2003 10:20:47 -0000
@@ -146,6 +146,9 @@ stream_write (GMimeStream *stream, char 
 	
 	g_return_val_if_fail (mem->buffer != NULL, -1);
 	
+	if (len == 0) /* can always write 0 bytes */
+		return 0;
+	
 	if (stream->bound_end == -1 && stream->position + len > mem->buffer->len) {
 		g_byte_array_set_size (mem->buffer, stream->position + len);
 		bound_end = mem->buffer->len;

PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]