+
+typedef struct
+{
+ GMainLoop* loop;
+ TnyAccount *account;
+ gboolean is_online;
+ gint count_tries;
+} CheckAccountIdleData;
+
+#define NUMBER_OF_TRIES 10 /* Try approx every second, ten times. */
+
+static gboolean
+on_timeout_check_account_is_online(CheckAccountIdleData* data)
+{
+ gboolean stop_trying = FALSE;
+ g_return_val_if_fail (data && data->account, FALSE);
+
+ printf ("DEBUG: %s: tny_account_get_connection_status()==%d\n", __FUNCTION__,
+ tny_account_get_connection_status (data->account));
+
+ if (data && data->account &&
+ /* We want to wait until TNY_CONNECTION_STATUS_INIT has changed to something else,
+ * after which the account is likely to be usable, or never likely to be usable soon: */
+ (tny_account_get_connection_status (data->account) != TNY_CONNECTION_STATUS_INIT) )
+ {
+ data->is_online = TRUE;
+
+ stop_trying = TRUE;
+ } else {
+ /* Give up if we have tried too many times: */
+ if (data->count_tries >= NUMBER_OF_TRIES) {
+ stop_trying = TRUE;
+ } else {
+ /* Wait for another timeout: */
+ ++(data->count_tries);
+ }
+ }
+
+ if (stop_trying) {
+ /* Allow the function that requested this idle callback to continue: */
+ if (data->loop)
+ g_main_loop_quit (data->loop);
+
+ if (data->account)
+ g_object_unref (data->account);
+
+ return FALSE; /* Don't call this again. */
+ } else {
+ return TRUE; /* Call this timeout callback again. */
+ }
+}
+
+/* Return TRUE immediately if the account is already online,
+ * otherwise check every second for NUMBER_OF_TRIES seconds and return TRUE as
+ * soon as the account is online, or FALSE if the account does
+ * not become online in the NUMBER_OF_TRIES seconds.
+ * This is useful when the D-Bus method was run immediately after
+ * the application was started (when using D-Bus activation),
+ * because the account usually takes a short time to go online.
+ * The return value is maybe not very useful.
+ */
+gboolean
+modest_platform_check_and_wait_for_account_is_online(TnyAccount *account)
+{
+ gboolean is_online;
+
+ g_return_val_if_fail (account, FALSE);
+
+ printf ("DEBUG: %s: account id=%s\n", __FUNCTION__, tny_account_get_id (account));
+
+ if (!tny_device_is_online (modest_runtime_get_device())) {
+ printf ("DEBUG: %s: device is offline.\n", __FUNCTION__);
+ return FALSE;
+ }
+
+ /* The local_folders account never seems to leave TNY_CONNECTION_STATUS_INIT,
+ * so we avoid wait unnecessarily: */
+ if (!TNY_IS_CAMEL_POP_STORE_ACCOUNT (account) &&
+ !TNY_IS_CAMEL_IMAP_STORE_ACCOUNT (account) ) {
+ return TRUE;
+ }
+
+ printf ("DEBUG: %s: tny_account_get_connection_status()==%d\n",
+ __FUNCTION__, tny_account_get_connection_status (account));
+
+ /* The POP & IMAP store accounts seem to be TNY_CONNECTION_STATUS_DISCONNECTED,
+ * and that seems to be an OK time to use them. Maybe it's just TNY_CONNECTION_STATUS_INIT that
+ * we want to avoid. */
+ if (tny_account_get_connection_status (account) != TNY_CONNECTION_STATUS_INIT)
+ return TRUE;
+
+ /* This blocks on the result: */
+ CheckAccountIdleData *data = g_slice_new0 (CheckAccountIdleData);
+ data->is_online = FALSE;
+ data->account = account;
+ g_object_ref (data->account);
+ data->count_tries = 0;
+
+ GMainContext *context = NULL; /* g_main_context_new (); */
+ data->loop = g_main_loop_new (context, FALSE /* not running */);
+
+ g_timeout_add (1000, (GSourceFunc)(on_timeout_check_account_is_online), data);
+
+ /* This main loop will run until the idle handler has stopped it: */
+ g_main_loop_run (data->loop);
+
+ g_main_loop_unref (data->loop);
+ /* g_main_context_unref (context); */
+
+ is_online = data->is_online;
+ g_slice_free (CheckAccountIdleData, data);
+
+ return is_online;
+}
+
+
+
+static void
+on_cert_dialog_response (GtkDialog *dialog, gint response_id, const gchar* cert)
+{
+ /* GTK_RESPONSE_HELP means we need to show the certificate */
+ if (response_id == GTK_RESPONSE_APPLY) {
+ GtkWidget *note;
+ gchar *msg;
+
+ /* Do not close the dialog */
+ g_signal_stop_emission_by_name (dialog, "response");
+
+ msg = g_strdup_printf (_("mcen_ni_view_unknown_certificate"), cert);
+ note = hildon_note_new_information (GTK_WINDOW(dialog), msg);
+ gtk_dialog_run (GTK_DIALOG(note));
+ gtk_widget_destroy (note);
+ }
+}
+
+
+gboolean
+modest_platform_run_certificate_confirmation_dialog (const gchar* server_name,
+ const gchar *certificate)
+{
+ GtkWidget *note;
+ gint response;
+ ModestWindow *main_win;
+
+ if (!modest_window_mgr_main_window_exists (modest_runtime_get_window_mgr())) {
+ g_debug ("%s: don't show dialogs if there's no main window; assuming 'Cancel'",
+ __FUNCTION__);
+ return FALSE;
+ }
+
+ /* don't create it */
+ main_win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(), FALSE);
+ g_return_val_if_fail (main_win, FALSE); /* should not happen */
+
+
+ gchar *question = g_strdup_printf (_("mcen_nc_unknown_certificate"),
+ server_name);
+
+ /* We use GTK_RESPONSE_APPLY because we want the button in the
+ middle of OK and CANCEL the same as the browser does for
+ example. With GTK_RESPONSE_HELP the view button is aligned
+ to the left while the other two to the right */
+ note = hildon_note_new_confirmation_add_buttons (
+ GTK_WINDOW(main_win),
+ question,
+ _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK,
+ _("mcen_bd_view"), GTK_RESPONSE_APPLY, /* abusing this... */
+ _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL,
+ NULL, NULL);
+
+ g_signal_connect (G_OBJECT(note), "response",
+ G_CALLBACK(on_cert_dialog_response),
+ (gpointer) certificate);
+
+ modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
+ GTK_WINDOW (note), (GtkWindow *) main_win);
+ response = gtk_dialog_run(GTK_DIALOG(note));
+
+ on_destroy_dialog (note);
+ g_free (question);
+
+ return response == GTK_RESPONSE_OK;
+}
+
+gboolean
+modest_platform_run_alert_dialog (const gchar* prompt,
+ gboolean is_question)
+{
+ ModestWindow *main_win;
+
+ if (!modest_window_mgr_main_window_exists (modest_runtime_get_window_mgr())) {
+ g_debug ("%s:\n'%s'\ndon't show dialogs if there's no main window;"
+ " assuming 'Cancel' for questions, 'Ok' otherwise", prompt, __FUNCTION__);
+ return is_question ? FALSE : TRUE;
+ }
+
+ main_win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), FALSE);
+ g_return_val_if_fail (main_win, FALSE); /* should not happen */
+
+ gboolean retval = TRUE;
+ if (is_question) {
+ /* The Tinymail documentation says that we should show Yes and No buttons,
+ * when it is a question.
+ * Obviously, we need tinymail to use more specific error codes instead,
+ * so we know what buttons to show. */
+ GtkWidget *dialog = GTK_WIDGET (hildon_note_new_confirmation (GTK_WINDOW (main_win),
+ prompt));
+ modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
+ GTK_WINDOW (dialog), (GtkWindow *) main_win);
+
+ const int response = gtk_dialog_run (GTK_DIALOG (dialog));
+ retval = (response == GTK_RESPONSE_YES) || (response == GTK_RESPONSE_OK);
+
+ on_destroy_dialog (dialog);
+ } else {
+ /* Just show the error text and use the default response: */
+ modest_platform_run_information_dialog (GTK_WINDOW (main_win),
+ prompt, FALSE);
+ }
+ return retval;
+}
+
+/***************/
+typedef struct {
+ GtkWindow *parent_window;
+ ModestConnectedPerformer callback;
+ TnyAccount *account;
+ gpointer user_data;
+ gchar *iap;
+ TnyDevice *device;
+} OnWentOnlineInfo;
+
+static void
+on_went_online_info_free (OnWentOnlineInfo *info)
+{
+ /* And if we cleanup, we DO cleanup :-) */
+
+ if (info->device)
+ g_object_unref (info->device);
+ if (info->iap)
+ g_free (info->iap);
+ if (info->parent_window)
+ g_object_unref (info->parent_window);
+ if (info->account)
+ g_object_unref (info->account);
+
+ g_slice_free (OnWentOnlineInfo, info);
+
+ /* We're done ... */
+
+ return;
+}
+
+static void
+on_account_went_online (TnyCamelAccount *account, gboolean canceled, GError *err, gpointer user_data)
+{
+ OnWentOnlineInfo *info = (OnWentOnlineInfo *) user_data;
+
+ /* Now it's really time to callback to the caller. If going online didn't succeed,
+ * err will be set. We don't free it, Tinymail does that! If a cancel happened,
+ * canceled will be set. Etcetera etcetera. */
+
+ if (info->callback) {
+ info->callback (canceled, err, info->parent_window, info->account, info->user_data);
+ }
+
+ /* This is our last call, we must cleanup here if we didn't yet do that */
+ on_went_online_info_free (info);
+
+ return;
+}
+
+
+static void
+on_conic_device_went_online (TnyMaemoConicDevice *device, const gchar* iap_id, gboolean canceled, GError *err, gpointer user_data)
+{
+ OnWentOnlineInfo *info = (OnWentOnlineInfo *) user_data;
+ info->iap = g_strdup (iap_id);
+
+ if (canceled || err || !info->account) {
+
+ /* If there's a problem or if there's no account (then that's it for us, we callback
+ * the caller's callback now. He'll have to handle err or canceled, of course.
+ * We are not really online, as the account is not really online here ... */
+
+ /* We'll use the err and the canceled of this cb. TnyMaemoConicDevice delivered us
+ * this info. We don't cleanup err, Tinymail does that! */
+
+ if (info->callback) {
+
+ /* info->account can be NULL here, this means that the user did not
+ * provide a nice account instance. We'll assume that the user knows
+ * what he's doing and is happy with just the device going online.
+ *
+ * We can't do magic, we don't know what account the user wants to
+ * see going online. So just the device goes online, end of story */
+
+ info->callback (canceled, err, info->parent_window, info->account, info->user_data);
+ }
+
+ } else if (info->account) {
+
+ /* If there's no problem and if we have an account, we'll put the account
+ * online too. When done, the callback of bringing the account online
+ * will callback the caller's callback. This is the most normal case. */
+
+ info->device = TNY_DEVICE (g_object_ref (device));
+
+ tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (info->account), TRUE,
+ on_account_went_online, info);
+
+ /* The on_account_went_online cb frees up the info, go look if you
+ * don't believe me! (so we return here) */
+
+ return;
+ }
+
+ /* We cleanup if we are not bringing the account online too */
+ on_went_online_info_free (info);
+
+ return;
+}
+
+void
+modest_platform_connect_and_perform (GtkWindow *parent_window,
+ gboolean force,
+ TnyAccount *account,
+ ModestConnectedPerformer callback,
+ gpointer user_data)
+{
+ gboolean device_online;
+ TnyDevice *device;
+ TnyConnectionStatus conn_status;
+ OnWentOnlineInfo *info;
+
+ device = modest_runtime_get_device();
+ device_online = tny_device_is_online (device);
+
+ /* If there is no account check only the device status */
+ if (!account) {
+
+ if (device_online) {
+
+ /* We promise to instantly perform the callback, so ... */
+ if (callback) {
+ callback (FALSE, NULL, parent_window, account, user_data);
+ }
+
+ } else {
+
+ info = g_slice_new0 (OnWentOnlineInfo);
+
+ info->iap = NULL;
+ info->device = NULL;
+ info->account = NULL;
+
+ if (parent_window)
+ info->parent_window = (GtkWindow *) g_object_ref (parent_window);
+ else
+ info->parent_window = NULL;
+ info->user_data = user_data;
+ info->callback = callback;
+
+ tny_maemo_conic_device_connect_async (TNY_MAEMO_CONIC_DEVICE (device), NULL,
+ force, on_conic_device_went_online,
+ info);
+
+ /* We'll cleanup in on_conic_device_went_online */
+ }
+
+ /* The other code has no more reason to run. This is all that we can do for the
+ * caller (he should have given us a nice and clean account instance!). We
+ * can't do magic, we don't know what account he intends to bring online. So
+ * we'll just bring the device online (and await his false bug report). */
+
+ return;
+ }
+
+
+ /* Return if the account is already connected */
+
+ conn_status = tny_account_get_connection_status (account);
+ if (device_online && conn_status == TNY_CONNECTION_STATUS_CONNECTED) {
+
+ /* We promise to instantly perform the callback, so ... */
+ if (callback) {
+ callback (FALSE, NULL, parent_window, account, user_data);
+ }
+
+ return;
+ }
+
+ /* Else, we are in a state that requires that we go online before we
+ * call the caller's callback. */
+
+ info = g_slice_new0 (OnWentOnlineInfo);
+
+ info->device = NULL;
+ info->iap = NULL;
+ info->account = TNY_ACCOUNT (g_object_ref (account));
+
+ if (parent_window)
+ info->parent_window = (GtkWindow *) g_object_ref (parent_window);
+ else
+ info->parent_window = NULL;
+
+ /* So we'll put the callback away for later ... */
+
+ info->user_data = user_data;
+ info->callback = callback;
+
+ if (!device_online) {
+
+ /* If also the device is offline, then we connect both the device
+ * and the account */
+
+ tny_maemo_conic_device_connect_async (TNY_MAEMO_CONIC_DEVICE (device), NULL,
+ force, on_conic_device_went_online,
+ info);
+
+ } else {
+
+ /* If the device is online, we'll just connect the account */
+
+ tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (account), TRUE,
+ on_account_went_online, info);
+ }
+
+ /* The info gets freed by on_account_went_online or on_conic_device_went_online
+ * in both situations, go look if you don't believe me! */
+
+ return;
+}
+
+void
+modest_platform_connect_if_remote_and_perform (GtkWindow *parent_window,
+ gboolean force,
+ TnyFolderStore *folder_store,
+ ModestConnectedPerformer callback,
+ gpointer user_data)
+{
+ TnyAccount *account = NULL;
+
+ if (!folder_store ||
+ (TNY_IS_MERGE_FOLDER (folder_store) &&
+ (tny_folder_get_folder_type (TNY_FOLDER(folder_store)) == TNY_FOLDER_TYPE_OUTBOX))) {
+
+ /* We promise to instantly perform the callback, so ... */
+ if (callback) {
+ GError *error = NULL;
+ g_set_error (&error, TNY_ERROR_DOMAIN, TNY_SERVICE_ERROR_UNKNOWN,
+ "Unable to move or not found folder");
+ callback (FALSE, error, parent_window, NULL, user_data);
+ g_error_free (error);
+ }
+ return;
+
+ } else if (TNY_IS_FOLDER (folder_store)) {
+ /* Get the folder's parent account: */
+ account = tny_folder_get_account (TNY_FOLDER (folder_store));
+ } else if (TNY_IS_ACCOUNT (folder_store)) {
+ /* Use the folder store as an account: */
+ account = TNY_ACCOUNT (g_object_ref (folder_store));
+ }
+
+ if (tny_account_get_account_type (account) == TNY_ACCOUNT_TYPE_STORE) {
+ if (!TNY_IS_CAMEL_POP_STORE_ACCOUNT (account) &&
+ !TNY_IS_CAMEL_IMAP_STORE_ACCOUNT (account)) {
+
+ /* No need to connect a local account */
+ if (callback)
+ callback (FALSE, NULL, parent_window, account, user_data);
+
+ goto clean;
+ }
+ }
+ modest_platform_connect_and_perform (parent_window, force, account, callback, user_data);
+
+ clean:
+ if (account)
+ g_object_unref (account);
+}
+
+static void
+src_account_connect_performer (gboolean canceled,
+ GError *err,
+ GtkWindow *parent_window,
+ TnyAccount *src_account,
+ gpointer user_data)
+{
+ DoubleConnectionInfo *info = (DoubleConnectionInfo *) user_data;
+
+ if (canceled || err) {
+ /* If there was any error call the user callback */
+ info->callback (canceled, err, parent_window, src_account, info->data);
+ } else {
+ /* Connect the destination account */
+ modest_platform_connect_if_remote_and_perform (parent_window, TRUE,
+ TNY_FOLDER_STORE (info->dst_account),
+ info->callback, info->data);
+ }
+
+ /* Free the info object */
+ g_object_unref (info->dst_account);
+ g_slice_free (DoubleConnectionInfo, info);
+}
+
+
+void
+modest_platform_double_connect_and_perform (GtkWindow *parent_window,
+ gboolean force,
+ TnyFolderStore *folder_store,
+ DoubleConnectionInfo *connect_info)
+{
+ modest_platform_connect_if_remote_and_perform(parent_window,
+ force,
+ folder_store,
+ src_account_connect_performer,
+ connect_info);
+}
+
+GtkWidget *
+modest_platform_get_account_settings_wizard (void)
+{
+ ModestEasysetupWizardDialog *dialog = modest_easysetup_wizard_dialog_new ();
+
+ return GTK_WIDGET (dialog);
+}
+
+ModestConnectedVia
+modest_platform_get_current_connection (void)
+{
+ TnyDevice *device = NULL;
+ ModestConnectedVia retval = MODEST_CONNECTED_VIA_ANY;
+
+ device = modest_runtime_get_device ();
+
+ if (!tny_device_is_online (device))
+ return MODEST_CONNECTED_VIA_ANY;
+
+#ifdef MODEST_HAVE_CONIC
+ /* Get iap id */
+ const gchar *iap_id = tny_maemo_conic_device_get_current_iap_id (TNY_MAEMO_CONIC_DEVICE (device));
+ if (iap_id) {
+ ConIcIap *iap = tny_maemo_conic_device_get_iap (
+ TNY_MAEMO_CONIC_DEVICE (device), iap_id);
+ const gchar *bearer_type = con_ic_iap_get_bearer_type (iap);
+ if (bearer_type) {
+ if (!strcmp (bearer_type, CON_IC_BEARER_WLAN_INFRA) ||
+ !strcmp (bearer_type, CON_IC_BEARER_WLAN_ADHOC) ||
+ !strcmp (bearer_type, "WIMAX")) {
+ retval = MODEST_CONNECTED_VIA_WLAN_OR_WIMAX;
+ } else {
+ retval = MODEST_CONNECTED_VIA_ANY;
+ }
+ }
+ g_object_unref (iap);
+ }
+#else
+ retval = MODEST_CONNECTED_VIA_WLAN_OR_WIMAX; /* assume WLAN (fast) internet */
+#endif /* MODEST_HAVE_CONIC */
+ return retval;
+}
+
+gboolean
+modest_platform_check_memory_low (ModestWindow *win,
+ gboolean visuals)
+{
+ gboolean lowmem;
+
+ /* are we in low memory state? */
+ lowmem = osso_mem_in_lowmem_state () ? TRUE : FALSE;
+
+ if (win && lowmem && visuals)
+ modest_platform_run_information_dialog (
+ GTK_WINDOW(win),
+ _KR("memr_ib_operation_disabled"),
+ TRUE);
+
+ if (lowmem)
+ g_debug ("%s: low memory reached. disallowing some operations",
+ __FUNCTION__);
+
+ return lowmem;
+}
+
+void
+modest_platform_run_folder_details_dialog (GtkWindow *parent_window,
+ TnyFolder *folder)
+{
+ GtkWidget *dialog;
+
+ /* Create dialog */
+ dialog = modest_details_dialog_new_with_folder (parent_window, folder);
+
+ /* Run dialog */
+ modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
+ GTK_WINDOW (dialog),
+ parent_window);
+ gtk_widget_show_all (dialog);
+
+ g_signal_connect_swapped (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy),
+ dialog);
+}
+
+void
+modest_platform_run_header_details_dialog (GtkWindow *parent_window,
+ TnyHeader *header,
+ gboolean async_get_size,
+ TnyMsg *msg)
+{
+ GtkWidget *dialog;
+
+ /* Create dialog */
+ dialog = modest_details_dialog_new_with_header (parent_window, header, TRUE);
+
+ /* Run dialog */
+ modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
+ GTK_WINDOW (dialog),
+ parent_window);
+ gtk_widget_show_all (dialog);
+
+ g_signal_connect_swapped (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy),
+ dialog);
+}
+
+osso_context_t *
+modest_platform_get_osso_context (void)
+{
+ return modest_maemo_utils_get_osso_context ();
+}
+
+GtkWidget*
+modest_platform_create_move_to_dialog (GtkWindow *parent_window,
+ GtkWidget **folder_view)
+{
+ GtkWidget *dialog, *folder_view_container;
+
+ dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
+ GTK_WINDOW (parent_window),
+ GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR |
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK,
+ _("mcen_bd_new"), MODEST_GTK_RESPONSE_NEW_FOLDER,
+ _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL,
+ NULL);
+
+ /* Create folder view */
+ *folder_view = modest_platform_create_folder_view (NULL);
+
+ /* Create pannable and add it to the dialog */
+ folder_view_container = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (folder_view_container),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), folder_view_container);
+ gtk_container_add (GTK_CONTAINER (folder_view_container), *folder_view);
+
+ gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
+
+ gtk_widget_show (GTK_DIALOG (dialog)->vbox);
+ gtk_widget_show (folder_view_container);
+ gtk_widget_show (*folder_view);
+
+ return dialog;
+}
+
+
+TnyList *
+modest_platform_get_list_to_move (ModestWindow *window)
+{
+ TnyList *list = NULL;
+
+ /* If it's a main window then it could be that we're moving a
+ folder or a set of messages */
+ if (MODEST_IS_MAIN_WINDOW (window)) {
+ ModestHeaderView *header_view = NULL;
+ ModestFolderView *folder_view = NULL;
+
+ folder_view = (ModestFolderView *)
+ modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+ header_view = (ModestHeaderView *)
+ modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
+
+ /* Get folder or messages to transfer */
+ if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
+ TnyFolderStore *src_folder;
+
+ src_folder = modest_folder_view_get_selected (folder_view);
+ if (src_folder) {
+ list = tny_simple_list_new ();
+ tny_list_prepend (list, G_OBJECT (src_folder));
+ g_object_unref (src_folder);
+ }
+ } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
+ list = modest_header_view_get_selected_headers(header_view);
+ }
+ } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
+ TnyHeader *header = NULL;
+
+ /* We simply return the currently viewed message */
+ header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (window));
+ if (header) {
+ list = tny_simple_list_new ();
+ tny_list_prepend (list, G_OBJECT (header));
+ g_object_unref (header);
+ }
+ } else {
+ g_return_val_if_reached (NULL);
+ }
+
+ return list;
+}