X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fmodest-tny-msg-actions.c;h=5baac6d592b2e2981693ec6bdc9973cee6d4c320;hb=68aa241807636e914b400e4510c8f0fadef623cb;hp=46c1f0d7a4d71e3d70ffb60d15ef2eafdb209588;hpb=4c17eac51757809148b84e229bede6323aac270a;p=modest diff --git a/src/modest-tny-msg-actions.c b/src/modest-tny-msg-actions.c index 46c1f0d..5baac6d 100644 --- a/src/modest-tny-msg-actions.c +++ b/src/modest-tny-msg-actions.c @@ -31,10 +31,8 @@ #include #include #include -#include -#include -#include #include +#include #ifdef HAVE_CONFIG_H #include @@ -51,7 +49,6 @@ get_body_text (TnyMsg *msg, gboolean want_html) GtkTextBuffer *buf; GtkTextIter start, end; const gchar *to_quote; - gchar *quoted; body = modest_tny_msg_actions_find_body_part(msg, want_html); if (!body) @@ -73,36 +70,11 @@ get_body_text (TnyMsg *msg, gboolean want_html) return to_quote; } -gchar* -modest_tny_msg_actions_quote (TnyMsg * self, const gchar * from, - time_t sent_date, gint limit, - const gchar * to_quote) -{ - gchar *quoted_msg = NULL; - const gchar *body; - - /* 2 cases: */ - - /* a) quote text from selection */ - 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 */ - body = get_body_text (self, FALSE); - if (body) - quoted_msg = modest_text_utils_quote (body, from, sent_date, limit); - - return quoted_msg; -} - - - -TnyMimePart * -modest_tny_msg_actions_find_body_part (TnyMsg *msg, gboolean want_html) +static TnyMimePart* +modest_tny_msg_actions_find_body_part_from_mime_part (TnyMimePart *msg, gboolean want_html) { const gchar *mime_type = want_html ? "text/html" : "text/plain"; - TnyMimePart *part; + TnyMimePart *part = NULL; TnyList *parts; TnyIterator *iter; @@ -110,22 +82,36 @@ modest_tny_msg_actions_find_body_part (TnyMsg *msg, gboolean want_html) return NULL; parts = TNY_LIST (tny_simple_list_new()); - tny_msg_get_parts ((TnyMsg*)msg, parts); + tny_mime_part_get_parts (TNY_MIME_PART (msg), parts); iter = tny_list_create_iterator(parts); - while (!tny_iterator_is_done(iter)) { - - part = TNY_MIME_PART(tny_iterator_get_current (iter)); - - if (tny_mime_part_content_type_is (part, mime_type) && - !tny_mime_part_is_attachment (part)) { - break; - } - part = NULL; - tny_iterator_next (iter); + /* no parts? assume it's single-part message */ + if (tny_iterator_is_done(iter)) + return TNY_MIME_PART (g_object_ref(G_OBJECT(msg))); + else { + do { + const gchar* content_type; + part = TNY_MIME_PART(tny_iterator_get_current (iter)); + + if (tny_mime_part_content_type_is (part, mime_type) && + !tny_mime_part_is_attachment (part)) + break; + + content_type = tny_mime_part_get_content_type (part); + if (g_str_has_prefix(content_type, "multipart")) { + part = modest_tny_msg_actions_find_body_part_from_mime_part (part, + want_html); + if (part) + break; + } + + part = NULL; + tny_iterator_next (iter); + + } while (!tny_iterator_is_done(iter)); } - + /* did we find a matching part? */ if (part) g_object_ref (G_OBJECT(part)); @@ -137,12 +123,22 @@ modest_tny_msg_actions_find_body_part (TnyMsg *msg, gboolean want_html) * try to find a text/plain part instead */ if (!part && want_html) - return modest_tny_msg_actions_find_body_part (msg, FALSE); + return modest_tny_msg_actions_find_body_part_from_mime_part (msg, FALSE); + if (!part) + g_warning ("cannot find body part"); + return part ? part : NULL; } +TnyMimePart* +modest_tny_msg_actions_find_body_part (TnyMsg *msg, gboolean want_html) +{ + return modest_tny_msg_actions_find_body_part_from_mime_part (TNY_MIME_PART(msg), + want_html); +} + TnyMimePart * modest_tny_msg_actions_find_nth_part (TnyMsg *msg, gint index) @@ -155,7 +151,7 @@ modest_tny_msg_actions_find_nth_part (TnyMsg *msg, gint index) g_return_val_if_fail (index > 0, NULL); parts = TNY_LIST(tny_simple_list_new()); - tny_msg_get_parts ((TnyMsg*)msg, parts); + tny_mime_part_get_parts (TNY_MIME_PART(msg), parts); iter = tny_list_create_iterator (parts); part = NULL;