1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 /* modest-tny-msg-view.c */
33 #include "modest-tny-msg-view.h"
34 #include "modest-tny-stream-gtkhtml.h"
35 #include "modest-tny-msg-actions.h"
37 #include <tny-text-buffer-stream.h>
41 #include <glib/gi18n.h>
42 #include <gtkhtml/gtkhtml.h>
43 #include <gtkhtml/gtkhtml-stream.h>
45 /* 'private'/'protected' functions */
46 static void modest_tny_msg_view_class_init (ModestTnyMsgViewClass *klass);
47 static void modest_tny_msg_view_init (ModestTnyMsgView *obj);
48 static void modest_tny_msg_view_finalize (GObject *obj);
51 static GSList* get_url_matches (GString *txt);
52 static gboolean fill_gtkhtml_with_txt (ModestTnyMsgView *self, GtkHTML* gtkhtml, const gchar* txt, TnyMsgIface *msg);
54 static gboolean on_link_clicked (GtkWidget *widget, const gchar *uri,
55 ModestTnyMsgView *msg_view);
56 static gboolean on_url_requested (GtkWidget *widget, const gchar *uri,
57 GtkHTMLStream *stream,
58 ModestTnyMsgView *msg_view);
59 static gchar *construct_virtual_filename(const gchar *filename, const gint position, const gchar *id, const gboolean active);
60 static gchar *construct_virtual_filename_from_mime_part(TnyMsgMimePartIface *msg, const gint position);
62 #define ATTACHMENT_ID_INLINE "attachment-inline"
63 #define ATTACHMENT_ID_LINK "attachment-link"
64 #define PREFIX_LINK_EMAIL "mailto:"
66 gint virtual_filename_get_pos(const gchar *filename);
68 * we need these regexps to find URLs in plain text e-mails
70 typedef struct _UrlMatchPattern UrlMatchPattern;
71 struct _UrlMatchPattern {
77 #define MAIL_VIEWER_URL_MATCH_PATTERNS {\
78 { "(file|http|ftp|https)://[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]+[-A-Za-z0-9_$%&=?/~#]",\
80 { "www\\.[-a-z0-9.]+[-a-z0-9](:[0-9]*)?(/[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]*[^]}\\),?!;:\"]?)?",\
82 { "ftp\\.[-a-z0-9.]+[-a-z0-9](:[0-9]*)?(/[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]*[^]}\\),?!;:\"]?)?",\
84 { "(voipto|callto|chatto|jabberto|xmpp):[-_a-z@0-9.\\+]+", \
86 { "mailto:[-_a-z0-9.\\+]+@[-_a-z0-9.]+", \
88 { "[-_a-z0-9.\\+]+@[-_a-z0-9.]+",\
95 MAILTO_CLICKED_SIGNAL,
100 typedef struct _ModestTnyMsgViewPrivate ModestTnyMsgViewPrivate;
101 struct _ModestTnyMsgViewPrivate {
104 gboolean show_attachments_inline;
106 #define MODEST_TNY_MSG_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
107 MODEST_TYPE_TNY_MSG_VIEW, \
108 ModestTnyMsgViewPrivate))
110 static GtkContainerClass *parent_class = NULL;
112 /* uncomment the following if you have defined any signals */
113 static guint signals[LAST_SIGNAL] = {0};
116 modest_tny_msg_view_get_type (void)
118 static GType my_type = 0;
120 static const GTypeInfo my_info = {
121 sizeof(ModestTnyMsgViewClass),
122 NULL, /* base init */
123 NULL, /* base finalize */
124 (GClassInitFunc) modest_tny_msg_view_class_init,
125 NULL, /* class finalize */
126 NULL, /* class data */
127 sizeof(ModestTnyMsgView),
129 (GInstanceInitFunc) modest_tny_msg_view_init,
131 my_type = g_type_register_static (GTK_TYPE_SCROLLED_WINDOW,
139 modest_tny_msg_view_class_init (ModestTnyMsgViewClass *klass)
141 GObjectClass *gobject_class;
142 gobject_class = (GObjectClass*) klass;
144 parent_class = g_type_class_peek_parent (klass);
145 gobject_class->finalize = modest_tny_msg_view_finalize;
147 g_type_class_add_private (gobject_class, sizeof(ModestTnyMsgViewPrivate));
149 signals[MAILTO_CLICKED_SIGNAL] =
150 g_signal_new ("on_mailto_clicked",
151 G_TYPE_FROM_CLASS (gobject_class),
153 G_STRUCT_OFFSET(ModestTnyMsgViewClass, mailto_clicked),
155 g_cclosure_marshal_VOID__STRING,
156 G_TYPE_NONE, 1, G_TYPE_STRING/*, 1, G_TYPE_POINTER*/);
160 modest_tny_msg_view_init (ModestTnyMsgView *obj)
162 ModestTnyMsgViewPrivate *priv;
164 priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(obj);
168 priv->gtkhtml = gtk_html_new();
170 priv->show_attachments_inline = FALSE;
172 gtk_html_set_editable (GTK_HTML(priv->gtkhtml), FALSE);
173 gtk_html_allow_selection (GTK_HTML(priv->gtkhtml), TRUE);
174 gtk_html_set_caret_mode (GTK_HTML(priv->gtkhtml), FALSE);
175 gtk_html_set_blocking (GTK_HTML(priv->gtkhtml), FALSE);
176 gtk_html_set_images_blocking (GTK_HTML(priv->gtkhtml), FALSE);
178 g_signal_connect (G_OBJECT(priv->gtkhtml), "link_clicked",
179 G_CALLBACK(on_link_clicked), obj);
181 g_signal_connect (G_OBJECT(priv->gtkhtml), "url_requested",
182 G_CALLBACK(on_url_requested), obj);
187 modest_tny_msg_view_finalize (GObject *obj)
193 modest_tny_msg_view_new (TnyMsgIface *msg, const gboolean show_attachments_inline)
196 ModestTnyMsgView* self;
197 ModestTnyMsgViewPrivate *priv;
199 obj = G_OBJECT(g_object_new(MODEST_TYPE_TNY_MSG_VIEW, NULL));
200 self = MODEST_TNY_MSG_VIEW(obj);
201 priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE (self);
203 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self),
204 GTK_POLICY_AUTOMATIC,
205 GTK_POLICY_AUTOMATIC);
208 gtk_container_add (GTK_CONTAINER(obj), priv->gtkhtml);
211 modest_tny_msg_view_set_message (self, msg);
213 modest_tny_msg_view_set_show_attachments_inline_flag(self, show_attachments_inline);
215 return GTK_WIDGET(self);
220 on_link_clicked (GtkWidget *widget, const gchar *uri,
221 ModestTnyMsgView *msg_view)
223 if (g_str_has_prefix(uri, PREFIX_LINK_EMAIL)) {
225 /* skip over "mailto:" */
226 s = g_strdup(uri + strlen(PREFIX_LINK_EMAIL));
227 /* strip ?subject=... and the like */
228 for (p = s; p[0]; p++)
233 g_signal_emit(msg_view, signals[MAILTO_CLICKED_SIGNAL], 0, s);
236 } else if (g_str_has_prefix(uri, ATTACHMENT_ID_LINK)) {
237 /* save or open attachment */
238 g_message ("link-to-save: %s", uri); /* FIXME */
241 g_message ("link clicked: %s", uri); /* FIXME */
247 static TnyMsgMimePartIface *
248 find_cid_image (TnyMsgIface *msg, const gchar *cid)
250 TnyMsgMimePartIface *part = NULL;
253 g_return_val_if_fail (msg, NULL);
254 g_return_val_if_fail (cid, NULL);
256 parts = (GList*) tny_msg_iface_get_parts (msg);
257 while (parts && !part) {
258 const gchar *part_cid;
259 part = TNY_MSG_MIME_PART_IFACE(parts->data);
260 part_cid = tny_msg_mime_part_iface_get_content_id (part);
261 printf("CMP:%s:%s\n", cid, part_cid);
262 if (part_cid && strcmp (cid, part_cid) == 0)
263 return part; /* we found it! */
273 static TnyMsgMimePartIface *
274 find_attachment_by_filename (TnyMsgIface *msg, const gchar *fn)
276 TnyMsgMimePartIface *part = NULL;
281 g_return_val_if_fail (msg, NULL);
282 g_return_val_if_fail (fn, NULL);
284 parts = (GList*) tny_msg_iface_get_parts (msg);
285 pos = virtual_filename_get_pos(fn);
287 if ((pos < 0) || (pos >= g_list_length(parts)))
290 part = g_list_nth_data(parts, pos);
292 dummy = construct_virtual_filename_from_mime_part(part, pos);
293 if (strcmp(dummy, fn) == 0) {
304 on_url_requested (GtkWidget *widget, const gchar *uri,
305 GtkHTMLStream *stream,
306 ModestTnyMsgView *msg_view)
309 ModestTnyMsgViewPrivate *priv;
310 priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE (msg_view);
312 g_message ("url requested: %s", uri);
314 if (!modest_tny_msg_view_get_show_attachments_inline_flag(msg_view))
315 return TRUE; /* debatable */
317 if (g_str_has_prefix (uri, "cid:")) {
318 /* +4 ==> skip "cid:" */
320 TnyMsgMimePartIface *part = find_cid_image (priv->msg, uri + 4);
322 g_message ("%s not found", uri + 4);
323 gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR);
325 TnyStreamIface *tny_stream =
326 TNY_STREAM_IFACE(modest_tny_stream_gtkhtml_new(stream));
327 tny_msg_mime_part_iface_decode_to_stream (part,tny_stream);
328 gtk_html_stream_close (stream, GTK_HTML_STREAM_OK);
330 } else if (g_str_has_prefix (uri, ATTACHMENT_ID_INLINE)) {
331 TnyMsgMimePartIface *part;
332 part = find_attachment_by_filename (priv->msg, uri);
334 g_message ("%s not found", uri);
335 gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR);
337 TnyStreamIface *tny_stream =
338 TNY_STREAM_IFACE(modest_tny_stream_gtkhtml_new(stream));
339 tny_msg_mime_part_iface_decode_to_stream (part,tny_stream);
340 gtk_html_stream_close (stream, GTK_HTML_STREAM_OK);
355 secure_filename(const gchar *fn)
360 s = g_string_new("");
363 for (p = tmp; p[0] ; p++ ) {
364 p[0] &= 0x5f; /* 01011111 */
365 p[0] |= 0x40; /* 01000000 */
367 g_string_printf(s, "0x%x:%s", g_str_hash(fn), tmp);
369 return g_string_free(s, FALSE);
371 g_string_printf(s, "0x%x", g_str_hash(fn));
372 return g_string_free(s, FALSE);
378 construct_virtual_filename(const gchar *filename,
381 const gboolean active)
387 return g_strdup("AttachmentInvalid");
389 s = g_string_new("");
391 g_string_append(s, ATTACHMENT_ID_INLINE);
393 g_string_append(s, ATTACHMENT_ID_LINK);
394 g_string_append_printf(s, ":%d:", position);
396 g_string_append(s, id);
397 g_string_append_c(s, ':');
399 fn = secure_filename(filename);
401 g_string_append(s, fn);
403 g_string_append_c(s, ':');
404 return g_string_free(s, FALSE);
409 construct_virtual_filename_from_mime_part(TnyMsgMimePartIface *msg, const gint position)
411 const gchar *id, *filename;
412 const gboolean active = TRUE;
414 filename = tny_msg_mime_part_iface_get_filename(
415 TNY_MSG_MIME_PART_IFACE(msg));
417 filename = "[unknown]";
418 id = tny_msg_mime_part_iface_get_content_id(
419 TNY_MSG_MIME_PART_IFACE(msg));
421 return construct_virtual_filename(filename, position, id, active);
425 get_next_token(const gchar *s, gint *len)
442 /* maybe I should use libregexp */
444 virtual_filename_get_pos(const gchar *filename)
446 const gchar *i1, *i2;
451 if ((!g_str_has_prefix(filename, ATTACHMENT_ID_INLINE ":")) &&
452 (!g_str_has_prefix(filename, ATTACHMENT_ID_LINK ":")))
456 i2 = get_next_token(i2, &len);
460 i2 = get_next_token(i2, &len);
463 dummy = g_string_new_len(i1, len);
464 pos = atoi(dummy->str);
465 g_string_free(dummy, FALSE);
471 attachments_as_html(ModestTnyMsgView *self, TnyMsgIface *msg)
473 ModestTnyMsgViewPrivate *priv;
474 gboolean attachments_found = FALSE;
476 const GList *attachment_list, *attachment;
477 const gchar *content_type, *filename, *id;
478 gchar *virtual_filename;
483 priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE (self);
485 appendix = g_string_new("");
486 g_string_printf(appendix, "<HTML><BODY>\n<hr><h5>%s:</h5>\n", _("Attachments"));
488 attachment_list = tny_msg_iface_get_parts(msg);
489 attachment = attachment_list;
492 content_type = tny_msg_mime_part_iface_get_content_type(
493 TNY_MSG_MIME_PART_IFACE(attachment->data));
497 if ((strcmp("image/jpeg", content_type) == 0) ||
498 (strcmp("image/gif", content_type) == 0)) {
499 filename = tny_msg_mime_part_iface_get_filename(
500 TNY_MSG_MIME_PART_IFACE(attachment->data));
502 filename = "[unknown]";
504 attachments_found = TRUE;
505 id = tny_msg_mime_part_iface_get_content_id(
506 TNY_MSG_MIME_PART_IFACE(attachment->data));
507 if (modest_tny_msg_view_get_show_attachments_inline_flag(self)) {
508 virtual_filename = construct_virtual_filename(filename,
509 g_list_position((GList *)attachment_list, (GList *) attachment),
511 g_string_append_printf(appendix, "<IMG src=\"%s\">\n<BR>", virtual_filename);
512 g_free(virtual_filename);
514 virtual_filename = construct_virtual_filename(filename,
515 g_list_position((GList *)attachment_list, (GList *) attachment),
517 g_string_append_printf(appendix,
518 "<A href=\"%s\">%s</A>: %s<BR>\n",
519 virtual_filename, filename, content_type);
520 g_free(virtual_filename);
522 attachment = attachment->next;
524 g_string_append(appendix, "</BODY></HTML>");
525 if (!attachments_found)
526 g_string_assign(appendix, "");
527 return g_string_free(appendix, FALSE);
531 hyperlinkify_plain_text (GString *txt)
534 GSList *match_list = get_url_matches (txt);
536 /* we will work backwards, so the offsets stay valid */
537 for (cursor = match_list; cursor; cursor = cursor->next) {
539 url_match_t *match = (url_match_t*) cursor->data;
540 gchar *url = g_strndup (txt->str + match->offset, match->len);
541 gchar *repl = NULL; /* replacement */
543 /* the prefix is NULL: use the one that is already there */
544 repl = g_strdup_printf ("<a href=\"%s%s\">%s</a>",
545 match->prefix ? match->prefix : "", url, url);
547 /* replace the old thing with our hyperlink
548 * replacement thing */
549 g_string_erase (txt, match->offset, match->len);
550 g_string_insert (txt, match->offset, repl);
555 g_free (cursor->data);
558 g_slist_free (match_list);
564 convert_to_html (const gchar *data)
567 gboolean first_space = TRUE;
575 html = g_string_sized_new (len + 100); /* just a guess... */
577 g_string_append_printf (html,
580 "<meta http-equiv=\"content-type\""
581 " content=\"text/html; charset=utf8\">"
585 /* replace with special html chars where needed*/
586 for (i = 0; i != len; ++i) {
590 case 0: break; /* ignore embedded \0s */
591 case '<' : g_string_append (html, "<"); break;
592 case '>' : g_string_append (html, ">"); break;
593 case '&' : g_string_append (html, """); break;
594 case '\n': g_string_append (html, "<br>\n"); break;
597 g_string_append (html, first_space ? " " : " ");
599 } else if (kar == '\t')
600 g_string_append (html, " ");
604 /* optimization trick: accumulate 'normal' chars, then copy */
606 kar = data [++charnum + i];
608 } while ((i + charnum < len) &&
609 (kar > '>' || (kar != '<' && kar != '>'
610 && kar != '&' && kar != ' '
611 && kar != '\n' && kar != '\t')));
612 g_string_append_len (html, &data[i], charnum);
618 g_string_append (html, "</tt></body></html>");
619 hyperlinkify_plain_text (html);
621 return g_string_free (html, FALSE);
628 cmp_offsets_reverse (const url_match_t *match1, const url_match_t *match2)
630 return match2->offset - match1->offset;
636 * check if the match is inside an existing match... */
638 chk_partial_match (const url_match_t *match, int* offset)
640 if (*offset >= match->offset && *offset < match->offset + match->len)
645 get_url_matches (GString *txt)
648 int rv, i, offset = 0;
649 GSList *match_list = NULL;
651 static UrlMatchPattern patterns[] = MAIL_VIEWER_URL_MATCH_PATTERNS;
652 const size_t pattern_num = sizeof(patterns)/sizeof(UrlMatchPattern);
654 /* initalize the regexps */
655 for (i = 0; i != pattern_num; ++i) {
656 patterns[i].preg = g_new0 (regex_t,1);
657 g_assert(regcomp (patterns[i].preg, patterns[i].regex,
658 REG_ICASE|REG_EXTENDED|REG_NEWLINE) == 0);
660 /* find all the matches */
661 for (i = 0; i != pattern_num; ++i) {
665 if ((rv = regexec (patterns[i].preg, txt->str + offset, 1, &rm, 0)) != 0) {
666 g_assert (rv == REG_NOMATCH); /* this should not happen */
667 break; /* try next regexp */
672 /* FIXME: optimize this */
673 /* to avoid partial matches on something that was already found... */
674 /* check_partial_match will put -1 in the data ptr if that is the case */
675 test_offset = offset + rm.rm_so;
676 g_slist_foreach (match_list, (GFunc)chk_partial_match, &test_offset);
678 /* make a list of our matches (<offset, len, prefix> tupels)*/
679 if (test_offset != -1) {
680 url_match_t *match = g_new (url_match_t,1);
681 match->offset = offset + rm.rm_so;
682 match->len = rm.rm_eo - rm.rm_so;
683 match->prefix = patterns[i].prefix;
684 match_list = g_slist_prepend (match_list, match);
690 for (i = 0; i != pattern_num; ++i) {
691 regfree (patterns[i].preg);
692 g_free (patterns[i].preg);
693 } /* don't free patterns itself -- it's static */
695 /* now sort the list, so the matches are in reverse order of occurence.
696 * that way, we can do the replacements starting from the end, so we don't need
697 * to recalculate the offsets
699 match_list = g_slist_sort (match_list,
700 (GCompareFunc)cmp_offsets_reverse);
705 fill_gtkhtml_with_txt (ModestTnyMsgView *self, GtkHTML* gtkhtml, const gchar* txt, TnyMsgIface *msg)
708 gchar *html_attachments;
710 g_return_val_if_fail (gtkhtml, FALSE);
711 g_return_val_if_fail (txt, FALSE);
713 html = g_string_new(convert_to_html (txt));
714 html_attachments = attachments_as_html(self, msg);
715 g_string_append(html, html_attachments);
717 gtk_html_load_from_string (gtkhtml, html->str, html->len);
718 g_string_free (html, TRUE);
719 g_free(html_attachments);
727 set_html_message (ModestTnyMsgView *self, TnyMsgMimePartIface *tny_body, TnyMsgIface *msg)
729 gchar *html_attachments;
730 TnyStreamIface *gtkhtml_stream;
731 ModestTnyMsgViewPrivate *priv;
733 g_return_val_if_fail (self, FALSE);
734 g_return_val_if_fail (tny_body, FALSE);
736 priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(self);
739 TNY_STREAM_IFACE(modest_tny_stream_gtkhtml_new
740 (gtk_html_begin(GTK_HTML(priv->gtkhtml))));
742 tny_stream_iface_reset (gtkhtml_stream);
743 tny_msg_mime_part_iface_decode_to_stream (tny_body, gtkhtml_stream);
744 html_attachments = attachments_as_html(self, msg);
745 tny_stream_iface_write (gtkhtml_stream, html_attachments, strlen(html_attachments));
746 tny_stream_iface_reset (gtkhtml_stream);
748 g_object_unref (G_OBJECT(gtkhtml_stream));
749 g_free (html_attachments);
755 /* this is a hack --> we use the tny_text_buffer_stream to
756 * get the message text, then write to gtkhtml 'by hand' */
758 set_text_message (ModestTnyMsgView *self, TnyMsgMimePartIface *tny_body, TnyMsgIface *msg)
761 GtkTextIter begin, end;
762 TnyStreamIface* txt_stream;
764 ModestTnyMsgViewPrivate *priv;
766 g_return_val_if_fail (self, FALSE);
767 g_return_val_if_fail (tny_body, FALSE);
769 priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(self);
771 buf = gtk_text_buffer_new (NULL);
772 txt_stream = TNY_STREAM_IFACE(tny_text_buffer_stream_new (buf));
774 tny_stream_iface_reset (txt_stream);
775 tny_msg_mime_part_iface_decode_to_stream (tny_body, txt_stream);
776 tny_stream_iface_reset (txt_stream);
778 gtk_text_buffer_get_bounds (buf, &begin, &end);
779 txt = gtk_text_buffer_get_text (buf, &begin, &end, FALSE);
781 fill_gtkhtml_with_txt (self, GTK_HTML(priv->gtkhtml), txt, msg);
783 g_object_unref (G_OBJECT(txt_stream));
784 g_object_unref (G_OBJECT(buf));
791 modest_tny_msg_view_get_selected_text (ModestTnyMsgView *self)
793 ModestTnyMsgViewPrivate *priv;
799 g_return_val_if_fail (self, NULL);
800 priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(self);
801 html = priv->gtkhtml;
803 /* I'm sure there is a better way to check for selected text */
804 sel = gtk_html_get_selection_html(GTK_HTML(html), &len);
810 clip = gtk_widget_get_clipboard(html, GDK_SELECTION_PRIMARY);
811 return gtk_clipboard_wait_for_text(clip);
815 modest_tny_msg_view_set_message (ModestTnyMsgView *self, TnyMsgIface *msg)
817 TnyMsgMimePartIface *body;
818 ModestTnyMsgViewPrivate *priv;
820 g_return_if_fail (self);
822 priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(self);
826 fill_gtkhtml_with_txt (self, GTK_HTML(priv->gtkhtml), "", msg);
830 body = modest_tny_msg_actions_find_body_part (msg, TRUE);
832 if (tny_msg_mime_part_iface_content_type_is (body, "text/html"))
833 set_html_message (self, body, msg);
835 set_text_message (self, body, msg);
838 /* nothing to show */
843 modest_tny_msg_view_redraw (ModestTnyMsgView *self)
845 ModestTnyMsgViewPrivate *priv;
847 g_return_if_fail (self);
848 priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(self);
849 modest_tny_msg_view_set_message(self, priv->msg);
853 modest_tny_msg_view_get_show_attachments_inline_flag (ModestTnyMsgView *self)
855 ModestTnyMsgViewPrivate *priv;
857 g_return_val_if_fail (self, FALSE);
858 priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(self);
859 return priv->show_attachments_inline;
863 modest_tny_msg_view_set_show_attachments_inline_flag (ModestTnyMsgView *self, gboolean flag)
865 ModestTnyMsgViewPrivate *priv;
868 g_return_val_if_fail (self, FALSE);
869 priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(self);
870 oldflag = priv->show_attachments_inline;
871 priv->show_attachments_inline = flag;
872 if (priv->show_attachments_inline != oldflag)
873 modest_tny_msg_view_redraw(self);
874 return priv->show_attachments_inline;