[geary/wip/save-sent-713263] Fix double Content-Type header



commit abae247688a347828f7b6232adaafd0895c650ec
Author: Charles Lindsay <chaz yorba org>
Date:   Mon Jan 27 15:29:57 2014 -0800

    Fix double Content-Type header
    
    This unfortunately means we have to dump the original message out to a
    buffer, then read it back in to create the cloned-message-without-bcc.

 src/engine/rfc822/rfc822-message.vala |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)
---
diff --git a/src/engine/rfc822/rfc822-message.vala b/src/engine/rfc822/rfc822-message.vala
index eba1aef..158283a 100644
--- a/src/engine/rfc822/rfc822-message.vala
+++ b/src/engine/rfc822/rfc822-message.vala
@@ -198,17 +198,20 @@ public class Geary.RFC822.Message : BaseObject {
     // Makes a copy of the given message without the BCC fields. This is used for sending the email
     // without sending the BCC headers to all recipients.
     public Message.without_bcc(Message email) {
-        message = new GMime.Message(true);
-        
-        email message headers  foreach((name, value) => {
-            if (name.down() != HEADER_BCC.down())
-                message.append_header(name, value);
-        });
-        
-        // Setup body depending on what MIME components were filled out.
-        message.set_mime_part(email.message.get_mime_part());
+        // GMime doesn't make it easy to get a copy of the body of a message.  It's easy to
+        // make a new message and add in all the headers, but calling set_mime_part() with
+        // the existing one's get_mime_part() result yields a double Content-Type header in
+        // the *original* message.  Clearly the objects aren't meant to be used like that.
+        // Barring any better way to clone a message, which I couldn't find by looking at
+        // the docs, we just dump out the old message to a buffer and read it back in to
+        // create the new object.  Kinda sucks, but our hands are tied.
+        try {
+            this.from_buffer (email.message_to_memory_buffer(false, false));
+        } catch (Error e) {
+            error("Error creating a memory buffer from a message: %s", e.message);
+        }
         
-        stock_from_gmime();
+        message.remove_header(HEADER_BCC);
     }
     
     private GMime.Object? coalesce_parts(Gee.List<GMime.Object> parts, string subtype) {


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