Patch: fix for attaching messages as parts



	Hi,

	This patch finally fixes the capability to attach a TnyMsg as a part of
a TnyMimePart in Camel.

	In other words, methods tny_mime_part_add_part (part, msg) and
tny_mime_part_get_parts where one of the parts is a TnyMsg should now
work :).


-- 
Jose Dapena Paz <jdapena igalia com>
Igalia
Index: libtinymail-camel/tny-camel-mime-part.c
===================================================================
--- libtinymail-camel/tny-camel-mime-part.c	(revision 2472)
+++ libtinymail-camel/tny-camel-mime-part.c	(working copy)
@@ -148,10 +148,19 @@
 				continue;
 
 			type = camel_mime_part_get_content_type (tpart);
-			if (camel_content_type_is (type, "message", "rfc822"))
+			if (CAMEL_IS_MIME_MESSAGE (tpart))
 			{
+				TnyHeader *nheader = _tny_camel_msg_header_new (CAMEL_MIME_MESSAGE (tpart), NULL);
+
+				newpart = TNY_MIME_PART (tny_camel_msg_new ());
+				_tny_camel_msg_set_header (TNY_CAMEL_MSG (newpart), nheader);
+				_tny_camel_mime_part_set_part (TNY_CAMEL_MIME_PART (newpart), CAMEL_MIME_PART (tpart));
+				g_object_unref (G_OBJECT (nheader));
+			}
+			else if (camel_content_type_is (type, "message", "rfc822"))
+			{
 				CamelDataWrapper *c = camel_medium_get_content_object (CAMEL_MEDIUM (tpart));
-			
+
 				if (c && CAMEL_IS_MIME_PART (c) && CAMEL_IS_MIME_MESSAGE (c)) 
 				{
 					TnyHeader *nheader = _tny_camel_msg_header_new (CAMEL_MIME_MESSAGE (c), NULL);
@@ -234,7 +243,26 @@
 		body = CAMEL_MULTIPART (containee);
 
 	cpart = tny_camel_mime_part_get_part (TNY_CAMEL_MIME_PART (part));
-	camel_multipart_add_part (body, cpart);
+	if (CAMEL_IS_MIME_MESSAGE (cpart)) {
+		CamelMimePart *message_part = camel_mime_part_new ();
+		const gchar *subject;
+		gchar *description;
+
+		subject = camel_mime_message_get_subject (CAMEL_MIME_MESSAGE (cpart));
+		if (subject)
+			description = g_strdup (subject);
+		else
+			description = _("Forwarded message");
+
+		camel_mime_part_set_disposition (message_part, "inline");
+		camel_medium_set_content_object (CAMEL_MEDIUM (message_part), 
+						 CAMEL_DATA_WRAPPER (cpart));
+		camel_mime_part_set_content_type (message_part, "message/rfc822");
+		camel_multipart_add_part (body, message_part);
+		camel_object_unref (CAMEL_OBJECT (message_part));
+	} else {
+		camel_multipart_add_part (body, cpart);
+	}
 	camel_object_unref (CAMEL_OBJECT (cpart));
 
 	retval = camel_multipart_get_number (body);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 2472)
+++ ChangeLog	(working copy)
@@ -1,3 +1,14 @@
+2007-07-17  Jose Dapena Paz  <jdapena igalia com>
+
+	* libtinymail/tny-camel-mime-part.c:
+	(tny_camel_mime_part_get_parts_default): improve detection
+	of attached messages, as we need to create a proper TnyMsg
+	object when the attachment is a message.
+	(tny_camel_mime_part_add_part_default): now when we are
+	attaching a message as a part, it's created adding a 
+	message/rfc822 mime part that contains the message as
+	its content object. This fixes attaching messages.
+
 2007-07-13  Philip Van Hoof  <pvanhoof gnome org>
 
 	* Allowing the POP code to do RETRs while the TOPs are working (while


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