diff options
Diffstat (limited to 'em-format/e-mail-formatter-attachment.c')
-rw-r--r-- | em-format/e-mail-formatter-attachment.c | 80 |
1 files changed, 51 insertions, 29 deletions
diff --git a/em-format/e-mail-formatter-attachment.c b/em-format/e-mail-formatter-attachment.c index 54647edd4a..08b0da2042 100644 --- a/em-format/e-mail-formatter-attachment.c +++ b/em-format/e-mail-formatter-attachment.c @@ -44,22 +44,25 @@ G_DEFINE_TYPE ( E_TYPE_MAIL_FORMATTER_EXTENSION) static const gchar *formatter_mime_types[] = { - "application/vnd.evolution.attachment", + E_MAIL_PART_ATTACHMENT_MIME_TYPE, "application/vnd.evolution.widget.attachment-button", NULL }; static EAttachmentStore * find_attachment_store (EMailPartList *part_list, - const gchar *start_id) + EMailPart *start) { EAttachmentStore *store = NULL; GQueue queue = G_QUEUE_INIT; GList *head, *link; + const gchar *start_id; gchar *tmp, *pos; EMailPart *part; gchar *id; + start_id = start->id; + e_mail_part_list_queue_parts (part_list, NULL, &queue); head = g_queue_peek_head_link (&queue); @@ -94,7 +97,7 @@ find_attachment_store (EMailPartList *part_list, g_free (tmp); if (part != NULL) - store = ((EMailPartAttachmentBar *) part)->store; + store = E_MAIL_PART_ATTACHMENT_BAR (part)->store; while (!g_queue_is_empty (&queue)) e_mail_part_unref (g_queue_pop_head (&queue)); @@ -117,17 +120,21 @@ emfe_attachment_format (EMailFormatterExtension *extension, GQueue *extensions; EMailPartAttachment *empa; CamelMimeFilterToHTMLFlags flags; - gchar *attachment_part_id; + const gchar *attachment_part_id; - g_return_val_if_fail (E_MAIL_PART_IS (part, EMailPartAttachment), FALSE); + g_return_val_if_fail (E_IS_MAIL_PART_ATTACHMENT (part), FALSE); empa = (EMailPartAttachment *) part; if ((context->mode == E_MAIL_FORMATTER_MODE_NORMAL) || (context->mode == E_MAIL_FORMATTER_MODE_PRINTING) || (context->mode == E_MAIL_FORMATTER_MODE_ALL_HEADERS)) { + EAttachment *attachment; GList *head, *link; + attachment = g_object_ref ( + E_MAIL_PART_ATTACHMENT (part)->attachment); + head = g_queue_peek_head_link (&part->validities); for (link = head; link != NULL; link = g_list_next (link)) { @@ -138,43 +145,45 @@ emfe_attachment_format (EMailFormatterExtension *extension, if ((pair->validity_type & E_MAIL_PART_VALIDITY_SIGNED) != 0) e_attachment_set_signed ( - empa->attachment, + attachment, pair->validity->sign.status); if ((pair->validity_type & E_MAIL_PART_VALIDITY_ENCRYPTED) != 0) e_attachment_set_encrypted ( - empa->attachment, + attachment, pair->validity->encrypt.status); } - store = find_attachment_store (context->part_list, part->id); + store = find_attachment_store (context->part_list, part); if (store) { GList *attachments = e_attachment_store_get_attachments (store); - if (!g_list_find (attachments, empa->attachment)) { + if (!g_list_find (attachments, attachment)) { e_attachment_store_add_attachment ( - store, empa->attachment); + store, attachment); } g_list_free (attachments); } else { g_warning ("Failed to locate attachment-bar for %s", part->id); } + + g_object_unref (attachment); } - /* If the attachment is requested as RAW, then call the handler directly - * and do not append any other code. */ + /* If the attachment is requested as RAW, then call the + * handler directly and do not append any other code. */ if ((context->mode == E_MAIL_FORMATTER_MODE_RAW) || (context->mode == E_MAIL_FORMATTER_MODE_PRINTING)) { - EMailExtensionRegistry *reg; + EMailExtensionRegistry *registry; GQueue *extensions; GList *iter; - reg = e_mail_formatter_get_extension_registry (formatter); + + registry = e_mail_formatter_get_extension_registry (formatter); extensions = e_mail_extension_registry_get_for_mime_type ( - reg, empa->snoop_mime_type); - if (!extensions) { + registry, empa->snoop_mime_type); + if (extensions == NULL) extensions = e_mail_extension_registry_get_fallback ( - reg, empa->snoop_mime_type); - } + registry, empa->snoop_mime_type); if (!extensions) return FALSE; @@ -184,23 +193,29 @@ emfe_attachment_format (EMailFormatterExtension *extension, EAttachment *attachment; GFileInfo *fi; const gchar *description; + const gchar *display_name; + + attachment = g_object_ref ( + E_MAIL_PART_ATTACHMENT (part)->attachment); - attachment = empa->attachment; fi = e_attachment_get_file_info (attachment); + display_name = g_file_info_get_display_name (fi); description = e_attachment_get_description (attachment); if (description && *description) { name = g_strdup_printf ( "<h2>Attachment: %s (%s)</h2>\n", - description, g_file_info_get_display_name (fi)); + description, display_name); } else { name = g_strdup_printf ( "<h2>Attachment: %s</h2>\n", - g_file_info_get_display_name (fi)); + display_name); } camel_stream_write_string (stream, name, cancellable, NULL); g_free (name); + + g_object_unref (attachment); } for (iter = g_queue_peek_head_link (extensions); iter; iter = iter->next) { @@ -343,28 +358,35 @@ emfe_attachment_get_widget (EMailFormatterExtension *extension, EMailPart *part, GHashTable *params) { - EMailPartAttachment *empa; + EAttachment *attachment; EAttachmentStore *store; EAttachmentView *view; GtkWidget *widget; - g_return_val_if_fail (E_MAIL_PART_IS (part, EMailPartAttachment), NULL); - empa = (EMailPartAttachment *) part; + g_return_val_if_fail (E_IS_MAIL_PART_ATTACHMENT (part), NULL); + + attachment = g_object_ref ( + E_MAIL_PART_ATTACHMENT (part)->attachment); - store = find_attachment_store (context, part->id); + store = find_attachment_store (context, part); widget = e_attachment_button_new (); - g_object_set_data (G_OBJECT (widget), "uri", part->id); + g_object_set_data_full ( + G_OBJECT (widget), + "uri", g_strdup (part->id), + (GDestroyNotify) g_free); e_attachment_button_set_attachment ( - E_ATTACHMENT_BUTTON (widget), empa->attachment); + E_ATTACHMENT_BUTTON (widget), attachment); + view = g_object_get_data (G_OBJECT (store), "attachment-bar"); - if (view) { + if (view != NULL) e_attachment_button_set_view ( E_ATTACHMENT_BUTTON (widget), view); - } gtk_widget_set_can_focus (widget, TRUE); gtk_widget_show (widget); + g_object_unref (attachment); + return widget; } |