From 2296e765df1629bfad48508d3a12274fa77b73a7 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 19 Jun 2006 14:30:47 +0000 Subject: [PATCH] * cleanup find_body_part a bit, and check if a part is not an attachment, if so, it cannot be the body part (before this, a text/html attachment would be shown when there was only a text/plain body) * constify modest_tny_msg_actions_quote pmo-trunk-r284 --- src/modest-tny-msg-actions.c | 42 +++++++++++++++++++++++++----------------- src/modest-tny-msg-actions.h | 9 ++++----- src/modest-tny-msg-view.c | 20 +++++++------------- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/modest-tny-msg-actions.c b/src/modest-tny-msg-actions.c index e75d188..0956eb0 100644 --- a/src/modest-tny-msg-actions.c +++ b/src/modest-tny-msg-actions.c @@ -68,23 +68,22 @@ htmltotext (TnyMsgMimePartIface * body) gchar * modest_tny_msg_actions_quote (const TnyMsgIface * self, const gchar * from, time_t sent_date, gint limit, - gchar * to_quote) + const gchar * to_quote) { gchar *quoted; /* 3 cases: */ /* a) quote text from selection */ - if (to_quote != NULL) { + if (to_quote != NULL) return modest_text_utils_quote (to_quote, from, sent_date, limit); - } - + /* b) try to find a text/plain part in the msg and quote it */ quoted = quote_msg (self, from, sent_date, limit, FALSE); - if (quoted != NULL) + if (quoted) return quoted; - + /* c) if that fails, try text/html */ return quote_msg (self, from, sent_date, limit, TRUE); } @@ -92,7 +91,7 @@ modest_tny_msg_actions_quote (const TnyMsgIface * self, const gchar * from, static gchar * quote_msg (const TnyMsgIface * src, const gchar * from, time_t sent_date, - gint limit, gboolean textorhtml) + gint limit, gboolean want_html) { TnyStreamIface *stream; TnyMsgMimePartIface *body; @@ -102,15 +101,13 @@ quote_msg (const TnyMsgIface * src, const gchar * from, time_t sent_date, gchar *quoted; /* the cast makes me uneasy... */ - body = modest_tny_msg_actions_find_body_part((TnyMsgIface *) src, - textorhtml ? "text/html" : "text/plain"); - + body = modest_tny_msg_actions_find_body_part((TnyMsgIface *) src, want_html); if (!body) return NULL; - if (textorhtml == TRUE) { + if (want_html) buf = htmltotext (body); - } else { + else { buf = gtk_text_buffer_new (NULL); stream = TNY_STREAM_IFACE (tny_text_buffer_stream_new (buf)); tny_stream_iface_reset (stream); @@ -123,26 +120,37 @@ quote_msg (const TnyMsgIface * src, const gchar * from, time_t sent_date, to_quote = gtk_text_buffer_get_text (buf, &start, &end, FALSE); quoted = modest_text_utils_quote (to_quote, from, sent_date, limit); g_object_unref (buf); + return quoted; } TnyMsgMimePartIface * -modest_tny_msg_actions_find_body_part (TnyMsgIface *self, const gchar *mime_type) +modest_tny_msg_actions_find_body_part (TnyMsgIface *self, gboolean want_html) { + const gchar *mime_type = want_html ? "text/html" : "text/plain"; TnyMsgMimePartIface *part = NULL; GList *parts; - + g_return_val_if_fail (self, NULL); g_return_val_if_fail (mime_type, NULL); parts = (GList*) tny_msg_iface_get_parts (self); while (parts && !part) { + part = TNY_MSG_MIME_PART_IFACE(parts->data); - if (!tny_msg_mime_part_iface_content_type_is (part, mime_type)) + + if (!tny_msg_mime_part_iface_content_type_is (part, mime_type) + ||tny_msg_mime_part_iface_is_attachment (part)) part = NULL; parts = parts->next; } - - return part; + + /* if were trying to find an HTML part and could find it, + * try to find a text/plain part instead + */ + if (!part && want_html) + return modest_tny_msg_actions_find_body_part (self, FALSE); + else + return part; } diff --git a/src/modest-tny-msg-actions.h b/src/modest-tny-msg-actions.h index 7637eb6..b389483 100644 --- a/src/modest-tny-msg-actions.h +++ b/src/modest-tny-msg-actions.h @@ -24,20 +24,19 @@ gchar *modest_tny_msg_actions_quote (const TnyMsgIface * self, const gchar * from, time_t sent_date, - gint limit, gchar *to_quote); + gint limit, const gchar *to_quote); /** * modest_tny_msg_actions_find_body_part: * @self: a message - * @mime_type: the mime type to find + * @want_html: prefer HTML-part when there are multiple body parts? * - * search a message for a body part of type @mime_type. @mime_type is a string - * like "text/plain". + * search a message for a body part * * Returns: the TnyMsgMimePartIface for the found part, or NULL if no matching part is found */ TnyMsgMimePartIface *modest_tny_msg_actions_find_body_part (TnyMsgIface * self, - const gchar * mime_type); + gboolean want_html); #endif /* __MODEST_TNY_MSG_ACTIONS_H__ */ diff --git a/src/modest-tny-msg-view.c b/src/modest-tny-msg-view.c index 57fbb8e..13ece7a 100644 --- a/src/modest-tny-msg-view.c +++ b/src/modest-tny-msg-view.c @@ -774,25 +774,19 @@ modest_tny_msg_view_set_message (ModestTnyMsgView *self, TnyMsgIface *msg) priv->msg = msg; fill_gtkhtml_with_txt (self, GTK_HTML(priv->gtkhtml), "", msg); - if (!msg) return; - body = modest_tny_msg_actions_find_body_part (msg, "text/html"); + body = modest_tny_msg_actions_find_body_part (msg, TRUE); if (body) { - set_html_message (self, body, msg); - return; - } - - body = modest_tny_msg_actions_find_body_part (msg, "text/plain"); - if (body) { - set_text_message (self, body, msg); + 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 */ } - - /* hmmmmm */ - fill_gtkhtml_with_txt (self, GTK_HTML(priv->gtkhtml), - _("Unsupported message type"), msg); } void -- 1.7.9.5