static void on_sendreceive_button_clicked (GtkWidget *widget, gpointer user_data);
+static void on_forward_attached_activated (GtkWidget *widget, gpointer user_data);
+
static void register_toolbar_callbacks (ModestUI *modest_ui);
GtkWidget *folder_view, *header_view;
GtkWidget *message_view;
GtkWidget *account_settings_item;
+ GtkWidget *forward_attached_menu_item;
GtkWidget *delete_item;
GtkWidget *open_item;
GtkWidget *view_attachments_item;
return FALSE;
}
+ forward_attached_menu_item = glade_xml_get_widget (priv->glade_xml, "forward_attached");
+ if (!forward_attached_menu_item) {
+ g_warning ("The forward_attached_menu_item isn't available!");
+ return FALSE;
+ }
+ g_signal_connect (forward_attached_menu_item, "activate", G_CALLBACK(on_forward_attached_activated),
+ modest_ui);
+
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(view_attachments_item),
modest_conf_get_bool(priv->modest_conf,
MODEST_CONF_MSG_VIEW_SHOW_ATTACHMENTS_INLINE,
}
// g_object_unref (store_actions);
}
+static void
+on_forward_attached_activated (GtkWidget *widget, gpointer user_data)
+{
+ ModestUI *modest_ui = (ModestUI *)user_data;
+
+ quoted_send_msg (modest_ui, QUOTED_SEND_FORWARD_ATTACHED);
+}
static void
new_editor_with_presets (ModestUI *modest_ui, const gchar *to_header,
const gchar *cc_header, const gchar *bcc_header,
- const gchar *subject_header, const gchar *body)
+ const gchar *subject_header, const gchar *body,
+ const GList *attachments)
{
GtkWidget *edit_win;
GladeXML *glade_xml;
modest_editor_window_set_bcc_header(MODEST_EDITOR_WINDOW(edit_win), bcc_header);
modest_editor_window_set_subject_header(MODEST_EDITOR_WINDOW(edit_win), subject_header);
modest_editor_window_set_body(MODEST_EDITOR_WINDOW(edit_win), body);
+ modest_editor_window_set_attachments(MODEST_EDITOR_WINDOW(edit_win), attachments);
modest_editor_window_set_modified(MODEST_EDITOR_WINDOW(edit_win), FALSE);
{
ModestUI *modest_ui = (ModestUI *) modest_ui;
- new_editor_with_presets(modest_ui, "", "", "", "", "");
+ new_editor_with_presets(modest_ui, "", "", "", "", "", NULL);
}
gchar *unquoted, *quoted;
time_t sent_date;
gint line_limit = 76;
+
+ GList *attachments = NULL;
g_return_if_fail (modest_ui);
switch (qstype) {
case QUOTED_SEND_REPLY:
g_string_prepend(re_sub, _("Re: "));
- new_editor_with_presets(modest_ui, from, /* cc */ "", /* bcc */ "", re_sub->str, quoted);
+ new_editor_with_presets(modest_ui, from, /* cc */ "", /* bcc */ "", re_sub->str, quoted, attachments);
break;
case QUOTED_SEND_FORWARD:
+ attachments = modest_tny_attachment_new_list_from_msg(msg, FALSE);
+ g_string_prepend(re_sub, _("Fwd: "));
+ new_editor_with_presets(modest_ui, /* from */ "", /* cc */ "", /* bcc */ "", re_sub->str, quoted, attachments);
+ break;
+ case QUOTED_SEND_FORWARD_ATTACHED:
+ attachments = modest_tny_attachment_new_list_from_msg(msg, TRUE);
g_string_prepend(re_sub, _("Fwd: "));
- new_editor_with_presets(modest_ui, /* from */ "", /* cc */ "", /* bcc */ "", re_sub->str, quoted);
+ new_editor_with_presets(modest_ui, /* from */ "", /* cc */ "", /* bcc */ "", re_sub->str, "", attachments);
break;
default:
break;
MODEST_IDENTITY_DEFAULT_IDENTITY,
MODEST_IDENTITY_EMAIL, NULL);
attachments = modest_editor_window_get_attachments(modest_editwin);
- /* while (attachments) {
- printf("att: %s\n", (gchar *) attachments->data);
- attachments = attachments->next;
- } */
if (!email_from)
email_from = "";
body,
attachments);
+ modest_tny_attachment_free_list(attachments);
g_free (body);
g_object_unref (G_OBJECT(actions));
typedef enum {
QUOTED_SEND_REPLY,
QUOTED_SEND_REPLY_ALL,
- QUOTED_SEND_FORWARD
+ QUOTED_SEND_FORWARD,
+ QUOTED_SEND_FORWARD_ATTACHED
} quoted_send_type;
/**
return modest_ui_editor_window_update_attachments(priv->user_data);
}
-GList * modest_editor_window_set_attachments(ModestEditorWindow *edit_win, GList* attachments)
+GList * modest_editor_window_set_attachments(ModestEditorWindow *edit_win, const GList* attachments)
{
ModestEditorWindowPrivate *priv;
+ GList *pos;
g_return_val_if_fail(edit_win, NULL);
priv = MODEST_EDITOR_WINDOW_GET_PRIVATE(edit_win);
- priv->attachments = attachments;
+ modest_tny_attachment_free_list(priv->attachments);
+ priv->attachments = g_list_copy((GList *)attachments);
+ for (pos = priv->attachments ; pos ; pos = pos->next )
+ g_object_ref(pos->data);
return priv->attachments;
}
* @edit_win: a ModestEditorWindow instance
* @attachments: a list of attachments
*
- * Sets the list of attachments to *attachments
+ * Frees the current attachments, then sets the list of attachments to *attachments
*
* Returns: The new GList* of attachments.
*/
-GList * modest_editor_window_set_attachments(ModestEditorWindow *edit_win, GList* attachments);
+GList * modest_editor_window_set_attachments(ModestEditorWindow *edit_win, const GList* attachments);
/**
* modest_editor_window_get_attachments:
/* insert (c)/licensing information) */
#include "modest-tny-attachment.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
+#include "modest-tny-msg-actions.h"
+
#include <tny-stream-camel.h>
#include <tny-fs-stream.h>
#include <camel/camel.h>
g_free(priv->mime_type);
g_free(priv->disposition);
g_free(priv->content_id);
- g_object_unref(G_OBJECT(priv->stream));
+ if (priv->stream)
+ g_object_unref(G_OBJECT(priv->stream));
}
ModestTnyAttachment *
ModestTnyAttachmentPrivate *priv;
priv = MODEST_TNY_ATTACHMENT_GET_PRIVATE(self);
+ if (!priv->name)
+ if (priv->filename)
+ priv->name = g_path_get_basename(priv->filename);
return priv->name;
}
g_free(priv->mime_type);
if (suffixes[pos])
- priv->mime_type = types[pos];
+ priv->mime_type = g_strdup(types[pos]);
else
priv->mime_type = NULL;
}
return TNY_STREAM_IFACE(tny_stream_camel_new(camel_stream_fs_new_with_fd(file)));
}
+void
+modest_tny_attachment_set_stream(ModestTnyAttachment *self, TnyStreamIface *thing)
+{
+ ModestTnyAttachmentPrivate *priv;
+
+ priv = MODEST_TNY_ATTACHMENT_GET_PRIVATE(self);
+ if (priv->stream)
+ g_object_unref(G_OBJECT(priv->stream));
+ priv->stream = thing;
+}
+
TnyStreamIface *
modest_tny_attachment_get_stream (ModestTnyAttachment *self)
{
priv->stream = make_stream_from_file(priv->filename);
return priv->stream;
}
+
+
+void
+modest_tny_attachment_free_list(GList *list)
+{
+ GList *pos;
+
+ for (pos = list; pos; pos = pos->next)
+ if (pos->data)
+ g_object_unref(pos->data);
+ g_list_free(list);
+ return;
+}
+
+
+ModestTnyAttachment *
+modest_tny_attachment_new_from_mime_part(TnyMsgMimePartIface *part)
+{
+ TnyStreamIface *mem_stream;
+ ModestTnyAttachment *self;
+
+ mem_stream = TNY_STREAM_IFACE(tny_stream_camel_new(camel_stream_mem_new()));
+ self = modest_tny_attachment_new();
+ tny_msg_mime_part_iface_decode_to_stream(part, mem_stream);
+ tny_stream_iface_reset(mem_stream);
+ modest_tny_attachment_set_stream(self, mem_stream);
+ modest_tny_attachment_set_mime_type(self,
+ tny_msg_mime_part_iface_get_content_type(part));
+ modest_tny_attachment_set_name(self,
+ tny_msg_mime_part_iface_get_filename(part));
+ return self;
+}
+
+
+GList *
+modest_tny_attachment_new_list_from_msg(const TnyMsgIface *msg, gboolean with_body)
+{
+ GList *list = NULL;
+ const GList *attachments;
+ TnyMsgMimePartIface *part;
+ ModestTnyAttachment *att;
+
+ if (with_body) {
+ /* TODO: make plain over html configurable */
+ part = modest_tny_msg_actions_find_body_part ((TnyMsgIface *)msg, "text/plain");
+ if (!part)
+ part = modest_tny_msg_actions_find_body_part ((TnyMsgIface *)msg, "text/html");
+ if (part) {
+ att = modest_tny_attachment_new_from_mime_part(part);
+ /* TODO: i18n */
+ modest_tny_attachment_set_name(att, "original message");
+ list = g_list_append(list, att);
+ }
+ }
+ attachments = tny_msg_iface_get_parts((TnyMsgIface *)msg);
+ while (attachments) {
+ part = attachments->data;
+ if (tny_msg_mime_part_iface_is_attachment(part)) {
+ att = modest_tny_attachment_new_from_mime_part(part);
+ list = g_list_append(list, att);
+ }
+ attachments = attachments->next;
+ }
+ return list;
+}
#include <glib-object.h>
#include <tny-stream-iface.h>
+#include <tny-msg-iface.h>
+#include <tny-msg-mime-part-iface.h>
/* other include files */
G_BEGIN_DECLS
TnyStreamIface * modest_tny_attachment_get_stream (ModestTnyAttachment *self);
+void modest_tny_attachment_free_list(GList *list);
+
+GList *modest_tny_attachment_new_list_from_msg(const TnyMsgIface *msg, gboolean with_body);
+
G_END_DECLS
#endif /* __MODEST_TNY_ATTACHMENT_H__ */
GList *pos;
gchar *content_type;
const gchar *attachment_content_type;
- gchar *attachment_filename;
+ const gchar *attachment_filename;
new_msg = TNY_MSG_IFACE(tny_msg_new ());
headers = TNY_MSG_HEADER_IFACE(tny_msg_header_new ());
}
for ( pos = (GList *)attachments_list;
- pos;
+ pos;
pos = pos->next ) {
attachment = pos->data;
- attachment_filename = g_path_get_basename(
- modest_tny_attachment_get_filename(attachment));
+ attachment_filename = modest_tny_attachment_get_name(attachment);
attachment_stream = modest_tny_attachment_get_stream(attachment);
attachment_part = TNY_MSG_MIME_PART_IFACE (tny_msg_mime_part_new (
camel_mime_part_new()));
attachment_content_type = modest_tny_attachment_get_mime_type(attachment);
+
tny_msg_mime_part_iface_construct_from_stream (attachment_part,
attachment_stream,
attachment_content_type);
tny_msg_mime_part_iface_set_filename(attachment_part, attachment_filename);
tny_msg_iface_add_part (new_msg, attachment_part);
- g_object_unref(G_OBJECT(attachment_stream));
//g_object_unref(G_OBJECT(attachment_part));
- g_free(attachment_filename);
//close(file);
}