]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
Ordine errato multipart nelle mail con attachment e testo e html.
authorAndrea Zagli <azagli@libero.it>
Sat, 20 May 2017 09:42:17 +0000 (11:42 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 20 May 2017 09:42:17 +0000 (11:42 +0200)
src/mail.c

index 435046b417c3cfbab02cc8901a07d14f7eb6f537..61b97ef73541f76c1f55b5a7251deffe3f4fb2de 100644 (file)
@@ -326,15 +326,53 @@ static CamelMimeMessage
        if (priv->body_plain != NULL
            && priv->body_html != NULL)
                {
+                       CamelMultipart *mp_alt;
+
+                       if (priv->attachments == NULL)
+                               {
+                                       mp_alt = mp;
+                               }
+                       else
+                               {
+                                       mp_alt = camel_multipart_new ();
+                                       camel_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (mp_alt), "multipart/alternative");
+                                       camel_multipart_set_boundary (mp_alt, NULL);
+                               }
+
                        part = camel_mime_part_new ();
                        camel_mime_part_set_content (part, priv->body_plain, strlen (priv->body_plain), "text/plain; charset=\"UTF-8\"");
-                       camel_multipart_add_part (mp, part);
+                       camel_multipart_add_part (mp_alt, part);
                        g_object_unref (part);
 
                        part = camel_mime_part_new ();
                        camel_mime_part_set_content (part, priv->body_html, strlen (priv->body_html), "text/html; charset=\"UTF-8\"");
-                       camel_multipart_add_part (mp, part);
+                       camel_multipart_add_part (mp_alt, part);
                        g_object_unref (part);
+
+                       if (priv->attachments != NULL)
+                               {
+                                       GOutputStream *ostream;
+
+                                       gpointer data;
+                                       gulong data_size;
+
+                                       ostream = g_memory_output_stream_new_resizable ();
+
+                                       camel_data_wrapper_write_to_output_stream_sync (CAMEL_DATA_WRAPPER (mp_alt), ostream, NULL, NULL);
+
+                                       g_object_get (G_OBJECT (ostream),
+                                                     "data", &data,
+                                                     "data-size", &data_size,
+                                                     NULL);
+
+                                       part = camel_mime_part_new ();
+                                       camel_mime_part_set_content (part, data, data_size, g_strdup_printf ("multipart/alternative; %s",
+                                                                                                            camel_multipart_get_boundary (mp_alt)));
+                                       camel_multipart_add_part (mp, part);
+                                       g_object_unref (part);
+
+                                       g_output_stream_close (ostream, NULL, NULL);
+                               }
                }
        else
                {
@@ -372,7 +410,6 @@ static CamelMimeMessage
                        GError *error;
                        GFileInfo *file_info;
                        CamelStream *cstream;
-                       GInputStream *istream;
 
                        attachs = priv->attachments;
                        while (attachs != NULL)