+ if (!account) {
+ g_printerr ("modest: failed to get tny account folder'\n", account_name);
+ } else {
+ gchar * from = modest_account_mgr_get_from_string (account_mgr,
+ account_name);
+ if (!from) {
+ g_printerr ("modest: no from address for account '%s'\n", account_name);
+ } else {
+ const gchar *cc = NULL;
+ const gchar *bcc = NULL;
+ const gchar *subject = NULL;
+ const gchar *body = NULL;
+
+ /* Get the relevant items from the list: */
+ GSList *list = list_names_and_values;
+ while (list) {
+ const gchar * name = (const gchar*)list->data;
+ GSList *list_value = g_slist_next (list);
+ const gchar * value = (const gchar*)list_value->data;
+
+ if (strcmp (name, "cc") == 0) {
+ cc = value;
+ } else if (strcmp (name, "bcc") == 0) {
+ bcc = value;
+ } else if (strcmp (name, "subject") == 0) {
+ subject = value;
+ } else if (strcmp (name, "body") == 0) {
+ body = value;
+ }
+
+ /* Go to the next pair: */
+ if (list_value) {
+ list = g_slist_next (list_value);
+ } else
+ list = NULL;
+ }
+
+ /* Create the message: */
+ TnyMsg *msg = modest_tny_msg_new (to, from,
+ cc, bcc, subject, body,
+ NULL /* attachments */);
+
+ if (!msg) {
+ g_printerr ("modest: failed to create message\n");
+ } else
+ {
+ /* Add the message to a folder and show its UI for editing: */
+ TnyFolder *folder = modest_tny_account_get_special_folder (account,
+ TNY_FOLDER_TYPE_DRAFTS);
+ if (!folder) {
+ g_printerr ("modest: failed to find Drafts folder\n");
+ } else {
+
+ tny_folder_add_msg (folder, msg, NULL); /* TODO: check err */
+
+ ModestWindow *win = modest_msg_edit_window_new (msg, account_name);
+ gtk_widget_show_all (GTK_WIDGET (win));
+
+ g_object_unref (G_OBJECT(folder));
+ }
+
+ g_object_unref (G_OBJECT(msg));
+ }
+
+ g_object_unref (G_OBJECT(account));
+ }
+ }
+
+ g_free (account_name);
+
+ /* Free the list, as required by the uri_parse_mailto() documentation: */
+ if (list_names_and_values)
+ g_slist_foreach (list_names_and_values, (GFunc)g_free, NULL);
+ g_slist_free (list_names_and_values);
+
+ g_free(to);
+
+ g_free(uri);
+
+ return FALSE; /* Do not call this callback again. */
+}
+
+static gint on_mail_to(GArray * arguments, gpointer data, osso_rpc_t * retval)
+{
+ if (arguments->len != MODEST_DEBUS_MAIL_TO_ARGS_COUNT)
+ return OSSO_ERROR;
+
+ /* Use g_idle to context-switch into the application's thread: */
+
+ /* Get the arguments: */
+ osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_MAIL_TO_ARG_URI);
+ gchar *uri = g_strdup (val.value.s);
+
+ /* printf(" debug: to=%s\n", idle_data->to); */
+ g_idle_add(on_idle_mail_to, (gpointer)uri);
+
+ /* Note that we cannot report failures during sending,
+ * because that would be asynchronous. */
+ return OSSO_OK;
+}
+
+
+static gboolean
+on_idle_open_message(gpointer user_data)
+{
+ gchar *uri = (gchar*)user_data;
+
+ g_message ("not implemented yet %s", __FUNCTION__);
+
+ g_free(uri);
+ return FALSE; /* Do not call this callback again. */
+}
+
+static gint on_open_message(GArray * arguments, gpointer data, osso_rpc_t * retval)
+{
+ if (arguments->len != MODEST_DEBUS_OPEN_MESSAGE_ARGS_COUNT)
+ return OSSO_ERROR;
+
+ /* Use g_idle to context-switch into the application's thread: */
+
+ /* Get the arguments: */
+ osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_OPEN_MESSAGE_ARG_URI);
+ gchar *uri = g_strdup (val.value.s);
+
+ /* printf(" debug: to=%s\n", idle_data->to); */
+ g_idle_add(on_idle_open_message, (gpointer)uri);
+
+ /* Note that we cannot report failures during sending,
+ * because that would be asynchronous. */
+ return OSSO_OK;
+}
+
+static gboolean
+on_idle_send_receive(gpointer user_data)
+{
+ ModestWindow* main_window = modest_window_mgr_get_main_window(
+ modest_runtime_get_window_mgr ());
+ do_send_receive(main_window);
+
+ return FALSE; /* Do not call this callback again. */
+}
+
+static gint on_send_receive(GArray * arguments, gpointer data, osso_rpc_t * retval)
+{
+ /* Use g_idle to context-switch into the application's thread: */
+
+ /* This method has no arguments. */
+
+ /* printf(" debug: to=%s\n", idle_data->to); */
+ g_idle_add(on_idle_send_receive, NULL);
+
+ /* Note that we cannot report failures during send/receive,
+ * because that would be asynchronous. */
+ return OSSO_OK;