g_chmod(helper->filepath, 0444);
/* Activate the file */
- modest_platform_activate_file (helper->filepath, tny_mime_part_get_content_type (mime_part));
+ modest_platform_activate_file (helper->filepath, modest_tny_mime_part_get_content_type (mime_part));
free:
/* Frees */
gchar *attachment_uid = NULL;
gint attachment_index = 0;
TnyList *attachments;
+ TnyMimePart *window_msg;
g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window));
g_return_if_fail (TNY_IS_MIME_PART (mime_part) || (mime_part == NULL));
return;
}
- if (!modest_tny_mime_part_is_msg (mime_part)) {
+ /* we also check for mime_part == priv->msg, as this means it's a direct attachment
+ * shown as attachment, so it should behave as a file */
+ window_msg = TNY_MIME_PART (tny_msg_view_get_msg (TNY_MSG_VIEW (priv->msg_view)));
+ if (!modest_tny_mime_part_is_msg (mime_part)||
+ mime_part == window_msg) {
gchar *filepath = NULL;
const gchar *att_filename = tny_mime_part_get_filename (mime_part);
gboolean show_error_banner = FALSE;
const gchar *content_type;
/* the file may already exist but it isn't writable,
* let's try to open it anyway */
- content_type = tny_mime_part_get_content_type (mime_part);
+ content_type = modest_tny_mime_part_get_content_type (mime_part);
modest_platform_activate_file (filepath, content_type);
} else {
g_warning ("%s: modest_utils_create_temp_stream failed", __FUNCTION__);
gtk_widget_show_all (GTK_WIDGET (msg_win));
}
}
+ g_object_unref (window_msg);
g_object_unref (mime_part);
}
gchar *folder = NULL;
gchar *filename = NULL;
gchar *save_multiple_str = NULL;
+ TnyMsg *window_msg;
g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window));
priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (window);
g_object_ref (mime_parts);
}
+ window_msg = tny_msg_view_get_msg (TNY_MSG_VIEW (priv->msg_view));
/* prepare dialog */
if (tny_list_get_length (mime_parts) == 1) {
TnyIterator *iter;
save_multiple_str = g_strdup_printf (_FM("sfil_va_number_of_objects_attachments"),
tny_list_get_length (mime_parts));
}
+ g_object_unref (window_msg);
save_dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window),
GTK_FILE_CHOOSER_ACTION_SAVE);
g_string_free (indent_prefix, TRUE);
}
+gchar *
+modest_tny_mime_part_get_headers_content_type (TnyMimePart *part)
+{
+ gchar *header_content_type;
+ gchar *header_content_type_lower;
+ gchar *suffix;
+
+ g_return_val_if_fail (TNY_IS_MIME_PART (part), NULL);
+
+ header_content_type = modest_tny_mime_part_get_header_value (part, "Content-Type");
+ header_content_type = g_strstrip (header_content_type);
+
+ /* remove the ; suffix */
+ suffix = index (header_content_type, ';');
+ suffix[0] = '\0';
+
+ header_content_type_lower = (header_content_type ) ?
+ g_ascii_strdown (header_content_type, -1) : NULL;
+ return header_content_type_lower;
+}
+
+gchar *
+modest_tny_mime_part_get_content_type (TnyMimePart *part)
+{
+ const gchar *content_type;
+ gchar *retval = NULL;
+
+ g_return_val_if_fail (TNY_IS_MIME_PART (part), NULL);
+ content_type = tny_mime_part_get_content_type (part);
+
+ if (g_str_has_prefix (content_type, "message/rfc822")) {
+ retval = modest_tny_mime_part_get_headers_content_type (part);
+ }
+
+ if (retval == NULL) {
+ retval = g_ascii_strdown (content_type, -1);
+ }
+
+ return retval;
+}
*/
void modest_tny_mime_part_to_string (TnyMimePart *part, gint indent);
+/**
+ * modest_tny_mime_part_get_content_type:
+ * @part: a #TnyMimePart
+ *
+ * obtains the content type in headers
+ */
+gchar *modest_tny_mime_part_get_headers_content_type (TnyMimePart *part);
+
+/**
+ * modest_tny_mime_part_get_content_type:
+ * @part: a #TnyMimePart
+ *
+ * obtains the content type of a mime part, taking into account that,
+ * for messages with type message/rfc822 it has to get it from
+ * the headers
+ */
+gchar *modest_tny_mime_part_get_content_type (TnyMimePart *part);
+
#endif /*__MODEST_TNY_MIME_PART_H__*/
/* no parts? assume it's single-part message */
if (tny_iterator_is_done(iter)) {
gchar *content_type;
- gchar *content_type_lower;
gboolean is_text_part;
g_object_unref (G_OBJECT(iter));
- content_type = g_strdup (tny_mime_part_get_content_type (msg));
+ content_type = modest_tny_mime_part_get_content_type (msg);
if (content_type == NULL)
return NULL;
- content_type = g_strstrip (content_type);
- content_type_lower = g_ascii_strdown (content_type, -1);
- g_free (content_type);
is_text_part =
- g_str_has_prefix (content_type_lower, "text/") ||
- g_str_has_prefix (content_type_lower, "message/rfc822");
- g_free (content_type_lower);
+ g_str_has_prefix (content_type, "text/");
+ g_free (content_type);
/* if this part cannot be a supported body return NULL */
if (!is_text_part) {
return NULL;
while (!tny_iterator_is_done (iter) && !result) {
TnyMimePart *mime_part = TNY_MIME_PART (tny_iterator_get_current (iter));
TnyList *nested_list = tny_simple_list_new ();
+
if (!for_remove && modest_tny_mime_part_is_msg (mime_part)) {
- selected_messages = TRUE;
- result = TRUE;
+ TnyMsg *window_msg;
+ window_msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
+ if ((TnyMimePart *) window_msg != mime_part) {
+ selected_messages = TRUE;
+ result = TRUE;
+ }
+ g_object_unref (window_msg);
}
tny_mime_part_get_parts (mime_part, nested_list);
if (!for_remove && tny_list_get_length (nested_list) > 0) {
#include <modest-attachment-view.h>
#include <modest-platform.h>
#include <modest-text-utils.h>
+#include <modest-tny-mime-part.h>
#include <tny-msg.h>
#include <modest-mail-operation.h>
#include <modest-mail-operation-queue.h>
filename = tny_header_dup_subject (header);
if (filename == NULL || filename[0] == '\0')
filename = g_strdup (_("mail_va_no_subject"));
- if (priv->is_purged)
+ if (priv->is_purged) {
file_icon_name = modest_platform_get_file_icon_name (NULL, NULL, NULL);
- else
- file_icon_name =
- modest_platform_get_file_icon_name (
- NULL, tny_mime_part_get_content_type (mime_part), NULL);
+ } else {
+ gchar *header_content_type;
+ header_content_type = modest_tny_mime_part_get_content_type (mime_part);
+ if ((g_str_has_prefix (header_content_type, "message/rfc822") ||
+ g_str_has_prefix (header_content_type, "multipart/") ||
+ g_str_has_prefix (header_content_type, "text/"))) {
+ file_icon_name =
+ modest_platform_get_file_icon_name (
+ NULL, tny_mime_part_get_content_type (mime_part), NULL);
+ } else {
+ file_icon_name =
+ modest_platform_get_file_icon_name (
+ NULL, header_content_type, NULL);
+ }
+ g_free (header_content_type);
+ }
g_object_unref (header);
}
} else {
file_icon_name = modest_platform_get_file_icon_name (NULL, NULL, NULL);
} else {
file_icon_name = modest_platform_get_file_icon_name (
- filename, tny_mime_part_get_content_type (mime_part), NULL);
+ filename, modest_tny_mime_part_get_content_type (mime_part), NULL);
show_size = TRUE;
}
}
return GTK_WIDGET (self);
}
+
void
modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, TnyMsg *msg)
{
ModestAttachmentsViewPrivate *priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (attachments_view);
TnyList *parts;
TnyIterator *iter;
- const gchar *msg_content_type = NULL;
+ gchar *msg_content_type = NULL;
if (msg == priv->msg) return;
/* If the top mime part is a multipart/related, we don't show the attachments, as they're
* embedded images in body */
- msg_content_type = tny_mime_part_get_content_type (TNY_MIME_PART (priv->msg));
+ msg_content_type = modest_tny_mime_part_get_content_type (TNY_MIME_PART (priv->msg));
if ((msg_content_type != NULL) && !strcasecmp (msg_content_type, "multipart/related")) {
gchar *header_content_type;
- gchar *header_content_type_lower;
gboolean application_multipart = FALSE;
- header_content_type = modest_tny_mime_part_get_header_value (TNY_MIME_PART (priv->msg), "Content-Type");
- header_content_type = g_strstrip (header_content_type);
- header_content_type_lower = (header_content_type ) ?
- g_ascii_strdown (header_content_type, -1) : NULL;
+
+ g_free (msg_content_type);
+
+ header_content_type = modest_tny_mime_part_get_headers_content_type (TNY_MIME_PART (priv->msg));
- if ((header_content_type_lower != NULL) &&
- !strstr (header_content_type_lower, "application/")) {
+ if ((header_content_type != NULL) &&
+ !strstr (header_content_type, "application/")) {
application_multipart = TRUE;
- g_free (header_content_type_lower);
}
g_free (header_content_type);
return;
}
} else {
- gchar *lower;
gboolean direct_attach;
- lower = g_ascii_strdown (msg_content_type, -1);
- direct_attach = (!g_str_has_prefix (lower, "message/rfc822") &&
- !g_str_has_prefix (lower, "multipart") &&
- !g_str_has_prefix (lower, "text/"));
- g_free (lower);
+ direct_attach = (!g_str_has_prefix (msg_content_type, "message/rfc822") &&
+ !g_str_has_prefix (msg_content_type, "multipart") &&
+ !g_str_has_prefix (msg_content_type, "text/"));
+
+ g_free (msg_content_type);
+
if (direct_attach) {
modest_attachments_view_add_attachment (attachments_view, TNY_MIME_PART (msg), TRUE, 0);
gtk_widget_queue_draw (GTK_WIDGET (attachments_view));