gint last_cid;
GList *attachments;
+ GList *images;
TnyHeaderFlags priority_flags;
priv->bcc_field = NULL;
priv->subject_field = NULL;
priv->attachments = NULL;
+ priv->images = NULL;
priv->last_cid = 0;
priv->zoom_level = 1.0;
}
static void
-replace_with_attachments (ModestMsgEditWindow *self, GList *attachments)
+replace_with_images (ModestMsgEditWindow *self, GList *attachments)
{
ModestMsgEditWindowPrivate *priv;
GList *node;
}
static void
+get_related_images (ModestMsgEditWindow *self, TnyMsg *msg)
+{
+ TnyMimePart *parent = NULL;
+ const gchar *content_type = NULL;
+ ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
+
+ content_type = tny_mime_part_get_content_type (TNY_MIME_PART (msg));
+
+ if (content_type && !g_strcasecmp (content_type, "multipart/related")) {
+ parent = g_object_ref (msg);
+ } else if (content_type && !g_strcasecmp (content_type, "multipart/mixed")) {
+ TnyList *parts = TNY_LIST (tny_simple_list_new ());
+ TnyIterator *iter;
+
+ tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
+ iter = tny_list_create_iterator (parts);
+ while (!tny_iterator_is_done (iter)) {
+ TnyMimePart *part;
+ part = TNY_MIME_PART (tny_iterator_get_current (iter));
+ content_type = tny_mime_part_get_content_type (part);
+ if (content_type && !g_strcasecmp (content_type, "multipart/related")) {
+ parent = part;
+ break;
+ } else {
+ g_object_unref (part);
+ }
+ tny_iterator_next (iter);
+ }
+ g_object_unref (iter);
+ g_object_unref (parts);
+ }
+
+ if (parent != NULL) {
+ TnyList *parts = TNY_LIST (tny_simple_list_new ());
+ TnyIterator *iter;
+
+ tny_mime_part_get_parts (TNY_MIME_PART (parent), parts);
+ iter = tny_list_create_iterator (parts);
+ while (!tny_iterator_is_done (iter)) {
+ TnyMimePart *part;
+ part = TNY_MIME_PART (tny_iterator_get_current (iter));
+ content_type = tny_mime_part_get_content_type (part);
+ if (content_type && g_str_has_prefix (content_type, "image/")) {
+ priv->images = g_list_prepend (priv->images, part);
+ } else {
+ g_object_unref (part);
+ }
+ tny_iterator_next (iter);
+ }
+ g_object_unref (iter);
+ g_object_unref (parts);
+ g_object_unref (parent);
+ }
+}
+
+static void
update_last_cid (ModestMsgEditWindow *self, GList *attachments)
{
GList *node;
} else {
gtk_widget_set_no_show_all (priv->attachments_caption, FALSE);
gtk_widget_show_all (priv->attachments_caption);
- replace_with_attachments (self, priv->attachments);
}
+ get_related_images (self, msg);
update_last_cid (self, priv->attachments);
+ update_last_cid (self, priv->images);
+ replace_with_images (self, priv->images);
if (preserve_is_rich && !is_html) {
wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
g_object_ref (cursor->data));
cursor = g_list_next (cursor);
}
+
+ GtkTextTagTable *tag_table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (priv->text_buffer));
+ cursor = priv->images;
+ data->images = NULL;
+ while (cursor) {
+ const gchar *cid;
+ if (!(TNY_IS_MIME_PART(cursor->data))) {
+ g_warning ("strange data in attachment list");
+ cursor = g_list_next (cursor);
+ continue;
+ }
+ cid = tny_mime_part_get_content_id (cursor->data);
+ if (cid) {
+ gchar *image_tag_id;
+ GtkTextTag *image_tag;
+ GtkTextIter iter;
+ image_tag_id = g_strdup_printf ("image-tag-%s", cid);
+ image_tag = gtk_text_tag_table_lookup (tag_table, image_tag_id);
+ g_free (image_tag_id);
+
+ gtk_text_buffer_get_start_iter (priv->text_buffer, &iter);
+ if (image_tag &&
+ ((gtk_text_iter_has_tag (&iter, image_tag))||
+ (gtk_text_iter_forward_to_tag_toggle (&iter, image_tag))))
+ data->images = g_list_append (data->images,
+ g_object_ref (cursor->data));
+ }
+ cursor = g_list_next (cursor);
+ }
data->priority_flags = priv->priority_flags;
g_list_foreach (data->attachments, (GFunc)unref_gobject, NULL);
g_list_free (data->attachments);
+ g_list_foreach (data->images, (GFunc)unref_gobject, NULL);
+ g_list_free (data->images);
g_slice_free (MsgData, data);
}
wp_text_buffer_insert_image (WP_TEXT_BUFFER (priv->text_buffer), &position, g_strdup (tny_mime_part_get_content_id (mime_part)), pixbuf);
}
- priv->attachments = g_list_prepend (priv->attachments, mime_part);
- modest_attachments_view_add_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
- mime_part);
- gtk_widget_set_no_show_all (priv->attachments_caption, FALSE);
- gtk_widget_show_all (priv->attachments_caption);
+ priv->images = g_list_prepend (priv->images, mime_part);
gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
g_free (filename);
if (tag == NULL+13) return;
g_object_get (G_OBJECT (tag), "name", &tag_name, NULL);
if ((tag_name != NULL) && (g_str_has_prefix (tag_name, "image-tag-replace-"))) {
- replace_with_attachments (window, priv->attachments);
+ replace_with_images (window, priv->images);
}
}
static gchar* modest_formatter_wrapper_inline (ModestFormatter *self, const gchar *text,
TnyHeader *header, GList *attachments);
+static TnyMimePart *find_body_parent (TnyMimePart *part);
+
static gchar *
extract_text (ModestFormatter *self, TnyMimePart *body)
{
g_return_val_if_fail (func, NULL);
/* Build new part */
- new_msg = modest_formatter_create_message (self, TRUE, attachments != NULL);
+ new_msg = modest_formatter_create_message (self, TRUE, attachments != NULL, FALSE);
body_part = modest_formatter_create_body_part (self, new_msg);
if (body)
fact = modest_runtime_get_platform_factory ();
/* Build new part */
- new_msg = modest_formatter_create_message (self, TRUE, TRUE);
+ new_msg = modest_formatter_create_message (self, TRUE, TRUE, FALSE);
body_part = modest_formatter_create_body_part (self, new_msg);
/* Create the two parts */
}
TnyMsg *
-modest_formatter_create_message (ModestFormatter *self, gboolean single_body, gboolean has_attachments)
+modest_formatter_create_message (ModestFormatter *self, gboolean single_body,
+ gboolean has_attachments, gboolean has_images)
{
TnyMsg *result = NULL;
TnyPlatformFactory *fact = NULL;
TnyMimePart *body_mime_part = NULL;
+ TnyMimePart *related_mime_part = NULL;
+
fact = modest_runtime_get_platform_factory ();
result = tny_platform_factory_new_msg (fact);
if (has_attachments) {
tny_mime_part_set_content_type (TNY_MIME_PART (result), "multipart/mixed");
+ if (has_images) {
+ related_mime_part = tny_platform_factory_new_mime_part (fact);
+ tny_mime_part_set_content_type (related_mime_part, "multipart/related");
+ tny_mime_part_add_part (TNY_MIME_PART (result), related_mime_part);
+ } else {
+ related_mime_part = g_object_ref (result);
+ }
+
+ if (!single_body) {
+ body_mime_part = tny_platform_factory_new_mime_part (fact);
+ tny_mime_part_set_content_type (body_mime_part, "multipart/alternative");
+ tny_mime_part_add_part (TNY_MIME_PART (related_mime_part), body_mime_part);
+ g_object_unref (body_mime_part);
+ }
+
+ g_object_unref (related_mime_part);
+ } else if (has_images) {
+ tny_mime_part_set_content_type (TNY_MIME_PART (result), "multipart/related");
+
if (!single_body) {
body_mime_part = tny_platform_factory_new_mime_part (fact);
tny_mime_part_set_content_type (body_mime_part, "multipart/alternative");
tny_mime_part_add_part (TNY_MIME_PART (result), body_mime_part);
g_object_unref (body_mime_part);
}
+
} else if (!single_body) {
tny_mime_part_set_content_type (TNY_MIME_PART (result), "multipart/alternative");
}
return result;
}
-TnyMimePart *
-modest_formatter_create_body_part (ModestFormatter *self, TnyMsg *msg)
+TnyMimePart *
+find_body_parent (TnyMimePart *part)
{
- TnyMimePart *result = NULL;
const gchar *msg_content_type = NULL;
- TnyPlatformFactory *fact = NULL;
+ msg_content_type = tny_mime_part_get_content_type (part);
- fact = modest_runtime_get_platform_factory ();
- msg_content_type = tny_mime_part_get_content_type (TNY_MIME_PART (msg));
- /* First it checks if the main part is alternative */
- if ((msg_content_type != NULL) &&
- (!g_strcasecmp (msg_content_type, "multipart/alternative"))) {
- result = tny_platform_factory_new_mime_part (fact);
- tny_mime_part_add_part (TNY_MIME_PART (msg), result);
- return result;
- } else if ((msg_content_type != NULL) &&
- (!g_strcasecmp (msg_content_type, "multipart/mixed"))) {
- TnyList *parts = NULL;
+ if ((msg_content_type != NULL) &&
+ (!g_strcasecmp (msg_content_type, "multipart/alternative")))
+ return g_object_ref (part);
+ else if ((msg_content_type != NULL) &&
+ (g_str_has_prefix (msg_content_type, "multipart/"))) {
TnyIterator *iter = NULL;
TnyMimePart *alternative_part = NULL;
-
- parts = TNY_LIST (tny_simple_list_new ());
- tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
+ TnyMimePart *related_part = NULL;
+ TnyList *parts = TNY_LIST (tny_simple_list_new ());
+ tny_mime_part_get_parts (TNY_MIME_PART (part), parts);
iter = tny_list_create_iterator (parts);
+
while (!tny_iterator_is_done (iter)) {
TnyMimePart *part = TNY_MIME_PART (tny_iterator_get_current (iter));
if (part && !g_strcasecmp(tny_mime_part_get_content_type (part), "multipart/alternative")) {
alternative_part = part;
break;
+ } else if (part && !g_strcasecmp (tny_mime_part_get_content_type (part), "multipart/related")) {
+ related_part = part;
+ break;
}
if (part)
tny_iterator_next (iter);
}
+ g_object_unref (iter);
+ g_object_unref (parts);
+ if (related_part) {
+ TnyMimePart *result;
+ result = find_body_parent (related_part);
+ g_object_unref (related_part);
+ return result;
+ } else if (alternative_part)
+ return alternative_part;
+ else
+ return g_object_ref (part);
+ } else
+ return NULL;
+}
+
+TnyMimePart *
+modest_formatter_create_body_part (ModestFormatter *self, TnyMsg *msg)
+{
+ TnyMimePart *result = NULL;
+ TnyPlatformFactory *fact = NULL;
+ TnyMimePart *parent = NULL;
+
+ parent = find_body_parent (TNY_MIME_PART (msg));
+ fact = modest_runtime_get_platform_factory ();
+ if (parent != NULL) {
result = tny_platform_factory_new_mime_part (fact);
- if (alternative_part != NULL) {
- tny_mime_part_add_part (alternative_part, result);
- } else {
- tny_mime_part_add_part (TNY_MIME_PART (msg), result);
- }
- g_object_unref (G_OBJECT (parts));
- return result;
+ tny_mime_part_add_part (TNY_MIME_PART (parent), result);
+ g_object_unref (parent);
} else {
- /* We add a reference as this method is intended to obtain
- a ref'ed part */
- g_object_ref (msg);
- return TNY_MIME_PART (msg);
+ result = g_object_ref (msg);
}
+
+ return result;
+
}
* @self: a #ModestFormatter
* @single_body: a #gboolean
* @has_attachments: a #gboolean
+ * @has_images: a #gboolean
*
* Creates an empty #TnyMsg with the expected parts for Modest
* formatters and body embedders.
* If @single_body is %TRUE, the body will be stored as a
* "multipart/alternative", and the parts will be the different
* alternatives. If %FALSE, this body will be stored directly.
+ *
+ * If @has_images is %TRUE, the body will be embedded in a
+ * multipart/related, that will also host attached images.
*/
-TnyMsg * modest_formatter_create_message (ModestFormatter *self, gboolean single_body, gboolean has_attachments);
+TnyMsg * modest_formatter_create_message (ModestFormatter *self, gboolean single_body,
+ gboolean has_attachments, gboolean has_images);
/**
* modest_formatter_create_body_part:
const gchar *cc, const gchar *bcc,
const gchar *subject, const gchar *plain_body,
const gchar *html_body, const GList *attachments_list,
+ const GList *images_list,
TnyHeaderFlags priority_flags,
ModestMailOperationCreateMsgCallback callback,
gpointer userdata);
gchar *plain_body;
gchar *html_body;
GList *attachments_list;
+ GList *images_list;
TnyHeaderFlags priority_flags;
ModestMailOperationCreateMsgCallback callback;
gpointer userdata;
if (info->html_body == NULL) {
new_msg = modest_tny_msg_new (info->to, info->from, info->cc,
info->bcc, info->subject, info->plain_body,
- info->attachments_list); /* FIXME: attachments */
+ info->attachments_list);
} else {
new_msg = modest_tny_msg_new_html_plain (info->to, info->from, info->cc,
info->bcc, info->subject, info->html_body,
- info->plain_body, info->attachments_list);
+ info->plain_body, info->attachments_list,
+ info->images_list);
}
if (new_msg) {
g_free (info->subject);
g_list_foreach (info->attachments_list, (GFunc) g_object_unref, NULL);
g_list_free (info->attachments_list);
+ g_list_foreach (info->images_list, (GFunc) g_object_unref, NULL);
+ g_list_free (info->images_list);
if (info->callback) {
CreateMsgIdleInfo *idle_info;
const gchar *subject, const gchar *plain_body,
const gchar *html_body,
const GList *attachments_list,
+ const GList *images_list,
TnyHeaderFlags priority_flags,
ModestMailOperationCreateMsgCallback callback,
gpointer userdata)
info->html_body = g_strdup (html_body);
info->attachments_list = g_list_copy ((GList *) attachments_list);
g_list_foreach (info->attachments_list, (GFunc) g_object_ref, NULL);
+ info->images_list = g_list_copy ((GList *) images_list);
+ g_list_foreach (info->images_list, (GFunc) g_object_ref, NULL);
info->priority_flags = priority_flags;
info->callback = callback;
const gchar *subject, const gchar *plain_body,
const gchar *html_body,
const GList *attachments_list,
+ const GList *images_list,
TnyHeaderFlags priority_flags)
{
ModestMailOperationPrivate *priv = NULL;
if (draft_msg)
g_object_ref (draft_msg);
modest_mail_operation_create_msg (self, from, to, cc, bcc, subject, plain_body, html_body,
- attachments_list, priority_flags,
+ attachments_list, images_list, priority_flags,
modest_mail_operation_send_new_mail_cb, info);
}
const gchar *subject, const gchar *plain_body,
const gchar *html_body,
const GList *attachments_list,
+ const GList *images_list,
TnyHeaderFlags priority_flags)
{
ModestMailOperationPrivate *priv = NULL;
g_object_ref (edit_window);
modest_mail_operation_create_msg (self, from, to, cc, bcc, subject, plain_body, html_body,
- attachments_list, priority_flags,
+ attachments_list, images_list, priority_flags,
modest_mail_operation_save_to_drafts_cb, info);
}
* @html_body: the html version of the body of the new mail. If NULL, the mail will
* be sent with the plain body only.
* @attachments_list: a #GList of attachments, each attachment must be a #TnyMimePart
+ * @images_list: a #GList of image attachments, each attachment must be a #TnyMimePart
*
* Sends a new mail message using the provided
* #TnyTransportAccount. This operation is synchronous, so the
const gchar *plain_body,
const gchar *html_body,
const GList *attachments_list,
+ const GList *images_list,
TnyHeaderFlags priority_flags);
* @html_body: the html version of the body of the new mail. If NULL, the mail will
* be sent with the plain body only.
* @attachments_list: a #GList of attachments, each attachment must be a #TnyMimePart
+ * @images_list: a #GList of image attachments, each attachment must be a #TnyMimePart
*
* Save a mail message to drafts using the provided
* #TnyTransportAccount. This operation is synchronous, so the
const gchar *plain_body,
const gchar *html_body,
const GList *attachments_list,
+ const GList *images_list,
TnyHeaderFlags priority_flags);
/**
* modest_mail_operation_update_account:
static TnyMimePart * add_body_part (TnyMsg *msg, const gchar *body,
const gchar *content_type);
static TnyMimePart * add_html_body_part (TnyMsg *msg, const gchar *body);
-static void add_attachments (TnyMsg *msg, GList *attachments_list);
+static void add_attachments (TnyMimePart *part, GList *attachments_list, gboolean add_inline);
+static void add_images (TnyMsg *msg, GList *attachments_list);
static char * get_content_type(const gchar *s);
static gboolean is_ascii(const gchar *s);
gchar *content_type;
/* Create new msg */
- new_msg = modest_formatter_create_message (NULL, TRUE, (attachments != NULL));
+ new_msg = modest_formatter_create_message (NULL, TRUE, (attachments != NULL), FALSE);
header = tny_msg_get_header (new_msg);
if ((from != NULL) && (strlen(from) > 0)) {
/* Add attachments */
if (attachments)
- add_attachments (new_msg, attachments);
+ add_attachments (TNY_MIME_PART (new_msg), attachments, FALSE);
return new_msg;
}
modest_tny_msg_new_html_plain (const gchar* mailto, const gchar* from, const gchar *cc,
const gchar *bcc, const gchar* subject,
const gchar *html_body, const gchar *plain_body,
- GList *attachments)
+ GList *attachments, GList *images)
{
TnyMsg *new_msg;
TnyHeader *header;
gchar *content_type;
/* Create new msg */
- new_msg = modest_formatter_create_message (NULL, FALSE, (attachments != NULL));
+ new_msg = modest_formatter_create_message (NULL, FALSE, (attachments != NULL), (images != NULL));
header = tny_msg_get_header (new_msg);
if ((from != NULL) && (strlen(from) > 0)) {
g_free (content_type);
/* Add attachments */
- add_attachments (new_msg, attachments);
+ add_attachments (TNY_MIME_PART (new_msg), attachments, FALSE);
+ add_images (new_msg, images);
return new_msg;
}
}
static void
-add_attachments (TnyMsg *msg, GList *attachments_list)
+add_attachments (TnyMimePart *part, GList *attachments_list, gboolean add_inline)
{
GList *pos;
TnyMimePart *attachment_part, *old_attachment;
old_attachment = pos->data;
if (!tny_mime_part_is_purged (old_attachment)) {
attachment_part = copy_mime_part (old_attachment);
- tny_mime_part_add_part (TNY_MIME_PART (msg), attachment_part);
+ tny_mime_part_add_part (TNY_MIME_PART (part), attachment_part);
+ tny_mime_part_set_header_pair (attachment_part, "Content-Disposition",
+ add_inline?"inline":"attachment");
g_object_unref (attachment_part);
}
}
}
+static void
+add_images (TnyMsg *msg, GList *images_list)
+{
+ TnyMimePart *related_part = NULL;
+ const gchar *content_type;
+
+ content_type = tny_mime_part_get_content_type (TNY_MIME_PART (msg));
+
+ if ((content_type != NULL) && !strcasecmp (content_type, "multipart/related")) {
+ related_part = g_object_ref (msg);
+ } else if ((content_type != NULL) && !strcasecmp (content_type, "multipart/mixed")) {
+ TnyList *parts = TNY_LIST (tny_simple_list_new ());
+ TnyIterator *iter = NULL;
+ tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
+ iter = tny_list_create_iterator (parts);
+
+ while (!tny_iterator_is_done (iter)) {
+ TnyMimePart *part = TNY_MIME_PART (tny_iterator_get_current (iter));
+ if (part && !g_strcasecmp (tny_mime_part_get_content_type (part), "multipart/related")) {
+ related_part = part;
+ break;
+ } else {
+ g_object_unref (part);
+ }
+ tny_iterator_next (iter);
+ }
+ g_object_unref (iter);
+ g_object_unref (parts);
+ }
+
+ if (related_part != NULL) {
+ /* TODO: attach images in their proper place */
+ add_attachments (related_part, images_list, TRUE);
+ }
+}
+
gchar *
modest_tny_msg_get_body (TnyMsg *msg, gboolean want_html, gboolean *is_html)
new_msg = create_reply_forward_mail (msg, NULL, from, signature, FALSE, forward_type,
attachments_list);
- add_attachments (new_msg, attachments_list);
+ add_attachments (TNY_MIME_PART (new_msg), attachments_list, FALSE);
/* Clean */
if (attachments_list)
* @subject: subject for the message
* @html_body: body for the message in HTML
* @plain_body: body for the message in plain text
- * @attachments: a list of attachments (local URIs)
+ * @attachments: a list of attachments (mime parts)
+ * @attachments: a list of images (mime parts)
*
* create a new TnyMsg with the given parameters
*
TnyMsg* modest_tny_msg_new_html_plain (const gchar* mailto, const gchar* mailfrom, const gchar *cc,
const gchar *bcc, const gchar* subject,
const gchar *html_body, const gchar *plain_body,
- GList *attachments);
+ GList *attachments, GList *images);
/**
* modest_tny_msg_find_body_part:
data->plain_body,
data->html_body,
data->attachments,
+ data->images,
data->priority_flags);
/* Frees */
g_free (from);
data->plain_body,
data->html_body,
data->attachments,
+ data->images,
data->priority_flags);
/* Free data: */
ModestAttachmentsViewPrivate *priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (attachments_view);
TnyList *parts;
TnyIterator *iter;
+ const gchar *msg_content_type = NULL;
if (msg == priv->msg) return;
return;
}
+ /* If the top mime part is a multipart/related, we don't show the attachments, as they're
+ * embedded images in body */
+ msg_content_type = tny_mime_part_get_content_type (TNY_MIME_PART (priv->msg));
+ if ((msg_content_type != NULL) && !strcasecmp (msg_content_type, "multipart/related")) {
+ gtk_widget_queue_draw (GTK_WIDGET (attachments_view));
+ return;
+ }
+
+
parts = TNY_LIST (tny_simple_list_new ());
tny_mime_part_get_parts (TNY_MIME_PART (priv->msg), parts);
iter = tny_list_create_iterator (parts);
typedef struct {
gchar *from, *to, *cc, *bcc, *subject, *plain_body, *html_body;
GList *attachments;
+ GList *images;
TnyHeaderFlags priority_flags;
TnyMsg *draft_msg;
gchar *account_name;