From f19058ea7a002e8ebf8351c55a86d3bb17a46cbc Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sat, 18 May 2013 11:24:40 -0400 Subject: Add e_mail_part_ref_mime_part(). --- em-format/e-mail-formatter-attachment.c | 5 ++++- em-format/e-mail-formatter-error.c | 6 +++++- em-format/e-mail-formatter-headers.c | 10 +++++++--- em-format/e-mail-formatter-image.c | 6 +++++- em-format/e-mail-formatter-print-headers.c | 15 ++++++++++----- em-format/e-mail-formatter-quote-attachment.c | 5 ++++- em-format/e-mail-formatter-quote-headers.c | 11 ++++++++--- em-format/e-mail-formatter-quote-text-plain.c | 8 ++++++-- em-format/e-mail-formatter-source.c | 14 +++++++++----- em-format/e-mail-formatter-text-plain.c | 12 +++++++++--- em-format/e-mail-formatter.c | 13 ++++++++----- em-format/e-mail-part.c | 25 +++++++++++++++++++++++++ em-format/e-mail-part.h | 1 + 13 files changed, 101 insertions(+), 30 deletions(-) (limited to 'em-format') diff --git a/em-format/e-mail-formatter-attachment.c b/em-format/e-mail-formatter-attachment.c index 40eb68c1b3..b7df8aae9b 100644 --- a/em-format/e-mail-formatter-attachment.c +++ b/em-format/e-mail-formatter-attachment.c @@ -122,6 +122,7 @@ emfe_attachment_format (EMailFormatterExtension *extension, EMailExtensionRegistry *reg; GQueue *extensions; EMailPartAttachment *empa; + CamelMimePart *mime_part; CamelMimeFilterToHTMLFlags flags; const gchar *attachment_part_id; const gchar *part_id; @@ -250,11 +251,13 @@ emfe_attachment_format (EMailFormatterExtension *extension, reg, empa->snoop_mime_type); } - text = e_mail_part_describe (part->part, empa->snoop_mime_type); + mime_part = e_mail_part_ref_mime_part (part); + text = e_mail_part_describe (mime_part, empa->snoop_mime_type); flags = e_mail_formatter_get_text_format_flags (formatter); html = camel_text_to_html ( text, flags & CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0); g_free (text); + g_object_unref (mime_part); if (empa->attachment_view_part_id) attachment_part_id = empa->attachment_view_part_id; diff --git a/em-format/e-mail-formatter-error.c b/em-format/e-mail-formatter-error.c index a329abfffd..8669c11ced 100644 --- a/em-format/e-mail-formatter-error.c +++ b/em-format/e-mail-formatter-error.c @@ -51,10 +51,12 @@ emfe_error_format (EMailFormatterExtension *extension, { CamelStream *filtered_stream; CamelMimeFilter *filter; + CamelMimePart *mime_part; CamelDataWrapper *dw; gchar *html; - dw = camel_medium_get_content (CAMEL_MEDIUM (part->part)); + mime_part = e_mail_part_ref_mime_part (part); + dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part)); html = g_strdup_printf ( "
", cancellable, NULL); + g_object_unref (mime_part); + return TRUE; } diff --git a/em-format/e-mail-formatter-headers.c b/em-format/e-mail-formatter-headers.c index afe780a4ee..39aceb30c7 100644 --- a/em-format/e-mail-formatter-headers.c +++ b/em-format/e-mail-formatter-headers.c @@ -532,6 +532,7 @@ emfe_headers_format (EMailFormatterExtension *extension, CamelStream *stream, GCancellable *cancellable) { + CamelMimePart *mime_part; GString *buffer; const GdkRGBA white = { 1.0, 1.0, 1.0, 1.0 }; const GdkRGBA *body_rgba = &white; @@ -543,7 +544,8 @@ emfe_headers_format (EMailFormatterExtension *extension, if (g_cancellable_is_cancelled (cancellable)) return FALSE; - if (!part->part) + mime_part = e_mail_part_ref_mime_part (part); + if (mime_part == NULL) return FALSE; switch (gtk_widget_get_default_direction ()) { @@ -599,13 +601,13 @@ emfe_headers_format (EMailFormatterExtension *extension, if (is_collapsable) format_short_headers ( formatter, buffer, - CAMEL_MEDIUM (part->part), + CAMEL_MEDIUM (mime_part), context->flags, cancellable); format_full_headers ( formatter, buffer, - CAMEL_MEDIUM (part->part), + CAMEL_MEDIUM (mime_part), context->mode, context->flags, cancellable); @@ -618,6 +620,8 @@ emfe_headers_format (EMailFormatterExtension *extension, g_string_free (buffer, TRUE); + g_object_unref (mime_part); + return TRUE; } diff --git a/em-format/e-mail-formatter-image.c b/em-format/e-mail-formatter-image.c index f69a59cdba..c504881f27 100644 --- a/em-format/e-mail-formatter-image.c +++ b/em-format/e-mail-formatter-image.c @@ -69,6 +69,7 @@ emfe_image_format (EMailFormatterExtension *extension, GCancellable *cancellable) { gchar *content; + CamelMimePart *mime_part; CamelDataWrapper *dw; GByteArray *ba; CamelStream *raw_content; @@ -76,7 +77,8 @@ emfe_image_format (EMailFormatterExtension *extension, if (g_cancellable_is_cancelled (cancellable)) return FALSE; - dw = camel_medium_get_content (CAMEL_MEDIUM (part->part)); + mime_part = e_mail_part_ref_mime_part (part); + dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part)); g_return_val_if_fail (dw, FALSE); raw_content = camel_stream_mem_new (); @@ -139,6 +141,8 @@ emfe_image_format (EMailFormatterExtension *extension, g_object_unref (raw_content); + g_object_unref (mime_part); + return TRUE; } diff --git a/em-format/e-mail-formatter-print-headers.c b/em-format/e-mail-formatter-print-headers.c index 6eec667463..65515508a5 100644 --- a/em-format/e-mail-formatter-print-headers.c +++ b/em-format/e-mail-formatter-print-headers.c @@ -61,12 +61,15 @@ emfpe_headers_format (EMailFormatterExtension *extension, const gchar *buf; gint attachments_count; gchar *part_id_prefix; + CamelMimePart *mime_part; GQueue *headers_queue; GQueue queue = G_QUEUE_INIT; GList *head, *link; const gchar *part_id; - buf = camel_medium_get_header (CAMEL_MEDIUM (part->part), "subject"); + mime_part = e_mail_part_ref_mime_part (part); + + buf = camel_medium_get_header (CAMEL_MEDIUM (mime_part), "subject"); subject = camel_header_decode_string (buf, "UTF-8"); str = g_string_new (""); g_string_append_printf (str, "

%s

\n", subject); @@ -90,7 +93,7 @@ emfpe_headers_format (EMailFormatterExtension *extension, raw_header.value = header->value; e_mail_formatter_format_header ( formatter, str, - CAMEL_MEDIUM (part->part), &raw_header, + CAMEL_MEDIUM (mime_part), &raw_header, header->flags | E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS, "UTF-8"); } else { @@ -106,7 +109,7 @@ emfpe_headers_format (EMailFormatterExtension *extension, if (raw_header.value && *raw_header.value) { e_mail_formatter_format_header ( formatter, str, - CAMEL_MEDIUM (part->part), &raw_header, + CAMEL_MEDIUM (mime_part), &raw_header, header->flags | E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS, "UTF-8"); } @@ -169,7 +172,7 @@ emfpe_headers_format (EMailFormatterExtension *extension, raw_header.value = tmp->str; e_mail_formatter_format_header ( formatter, str, - CAMEL_MEDIUM (part->part), &raw_header, + CAMEL_MEDIUM (mime_part), &raw_header, E_MAIL_FORMATTER_HEADER_FLAG_BOLD | E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS, "UTF-8"); } @@ -201,7 +204,7 @@ emfpe_headers_format (EMailFormatterExtension *extension, raw_header.value = g_strdup_printf ("%d", attachments_count); e_mail_formatter_format_header ( formatter, str, - CAMEL_MEDIUM (part->part), &raw_header, + CAMEL_MEDIUM (mime_part), &raw_header, E_MAIL_FORMATTER_HEADER_FLAG_BOLD | E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS, "UTF-8"); g_free (raw_header.value); @@ -216,6 +219,8 @@ emfpe_headers_format (EMailFormatterExtension *extension, g_string_free (str, TRUE); g_free (part_id_prefix); + g_object_unref (mime_part); + return TRUE; } diff --git a/em-format/e-mail-formatter-quote-attachment.c b/em-format/e-mail-formatter-quote-attachment.c index 6f5068bae1..3443392555 100644 --- a/em-format/e-mail-formatter-quote-attachment.c +++ b/em-format/e-mail-formatter-quote-attachment.c @@ -59,6 +59,7 @@ emfqe_attachment_format (EMailFormatterExtension *extension, EMailPartAttachment *empa; EMailPart *attachment_view_part; CamelMimeFilterToHTMLFlags text_format_flags; + CamelMimePart *mime_part; empa = E_MAIL_PART_ATTACHMENT (part); @@ -74,9 +75,11 @@ emfqe_attachment_format (EMailFormatterExtension *extension, text_format_flags = e_mail_formatter_get_text_format_flags (formatter); + mime_part = e_mail_part_ref_mime_part (part); text = e_mail_part_describe ( - part->part, + mime_part, empa ? empa->snoop_mime_type : part->mime_type); + g_object_unref (mime_part); html = camel_text_to_html ( text, diff --git a/em-format/e-mail-formatter-quote-headers.c b/em-format/e-mail-formatter-quote-headers.c index fa6c02752b..f23397b3b5 100644 --- a/em-format/e-mail-formatter-quote-headers.c +++ b/em-format/e-mail-formatter-quote-headers.c @@ -190,6 +190,7 @@ emqfe_headers_format (EMailFormatterExtension *extension, GCancellable *cancellable) { CamelContentType *ct; + CamelMimePart *mime_part; const gchar *charset; GList *iter; GString *buffer; @@ -198,7 +199,9 @@ emqfe_headers_format (EMailFormatterExtension *extension, if (!part) return FALSE; - ct = camel_mime_part_get_content_type ((CamelMimePart *) part->part); + mime_part = e_mail_part_ref_mime_part (part); + + ct = camel_mime_part_get_content_type (mime_part); charset = camel_content_type_param (ct, "charset"); charset = camel_iconv_charset_name (charset); @@ -214,13 +217,13 @@ emqfe_headers_format (EMailFormatterExtension *extension, flags = h->flags & ~E_MAIL_FORMATTER_HEADER_FLAG_HTML; flags |= E_MAIL_FORMATTER_HEADER_FLAG_NOELIPSIZE; - for (raw_header = part->part->headers; raw_header; raw_header = raw_header->next) { + for (raw_header = mime_part->headers; raw_header; raw_header = raw_header->next) { if (g_strcmp0 (raw_header->name, h->name) == 0) { emfqe_format_header ( formatter, buffer, - (CamelMedium *) part->part, + CAMEL_MEDIUM (mime_part), raw_header, flags, charset); break; } @@ -235,6 +238,8 @@ emqfe_headers_format (EMailFormatterExtension *extension, g_string_free (buffer, TRUE); + g_object_unref (mime_part); + return TRUE; } diff --git a/em-format/e-mail-formatter-quote-text-plain.c b/em-format/e-mail-formatter-quote-text-plain.c index 9544a39f96..efe0638e44 100644 --- a/em-format/e-mail-formatter-quote-text-plain.c +++ b/em-format/e-mail-formatter-quote-text-plain.c @@ -56,13 +56,15 @@ emqfe_text_plain_format (EMailFormatterExtension *extension, CamelStream *filtered_stream; CamelMimeFilter *html_filter; CamelMimeFilter *sig_strip; + CamelMimePart *mime_part; CamelContentType *type; EMailFormatterQuoteContext *qf_context; CamelMimeFilterToHTMLFlags text_flags; const gchar *format; guint32 rgb = 0x737373; - if (!part->part) + mime_part = e_mail_part_ref_mime_part (part); + if (mime_part == NULL) return FALSE; qf_context = (EMailFormatterQuoteContext *) context; @@ -76,7 +78,7 @@ emqfe_text_plain_format (EMailFormatterExtension *extension, text_flags |= CAMEL_MIME_FILTER_TOHTML_MARK_CITATION; /* Check for RFC 2646 flowed text. */ - type = camel_mime_part_get_content_type (part->part); + type = camel_mime_part_get_content_type (mime_part); if (camel_content_type_is (type, "text", "plain") && (format = camel_content_type_param (type, "format")) && !g_ascii_strcasecmp (format, "flowed")) @@ -102,6 +104,8 @@ emqfe_text_plain_format (EMailFormatterExtension *extension, camel_stream_flush (filtered_stream, cancellable, NULL); g_object_unref (filtered_stream); + g_object_unref (mime_part); + return TRUE; } diff --git a/em-format/e-mail-formatter-source.c b/em-format/e-mail-formatter-source.c index faa4c76521..944f9a4c14 100644 --- a/em-format/e-mail-formatter-source.c +++ b/em-format/e-mail-formatter-source.c @@ -53,7 +53,9 @@ emfe_source_format (EMailFormatterExtension *extension, GString *buffer; CamelStream *filtered_stream; CamelMimeFilter *filter; - CamelDataWrapper *dw = (CamelDataWrapper *) part->part; + CamelMimePart *mime_part; + + mime_part = e_mail_part_ref_mime_part (part); filtered_stream = camel_stream_filter_new (stream); @@ -67,7 +69,7 @@ emfe_source_format (EMailFormatterExtension *extension, buffer = g_string_new (""); - if (CAMEL_IS_MIME_MESSAGE (part->part)) { + if (CAMEL_IS_MIME_MESSAGE (mime_part)) { g_string_append_printf ( buffer, "
", cancellable, NULL); camel_data_wrapper_write_to_stream_sync ( - dw, filtered_stream, - cancellable, NULL); + CAMEL_DATA_WRAPPER (mime_part), + filtered_stream, cancellable, NULL); camel_stream_flush (filtered_stream, cancellable, NULL); g_object_unref (filtered_stream); @@ -111,12 +113,14 @@ emfe_source_format (EMailFormatterExtension *extension, g_string_free (buffer, TRUE); - if (CAMEL_IS_MIME_MESSAGE (part->part)) { + if (CAMEL_IS_MIME_MESSAGE (mime_part)) { camel_stream_write_string (stream, "
", cancellable, NULL); } else { camel_stream_write_string (stream, "
", cancellable, NULL); } + g_object_unref (mime_part); + return TRUE; } diff --git a/em-format/e-mail-formatter-text-plain.c b/em-format/e-mail-formatter-text-plain.c index 33ede66957..638f0119a1 100644 --- a/em-format/e-mail-formatter-text-plain.c +++ b/em-format/e-mail-formatter-text-plain.c @@ -54,7 +54,6 @@ emfe_text_plain_format (EMailFormatterExtension *extension, CamelStream *stream, GCancellable *cancellable) { - CamelDataWrapper *dw; CamelStream *filtered_stream; CamelMimeFilter *html_filter; gchar *content; @@ -67,6 +66,8 @@ emfe_text_plain_format (EMailFormatterExtension *extension, if ((context->mode == E_MAIL_FORMATTER_MODE_RAW) || (context->mode == E_MAIL_FORMATTER_MODE_PRINTING)) { CamelMimeFilterToHTMLFlags flags; + CamelMimePart *mime_part; + CamelDataWrapper *dw; if (context->mode == E_MAIL_FORMATTER_MODE_RAW) { gchar *header; @@ -83,9 +84,12 @@ emfe_text_plain_format (EMailFormatterExtension *extension, flags = e_mail_formatter_get_text_format_flags (formatter); - dw = camel_medium_get_content (CAMEL_MEDIUM (part->part)); - if (!dw) + mime_part = e_mail_part_ref_mime_part (part); + dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part)); + if (dw == NULL) { + g_object_unref (mime_part); return FALSE; + } /* Check for RFC 2646 flowed text. */ if (camel_content_type_is (dw->mime_type, "text", "plain") @@ -129,6 +133,8 @@ emfe_text_plain_format (EMailFormatterExtension *extension, cancellable, NULL); } + g_object_unref (mime_part); + return TRUE; } else { diff --git a/em-format/e-mail-formatter.c b/em-format/e-mail-formatter.c index e2e6da75a3..4ce93a7db2 100644 --- a/em-format/e-mail-formatter.c +++ b/em-format/e-mail-formatter.c @@ -1037,14 +1037,14 @@ e_mail_formatter_format_text (EMailFormatter *formatter, const gchar *charset = NULL; CamelMimeFilter *windows = NULL; CamelStream *mem_stream = NULL; - CamelDataWrapper *dw; + CamelMimePart *mime_part; CamelContentType *mime_type; if (g_cancellable_is_cancelled (cancellable)) return; - dw = CAMEL_DATA_WRAPPER (part->part); - mime_type = dw->mime_type; + mime_part = e_mail_part_ref_mime_part (part); + mime_type = CAMEL_DATA_WRAPPER (mime_part)->mime_type; if (formatter->priv->charset != NULL) { charset = formatter->priv->charset; @@ -1067,7 +1067,8 @@ e_mail_formatter_format_text (EMailFormatter *formatter, CAMEL_STREAM_FILTER (filter_stream), windows); camel_data_wrapper_decode_to_stream_sync ( - dw, filter_stream, cancellable, NULL); + CAMEL_DATA_WRAPPER (mime_part), + filter_stream, cancellable, NULL); camel_stream_flush (filter_stream, cancellable, NULL); g_object_unref (filter_stream); @@ -1088,7 +1089,7 @@ e_mail_formatter_format_text (EMailFormatter *formatter, } camel_data_wrapper_decode_to_stream_sync ( - camel_medium_get_content (CAMEL_MEDIUM (dw)), + camel_medium_get_content (CAMEL_MEDIUM (mime_part)), filter_stream, cancellable, NULL); camel_stream_flush (filter_stream, cancellable, NULL); g_object_unref (filter_stream); @@ -1103,6 +1104,8 @@ e_mail_formatter_format_text (EMailFormatter *formatter, g_object_unref (windows); g_object_unref (mem_stream); + + g_object_unref (mime_part); } gchar * diff --git a/em-format/e-mail-part.c b/em-format/e-mail-part.c index 945175cca2..68434d0ce9 100644 --- a/em-format/e-mail-part.c +++ b/em-format/e-mail-part.c @@ -31,6 +31,8 @@ #include "e-mail-part.h" +#include + struct _EMailPartPrivate { guint ref_cnt; gsize instance_size; @@ -221,6 +223,29 @@ e_mail_part_id_has_suffix (EMailPart *part, return g_str_has_suffix (part->id, suffix); } +gboolean +e_mail_part_id_has_substr (EMailPart *part, + const gchar *substr) +{ + g_return_val_if_fail (part != NULL, FALSE); + g_return_val_if_fail (substr != NULL, FALSE); + + return (strstr (part->id, substr) != NULL); +} + +CamelMimePart * +e_mail_part_ref_mime_part (EMailPart *part) +{ + CamelMimePart *mime_part = NULL; + + g_return_val_if_fail (part != NULL, NULL); + + if (part->part != NULL) + mime_part = g_object_ref (part->part); + + return mime_part; +} + static EMailPartValidityPair * mail_part_find_validity_pair (EMailPart *part, guint32 validity_type) diff --git a/em-format/e-mail-part.h b/em-format/e-mail-part.h index c67cb8326f..3e9c7111d7 100644 --- a/em-format/e-mail-part.h +++ b/em-format/e-mail-part.h @@ -105,6 +105,7 @@ gboolean e_mail_part_id_has_suffix (EMailPart *part, const gchar *suffix); gboolean e_mail_part_id_has_substr (EMailPart *part, const gchar *substr); +CamelMimePart * e_mail_part_ref_mime_part (EMailPart *part); void e_mail_part_update_validity (EMailPart *part, CamelCipherValidity *validity, guint32 validity_type); -- cgit v1.2.3