return TRUE;
}
+gboolean
+libmodest_dbus_client_compose_mail (osso_context_t *osso_context, const gchar *to, const gchar *cc,
+ const gchar *bcc, const gchar* subject, const gchar* body, GSList *attachments)
+{
+ osso_rpc_t retval;
+ gchar *attachments_str = NULL;
+ gchar *tmp = NULL;
+ GSList *next = NULL;
+
+ attachments_str = g_strdup( (gchar *) attachments->data );
+
+ for (next = g_slist_next(attachments); next != NULL; next = g_slist_next(next))
+ {
+ tmp = g_strconcat(attachments_str, ",", (gchar *) (next->data), NULL);
+ g_free(attachments_str);
+ attachments_str = tmp;
+ if (attachments_str == NULL) {
+ return OSSO_ERROR;
+ }
+ }
+
+ const osso_return_t ret = osso_rpc_run_with_defaults(osso_context,
+ MODEST_DBUS_NAME,
+ MODEST_DBUS_METHOD_COMPOSE_MAIL, &retval,
+ DBUS_TYPE_STRING, to,
+ DBUS_TYPE_STRING, cc,
+ DBUS_TYPE_STRING, bcc,
+ DBUS_TYPE_STRING, subject,
+ DBUS_TYPE_STRING, body,
+ DBUS_TYPE_STRING, attachments_str,
+ DBUS_TYPE_INVALID);
+
+ if (ret != OSSO_OK) {
+ printf("debug: osso_rpc_run() failed.\n");
+ return FALSE;
+ } else {
+ printf("debug: osso_rpc_run() succeeded.\n");
+ }
+
+ osso_rpc_free_val(&retval);
+
+ return TRUE;
+}
+
gboolean
libmodest_dbus_client_open_message (osso_context_t *osso_context, const gchar *mail_uri)
{
return TRUE;
}
-
-
gchar *body;
} SendMailIdleData;
+typedef struct
+{
+ gchar *to;
+ gchar *cc;
+ gchar *bcc;
+ gchar *subject;
+ gchar *body;
+ GSList *attachments;
+} ComposeMailIdleData;
+
static gboolean
on_idle_send_mail(gpointer user_data)
{
static gboolean
on_idle_compose_mail(gpointer user_data)
{
- gchar *uri = (gchar*)user_data;
-
-
+ ComposeMailIdleData *idle_data = (ComposeMailIdleData*)user_data;
+
/* Get the TnyTransportAccount so we can instantiate a mail operation: */
ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
gchar *account_name = modest_account_mgr_get_default_account (account_mgr);
if (!from) {
g_printerr ("modest: no from address for account '%s'\n", account_name);
} else {
- const gchar *subject = NULL;
- const gchar *body = NULL;
-
- subject = uri;
- body = uri;
-
/* Create the message: */
- TnyMsg *msg = modest_tny_msg_new (NULL, from,
- NULL, NULL, subject, body,
- NULL /* attachments */);
+ TnyMsg *msg = modest_tny_msg_new (idle_data->to, from,
+ idle_data->cc, idle_data->bcc, idle_data->subject, idle_data->body,
+ idle_data->attachments);
if (!msg) {
g_printerr ("modest: failed to create message\n");
g_object_unref (G_OBJECT(account));
}
}
-
+
+ /* Free the idle data: */
+ g_free (idle_data->to);
+ g_free (idle_data->cc);
+ g_free (idle_data->bcc);
+ g_free (idle_data->subject);
+ g_free (idle_data->body);
+ g_free (idle_data->attachments);
+ g_free (idle_data);
+
g_free (account_name);
- g_free(uri);
return FALSE; /* Do not call this callback again. */
}
static gint on_compose_mail(GArray * arguments, gpointer data, osso_rpc_t * retval)
{
- if (arguments->len != MODEST_DEBUS_OPEN_MESSAGE_ARGS_COUNT)
+ gchar **list = NULL;
+ gint i = 0;
+
+ if (arguments->len != MODEST_DEBUS_COMPOSE_MAIL_ARGS_COUNT)
return OSSO_ERROR;
- /* Use g_idle to context-switch into the application's thread: */
+ /* Use g_idle to context-switch into the application's thread: */
+ ComposeMailIdleData *idle_data = g_new0(ComposeMailIdleData, 1); /* Freed in the idle callback. */
+
+ /* Get the arguments: */
+ osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_TO);
+ idle_data->to = g_strdup (val.value.s);
+
+ val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_CC);
+ idle_data->cc = g_strdup (val.value.s);
+
+ val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_BCC);
+ idle_data->bcc = g_strdup (val.value.s);
+
+ val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_SUBJECT);
+ idle_data->subject = g_strdup (val.value.s);
+
+ val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_BODY);
+ idle_data->body = g_strdup (val.value.s);
+
+ val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_ATTACHMENTS);
+ gchar *attachments_str = g_strdup (val.value.s);
+
+ list = g_strsplit(attachments_str, ",", 0);
+ for (i=0; list[i] != NULL; i++) {
+ idle_data->attachments = g_slist_append(idle_data->attachments, g_strdup(list[i]));
+ }
+ g_strfreev(list);
- /* 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_compose_mail, (gpointer)uri);
+ g_idle_add(on_idle_compose_mail, (gpointer)idle_data);
/* Note that we cannot report failures during sending,
* because that would be asynchronous. */