#include <modest-tny-account.h>
#include <modest-mime-part-view.h>
#include <modest-isearch-view.h>
+#include <modest-tny-mime-part.h>
#include <math.h>
#include <errno.h>
#include <glib/gstdio.h>
+#include <modest-debug.h>
#define DEFAULT_FOLDER "MyDocs/.documents"
ModestWindow *main_window = NULL;
ModestWindowMgr *mgr = NULL;
+ MODEST_DEBUG_BLOCK (
+ modest_tny_mime_part_to_string (TNY_MIME_PART (msg), 0);
+ );
+
mgr = modest_runtime_get_window_mgr ();
window = MODEST_MSG_VIEW_WINDOW (modest_window_mgr_get_msg_view_window (mgr));
g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window), NULL);
return;
}
- if (!TNY_IS_MSG (mime_part)) {
+ if (!modest_tny_mime_part_is_msg (mime_part)) {
gchar *filepath = NULL;
const gchar *att_filename = tny_mime_part_get_filename (mime_part);
const gchar *content_type;
iter = tny_list_create_iterator (mime_parts);
TnyMimePart *mime_part = (TnyMimePart *) tny_iterator_get_current (iter);
g_object_unref (iter);
- if (!TNY_IS_MSG (mime_part) && tny_mime_part_is_attachment (mime_part)) {
+ if (!modest_tny_mime_part_is_msg (mime_part) && tny_mime_part_is_attachment (mime_part)) {
filename = tny_mime_part_get_filename (mime_part);
} else {
g_warning ("Tried to save a non-file attachment");
iter = tny_list_create_iterator (mime_parts);
part = (TnyMimePart *) tny_iterator_get_current (iter);
g_object_unref (iter);
- if (TNY_IS_MSG (part)) {
+ if (modest_tny_mime_part_is_msg (part)) {
TnyHeader *header;
header = tny_msg_get_header (TNY_MSG (part));
filename = tny_header_get_subject (header);
construct_from_text (body_part, "", priv->content_type);
g_object_unref (body_part);
- /* Add parts */
- tny_mime_part_add_part (TNY_MIME_PART (new_msg), TNY_MIME_PART (msg));
+ if (msg) {
+ /* Add parts */
+ tny_mime_part_add_part (TNY_MIME_PART (new_msg), TNY_MIME_PART (msg));
+ }
return new_msg;
}
return TRUE;
}
+gboolean
+modest_tny_mime_part_is_msg (TnyMimePart *part)
+{
+ const gchar *content_type;
+
+ if (!TNY_IS_MSG (part))
+ return FALSE;
+
+ content_type = tny_mime_part_get_content_type (part);
+ if ((g_str_has_prefix (content_type, "message/rfc822") ||
+ g_str_has_prefix (content_type, "multipart/") ||
+ g_str_has_prefix (content_type, "text/"))) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+void
+modest_tny_mime_part_to_string (TnyMimePart *part, gint indent)
+{
+ return;
+ gint i;
+ GString *indent_prefix;
+ TnyList *list, *pairs_list;
+ TnyIterator *iter, *pairs_iter;
+
+ indent_prefix = g_string_new ("");
+ for (i = 0; i < indent; i++) {
+ indent_prefix = g_string_append_c (indent_prefix, ' ');
+ }
+
+ if (TNY_IS_MSG (part)) {
+ TnyHeader *header;
+
+ header = tny_msg_get_header (TNY_MSG (part));
+ g_print ("(%s(MSG))\n", indent_prefix->str);
+ g_object_unref (header);
+ }
+
+ list = tny_simple_list_new ();
+ tny_mime_part_get_parts (part, list);
+ pairs_list = tny_simple_list_new ();
+ tny_mime_part_get_header_pairs (part, pairs_list);
+ g_print ("%s(content=%s parts=%d location=%s)\n", indent_prefix->str,
+ tny_mime_part_get_content_type (part),
+ tny_list_get_length (list),
+ tny_mime_part_get_content_location (part));
+ for (pairs_iter = tny_list_create_iterator (pairs_list);
+ !tny_iterator_is_done (pairs_iter);
+ tny_iterator_next (pairs_iter)) {
+ TnyPair *pair = TNY_PAIR (tny_iterator_get_current (pairs_iter));
+ g_print ("%s(%s:%s)\n", indent_prefix->str, tny_pair_get_name (pair), tny_pair_get_value (pair));
+ g_object_unref (pair);
+ }
+ for (iter = tny_list_create_iterator (list);
+ !tny_iterator_is_done (iter);
+ tny_iterator_next (iter)) {
+ TnyMimePart *child;
+ child = (TnyMimePart *) tny_iterator_get_current (iter);
+ modest_tny_mime_part_to_string (child, indent + 3);
+ g_object_unref (child);
+ }
+ g_object_unref (iter);
+ g_object_unref (list);
+
+ g_string_free (indent_prefix, TRUE);
+}
gboolean modest_tny_mime_part_is_attachment_for_modest (TnyMimePart *part);
+/**
+ * modest_tny_mime_part_is_msg:
+ * @part: a #TnyMimePart
+ *
+ * determines if this is a message (it's a TnyMsg and it's not a
+ * file attached as the top mime part of the TnyMsg).
+ *
+ * Returns: %TRUE if it's a real message, %FALSE otherwise
+ */
+gboolean modest_tny_mime_part_is_msg (TnyMimePart *part);
+
+/**
+ * modest_tny_mime_part_to_string:
+ * @part: a #TnyMimePart
+ * @indent: indent level (should be 0)
+ *
+ * Shows in stdout a text representation of the mime structure of
+ * the message. This is intended for debugging.
+ */
+void modest_tny_mime_part_to_string (TnyMimePart *part, gint indent);
+
#endif /*__MODEST_TNY_MIME_PART_H__*/
TnyMimePart *part = NULL;
TnyList *parts = NULL;
TnyIterator *iter = NULL;
+ gchar *header_content_type;
+ gchar *header_content_type_lower;
if (!msg)
return NULL;
+ /* If it's an application multipart, then we don't get into as we don't
+ * support them (for example application/sml or wap messages */
+ header_content_type = modest_tny_mime_part_get_header_value (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;
+ if (header_content_type_lower &&
+ g_str_has_prefix (header_content_type_lower, "multipart/") &&
+ strstr (header_content_type_lower, "application/")) {
+ g_free (header_content_type_lower);
+ g_free (header_content_type);
+ return NULL;
+ }
+ g_free (header_content_type_lower);
+ g_free (header_content_type);
+
parts = TNY_LIST (tny_simple_list_new());
tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
/* no parts? assume it's single-part message */
if (tny_iterator_is_done(iter)) {
+ const gchar *content_type;
g_object_unref (G_OBJECT(iter));
- return TNY_MIME_PART (g_object_ref(G_OBJECT(msg)));
+ content_type = tny_mime_part_get_content_type (msg);
+ /* if this part cannot be a supported body return NULL */
+ if (!g_str_has_prefix (content_type, "text/")) {
+ return NULL;
+ } else {
+ return TNY_MIME_PART (g_object_ref(G_OBJECT(msg)));
+ }
} else {
do {
gchar *tmp, *content_type = NULL;
else {
/* for attachements; inline if there is a text part, and include the
* full old mail if there was none */
- if (no_text_part)
+ if (no_text_part) {
new_msg = modest_formatter_attach (formatter, msg, header);
- else
+ } else {
new_msg = modest_formatter_inline (formatter, body, header,
attachments);
+ }
}
g_object_unref (G_OBJECT(formatter));
g_object_unref (G_OBJECT (header));
/* ugly to unref it here instead of in the calling func */
+ if (!is_reply & !no_text_part) {
+ add_attachments (TNY_MIME_PART (new_msg), attachments, FALSE);
+ }
+
return new_msg;
}
new_msg = create_reply_forward_mail (msg, NULL, from, signature, FALSE, forward_type,
attachments_list);
- add_attachments (TNY_MIME_PART (new_msg), attachments_list, FALSE);
/* Clean */
if (attachments_list) {
* embedded images in body */
msg_content_type = tny_mime_part_get_content_type (TNY_MIME_PART (priv->msg));
if ((msg_content_type != NULL) && !strcasecmp (msg_content_type, "multipart/related")) {
- gtk_widget_queue_draw (GTK_WIDGET (attachments_view));
- return;
+ 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;
+
+ if (!strstr (header_content_type_lower, "application/"))
+ application_multipart = TRUE;
+
+ g_free (header_content_type);
+ g_free (header_content_type_lower);
+ if (application_multipart) {
+ gtk_widget_queue_draw (GTK_WIDGET (attachments_view));
+ 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);
+ if (direct_attach) {
+ modest_attachments_view_add_attachment (attachments_view, TNY_MIME_PART (msg), TRUE, 0);
+ gtk_widget_queue_draw (GTK_WIDGET (attachments_view));
+ return;
+ }
}
parts = TNY_LIST (tny_simple_list_new ());