1 /* Copyright (c) 2007, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "modest-dbus-callbacks.h"
31 #include "modest-runtime.h"
32 #include "modest-account-mgr.h"
33 #include "modest-account-mgr-helpers.h"
36 /* Callback for normal D-BUS messages */
37 static gint on_send_mail(GArray * arguments, gpointer data, osso_rpc_t * retval)
39 if (arguments->len != MODEST_DEBUS_SEND_MAIL_ARGS_COUNT)
42 /* Get the arguments: */
43 osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_TO);
44 gchar *to = val.value.s;
46 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_CC);
47 gchar *cc = val.value.s;
49 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_BCC);
50 gchar *bcc = val.value.s;
52 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_SUBJECT);
53 gchar *subject = val.value.s;
55 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_BODY);
56 gchar *body = val.value.s;
58 printf(" debug: to=%s\n", to);
60 /* Get the TnyTransportAccount so we can instantiate a mail operation: */
61 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
62 gchar *account_name = modest_account_mgr_get_default_account (account_mgr);
64 g_printerr ("modest: no account found\n");
68 TnyTransportAccount *transport_account =
69 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
70 (modest_runtime_get_account_store(),
72 TNY_ACCOUNT_TYPE_TRANSPORT));
73 if (!transport_account) {
74 g_printerr ("modest: no transport account found for '%s'\n", account_name);
75 g_free (account_name);
79 /* Create the mail operation: */
80 ModestMailOperation *mail_operation = modest_mail_operation_new ();
81 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
83 /* Use the mail operation: */
84 gchar * from = modest_account_mgr_get_from_string (account_mgr,
86 modest_mail_operation_send_new_mail (mail_operation,
90 body, /* plain_body */
92 NULL, /* attachments_list, GSList of TnyMimePart. */
95 g_object_unref (G_OBJECT (transport_account));
96 g_object_unref (G_OBJECT (mail_operation));
98 g_free (account_name);
101 /* Callback for normal D-BUS messages */
102 gint modest_dbus_req_handler(const gchar * interface, const gchar * method,
103 GArray * arguments, gpointer data,
106 printf("debug: modest_dbus_req_handler()\n");
107 printf("debug: method received: %s\n", method);
109 if (g_ascii_strcasecmp(method, MODEST_DBUS_EXAMPLE_MESSAGE) == 0) {
111 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_SEND_MAIL) == 0) {
112 return on_send_mail (arguments, data, retval);