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"
34 #include "modest-tny-account.h"
35 #include "modest-ui-actions.h"
37 #include "modest-search.h"
38 #include "widgets/modest-msg-edit-window.h"
39 #include "modest-tny-msg.h"
40 #include <libmodest-dbus-client/libmodest-dbus-client.h>
41 #include <libgnomevfs/gnome-vfs-utils.h>
44 #include <glib/gstdio.h>
45 #include <libgnomevfs/gnome-vfs-mime.h>
46 #include <tny-fs-stream.h>
49 #include <tny-iterator.h>
50 #include <tny-simple-list.h>
70 } ComposeMailIdleData;
73 on_idle_send_mail(gpointer user_data)
75 SendMailIdleData *idle_data = (SendMailIdleData*)user_data;
77 /* Get the TnyTransportAccount so we can instantiate a mail operation: */
78 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
79 gchar *account_name = modest_account_mgr_get_default_account (account_mgr);
81 g_printerr ("modest: no account found\n");
84 TnyTransportAccount *transport_account = NULL;
86 transport_account = TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
87 (modest_runtime_get_account_store(),
91 if (!transport_account) {
92 g_printerr ("modest: no transport account found for '%s'\n", account_name);
95 /* Create the mail operation: */
96 if (transport_account) {
97 /* Use the mail operation: */
98 gchar * from = modest_account_mgr_get_from_string (account_mgr,
101 g_printerr ("modest: no from address for account '%s'\n", account_name);
103 ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, NULL);
104 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
106 modest_mail_operation_send_new_mail (mail_operation,
110 idle_data->to, idle_data->cc, idle_data->bcc, idle_data->subject,
111 idle_data->body, /* plain_body */
112 NULL, /* html_body */
113 NULL, /* attachments_list, GSList of TnyMimePart. */
117 g_object_unref (G_OBJECT (mail_operation));
120 g_object_unref (G_OBJECT (transport_account));
123 g_free (account_name);
125 /* Free the idle data: */
126 g_free (idle_data->to);
127 g_free (idle_data->cc);
128 g_free (idle_data->bcc);
129 g_free (idle_data->subject);
130 g_free (idle_data->body);
131 g_free (idle_data->attachments);
134 return FALSE; /* Do not call this callback again. */
137 /* TODO: Is this actually used by anything?
138 * I guess that everything uses *_compose_mail() instead. murrayc.
140 static gint on_send_mail(GArray * arguments, gpointer data, osso_rpc_t * retval)
142 if (arguments->len != MODEST_DEBUS_SEND_MAIL_ARGS_COUNT)
145 /* Use g_idle to context-switch into the application's thread: */
146 SendMailIdleData *idle_data = g_new0(SendMailIdleData, 1); /* Freed in the idle callback. */
148 /* Get the arguments: */
149 osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_TO);
150 idle_data->to = g_strdup (val.value.s);
152 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_CC);
153 idle_data->cc = g_strdup (val.value.s);
155 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_BCC);
156 idle_data->bcc = g_strdup (val.value.s);
158 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_SUBJECT);
159 idle_data->subject = g_strdup (val.value.s);
161 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_BODY);
162 idle_data->body = g_strdup (val.value.s);
164 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_ATTACHMENTS);
165 idle_data->attachments = g_strdup (val.value.s);
167 /* printf(" debug: to=%s\n", idle_data->to); */
168 g_idle_add(on_idle_send_mail, (gpointer)idle_data);
170 /* Note that we cannot report failures during sending,
171 * because that would be asynchronous. */
176 * @uri An escaped URI. URIs should always be escaped.
177 * @len The length of the @uri string, or -1 if the string is null terminated.
179 * Decode a URI, or URI fragment, as per RFC 1738.
180 * http://www.ietf.org/rfc/rfc1738.txt
182 * Return value: An unescaped string. This should be freed with g_free().
184 static gchar* uri_unescape(const gchar* uri, size_t len)
192 /* Allocate an extra string so we can be sure that it is null-terminated,
193 * so we can use gnome_vfs_unescape_string().
194 * This is not efficient. */
195 gchar * escaped_nullterminated = g_strndup (uri, len);
196 gchar *result = gnome_vfs_unescape_string (escaped_nullterminated, NULL);
197 g_free (escaped_nullterminated);
202 /** uri_parse_mailto:
203 * @mailto A mailto URI, with the mailto: prefix.
204 * @list_items_and_values: A pointer to a list that should be filled with item namesand value strings,
205 * with each name item being followed by a value item. This list should be freed with g_slist_free) after
206 * all the string items have been freed. This parameter may be NULL.
207 * Parse a mailto URI as per RFC2368.
208 * http://www.ietf.org/rfc/rfc2368.txt
210 * Return value: The to address, unescaped. This should be freed with g_free().
212 static gchar* uri_parse_mailto (const gchar* mailto, GSList** list_items_and_values)
214 const gchar* start_to = NULL;
215 /* Remove the mailto: prefix:
216 * 7 is the length of "mailto:": */
217 if (strncmp (mailto, "mailto:", 7) == 0) {
218 start_to = mailto + 7;
224 /* Look for ?, or the end of the string, marking the end of the to address: */
225 const size_t len_to = strcspn (start_to, "?");
226 gchar* result_to = uri_unescape (start_to, len_to);
227 printf("debug: result_to=%s\n", result_to);
229 /* Get any other items: */
230 const size_t len_mailto = strlen (start_to);
231 const gchar* p = start_to + len_to + 1; /* parsed so far. */
232 const gchar* end = start_to + len_mailto;
233 /* GSList *items = NULL; */
234 const gchar* start_item_name = p;
235 size_t len_item_name = 0;
236 const gchar* start_item_value = NULL;
239 /* Looking for the end of a name; */
240 if (start_item_name) {
241 const size_t len = strcspn (p, "="); /* Returns whole string if none found. */
243 /* This marks the end of a name and the start of the value: */
246 /* Skip over the name and mark the start of the value: */
247 p += (len + 1); /* Skip over the = */
248 start_item_value = p;
252 /* Looking for the end of a value: */
253 if (start_item_value) {
254 const size_t len = strcspn (p, "?"); /* Returns whole string if none found. */
255 /* ? marks the start of a new item: */
257 if (start_item_name && len_item_name) {
258 /* Finish the previously-started item: */
259 gchar *item_value = uri_unescape (start_item_value, len);
260 gchar *item_name = g_strndup (start_item_name, len_item_name);
261 /* printf ("debug: item name=%s, value=%s\n", item_name, item_value); */
263 /* Append the items to the list */
264 if(list_items_and_values) {
265 *list_items_and_values = g_slist_append (*list_items_and_values, item_name);
266 *list_items_and_values = g_slist_append (*list_items_and_values, item_value);
270 /* Skip over the value and mark the start of a possible new name/value pair: */
271 p += (len + 1); /* Skip over the ? */
274 start_item_value = NULL;
285 on_idle_mail_to(gpointer user_data)
287 /* This is based on the implemenation of main.c:start_uil(): */
289 gchar *uri = (gchar*)user_data;
290 GSList *list_names_and_values = NULL;
291 gchar *to = uri_parse_mailto (uri, &list_names_and_values);
293 /* Get the TnyTransportAccount so we can instantiate a mail operation: */
294 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
295 gchar *account_name = modest_account_mgr_get_default_account (account_mgr);
297 g_printerr ("modest: no account found\n");
300 TnyAccount *account = NULL;
302 account = modest_tny_account_store_get_transport_account_for_open_connection (
303 modest_runtime_get_account_store(), account_name);
307 g_printerr ("modest: failed to get tny account folder'\n", account_name);
309 gchar * from = modest_account_mgr_get_from_string (account_mgr,
312 g_printerr ("modest: no from address for account '%s'\n", account_name);
314 const gchar *cc = NULL;
315 const gchar *bcc = NULL;
316 const gchar *subject = NULL;
317 const gchar *body = NULL;
319 /* Get the relevant items from the list: */
320 GSList *list = list_names_and_values;
322 const gchar * name = (const gchar*)list->data;
323 GSList *list_value = g_slist_next (list);
324 const gchar * value = (const gchar*)list_value->data;
326 if (strcmp (name, "cc") == 0) {
328 } else if (strcmp (name, "bcc") == 0) {
330 } else if (strcmp (name, "subject") == 0) {
332 } else if (strcmp (name, "body") == 0) {
336 /* Go to the next pair: */
338 list = g_slist_next (list_value);
343 /* Create the message: */
344 TnyMsg *msg = modest_tny_msg_new (to, from,
345 cc, bcc, subject, body,
346 NULL /* attachments */);
349 g_printerr ("modest: failed to create message\n");
352 /* Add the message to a folder and show its UI for editing: */
353 TnyFolder *folder = modest_tny_account_get_special_folder (account,
354 TNY_FOLDER_TYPE_DRAFTS);
356 g_printerr ("modest: failed to find Drafts folder\n");
359 tny_folder_add_msg (folder, msg, NULL); /* TODO: check err */
361 ModestWindow *win = modest_msg_edit_window_new (msg, account_name);
362 gtk_widget_show_all (GTK_WIDGET (win));
364 g_object_unref (G_OBJECT(folder));
367 g_object_unref (G_OBJECT(msg));
370 g_object_unref (G_OBJECT(account));
374 g_free (account_name);
376 /* Free the list, as required by the uri_parse_mailto() documentation: */
377 if (list_names_and_values)
378 g_slist_foreach (list_names_and_values, (GFunc)g_free, NULL);
379 g_slist_free (list_names_and_values);
385 return FALSE; /* Do not call this callback again. */
388 static gint on_mail_to(GArray * arguments, gpointer data, osso_rpc_t * retval)
390 if (arguments->len != MODEST_DEBUS_MAIL_TO_ARGS_COUNT)
393 /* Use g_idle to context-switch into the application's thread: */
395 /* Get the arguments: */
396 osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_MAIL_TO_ARG_URI);
397 gchar *uri = g_strdup (val.value.s);
399 /* printf(" debug: to=%s\n", idle_data->to); */
400 g_idle_add(on_idle_mail_to, (gpointer)uri);
402 /* Note that we cannot report failures during sending,
403 * because that would be asynchronous. */
412 on_idle_compose_mail(gpointer user_data)
414 ComposeMailIdleData *idle_data = (ComposeMailIdleData*)user_data;
418 /* Get the TnyTransportAccount so we can instantiate a mail operation: */
419 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
420 gchar *account_name = modest_account_mgr_get_default_account (account_mgr);
422 g_printerr ("modest: no account found\n");
425 TnyAccount *account = NULL;
427 account = modest_tny_account_store_get_transport_account_for_open_connection (
428 modest_runtime_get_account_store(), account_name);
432 g_printerr ("modest: failed to get tny account folder'%s'\n", account_name);
434 gchar * from = modest_account_mgr_get_from_string (account_mgr,
437 g_printerr ("modest: no from address for account '%s'\n", account_name);
440 /* Create the message: */
441 TnyMsg *msg = modest_tny_msg_new (idle_data->to, from,
442 idle_data->cc, idle_data->bcc, idle_data->subject, idle_data->body,
443 NULL); /* NULL because m_t_m_n doesn't use it */
446 g_printerr ("modest: failed to create message\n");
449 /* Add the message to a folder and show its UI for editing: */
450 TnyFolder *folder = modest_tny_account_get_special_folder (account,
451 TNY_FOLDER_TYPE_DRAFTS);
453 g_printerr ("modest: failed to find Drafts folder\n");
456 tny_folder_add_msg (folder, msg, NULL); /* TODO: check err */
458 ModestWindow *win = modest_msg_edit_window_new (msg, account_name);
460 list = g_strsplit(idle_data->attachments, ",", 0);
461 for (i=0; list[i] != NULL; i++) {
462 modest_msg_edit_window_attach_file_noninteractive(
463 (ModestMsgEditWindow *)win, list[i]);
467 gtk_widget_show_all (GTK_WIDGET (win));
469 g_object_unref (G_OBJECT(folder));
472 g_object_unref (G_OBJECT(msg));
475 g_object_unref (G_OBJECT(account));
479 /* Free the idle data: */
480 g_free (idle_data->to);
481 g_free (idle_data->cc);
482 g_free (idle_data->bcc);
483 g_free (idle_data->subject);
484 g_free (idle_data->body);
485 g_free (idle_data->attachments);
488 g_free (account_name);
489 return FALSE; /* Do not call this callback again. */
492 static gint on_compose_mail(GArray * arguments, gpointer data, osso_rpc_t * retval)
496 if (arguments->len != MODEST_DEBUS_COMPOSE_MAIL_ARGS_COUNT)
499 /* Use g_idle to context-switch into the application's thread: */
500 ComposeMailIdleData *idle_data = g_new0(ComposeMailIdleData, 1); /* Freed in the idle callback. */
502 /* Get the arguments: */
503 osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_TO);
504 idle_data->to = g_strdup (val.value.s);
506 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_CC);
507 idle_data->cc = g_strdup (val.value.s);
509 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_BCC);
510 idle_data->bcc = g_strdup (val.value.s);
512 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_SUBJECT);
513 idle_data->subject = g_strdup (val.value.s);
515 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_BODY);
516 idle_data->body = g_strdup (val.value.s);
518 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_ATTACHMENTS);
519 idle_data->attachments = g_strdup (val.value.s);
521 g_idle_add(on_idle_compose_mail, (gpointer)idle_data);
523 /* Note that we cannot report failures during sending,
524 * because that would be asynchronous. */
530 find_message_by_url (const char *uri, TnyAccount **ac_out)
532 ModestTnyAccountStore *astore;
541 astore = modest_runtime_get_account_store ();
543 if (astore == NULL) {
547 account = tny_account_store_find_account (TNY_ACCOUNT_STORE (astore),
550 if (account == NULL) {
551 g_debug ("%s: tny_account_store_find_account() failed.\n", __FUNCTION__);
555 g_debug ("%s: Found account.\n", __FUNCTION__);
557 if ( ! TNY_IS_STORE_ACCOUNT (account)) {
561 g_debug ("%s: Account is store account.\n", __FUNCTION__);
565 folder = tny_store_account_find_folder (TNY_STORE_ACCOUNT (account),
569 if (folder == NULL) {
570 g_debug ("%s: tny_store_account_find_folder() failed.\n", __FUNCTION__);
573 g_debug ("%s: Found folder. (%s)\n", __FUNCTION__, uri);
576 msg = tny_folder_find_msg (folder, uri, &err);
579 g_debug ("%s: tny_folder_find_msg() failed for folder %s\n with error=%s.\n",
580 __FUNCTION__, tny_folder_get_id (folder), err->message);
587 if (account && !msg) {
588 g_object_unref (account);
593 g_object_unref (folder);
600 on_idle_open_message (gpointer user_data)
602 ModestWindow *msg_view;
607 const char *account_name;
610 uri = (char *) user_data;
612 g_debug ("%s: Trying to find msg by url: %s", __FUNCTION__, uri);
613 msg = find_message_by_url (uri, &account);
617 g_debug (" %s: message not found.", __FUNCTION__);
620 g_debug (" %s: Found message.", __FUNCTION__);
622 header = tny_msg_get_header (msg);
623 account_name = tny_account_get_name (account);
624 msg_uid = tny_header_get_uid (header);
626 msg_view = modest_msg_view_window_new (msg,
629 /* TODO: does that leak the msg_view ?! */
631 gtk_widget_show_all (GTK_WIDGET (msg_view));
633 g_object_unref (header);
634 g_object_unref (account);
636 return FALSE; /* Do not call this callback again. */
639 static gint on_open_message(GArray * arguments, gpointer data, osso_rpc_t * retval)
641 if (arguments->len != MODEST_DEBUS_OPEN_MESSAGE_ARGS_COUNT)
644 /* Use g_idle to context-switch into the application's thread: */
646 /* Get the arguments: */
647 osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_OPEN_MESSAGE_ARG_URI);
648 gchar *uri = g_strdup (val.value.s);
650 /* printf(" debug: to=%s\n", idle_data->to); */
651 g_idle_add(on_idle_open_message, (gpointer)uri);
653 /* Note that we cannot report failures during sending,
654 * because that would be asynchronous. */
660 on_delete_message (GArray *arguments, gpointer data, osso_rpc_t *retval)
666 TnyHeader *msg_header;
675 if (arguments->len != MODEST_DEBUS_DELETE_MESSAGE_ARGS_COUNT) {
679 val = g_array_index (arguments,
681 MODEST_DEBUS_DELETE_MESSAGE_ARG_URI);
683 uri = (const char *) val.value.s;
685 g_debug ("Searching message (delete message)");
687 msg = find_message_by_url (uri, &account);
693 g_debug ("Found message");
695 msg_header = tny_msg_get_header (msg);
696 uid = tny_header_get_uid (msg_header);
697 folder = tny_msg_get_folder (msg);
700 /* tny_msg_get_header () flaw:
701 * From tinythingy doc: You can't use the returned instance with the
702 * TnyFolder operations
704 * To get a header instance that will work with these folder methods,
705 * you can use tny_folder_get_headers.
707 * Ok, we will do so then. Sigh.
709 headers = tny_simple_list_new ();
711 tny_folder_get_headers (folder, headers, TRUE, NULL);
712 iter = tny_list_create_iterator (headers);
715 g_debug ("Searching header for msg in folder");
716 while (!tny_iterator_is_done (iter)) {
719 header = TNY_HEADER (tny_iterator_get_current (iter));
720 cur_id = tny_header_get_uid (header);
722 if (cur_id && uid && g_str_equal (cur_id, uid)) {
723 g_debug ("Found correspoding header from folder");
728 g_object_unref (header);
729 tny_iterator_next (iter);
732 g_object_unref (iter);
733 g_object_unref (headers);
735 g_object_unref (msg_header);
736 g_object_unref (msg);
738 if (header == NULL) {
739 g_object_unref (folder);
746 tny_folder_remove_msg (folder, header, &error);
750 g_error_free (error);
753 g_object_unref (folder);
758 on_idle_send_receive(gpointer user_data)
762 /* Pick the main window if it exists */
763 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ());
765 /* Send & receive all if "Update automatically" is set */
766 /* TODO: check the auto-update parameter in the configuration */
767 modest_ui_actions_do_send_receive_all (win);
769 return FALSE; /* Do not call this callback again. */
772 static gint on_send_receive(GArray * arguments, gpointer data, osso_rpc_t * retval)
774 /* Use g_idle to context-switch into the application's thread: */
776 /* This method has no arguments. */
778 /* printf(" debug: to=%s\n", idle_data->to); */
779 g_idle_add(on_idle_send_receive, NULL);
781 /* Note that we cannot report failures during send/receive,
782 * because that would be asynchronous. */
787 on_idle_open_default_inbox(gpointer user_data)
790 modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ());
792 /* Get the folder view */
793 GtkWidget *folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
794 MODEST_WIDGET_TYPE_FOLDER_VIEW);
795 modest_folder_view_select_first_inbox_or_local (
796 MODEST_FOLDER_VIEW (folder_view));
798 return FALSE; /* Do not call this callback again. */
801 static gint on_open_default_inbox(GArray * arguments, gpointer data, osso_rpc_t * retval)
803 /* Use g_idle to context-switch into the application's thread: */
805 /* This method has no arguments. */
807 g_idle_add(on_idle_open_default_inbox, NULL);
809 /* Note that we cannot report failures during send/receive,
810 * because that would be asynchronous. */
814 /* Callback for normal D-BUS messages */
815 gint modest_dbus_req_handler(const gchar * interface, const gchar * method,
816 GArray * arguments, gpointer data,
820 g_debug ("debug: %s\n", __FUNCTION__);
821 g_debug ("debug: %s: method received: %s\n", __FUNCTION__, method);
823 if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_SEND_MAIL) == 0) {
824 return on_send_mail (arguments, data, retval);
825 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_MAIL_TO) == 0) {
826 return on_mail_to (arguments, data, retval);
827 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_OPEN_MESSAGE) == 0) {
828 return on_open_message (arguments, data, retval);
829 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_SEND_RECEIVE) == 0) {
830 return on_send_receive (arguments, data, retval);
831 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_COMPOSE_MAIL) == 0) {
832 return on_compose_mail (arguments, data, retval);
833 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_DELETE_MESSAGE) == 0) {
834 return on_delete_message (arguments,data, retval);
835 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_OPEN_DEFAULT_INBOX) == 0) {
836 return on_open_default_inbox (arguments, data, retval);
839 /* We need to return INVALID here so
840 * osso is returning DBUS_HANDLER_RESULT_NOT_YET_HANDLED
841 * so our modest_dbus_req_filter can kick in!
847 #define SEARCH_HIT_DBUS_TYPE \
848 DBUS_STRUCT_BEGIN_CHAR_AS_STRING \
849 DBUS_TYPE_STRING_AS_STRING \
850 DBUS_TYPE_STRING_AS_STRING \
851 DBUS_TYPE_STRING_AS_STRING \
852 DBUS_TYPE_STRING_AS_STRING \
853 DBUS_TYPE_UINT64_AS_STRING \
854 DBUS_TYPE_BOOLEAN_AS_STRING \
855 DBUS_TYPE_BOOLEAN_AS_STRING \
856 DBUS_TYPE_INT64_AS_STRING \
857 DBUS_STRUCT_END_CHAR_AS_STRING
860 search_result_to_message (DBusMessage *reply,
863 DBusMessageIter iter;
864 DBusMessageIter array_iter;
867 dbus_message_iter_init_append (reply, &iter);
868 dbus_message_iter_open_container (&iter,
870 SEARCH_HIT_DBUS_TYPE,
873 for (hit_iter = hits; hit_iter; hit_iter = hit_iter->next) {
874 DBusMessageIter struct_iter;
875 ModestSearchHit *hit;
881 gboolean has_attachment;
885 hit = (ModestSearchHit *) hit_iter->data;
887 msg_url = hit->msgid;
888 subject = hit->subject;
889 folder = hit->folder;
890 sender = hit->sender;
892 has_attachment = hit->has_attachment;
893 is_unread = hit->is_unread;
896 g_debug ("DEBUG: %s: Adding hit: %s", __FUNCTION__, msg_url);
898 dbus_message_iter_open_container (&array_iter,
903 dbus_message_iter_append_basic (&struct_iter,
907 dbus_message_iter_append_basic (&struct_iter,
911 dbus_message_iter_append_basic (&struct_iter,
915 dbus_message_iter_append_basic (&struct_iter,
919 dbus_message_iter_append_basic (&struct_iter,
923 dbus_message_iter_append_basic (&struct_iter,
927 dbus_message_iter_append_basic (&struct_iter,
931 dbus_message_iter_append_basic (&struct_iter,
935 dbus_message_iter_close_container (&array_iter,
939 g_free (hit->subject);
940 g_free (hit->folder);
941 g_free (hit->sender);
943 g_slice_free (ModestSearchHit, hit);
946 dbus_message_iter_close_container (&iter, &array_iter);
952 modest_dbus_req_filter (DBusConnection *con,
953 DBusMessage *message,
956 gboolean handled = FALSE;
959 if (dbus_message_is_method_call (message,
961 MODEST_DBUS_METHOD_SEARCH)) {
962 ModestDBusSearchFlags dbus_flags;
964 DBusMessage *reply = NULL;
968 dbus_int32_t flags_v;
969 dbus_uint32_t serial;
970 dbus_uint32_t size_v;
979 dbus_error_init (&error);
984 res = dbus_message_get_args (message,
986 DBUS_TYPE_STRING, &query,
987 DBUS_TYPE_STRING, &folder,
988 DBUS_TYPE_INT64, &sd_v,
989 DBUS_TYPE_INT64, &ed_v,
990 DBUS_TYPE_INT32, &flags_v,
991 DBUS_TYPE_UINT32, &size_v,
994 dbus_flags = (ModestDBusSearchFlags) flags_v;
995 start_date = (time_t) sd_v;
996 end_date = (time_t) ed_v;
998 memset (&search, 0, sizeof (search));
999 #ifdef MODEST_HAVE_OGS
1000 search.query = query;
1002 search.before = start_date;
1003 search.after = end_date;
1006 if (dbus_flags & MODEST_DBUS_SEARCH_SUBJECT) {
1007 search.flags |= MODEST_SEARCH_SUBJECT;
1008 search.subject = query;
1011 if (dbus_flags & MODEST_DBUS_SEARCH_SENDER) {
1012 search.flags |= MODEST_SEARCH_SENDER;
1013 search.from = query;
1016 if (dbus_flags & MODEST_DBUS_SEARCH_RECIPIENT) {
1017 search.flags |= MODEST_SEARCH_RECIPIENT;
1018 search.recipient = query;
1021 if (dbus_flags & MODEST_DBUS_SEARCH_BODY) {
1022 search.flags |= MODEST_SEARCH_BODY;
1023 search.subject = query;
1027 search.flags |= MODEST_SEARCH_BEFORE;
1028 search.before = start_date;
1032 search.flags |= MODEST_SEARCH_AFTER;
1033 search.after = end_date;
1037 search.flags |= MODEST_SEARCH_SIZE;
1038 search.minsize = size_v;
1041 #ifdef MODEST_HAVE_OGS
1042 search.flags |= MODEST_SEARCH_USE_OGS;
1043 g_debug ("Starting search for %s", search.query);
1045 hits = modest_search_all_accounts (&search);
1047 reply = dbus_message_new_method_return (message);
1049 search_result_to_message (reply, hits);
1051 if (reply == NULL) {
1052 g_warning ("Could not create reply");
1056 dbus_connection_send (con, reply, &serial);
1057 dbus_connection_flush (con);
1058 dbus_message_unref (reply);
1067 DBUS_HANDLER_RESULT_HANDLED :
1068 DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
1073 modest_osso_cb_hw_state_handler(osso_hw_state_t *state, gpointer data)
1076 /* printf("%s()\n", __PRETTY_FUNCTION__); */
1078 if(state->system_inactivity_ind)
1081 else if(state->save_unsaved_data_ind)
1089 /* printf("debug: %s(): return\n", __PRETTY_FUNCTION__); */