From: Marcus Bauer Date: Wed, 23 May 2007 07:10:55 +0000 (+0000) Subject: 2007-05-23 Marcus Bauer X-Git-Tag: git_migration_finished~3527 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=b9ed460defaba68c025556d4d658bd9f0b288d91;ds=sidebyside 2007-05-23 Marcus Bauer * libmodest-dbus-client/libmodest-dbus-client.c: (libmodest_dbus_client_compose_mail): function added * src/dbus_api/modest-dbus-api.h: * src/dbus_api/modest-dbus-callbacks.c: (on_idle_compose_mail), (on_compose_mail): Implementation of the SendAsMail functionality pmo-trunk-r1959 --- diff --git a/ChangeLog2 b/ChangeLog2 index 2312f11..dab6a4d 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,3 +1,11 @@ +2007-05-23 Marcus Bauer + + * libmodest-dbus-client/libmodest-dbus-client.c: + (libmodest_dbus_client_compose_mail): function added + * src/dbus_api/modest-dbus-api.h: + * src/dbus_api/modest-dbus-callbacks.c: (on_idle_compose_mail), + (on_compose_mail): Implementation of the SendAsMail functionality + 2007-05-22 Murray Cumming * src/modest-account-mgr.c: diff --git a/libmodest-dbus-client/libmodest-dbus-client.c b/libmodest-dbus-client/libmodest-dbus-client.c index 7108838..fefaaf2 100644 --- a/libmodest-dbus-client/libmodest-dbus-client.c +++ b/libmodest-dbus-client/libmodest-dbus-client.c @@ -79,6 +79,50 @@ libmodest_dbus_client_mail_to (osso_context_t *osso_context, const gchar *mailto 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) { @@ -121,5 +165,3 @@ libmodest_dbus_client_send_and_receive (osso_context_t *osso_context) return TRUE; } - - diff --git a/src/dbus_api/modest-dbus-api.h b/src/dbus_api/modest-dbus-api.h index bc15972..ad88a25 100644 --- a/src/dbus_api/modest-dbus-api.h +++ b/src/dbus_api/modest-dbus-api.h @@ -69,6 +69,15 @@ enum ModestDbusOpenMessageArguments #define MODEST_DBUS_METHOD_SEND_RECEIVE "SendReceive" #define MODEST_DBUS_METHOD_COMPOSE_MAIL "ComposeMail" - +enum ModestDbusComposeMailArguments +{ + MODEST_DEBUS_COMPOSE_MAIL_ARG_TO, + MODEST_DEBUS_COMPOSE_MAIL_ARG_CC, + MODEST_DEBUS_COMPOSE_MAIL_ARG_BCC, + MODEST_DEBUS_COMPOSE_MAIL_ARG_SUBJECT, + MODEST_DEBUS_COMPOSE_MAIL_ARG_BODY, + MODEST_DEBUS_COMPOSE_MAIL_ARG_ATTACHMENTS, + MODEST_DEBUS_COMPOSE_MAIL_ARGS_COUNT +}; #endif /* __MODEST_DBUS_API__ */ diff --git a/src/dbus_api/modest-dbus-callbacks.c b/src/dbus_api/modest-dbus-callbacks.c index 75bf676..29ebea8 100644 --- a/src/dbus_api/modest-dbus-callbacks.c +++ b/src/dbus_api/modest-dbus-callbacks.c @@ -48,6 +48,16 @@ typedef struct 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) { @@ -379,9 +389,8 @@ static gint on_mail_to(GArray * arguments, gpointer data, osso_rpc_t * retval) 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); @@ -403,17 +412,11 @@ on_idle_compose_mail(gpointer user_data) 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"); @@ -440,25 +443,59 @@ on_idle_compose_mail(gpointer user_data) 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. */