* all:
[modest] / src / gtk / modest-edit-msg-window.c
index d09f149..5707116 100644 (file)
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
+#include <glib/gi18n.h>
+#include <tny-account-store.h>
 #include "modest-edit-msg-window.h"
-#include <widgets/modest-msg-view.h>
-#include <modest-widget-memory.h>
-#include <modest-widget-factory.h>
+#include "modest-edit-msg-window-ui.h"
 #include "modest-icon-names.h"
-#include <modest-tny-transport-actions.h>
+#include "modest-icon-factory.h"
+#include "modest-widget-memory.h"
+#include "modest-mail-operation.h"
+#include "modest-tny-platform-factory.h"
+#include "modest-tny-msg-actions.h"
+#include <tny-simple-list.h>
+#include "modest-ui-actions.h"
 
 static void  modest_edit_msg_window_class_init   (ModestEditMsgWindowClass *klass);
 static void  modest_edit_msg_window_init         (ModestEditMsgWindow *obj);
@@ -48,14 +53,17 @@ enum {
 typedef struct _ModestEditMsgWindowPrivate ModestEditMsgWindowPrivate;
 struct _ModestEditMsgWindowPrivate {
 
-       ModestConf *conf;
-       ModestWidgetFactory *factory;
+       ModestWidgetFactory *widget_factory;
+       TnyPlatformFactory *fact;
+       TnyAccountStore *account_store;
+       GtkUIManager *ui_manager;
        
        GtkWidget      *toolbar, *menubar;
        GtkWidget      *msg_body;
-       GtkWidget      *to_field, *cc_field, *bcc_field,
+       GtkWidget      *from_field, *to_field, *cc_field, *bcc_field,
                       *subject_field;
 };
+
 #define MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                     MODEST_TYPE_EDIT_MSG_WINDOW, \
                                                     ModestEditMsgWindowPrivate))
@@ -114,7 +122,8 @@ modest_edit_msg_window_init (ModestEditMsgWindow *obj)
        ModestEditMsgWindowPrivate *priv;
        priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(obj);
 
-       priv->factory = NULL;
+       priv->fact = modest_tny_platform_factory_get_instance ();
+       priv->widget_factory = NULL;
        priv->toolbar = NULL;
        priv->menubar = NULL;
 }
