From 221c841d423c567f3bfb8b12ea039d7e932fdefa Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Tue, 10 Aug 2010 06:01:18 -0400 Subject: Bug 626453 - Show attachments inline when printing --- em-format/em-format.c | 60 +++++++++++++++++++++++++++++++++++---------------- em-format/em-format.h | 11 +++++++--- 2 files changed, 50 insertions(+), 21 deletions(-) (limited to 'em-format') diff --git a/em-format/em-format.c b/em-format/em-format.c index a323c56d65..74bcb31e43 100644 --- a/em-format/em-format.c +++ b/em-format/em-format.c @@ -117,6 +117,35 @@ emf_finalize (GObject *object) G_OBJECT_CLASS (parent_class)->finalize (object); } +static gboolean +emf_is_inline (EMFormat *emf, + const gchar *part_id, + CamelMimePart *mime_part, + const EMFormatHandler *handle) +{ + struct _EMFormatCache *emfc; + const gchar *disposition; + + if (handle == NULL) + return FALSE; + + emfc = g_hash_table_lookup (emf->inline_table, part_id); + if (emfc && emfc->state != INLINE_UNSET) + return emfc->state & 1; + + /* Some types need to override the disposition. + * e.g. application/x-pkcs7-mime */ + if (handle->flags & EM_FORMAT_HANDLER_INLINE_DISPOSITION) + return TRUE; + + disposition = camel_mime_part_get_disposition (mime_part); + if (disposition != NULL) + return g_ascii_strcasecmp (disposition, "inline") == 0; + + /* Otherwise, use the default for this handler type. */ + return (handle->flags & EM_FORMAT_HANDLER_INLINE) != 0; +} + static void emf_base_init (EMFormatClass *class) { @@ -138,6 +167,7 @@ emf_class_init (EMFormatClass *class) class->format_clone = emf_format_clone; class->format_secure = emf_format_secure; class->busy = emf_busy; + class->is_inline = emf_is_inline; signals[EMF_COMPLETE] = g_signal_new ( "complete", @@ -1040,28 +1070,22 @@ gint em_format_is_attachment(EMFormat *emf, CamelMimePart *part) * * Return value: **/ -gint em_format_is_inline(EMFormat *emf, const gchar *partid, CamelMimePart *part, const EMFormatHandler *handle) +gboolean +em_format_is_inline (EMFormat *emf, + const gchar *part_id, + CamelMimePart *mime_part, + const EMFormatHandler *handle) { - struct _EMFormatCache *emfc; - const gchar *tmp; - - if (handle == NULL) - return FALSE; - - emfc = g_hash_table_lookup(emf->inline_table, partid); - if (emfc && emfc->state != INLINE_UNSET) - return emfc->state & 1; + EMFormatClass *class; - /* some types need to override the disposition, e.g. application/x-pkcs7-mime */ - if (handle->flags & EM_FORMAT_HANDLER_INLINE_DISPOSITION) - return TRUE; + g_return_val_if_fail (EM_IS_FORMAT (emf), FALSE); + g_return_val_if_fail (part_id != NULL, FALSE); + g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), FALSE); - tmp = camel_mime_part_get_disposition(part); - if (tmp) - return g_ascii_strcasecmp(tmp, "inline") == 0; + class = EM_FORMAT_GET_CLASS (emf); + g_return_val_if_fail (class->is_inline != NULL, FALSE); - /* otherwise, use the default for this handler type */ - return (handle->flags & EM_FORMAT_HANDLER_INLINE) != 0; + return class->is_inline (emf, part_id, mime_part, handle); } /** diff --git a/em-format/em-format.h b/em-format/em-format.h index 965ca20399..5ae0e7f2ae 100644 --- a/em-format/em-format.h +++ b/em-format/em-format.h @@ -251,6 +251,11 @@ struct _EMFormatClass { /* Shows optional way to open messages */ void (*format_optional)(EMFormat *, CamelStream *, CamelMimePart *, CamelStream* ); + gboolean (*is_inline) (EMFormat *emf, + const gchar *part_id, + CamelMimePart *mime_part, + const EMFormatHandler *handle); + /* signals */ /* complete, alternative to polling busy, for asynchronous work */ void (*complete)(EMFormat *); @@ -277,9 +282,9 @@ void em_format_add_header (EMFormat *emf, gint em_format_is_attachment (EMFormat *emf, CamelMimePart *part); -gint em_format_is_inline (EMFormat *emf, - const gchar *partid, - CamelMimePart *part, +gboolean em_format_is_inline (EMFormat *emf, + const gchar *part_id, + CamelMimePart *mime_part, const EMFormatHandler *handle); void em_format_set_inline (EMFormat *emf, const gchar *partid, -- cgit v1.2.3