+
+ // FIXME: tinymail
+ tny_msg_mime_part_iface_decode_to_stream ((TnyMsgMimePartIface*)tny_body,
+ gtkhtml_stream);
+
+ g_object_unref (G_OBJECT(gtkhtml_stream));
+
+ return TRUE;
+}
+
+
+/* this is a hack --> we use the tny_text_buffer_stream to
+ * get the message text, then write to gtkhtml 'by hand' */
+static gboolean
+set_text_message (ModestTnyMsgView *self, const TnyMsgMimePartIface *tny_body,
+ const TnyMsgIface *msg)
+{
+ GtkTextBuffer *buf;
+ GtkTextIter begin, end;
+ TnyStreamIface* txt_stream, *gtkhtml_stream;
+ gchar *txt, *html_attachments;
+ ModestTnyMsgViewPrivate *priv;
+
+ g_return_val_if_fail (self, FALSE);
+ g_return_val_if_fail (tny_body, FALSE);
+
+ priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(self);
+
+ buf = gtk_text_buffer_new (NULL);
+ txt_stream = TNY_STREAM_IFACE(tny_text_buffer_stream_new (buf));
+
+ tny_stream_iface_reset (txt_stream);
+
+ gtkhtml_stream =
+ TNY_STREAM_IFACE(modest_tny_stream_gtkhtml_new
+ (gtk_html_begin(GTK_HTML(priv->gtkhtml))));
+
+ html_attachments = attachments_as_html(self, msg);
+ if (html_attachments) {
+ tny_stream_iface_write (gtkhtml_stream, html_attachments,
+ strlen(html_attachments));
+ tny_stream_iface_reset (gtkhtml_stream);
+ g_free (html_attachments);
+ }
+
+ // FIXME: tinymail
+ tny_msg_mime_part_iface_decode_to_stream ((TnyMsgMimePartIface*)tny_body,
+ txt_stream);
+ tny_stream_iface_reset (txt_stream);
+
+ gtk_text_buffer_get_bounds (buf, &begin, &end);
+ txt = gtk_text_buffer_get_text (buf, &begin, &end, FALSE);
+ if (txt) {
+ gchar *html = convert_to_html (txt);
+ tny_stream_iface_write (gtkhtml_stream, html, strlen(html));
+ tny_stream_iface_reset (gtkhtml_stream);
+ g_free (txt);
+ g_free (html);
+ }
+
+ g_object_unref (G_OBJECT(gtkhtml_stream));
+ g_object_unref (G_OBJECT(txt_stream));
+ g_object_unref (G_OBJECT(buf));
+
+ return TRUE;
+}
+
+gchar *
+modest_tny_msg_view_get_selected_text (ModestTnyMsgView *self)
+{
+ ModestTnyMsgViewPrivate *priv;
+ gchar *sel;
+ GtkWidget *html;
+ int len;
+ GtkClipboard *clip;
+
+ g_return_val_if_fail (self, NULL);
+ priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(self);
+ html = priv->gtkhtml;
+
+ /* I'm sure there is a better way to check for selected text */
+ sel = gtk_html_get_selection_html(GTK_HTML(html), &len);
+ if (!sel)
+ return NULL;
+
+ g_free(sel);
+
+ clip = gtk_widget_get_clipboard(html, GDK_SELECTION_PRIMARY);
+ return gtk_clipboard_wait_for_text(clip);
+}
+
+
+void
+modest_tny_msg_view_set_message (ModestTnyMsgView *self, const TnyMsgIface *msg)
+{
+ TnyMsgMimePartIface *body;
+ ModestTnyMsgViewPrivate *priv;
+
+ g_return_if_fail (self);
+
+ priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(self);
+
+ priv->msg = msg;
+
+ body = modest_tny_msg_actions_find_body_part (msg, TRUE);
+ if (body) {
+ if (tny_msg_mime_part_iface_content_type_is (body, "text/html"))
+ set_html_message (self, body, msg);
+ else
+ set_text_message (self, body, msg);
+ return;
+ } else {
+ /* nothing to show */
+ }