@@ -125,201 +134,33 @@ static void
 save_settings (ModestEditMsgWindow *self)
 {
        ModestEditMsgWindowPrivate *priv;
-       priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(self);
-       modest_widget_memory_save_settings (priv->conf,
-                                           GTK_WIDGET(self),
-                                           "modest-edit-msg-window");
-}
-
-
-static void
-restore_settings (ModestEditMsgWindow *self)
-{
-       ModestEditMsgWindowPrivate *priv;
-       priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(self);
-       modest_widget_memory_restore_settings (priv->conf, GTK_WIDGET(self),
-                                              "modest-edit-msg-window");
-}
-
-       
-
-static void
-on_menu_quit (ModestEditMsgWindow *self, guint action, GtkWidget *widget)
-{
-       save_settings (self);
-       gtk_widget_destroy (GTK_WIDGET(self));
-}
-
-
-
-
-
-/* Our menu, an array of GtkItemFactoryEntry structures that defines each menu item */
-static GtkItemFactoryEntry menu_items[] = {
-       { "/_File",             NULL,                   NULL,           0, "<Branch>" },
-       { "/File/_New",         "<control>N",           NULL,           0, "<StockItem>", GTK_STOCK_NEW },
-       { "/File/_Open",        "<control>O",           NULL,           0, "<StockItem>", GTK_STOCK_OPEN },
-       { "/File/_Save",        "<control>S",           NULL,           0, "<StockItem>", GTK_STOCK_SAVE },
-       { "/File/Save _As",     NULL,                   NULL,           0, "<Item>" },
-       { "/File/Save Draft",   "<control><shift>S",    NULL,           0, "<Item>" },
-
-
-       { "/File/sep1",         NULL,                   NULL,           0, "<Separator>" },
-       { "/File/_Quit",        "<CTRL>Q",              on_menu_quit,   0, "<StockItem>", GTK_STOCK_QUIT },
-
-       { "/_Edit",             NULL,                   NULL,           0, "<Branch>" },
-       { "/Edit/_Undo",        "<CTRL>Z",              NULL,           0, "<StockItem>", GTK_STOCK_UNDO },
-       { "/Edit/_Redo",        "<shift><CTRL>Z",       NULL,           0, "<StockItem>", GTK_STOCK_REDO },
-       { "/File/sep1",         NULL,                   NULL,           0, "<Separator>" },
-       { "/Edit/Cut",          "<control>X",           NULL,           0, "<StockItem>", GTK_STOCK_CUT  },
-       { "/Edit/Copy",         "<CTRL>C",              NULL,           0, "<StockItem>", GTK_STOCK_COPY },
-       { "/Edit/Paste",        NULL,                   NULL,           0, "<StockItem>", GTK_STOCK_PASTE},
-       { "/Edit/sep1",         NULL,                   NULL,           0, "<Separator>" },
-       { "/Edit/Delete",       "<CTRL>Q",              NULL,           0, "<Item>" },
-       { "/Edit/Select all",   "<CTRL>A",              NULL,           0, "<Item>" },
-       { "/Edit/Deselect all",  "<Shift><CTRL>A",      NULL,           0, "<Item>" },
-
-       { "/_View",             NULL,           NULL,           0, "<Branch>" },
-       { "/View/To-field",          NULL,              NULL,           0, "<CheckItem>" },
-       
-       { "/View/Cc-field:",          NULL,             NULL,           0, "<CheckItem>" },
-       { "/View/Bcc-field:",          NULL,            NULL,           0, "<CheckItem>" },
-       
-       
-       { "/_Insert",             NULL,         NULL,           0, "<Branch>" },
-/*     { "/Actions/_Reply",    NULL,                   NULL,           0, "<Item>" }, */
-/*     { "/Actions/_Forward",  NULL,                   NULL,           0, "<Item>" }, */
-/*     { "/Actions/_Bounce",   NULL,                   NULL,           0, "<Item>" },   */
-       
-       { "/_Format",            NULL,                  NULL,           0, "<Branch>" }
-/*     { "/Options/_Accounts",  NULL,                  on_menu_accounts,0, "<Item>" }, */
-/*     { "/Options/_Contacts",  NULL,                  NULL,           0, "<Item>" }, */
-
-
-/*     { "/_Help",         NULL,                       NULL,           0, "<Branch>" }, */
-/*     { "/_Help/About",   NULL,                       on_menu_about,  0, "<StockItem>", GTK_STOCK_ABOUT}, */
-};
-
-static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
-
-
-static GtkWidget *
-menubar_new (ModestEditMsgWindow *self)
-{
-       GtkItemFactory *item_factory;
-       GtkAccelGroup *accel_group;
-       
-       /* Make an accelerator group (shortcut keys) */
-       accel_group = gtk_accel_group_new ();
-       
-       /* Make an ItemFactory (that makes a menubar) */
-       item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>",
-                                            accel_group);
-       
-       /* This function generates the menu items. Pass the item factory,
-          the number of items in the array, the array itself, and any
-          callback data for the the menu items. */
-       gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, self);
-       
-       ///* Attach the new accelerator group to the window. */
-       gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
-       
-       /* Finally, return the actual menu bar created by the item factory. */
-       return gtk_item_factory_get_widget (item_factory, "<main>");
-}
-
-
-static void
-send_mail (ModestEditMsgWindow *self)
-{
-       const gchar *from, *to, *cc, *bcc, *subject;
-       gchar *body;
-       ModestEditMsgWindowPrivate *priv;
+       ModestConf *conf;
 
-       GtkTextBuffer *buf;
-       GtkTextIter b, e;
-       
        priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(self);
+       conf = modest_tny_platform_factory_get_conf_instance
+               (MODEST_TNY_PLATFORM_FACTORY(priv->fact));
 
-       /* don't free these */
-       from = "djcb@djcbsoftware.nl";
-       to   =  gtk_entry_get_text (GTK_ENTRY(priv->to_field));
-       cc   =  gtk_entry_get_text (GTK_ENTRY(priv->cc_field));
-       bcc  =  gtk_entry_get_text (GTK_ENTRY(priv->bcc_field));
-       to   =  gtk_entry_get_text (GTK_ENTRY(priv->subject_field));
-
-       /* don't unref */
-       buf   =  gtk_text_view_get_buffer (GTK_TEXT_VIEW(priv->msg_body));
-       
-       gtk_text_buffer_get_bounds (buf, &b, &e);
-       body  = gtk_text_buffer_get_text (buf, &b, &e,
-                                         FALSE); /* free this one */
-
-//     modest_tny_transport_actions_send_message (transport_account,
-//                                                from, to, cc, bcc,
-//                                                subject, *body, NULL);
-       g_free (body);
+       modest_widget_memory_save (conf, G_OBJECT(self), "modest-edit-msg-window");
 }
 
 
 static void
