aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-05-23 00:11:49 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-05-24 04:36:01 +0800
commit256422cab27d0b7adbe99fdeaceb72cd78c129bb (patch)
tree8d087e570e7656e7d088232d98c52636c95baed0
parent37c5951635a4f45ba26b0f95ce7af61275d47fba (diff)
downloadgsoc2013-evolution-256422cab27d0b7adbe99fdeaceb72cd78c129bb.tar
gsoc2013-evolution-256422cab27d0b7adbe99fdeaceb72cd78c129bb.tar.gz
gsoc2013-evolution-256422cab27d0b7adbe99fdeaceb72cd78c129bb.tar.bz2
gsoc2013-evolution-256422cab27d0b7adbe99fdeaceb72cd78c129bb.tar.lz
gsoc2013-evolution-256422cab27d0b7adbe99fdeaceb72cd78c129bb.tar.xz
gsoc2013-evolution-256422cab27d0b7adbe99fdeaceb72cd78c129bb.tar.zst
gsoc2013-evolution-256422cab27d0b7adbe99fdeaceb72cd78c129bb.zip
Attachment-related cleanups.
-rw-r--r--calendar/gui/dialogs/comp-editor.c20
-rw-r--r--e-util/e-attachment-button.c99
-rw-r--r--e-util/e-attachment-handler-image.c14
-rw-r--r--e-util/e-attachment-store.c16
-rw-r--r--e-util/e-attachment.c140
-rw-r--r--em-format/e-mail-formatter-attachment.c6
-rw-r--r--em-format/e-mail-parser.c18
-rw-r--r--modules/calendar/e-cal-attachment-handler.c2
-rw-r--r--modules/mail/e-mail-attachment-handler.c98
9 files changed, 220 insertions, 193 deletions
diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c
index abbf737206..778e69008d 100644
--- a/calendar/gui/dialogs/comp-editor.c
+++ b/calendar/gui/dialogs/comp-editor.c
@@ -3209,7 +3209,7 @@ attachment_loaded_cb (EAttachment *attachment,
*/
file_info = e_attachment_get_file_info (attachment);
- if (!file_info) {
+ if (file_info == NULL) {
/* failed to load an attachment file */
e_attachment_load_handle_error (attachment, result, parent);
return;
@@ -3697,7 +3697,8 @@ comp_editor_get_mime_attach_list (CompEditor *editor)
CamelStream *stream;
GByteArray *byte_array;
guchar *buffer = NULL;
- const gchar *desc, *disp;
+ const gchar *description;
+ const gchar *disposition;
gint column_id;
column_id = E_ATTACHMENT_STORE_COLUMN_ATTACHMENT;
@@ -3726,18 +3727,19 @@ comp_editor_get_mime_attach_list (CompEditor *editor)
cal_mime_attach->length = byte_array->len;
cal_mime_attach->filename =
g_strdup (camel_mime_part_get_filename (mime_part));
- desc = camel_mime_part_get_description (mime_part);
- if (!desc || *desc == '\0')
- desc = _("attachment");
- cal_mime_attach->description = g_strdup (desc);
+ description = camel_mime_part_get_description (mime_part);
+ if (description == NULL || *description == '\0')
+ description = _("attachment");
+ cal_mime_attach->description = g_strdup (description);
cal_mime_attach->content_type = g_strdup (
camel_data_wrapper_get_mime_type (wrapper));
cal_mime_attach->content_id = g_strdup (
camel_mime_part_get_content_id (mime_part));
- disp = camel_mime_part_get_disposition (mime_part);
- if (disp && !g_ascii_strcasecmp (disp, "inline"))
- cal_mime_attach->disposition = TRUE;
+ disposition = camel_mime_part_get_disposition (mime_part);
+ cal_mime_attach->disposition =
+ (disposition != NULL) &&
+ (g_ascii_strcasecmp (disposition, "inline") == 0);
attach_list = g_slist_append (attach_list, cal_mime_attach);
diff --git a/e-util/e-attachment-button.c b/e-util/e-attachment-button.c
index a2057e3354..7778bb106f 100644
--- a/e-util/e-attachment-button.c
+++ b/e-util/e-attachment-button.c
@@ -271,58 +271,57 @@ attachment_button_expand_drag_data_get_cb (EAttachmentButton *button,
guint time)
{
EAttachmentView *view;
+ EAttachment *attachment;
+ gchar *mime_type = NULL;
- if (button->priv->attachment) {
- gchar *mime_type;
-
- mime_type = e_attachment_get_mime_type (
- button->priv->attachment);
-
- if (mime_type) {
- gboolean processed = FALSE;
- GdkAtom atom;
- gchar *atom_name;
-
- atom = gtk_selection_data_get_target (selection);
- atom_name = gdk_atom_name (atom);
-
- if (g_strcmp0 (atom_name, mime_type) == 0) {
- CamelMimePart *mime_part;
-
- mime_part = e_attachment_get_mime_part (
- button->priv->attachment);
-
- if (CAMEL_IS_MIME_PART (mime_part)) {
- CamelDataWrapper *wrapper;
- CamelStream *stream;
- GByteArray *buffer;
-
- buffer = g_byte_array_new ();
- stream = camel_stream_mem_new ();
- camel_stream_mem_set_byte_array (
- CAMEL_STREAM_MEM (stream),
- buffer);
- wrapper = camel_medium_get_content (
- CAMEL_MEDIUM (mime_part));
- camel_data_wrapper_decode_to_stream_sync (
- wrapper, stream, NULL, NULL);
- g_object_unref (stream);
-
- gtk_selection_data_set (
- selection, atom, 8,
- buffer->data, buffer->len);
- processed = TRUE;
-
- g_byte_array_free (buffer, TRUE);
- }
- }
+ attachment = e_attachment_button_get_attachment (button);
+
+ if (attachment != NULL)
+ mime_type = e_attachment_get_mime_type (attachment);
+
+ if (mime_type != NULL) {
+ gboolean processed = FALSE;
+ GdkAtom atom;
+ gchar *atom_name;
+
+ atom = gtk_selection_data_get_target (selection);
+ atom_name = gdk_atom_name (atom);
+
+ if (g_strcmp0 (atom_name, mime_type) == 0) {
+ CamelMimePart *mime_part;
+
+ mime_part = e_attachment_get_mime_part (attachment);
- g_free (atom_name);
- g_free (mime_type);
+ if (mime_part != NULL) {
+ CamelDataWrapper *wrapper;
+ CamelStream *stream;
+ GByteArray *buffer;
- if (processed)
- return;
+ buffer = g_byte_array_new ();
+ stream = camel_stream_mem_new ();
+ camel_stream_mem_set_byte_array (
+ CAMEL_STREAM_MEM (stream),
+ buffer);
+ wrapper = camel_medium_get_content (
+ CAMEL_MEDIUM (mime_part));
+ camel_data_wrapper_decode_to_stream_sync (
+ wrapper, stream, NULL, NULL);
+ g_object_unref (stream);
+
+ gtk_selection_data_set (
+ selection, atom, 8,
+ buffer->data, buffer->len);
+ processed = TRUE;
+
+ g_byte_array_free (buffer, TRUE);
+ }
}
+
+ g_free (atom_name);
+ g_free (mime_type);
+
+ if (processed)
+ return;
}
view = e_attachment_button_get_view (button);
@@ -787,11 +786,11 @@ e_attachment_button_set_attachment (EAttachmentButton *button,
list = gtk_target_list_new (NULL, 0);
gtk_target_list_add_uri_targets (list, 0);
- if (attachment) {
+ if (attachment != NULL) {
gchar *simple_type;
simple_type = e_attachment_get_mime_type (attachment);
- if (simple_type) {
+ if (simple_type != NULL) {
GtkTargetEntry attach_entry[] = { { NULL, 0, 2 } };
attach_entry[0].target = simple_type;
diff --git a/e-util/e-attachment-handler-image.c b/e-util/e-attachment-handler-image.c
index 36c3a83614..602f001ba6 100644
--- a/e-util/e-attachment-handler-image.c
+++ b/e-util/e-attachment-handler-image.c
@@ -155,9 +155,7 @@ attachment_handler_image_update_actions_cb (EAttachmentView *view,
EAttachmentHandler *handler)
{
EAttachment *attachment;
- GFileInfo *file_info;
GtkActionGroup *action_group;
- const gchar *content_type;
gchar *mime_type;
GList *selected;
gboolean visible = FALSE;
@@ -168,10 +166,6 @@ attachment_handler_image_update_actions_cb (EAttachmentView *view,
goto exit;
attachment = E_ATTACHMENT (selected->data);
- file_info = e_attachment_get_file_info (attachment);
-
- if (file_info == NULL)
- goto exit;
if (e_attachment_get_loading (attachment))
goto exit;
@@ -179,10 +173,10 @@ attachment_handler_image_update_actions_cb (EAttachmentView *view,
if (e_attachment_get_saving (attachment))
goto exit;
- content_type = g_file_info_get_content_type (file_info);
-
- mime_type = g_content_type_get_mime_type (content_type);
- visible = (g_ascii_strncasecmp (mime_type, "image/", 6) == 0);
+ mime_type = e_attachment_get_mime_type (attachment);
+ visible =
+ (mime_type != NULL) &&
+ (g_ascii_strncasecmp (mime_type, "image/", 6) == 0);
g_free (mime_type);
exit:
diff --git a/e-util/e-attachment-store.c b/e-util/e-attachment-store.c
index 55bc795095..8ea2f8965b 100644
--- a/e-util/e-attachment-store.c
+++ b/e-util/e-attachment-store.c
@@ -727,18 +727,18 @@ e_attachment_store_get_uris_async (EAttachmentStore *store,
for (iter = attachment_list; iter != NULL; iter = iter->next) {
EAttachment *attachment = iter->data;
GFile *file;
- gchar *uri;
file = e_attachment_get_file (attachment);
- if (file == NULL)
- continue;
+ if (file != NULL) {
+ gchar *uri;
- uri = g_file_get_uri (file);
- uri_context->uris[uri_context->index++] = uri;
+ uri = g_file_get_uri (file);
+ uri_context->uris[uri_context->index++] = uri;
- /* Mark the list node for deletion. */
- trash = g_list_prepend (trash, iter);
- g_object_unref (attachment);
+ /* Mark the list node for deletion. */
+ trash = g_list_prepend (trash, iter);
+ g_object_unref (attachment);
+ }
}
/* Expunge the list. */
diff --git a/e-util/e-attachment.c b/e-util/e-attachment.c
index 495c805f16..9f758c510c 100644
--- a/e-util/e-attachment.c
+++ b/e-util/e-attachment.c
@@ -110,34 +110,35 @@ create_system_thumbnail (EAttachment *attachment,
{
GFile *file;
GFile *icon_file;
+ gchar *file_path = NULL;
gchar *thumbnail = NULL;
+ gboolean success = FALSE;
- g_return_val_if_fail (attachment != NULL, FALSE);
+ g_return_val_if_fail (E_IS_ATTACHMENT (attachment), FALSE);
g_return_val_if_fail (icon != NULL, FALSE);
file = e_attachment_get_file (attachment);
+ if (file != NULL)
+ file_path = g_file_get_path (file);
- if (file && g_file_has_uri_scheme (file, "file")) {
- gchar *path = g_file_get_path (file);
- if (path) {
- thumbnail = e_icon_factory_create_thumbnail (path);
- g_free (path);
- }
+ if (file_path != NULL) {
+ thumbnail = e_icon_factory_create_thumbnail (file_path);
+ g_free (file_path);
}
if (thumbnail == NULL)
- return FALSE;
+ goto exit;
icon_file = g_file_new_for_path (thumbnail);
- if (*icon)
+ if (*icon != NULL)
g_object_unref (*icon);
*icon = g_file_icon_new (icon_file);
g_object_unref (icon_file);
- if (file) {
+ if (file != NULL) {
GFileInfo *file_info;
const gchar *attribute;
@@ -151,7 +152,10 @@ create_system_thumbnail (EAttachment *attachment,
g_free (thumbnail);
- return TRUE;
+ success = TRUE;
+
+exit:
+ return success;
}
static gchar *
@@ -535,7 +539,7 @@ attachment_set_property (GObject *object,
case PROP_MIME_PART:
e_attachment_set_mime_part (
E_ATTACHMENT (object),
- g_value_get_boxed (value));
+ g_value_get_object (value));
return;
case PROP_REFERENCE:
@@ -563,79 +567,92 @@ attachment_get_property (GObject *object,
switch (property_id) {
case PROP_CAN_SHOW:
g_value_set_boolean (
- value, e_attachment_get_can_show (
+ value,
+ e_attachment_get_can_show (
E_ATTACHMENT (object)));
return;
case PROP_DISPOSITION:
g_value_set_string (
- value, e_attachment_get_disposition (
+ value,
+ e_attachment_get_disposition (
E_ATTACHMENT (object)));
return;
case PROP_ENCRYPTED:
g_value_set_int (
- value, e_attachment_get_encrypted (
+ value,
+ e_attachment_get_encrypted (
E_ATTACHMENT (object)));
return;
case PROP_FILE:
g_value_set_object (
- value, e_attachment_get_file (
+ value,
+ e_attachment_get_file (
E_ATTACHMENT (object)));
return;
case PROP_FILE_INFO:
g_value_set_object (
- value, e_attachment_get_file_info (
+ value,
+ e_attachment_get_file_info (
E_ATTACHMENT (object)));
return;
case PROP_ICON:
g_value_set_object (
- value, e_attachment_get_icon (
+ value,
+ e_attachment_get_icon (
E_ATTACHMENT (object)));
return;
case PROP_SHOWN:
g_value_set_boolean (
- value, e_attachment_get_shown (
+ value,
+ e_attachment_get_shown (
E_ATTACHMENT (object)));
return;
case PROP_LOADING:
g_value_set_boolean (
- value, e_attachment_get_loading (
+ value,
+ e_attachment_get_loading (
E_ATTACHMENT (object)));
return;
case PROP_MIME_PART:
- g_value_set_boxed (
- value, e_attachment_get_mime_part (
+ g_value_set_object (
+ value,
+ e_attachment_get_mime_part (
E_ATTACHMENT (object)));
return;
case PROP_PERCENT:
g_value_set_int (
- value, e_attachment_get_percent (
+ value,
+ e_attachment_get_percent (
E_ATTACHMENT (object)));
return;
case PROP_REFERENCE:
g_value_set_boxed (
- value, e_attachment_get_reference (
+ value,
+ e_attachment_get_reference (
E_ATTACHMENT (object)));
return;
case PROP_SAVING:
g_value_set_boolean (
- value, e_attachment_get_saving (
+ value,
+ e_attachment_get_saving (
E_ATTACHMENT (object)));
return;
case PROP_SIGNED:
g_value_set_int (
- value, e_attachment_get_signed (
+ value,
+ e_attachment_get_signed (
E_ATTACHMENT (object)));
return;
}
@@ -650,30 +667,11 @@ attachment_dispose (GObject *object)
priv = E_ATTACHMENT_GET_PRIVATE (object);
- if (priv->file != NULL) {
- g_object_unref (priv->file);
- priv->file = NULL;
- }
-
- if (priv->icon != NULL) {
- g_object_unref (priv->icon);
- priv->icon = NULL;
- }
-
- if (priv->file_info != NULL) {
- g_object_unref (priv->file_info);
- priv->file_info = NULL;
- }
-
- if (priv->cancellable != NULL) {
- g_object_unref (priv->cancellable);
- priv->cancellable = NULL;
- }
-
- if (priv->mime_part != NULL) {
- g_object_unref (priv->mime_part);
- priv->mime_part = NULL;
- }
+ g_clear_object (&priv->file);
+ g_clear_object (&priv->icon);
+ g_clear_object (&priv->file_info);
+ g_clear_object (&priv->cancellable);
+ g_clear_object (&priv->mime_part);
if (priv->emblem_timeout_id > 0) {
g_source_remove (priv->emblem_timeout_id);
@@ -1198,10 +1196,13 @@ e_attachment_set_file_info (EAttachment *attachment,
/**
* e_attachment_get_mime_type:
+ * @attachment: an #EAttachment
+ *
+ * Returns the MIME type of @attachment according to its #GFileInfo.
+ * If the @attachment has no #GFileInfo then the function returns %NULL.
+ * Free the returned MIME type string with g_free().
*
- * Returns mime_type part of the file_info as a newly allocated string,
- * which should be freed with g_free().
- * Returns NULL, if mime_type not found or set on the attachment.
+ * Returns: a newly-allocated MIME type string, or %NULL
**/
gchar *
e_attachment_get_mime_type (EAttachment *attachment)
@@ -1415,7 +1416,9 @@ e_attachment_is_rfc822 (EAttachment *attachment)
g_return_val_if_fail (E_IS_ATTACHMENT (attachment), FALSE);
mime_type = e_attachment_get_mime_type (attachment);
- is_rfc822 = mime_type && g_ascii_strcasecmp (mime_type, "message/rfc822") == 0;
+ is_rfc822 =
+ (mime_type != NULL) &&
+ (g_ascii_strcasecmp (mime_type, "message/rfc822") == 0);
g_free (mime_type);
return is_rfc822;
@@ -1789,7 +1792,8 @@ attachment_load_from_mime_part_thread (GSimpleAsyncResult *simple,
CamelStream *null;
CamelDataWrapper *dw;
- load_context = g_object_get_data (G_OBJECT (simple), ATTACHMENT_LOAD_CONTEXT);
+ load_context = g_object_get_data (
+ G_OBJECT (simple), ATTACHMENT_LOAD_CONTEXT);
g_return_if_fail (load_context != NULL);
g_object_set_data (G_OBJECT (simple), ATTACHMENT_LOAD_CONTEXT, NULL);
@@ -1849,15 +1853,16 @@ attachment_load_from_mime_part_thread (GSimpleAsyncResult *simple,
} else {
CamelDataWrapper *content;
- content = camel_medium_get_content (CAMEL_MEDIUM (mime_part));
+ content = camel_medium_get_content (
+ CAMEL_MEDIUM (mime_part));
if (CAMEL_IS_MIME_MESSAGE (content))
msg = CAMEL_MIME_MESSAGE (content);
}
- if (msg)
+ if (msg != NULL)
subject = camel_mime_message_get_subject (msg);
- if (subject && *subject)
+ if (subject != NULL && *subject != '\0')
string = subject;
}
} else {
@@ -1883,7 +1888,8 @@ attachment_load_from_mime_part_thread (GSimpleAsyncResult *simple,
dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part));
null = camel_stream_null_new ();
/* this actually downloads the part and makes it available later */
- camel_data_wrapper_decode_to_stream_sync (dw, null, attachment->priv->cancellable, NULL);
+ camel_data_wrapper_decode_to_stream_sync (
+ dw, null, attachment->priv->cancellable, NULL);
g_file_info_set_size (file_info, CAMEL_STREAM_NULL (null)->written);
g_object_unref (null);
@@ -1944,7 +1950,9 @@ e_attachment_load_async (EAttachment *attachment,
attachment_load_query_info_cb, load_context);
} else if (mime_part != NULL) {
- g_object_set_data (G_OBJECT (load_context->simple), ATTACHMENT_LOAD_CONTEXT, load_context);
+ g_object_set_data (
+ G_OBJECT (load_context->simple),
+ ATTACHMENT_LOAD_CONTEXT, load_context);
g_simple_async_result_run_in_thread (
load_context->simple,
@@ -1967,14 +1975,18 @@ e_attachment_load_finish (EAttachment *attachment,
simple = G_SIMPLE_ASYNC_RESULT (result);
load_context = g_simple_async_result_get_op_res_gpointer (simple);
- if (load_context && load_context->mime_part) {
+
+ if (load_context != NULL && load_context->mime_part != NULL) {
const gchar *string;
- string = camel_mime_part_get_disposition (load_context->mime_part);
+ string = camel_mime_part_get_disposition (
+ load_context->mime_part);
e_attachment_set_disposition (attachment, string);
- e_attachment_set_file_info (attachment, load_context->file_info);
- e_attachment_set_mime_part (attachment, load_context->mime_part);
+ e_attachment_set_file_info (
+ attachment, load_context->file_info);
+ e_attachment_set_mime_part (
+ attachment, load_context->mime_part);
}
g_simple_async_result_propagate_error (simple, error);
diff --git a/em-format/e-mail-formatter-attachment.c b/em-format/e-mail-formatter-attachment.c
index 0a100e0987..1003b55eef 100644
--- a/em-format/e-mail-formatter-attachment.c
+++ b/em-format/e-mail-formatter-attachment.c
@@ -209,7 +209,7 @@ emfe_attachment_format (EMailFormatterExtension *extension,
display_name = g_file_info_get_display_name (fi);
description = e_attachment_get_description (attachment);
- if (description && *description) {
+ if (description != NULL && *description != '\0') {
name = g_strdup_printf (
"<h2>Attachment: %s (%s)</h2>\n",
description, display_name);
@@ -219,7 +219,9 @@ emfe_attachment_format (EMailFormatterExtension *extension,
display_name);
}
- camel_stream_write_string (stream, name, cancellable, NULL);
+ camel_stream_write_string (
+ stream, name, cancellable, NULL);
+
g_free (name);
g_object_unref (attachment);
diff --git a/em-format/e-mail-parser.c b/em-format/e-mail-parser.c
index 929662f943..f31e0ca199 100644
--- a/em-format/e-mail-parser.c
+++ b/em-format/e-mail-parser.c
@@ -732,22 +732,22 @@ e_mail_parser_wrap_as_attachment (EMailParser *parser,
NULL);
if (size != 0) {
- GFileInfo *fileinfo;
+ GFileInfo *file_info;
- fileinfo = e_attachment_get_file_info (attachment);
+ file_info = e_attachment_get_file_info (attachment);
- if (!fileinfo) {
- fileinfo = g_file_info_new ();
+ if (file_info == NULL) {
+ file_info = g_file_info_new ();
g_file_info_set_content_type (
- fileinfo, empa->snoop_mime_type);
+ file_info, empa->snoop_mime_type);
} else {
- g_object_ref (fileinfo);
+ g_object_ref (file_info);
}
- g_file_info_set_size (fileinfo, size);
- e_attachment_set_file_info (attachment, fileinfo);
+ g_file_info_set_size (file_info, size);
+ e_attachment_set_file_info (attachment, file_info);
- g_object_unref (fileinfo);
+ g_object_unref (file_info);
}
g_object_unref (attachment);
diff --git a/modules/calendar/e-cal-attachment-handler.c b/modules/calendar/e-cal-attachment-handler.c
index 539a5ba3a4..343d4bad14 100644
--- a/modules/calendar/e-cal-attachment-handler.c
+++ b/modules/calendar/e-cal-attachment-handler.c
@@ -80,7 +80,7 @@ attachment_handler_get_component (EAttachment *attachment)
return NULL;
mime_part = e_attachment_get_mime_part (attachment);
- if (!CAMEL_IS_MIME_PART (mime_part))
+ if (mime_part == NULL)
return NULL;
buffer = g_byte_array_new ();
diff --git a/modules/mail/e-mail-attachment-handler.c b/modules/mail/e-mail-attachment-handler.c
index d6caecf556..d041bc9ad1 100644
--- a/modules/mail/e-mail-attachment-handler.c
+++ b/modules/mail/e-mail-attachment-handler.c
@@ -65,10 +65,13 @@ mail_attachment_handler_get_selected_message (EAttachmentHandler *handler)
EAttachment *attachment;
EAttachmentView *view;
CamelMimePart *mime_part;
- CamelDataWrapper *wrapper;
CamelMimeMessage *message = NULL;
- CamelContentType *content_type;
+ CamelDataWrapper *outer_wrapper;
+ CamelContentType *outer_content_type;
+ CamelDataWrapper *inner_wrapper;
+ CamelContentType *inner_content_type;
GList *selected;
+ gboolean inner_and_outer_content_types_match;
view = e_attachment_handler_get_view (handler);
@@ -77,41 +80,55 @@ mail_attachment_handler_get_selected_message (EAttachmentHandler *handler)
attachment = E_ATTACHMENT (selected->data);
mime_part = e_attachment_get_mime_part (attachment);
- wrapper = camel_medium_get_content (CAMEL_MEDIUM (mime_part));
-
- content_type = camel_data_wrapper_get_mime_type_field (wrapper);
- if (content_type && camel_content_type_is (content_type, "message", "rfc822")) {
- CamelDataWrapper *inner;
- CamelContentType *inner_content_type;
-
- inner = camel_medium_get_content (CAMEL_MEDIUM (wrapper));
- inner_content_type = camel_data_wrapper_get_mime_type_field (inner);
- if (!camel_content_type_is (inner_content_type, content_type->type, content_type->subtype)) {
- CamelStream *mem;
-
- /* Create a message copy in case the inner content-type doesn't match
- * the mime_part's content type, which can happen for multipart/digest,
- * where it confuses the formatter on reply, which skips all rfc822 subparts.
- */
- mem = camel_stream_mem_new ();
- camel_data_wrapper_write_to_stream_sync (CAMEL_DATA_WRAPPER (wrapper), mem, NULL, NULL);
-
- g_seekable_seek (G_SEEKABLE (mem), 0, G_SEEK_SET, NULL, NULL);
- message = camel_mime_message_new ();
- if (!camel_data_wrapper_construct_from_stream_sync (CAMEL_DATA_WRAPPER (message), mem, NULL, NULL)) {
- g_object_unref (message);
- message = NULL;
- }
-
- g_object_unref (mem);
- }
+
+ outer_wrapper =
+ camel_medium_get_content (CAMEL_MEDIUM (mime_part));
+ outer_content_type =
+ camel_data_wrapper_get_mime_type_field (outer_wrapper);
+
+ if (!camel_content_type_is (outer_content_type, "message", "rfc822"))
+ goto exit;
+
+ inner_wrapper =
+ camel_medium_get_content (CAMEL_MEDIUM (outer_wrapper));
+ inner_content_type =
+ camel_data_wrapper_get_mime_type_field (inner_wrapper);
+
+ inner_and_outer_content_types_match =
+ camel_content_type_is (
+ inner_content_type,
+ outer_content_type->type,
+ outer_content_type->subtype);
+
+ if (!inner_and_outer_content_types_match) {
+ CamelStream *mem;
+ gboolean success;
+
+ /* Create a message copy in case the inner content
+ * type doesn't match the mime_part's content type,
+ * which can happen for multipart/digest, where it
+ * confuses the formatter on reply, which skips all
+ * rfc822 subparts. */
+ mem = camel_stream_mem_new ();
+ camel_data_wrapper_write_to_stream_sync (
+ CAMEL_DATA_WRAPPER (outer_wrapper), mem, NULL, NULL);
+
+ g_seekable_seek (
+ G_SEEKABLE (mem), 0, G_SEEK_SET, NULL, NULL);
+ message = camel_mime_message_new ();
+ success = camel_data_wrapper_construct_from_stream_sync (
+ CAMEL_DATA_WRAPPER (message), mem, NULL, NULL);
+ if (!success)
+ g_clear_object (&message);
+
+ g_object_unref (mem);
}
- if (!message)
- message = g_object_ref (wrapper);
+exit:
+ if (message == NULL)
+ message = g_object_ref (outer_wrapper);
- g_list_foreach (selected, (GFunc) g_object_unref, NULL);
- g_list_free (selected);
+ g_list_free_full (selected, (GDestroyNotify) g_object_unref);
return message;
}
@@ -445,7 +462,6 @@ mail_attachment_handler_update_actions (EAttachmentView *view,
{
EAttachment *attachment;
CamelMimePart *mime_part;
- CamelDataWrapper *wrapper;
GtkActionGroup *action_group;
GList *selected;
gboolean visible = FALSE;
@@ -463,12 +479,14 @@ mail_attachment_handler_update_actions (EAttachmentView *view,
mime_part = e_attachment_get_mime_part (attachment);
- if (!CAMEL_IS_MIME_PART (mime_part))
- goto exit;
-
- wrapper = camel_medium_get_content (CAMEL_MEDIUM (mime_part));
+ if (mime_part != NULL) {
+ CamelMedium *medium;
+ CamelDataWrapper *content;
- visible = CAMEL_IS_MIME_MESSAGE (wrapper);
+ medium = CAMEL_MEDIUM (mime_part);
+ content = camel_medium_get_content (medium);
+ visible = CAMEL_IS_MIME_MESSAGE (content);
+ }
exit:
action_group = e_attachment_view_get_action_group (view, "mail");