-on_toolbar_button_clicked (ModestToolbar *toolbar, ModestToolbarButton button_id,
-                          ModestEditMsgWindow *self)
-{
-       switch (button_id) {
-       case MODEST_TOOLBAR_BUTTON_MAIL_SEND:
-               send_mail (self);
-               save_settings (self);
-               gtk_widget_destroy (GTK_WIDGET(self));
-               break;
-               
-       case MODEST_TOOLBAR_BUTTON_REPLY:
-       case MODEST_TOOLBAR_BUTTON_REPLY_ALL:
-       case MODEST_TOOLBAR_BUTTON_FORWARD:
-       case MODEST_TOOLBAR_BUTTON_SEND_RECEIVE:
-       case MODEST_TOOLBAR_BUTTON_NEXT:
-       case MODEST_TOOLBAR_BUTTON_PREV:
-       case MODEST_TOOLBAR_BUTTON_DELETE:
-
-       default:
-               g_printerr ("modest: key %d pressed\n", button_id);
-       }
-}
-
-
-
-
-static ModestToolbar*
-toolbar_new (ModestEditMsgWindow *self)
+restore_settings (ModestEditMsgWindow *self)
 {
-       int i;
-       ModestToolbar *toolbar;
-       GSList *buttons = NULL;
        ModestEditMsgWindowPrivate *priv;
+       ModestConf *conf;
 
-       ModestToolbarButton button_ids[] = {
-               MODEST_TOOLBAR_BUTTON_MAIL_SEND
-       };              
-       
        priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(self);
-
-       for (i = 0 ; i != sizeof(button_ids) / sizeof(ModestToolbarButton); ++i)
-               buttons = g_slist_append (buttons, GINT_TO_POINTER(button_ids[i]));
-       
-       toolbar = modest_widget_factory_get_edit_toolbar (priv->factory, buttons);
-       g_slist_free (buttons);
-
-       g_signal_connect (G_OBJECT(toolbar), "button_clicked",
-                         G_CALLBACK(on_toolbar_button_clicked), self);
-       
-       return toolbar;
+       conf = modest_tny_platform_factory_get_conf_instance
+               (MODEST_TNY_PLATFORM_FACTORY(priv->fact));
+       modest_widget_memory_restore (conf, G_OBJECT(self), "modest-edit-msg-window");
 }
 
 
 static void
 init_window (ModestEditMsgWindow *obj)
 {
-       GtkWidget *to_button, *cc_button, *bcc_button, *subject_label; 
+       GtkWidget *to_button, *cc_button, *bcc_button; 
        GtkWidget *header_table;
        GtkWidget *main_vbox;
        
@@ -329,35 +170,34 @@ init_window (ModestEditMsgWindow *obj)
        to_button     = gtk_button_new_with_label (_("To..."));
        cc_button     = gtk_button_new_with_label (_("Cc..."));
        bcc_button    = gtk_button_new_with_label (_("Bcc..."));
-       subject_label = gtk_label_new (_("Subject:"));
+
+       priv->from_field    = modest_widget_factory_get_combo_box (priv->widget_factory,
+                                                                  MODEST_COMBO_BOX_TYPE_TRANSPORTS);
+       priv->to_field      = gtk_entry_new_with_max_length (80);
+       priv->cc_field      = gtk_entry_new_with_max_length (80);
+       priv->bcc_field     = gtk_entry_new_with_max_length (80);
+       priv->subject_field = gtk_entry_new_with_max_length (80);
+       
+       header_table = gtk_table_new (5,2, FALSE);
        
-       priv->to_field      = gtk_entry_new_with_max_length (40);
-       priv->cc_field      = gtk_entry_new_with_max_length (40);
-       priv->bcc_field     = gtk_entry_new_with_max_length (40);
-       priv->subject_field = gtk_entry_new_with_max_length (40);
-
-       header_table = gtk_table_new (4,2, FALSE);
-       gtk_table_attach (GTK_TABLE(header_table), to_button,     0,1,0,1,
-                         GTK_SHRINK, 0, 0, 0);
-       gtk_table_attach (GTK_TABLE(header_table), cc_button,     0,1,1,2,
-                         GTK_SHRINK, 0, 0, 0);
-       gtk_table_attach (GTK_TABLE(header_table), bcc_button,    0,1,2,3,
-                         GTK_SHRINK, 0, 0, 0);
-       gtk_table_attach (GTK_TABLE(header_table), subject_label, 0,1,3,4,
-                         GTK_SHRINK, 0, 0, 0);
-       gtk_table_attach_defaults (GTK_TABLE(header_table), priv->to_field,     1,2,0,1);
-       gtk_table_attach_defaults (GTK_TABLE(header_table), priv->cc_field,     1,2,1,2);
-       gtk_table_attach_defaults (GTK_TABLE(header_table), priv->bcc_field,    1,2,2,3);
-       gtk_table_attach_defaults (GTK_TABLE(header_table), priv->subject_field,1,2,3,4);
+       gtk_table_attach (GTK_TABLE(header_table), gtk_label_new (_("From:")),
+                         0,1,0,1, GTK_SHRINK, 0, 0, 0);
+       gtk_table_attach (GTK_TABLE(header_table), to_button,     0,1,1,2, GTK_SHRINK, 0, 0, 0);
+       gtk_table_attach (GTK_TABLE(header_table), cc_button,     0,1,2,3, GTK_SHRINK, 0, 0, 0);
+       gtk_table_attach (GTK_TABLE(header_table), bcc_button,    0,1,3,4, GTK_SHRINK, 0, 0, 0);
+       gtk_table_attach (GTK_TABLE(header_table), gtk_label_new (_("Subject:")),
+                         0,1,4,5, GTK_SHRINK, 0, 0, 0);
+
+       gtk_table_attach_defaults (GTK_TABLE(header_table), priv->from_field,   1,2,0,1);
+       gtk_table_attach_defaults (GTK_TABLE(header_table), priv->to_field,     1,2,1,2);
+       gtk_table_attach_defaults (GTK_TABLE(header_table), priv->cc_field,     1,2,2,3);
+       gtk_table_attach_defaults (GTK_TABLE(header_table), priv->bcc_field,    1,2,3,4);
+       gtk_table_attach_defaults (GTK_TABLE(header_table), priv->subject_field,1,2,4,5);
 
        priv->msg_body = gtk_text_view_new ();
        
        main_vbox = gtk_vbox_new  (FALSE, 6);
 
-       priv->menubar = menubar_new (obj);
-       priv->toolbar = GTK_WIDGET(toolbar_new (obj));
-
        gtk_box_pack_start (GTK_BOX(main_vbox), priv->menubar, FALSE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX(main_vbox), priv->toolbar, FALSE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX(main_vbox), header_table, FALSE, FALSE, 6);
@@ -376,11 +216,8 @@ modest_edit_msg_window_finalize (GObject *obj)
 
        priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(obj);
 
-       g_object_unref (G_OBJECT(priv->conf));
-       priv->conf = NULL;
-
-       g_object_unref (G_OBJECT(priv->factory));
-       priv->factory = NULL;
+       g_object_unref (G_OBJECT(priv->widget_factory));
+       priv->widget_factory = NULL;
        
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 
@@ -396,28 +233,62 @@ on_delete_event (GtkWidget *widget, GdkEvent *event, ModestEditMsgWindow *self)
 }
 
 
-GtkWidget*
-modest_edit_msg_window_new (ModestConf *conf, ModestWidgetFactory *factory,
-                           ModestEditType type, TnyMsgIface *msg)
+ModestWindow *
+modest_edit_msg_window_new (ModestWidgetFactory *factory,
+                           TnyAccountStore *account_store,
+                           ModestEditType type)
 {
        GObject *obj;
        ModestEditMsgWindowPrivate *priv;
+       GtkActionGroup *action_group;
+       GError *error = NULL;
 
-       g_return_val_if_fail (conf, NULL);
        g_return_val_if_fail (factory, NULL);
-       g_return_val_if_fail (type >= 0 && type < MODEST_EDIT_TYPE_NUM, NULL);
-       g_return_val_if_fail (!(type==MODEST_EDIT_TYPE_NEW && msg), NULL); 
-       g_return_val_if_fail (!(type!=MODEST_EDIT_TYPE_NEW && !msg), NULL);     
+       g_return_val_if_fail (type < MODEST_EDIT_TYPE_NUM, NULL);
        
        obj = g_object_new(MODEST_TYPE_EDIT_MSG_WINDOW, NULL);
        priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(obj);
 
-       g_object_ref (G_OBJECT(conf));
-       priv->conf = conf;
+       priv->widget_factory = g_object_ref (factory);
+       priv->account_store  = g_object_ref (account_store);
+
+       /* ****** */
+       priv->ui_manager = gtk_ui_manager_new();
+       action_group = gtk_action_group_new ("ModestEditMsgWindowActions");
+
+       /* Add common actions */
+       gtk_action_group_add_actions (action_group,
+                                     modest_edit_msg_action_entries,
+                                     G_N_ELEMENTS (modest_edit_msg_action_entries),
+                                     obj);
+       gtk_action_group_add_toggle_actions (action_group,
+                                            modest_edit_msg_toggle_action_entries,
+                                            G_N_ELEMENTS (modest_edit_msg_toggle_action_entries),
+                                            obj);
+       gtk_ui_manager_insert_action_group (priv->ui_manager, action_group, 0);
+       g_object_unref (action_group);
+
+       /* Load the UI definition */
+       gtk_ui_manager_add_ui_from_file (priv->ui_manager, MODEST_UIDIR "modest-edit-msg-window-ui.xml", &error);
+       if (error != NULL) {
+               g_warning ("Could not merge modest-edit-msg-window-ui.xml: %s", error->message);
+               g_error_free (error);
+               error = NULL;
+       }
+       /* ****** */
+
+       /* Add accelerators */
+       gtk_window_add_accel_group (GTK_WINDOW (obj), 
+                                   gtk_ui_manager_get_accel_group (priv->ui_manager));
 
-       g_object_ref (factory);
-       priv->factory = factory;
 
+       /* Toolbar / Menubar */
+       priv->toolbar = gtk_ui_manager_get_widget (priv->ui_manager, "/EditMsgWindowToolBar");
+       priv->menubar = gtk_ui_manager_get_widget (priv->ui_manager, "/EditMsgWindowMenuBar");
+
+       gtk_toolbar_set_tooltips (GTK_TOOLBAR (priv->toolbar), TRUE);
+
+       /* Init window */
        init_window (MODEST_EDIT_MSG_WINDOW(obj));
 
        restore_settings (MODEST_EDIT_MSG_WINDOW(obj));
@@ -428,6 +299,110 @@ modest_edit_msg_window_new (ModestConf *conf, ModestWidgetFactory *factory,
 
        g_signal_connect (G_OBJECT(obj), "delete-event",
                          G_CALLBACK(on_delete_event), obj);
+
+       return (ModestWindow *) (obj);
+}
+
+void
+modest_edit_msg_window_set_msg (ModestEditMsgWindow *self, TnyMsg *msg)
+{
+       TnyHeader *header;
+       GtkTextBuffer *buf;
+       const gchar *to, *cc, *bcc, *subject;
+       ModestEditMsgWindowPrivate *priv;
+
+       g_return_if_fail (MODEST_IS_EDIT_MSG_WINDOW (self));
+       g_return_if_fail (TNY_IS_MSG (msg));
+
+       priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE (self);
+
+       header  = tny_msg_get_header (msg);
+       to      = tny_header_get_to (header);
+       cc      = tny_header_get_cc (header);
+       bcc     = tny_header_get_bcc (header);
+       subject = tny_header_get_subject (header);
+
+       if (to)
+               gtk_entry_set_text (GTK_ENTRY(priv->to_field),  to);
+       if (cc)
+               gtk_entry_set_text (GTK_ENTRY(priv->cc_field),  cc);
+       if (bcc)
+               gtk_entry_set_text (GTK_ENTRY(priv->bcc_field), bcc);
+       if (subject)
+               gtk_entry_set_text (GTK_ENTRY(priv->subject_field), subject);   
+       
+       buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW(priv->msg_body));
+       gtk_text_buffer_set_text (buf,
+                                 (const gchar *) modest_tny_msg_actions_find_body (msg, FALSE),
+                                 -1);
+
+       /* TODO: lower priority, select in the From: combo to the
+          value that comes from msg <- not sure, should it be
+          allowed? */
        
-       return GTK_WIDGET (obj);
+       /* TODO: set attachments */
+}
+
+ModestWidgetFactory *
+modest_edit_msg_window_get_widget_factory (ModestEditMsgWindow *edit_window)
+{
+       ModestEditMsgWindowPrivate *priv;
+       
+       g_return_val_if_fail (MODEST_IS_EDIT_MSG_WINDOW (edit_window), NULL);
+
+       priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE (edit_window);
+
+       return g_object_ref (priv->widget_factory);
+}
+
+TnyAccountStore * 
+modest_edit_msg_window_get_account_store (ModestEditMsgWindow *edit_window)
+{
+       ModestEditMsgWindowPrivate *priv;
+       
+       g_return_val_if_fail (MODEST_IS_EDIT_MSG_WINDOW (edit_window), NULL);
+
+       priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE (edit_window);
+
+       return g_object_ref (priv->account_store);
+}
+
+MsgData * 
+modest_edit_msg_window_get_msg_data (ModestEditMsgWindow *edit_window)
+{
+       MsgData *data;
+       ModestAccountData *account_data;
+       GtkTextBuffer *buf;
+       GtkTextIter b, e;
+       ModestEditMsgWindowPrivate *priv;
+       
+       g_return_val_if_fail (MODEST_IS_EDIT_MSG_WINDOW (edit_window), NULL);
+
+       priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE (edit_window);
+       
+       account_data = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->from_field));
+       buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->msg_body));        
+       gtk_text_buffer_get_bounds (buf, &b, &e);
+
+       /* don't free these (except from) */
+       data = g_slice_new0 (MsgData);
+       data->from    =  g_strdup_printf ("%s <%s>", account_data->fullname, account_data->email) ;
+       data->to      =  (gchar*) gtk_entry_get_text (GTK_ENTRY(priv->to_field));
+       data->cc      =  (gchar*) gtk_entry_get_text (GTK_ENTRY(priv->cc_field));
+       data->bcc     =  (gchar*) gtk_entry_get_text (GTK_ENTRY(priv->bcc_field));
+       data->subject =  (gchar*) gtk_entry_get_text (GTK_ENTRY(priv->subject_field));  
+       data->body    =  gtk_text_buffer_get_text (buf, &b, &e, FALSE);
+
+       return data;
+}
+
+void 
+modest_edit_msg_window_free_msg_data (ModestEditMsgWindow *edit_window,
+                                     MsgData *data)
+{
+       g_return_if_fail (MODEST_IS_EDIT_MSG_WINDOW (edit_window));
+
+       g_free (data->from);
+       g_free (data->body);
+       g_slice_free (MsgData, data);
 }