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"
36 #include "modest-search.h"
37 #include "widgets/modest-msg-edit-window.h"
38 #include "modest-tny-msg.h"
39 #include <libmodest-dbus-client/libmodest-dbus-client.h>
40 #include <libgnomevfs/gnome-vfs-utils.h>
45 #include <tny-iterator.h>
46 #include <tny-simple-list.h>
65 } ComposeMailIdleData;
68 on_idle_send_mail(gpointer user_data)
70 SendMailIdleData *idle_data = (SendMailIdleData*)user_data;
72 /* Get the TnyTransportAccount so we can instantiate a mail operation: */
73 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
74 gchar *account_name = modest_account_mgr_get_default_account (account_mgr);
76 g_printerr ("modest: no account found\n");
79 TnyTransportAccount *transport_account = NULL;
81 transport_account = TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
82 (modest_runtime_get_account_store(),
86 if (!transport_account) {
87 g_printerr ("modest: no transport account found for '%s'\n", account_name);
90 /* Create the mail operation: */
91 if (transport_account) {
92 /* Use the mail operation: */
93 gchar * from = modest_account_mgr_get_from_string (account_mgr,
96 g_printerr ("modest: no from address for account '%s'\n", account_name);
98 ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, NULL);
99 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
101 modest_mail_operation_send_new_mail (mail_operation,
104 idle_data->to, idle_data->cc, idle_data->bcc, idle_data->subject,
105 idle_data->body, /* plain_body */
106 NULL, /* html_body */
107 NULL, /* attachments_list, GSList of TnyMimePart. */
111 g_object_unref (G_OBJECT (mail_operation));
114 g_object_unref (G_OBJECT (transport_account));
117 g_free (account_name);
119 /* Free the idle data: */
120 g_free (idle_data->to);
121 g_free (idle_data->cc);
122 g_free (idle_data->bcc);
123 g_free (idle_data->subject);
124 g_free (idle_data->body);
127 return FALSE; /* Do not call this callback again. */
130 static gint on_send_mail(GArray * arguments, gpointer data, osso_rpc_t * retval)
132 if (arguments->len != MODEST_DEBUS_SEND_MAIL_ARGS_COUNT)
135 /* Use g_idle to context-switch into the application's thread: */
136 SendMailIdleData *idle_data = g_new0(SendMailIdleData, 1); /* Freed in the idle callback. */
138 /* Get the arguments: */
139 osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_TO);
140 idle_data->to = g_strdup (val.value.s);
142 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_CC);
143 idle_data->cc = g_strdup (val.value.s);
145 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_BCC);
146 idle_data->bcc = g_strdup (val.value.s);
148 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_SUBJECT);
149 idle_data->subject = g_strdup (val.value.s);
151 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_BODY);
152 idle_data->body = g_strdup (val.value.s);
154 /* printf(" debug: to=%s\n", idle_data->to); */
155 g_idle_add(on_idle_send_mail, (gpointer)idle_data);
157 /* Note that we cannot report failures during sending,
158 * because that would be asynchronous. */
163 * @uri An escaped URI. URIs should always be escaped.
164 * @len The length of the @uri string, or -1 if the string is null terminated.
166 * Decode a URI, or URI fragment, as per RFC 1738.
167 * http://www.ietf.org/rfc/rfc1738.txt
169 * Return value: An unescaped string. This should be freed with g_free().
171 static gchar* uri_unescape(const gchar* uri, size_t len)
179 /* Allocate an extra string so we can be sure that it is null-terminated,
180 * so we can use gnome_vfs_unescape_string().
181 * This is not efficient. */
182 gchar * escaped_nullterminated = g_strndup (uri, len);
183 gchar *result = gnome_vfs_unescape_string (escaped_nullterminated, NULL);
184 g_free (escaped_nullterminated);
189 /** uri_parse_mailto:
190 * @mailto A mailto URI, with the mailto: prefix.
191 * @list_items_and_values: A pointer to a list that should be filled with item namesand value strings,
192 * with each name item being followed by a value item. This list should be freed with g_slist_free) after
193 * all the string items have been freed. This parameter may be NULL.
194 * Parse a mailto URI as per RFC2368.
195 * http://www.ietf.org/rfc/rfc2368.txt
197 * Return value: The to address, unescaped. This should be freed with g_free().
199 static gchar* uri_parse_mailto (const gchar* mailto, GSList** list_items_and_values)
201 const gchar* start_to = NULL;
202 /* Remove the mailto: prefix:
203 * 7 is the length of "mailto:": */
204 if (strncmp (mailto, "mailto:", 7) == 0) {
205 start_to = mailto + 7;
211 /* Look for ?, or the end of the string, marking the end of the to address: */
212 const size_t len_to = strcspn (start_to, "?");
213 gchar* result_to = uri_unescape (start_to, len_to);
214 printf("debug: result_to=%s\n", result_to);
216 /* Get any other items: */
217 const size_t len_mailto = strlen (start_to);
218 const gchar* p = start_to + len_to + 1; /* parsed so far. */
219 const gchar* end = start_to + len_mailto;
220 /* GSList *items = NULL; */
221 const gchar* start_item_name = p;
222 size_t len_item_name = 0;
223 const gchar* start_item_value = NULL;
226 /* Looking for the end of a name; */
227 if (start_item_name) {
228 const size_t len = strcspn (p, "="); /* Returns whole string if none found. */
230 /* This marks the end of a name and the start of the value: */
233 /* Skip over the name and mark the start of the value: */
234 p += (len + 1); /* Skip over the = */
235 start_item_value = p;
239 /* Looking for the end of a value: */
240 if (start_item_value) {
241 const size_t len = strcspn (p, "?"); /* Returns whole string if none found. */
242 /* ? marks the start of a new item: */
244 if (start_item_name && len_item_name) {
245 /* Finish the previously-started item: */
246 gchar *item_value = uri_unescape (start_item_value, len);
247 gchar *item_name = g_strndup (start_item_name, len_item_name);
248 /* printf ("debug: item name=%s, value=%s\n", item_name, item_value); */
250 /* Append the items to the list */
251 if(list_items_and_values) {
252 *list_items_and_values = g_slist_append (*list_items_and_values, item_name);
253 *list_items_and_values = g_slist_append (*list_items_and_values, item_value);
257 /* Skip over the value and mark the start of a possible new name/value pair: */
258 p += (len + 1); /* Skip over the ? */
261 start_item_value = NULL;
272 on_idle_mail_to(gpointer user_data)
274 /* This is based on the implemenation of main.c:start_uil(): */
276 gchar *uri = (gchar*)user_data;
277 GSList *list_names_and_values = NULL;
278 gchar *to = uri_parse_mailto (uri, &list_names_and_values);
280 /* Get the TnyTransportAccount so we can instantiate a mail operation: */
281 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
282 gchar *account_name = modest_account_mgr_get_default_account (account_mgr);
284 g_printerr ("modest: no account found\n");
287 TnyAccount *account = NULL;
289 account = modest_tny_account_store_get_transport_account_for_open_connection (
290 modest_runtime_get_account_store(), account_name);
294 g_printerr ("modest: failed to get tny account folder'\n", account_name);
296 gchar * from = modest_account_mgr_get_from_string (account_mgr,
299 g_printerr ("modest: no from address for account '%s'\n", account_name);
301 const gchar *cc = NULL;
302 const gchar *bcc = NULL;
303 const gchar *subject = NULL;
304 const gchar *body = NULL;
306 /* Get the relevant items from the list: */
307 GSList *list = list_names_and_values;
309 const gchar * name = (const gchar*)list->data;
310 GSList *list_value = g_slist_next (list);
311 const gchar * value = (const gchar*)list_value->data;
313 if (strcmp (name, "cc") == 0) {
315 } else if (strcmp (name, "bcc") == 0) {
317 } else if (strcmp (name, "subject") == 0) {
319 } else if (strcmp (name, "body") == 0) {
323 /* Go to the next pair: */
325 list = g_slist_next (list_value);
330 /* Create the message: */
331 TnyMsg *msg = modest_tny_msg_new (to, from,
332 cc, bcc, subject, body,
333 NULL /* attachments */);
336 g_printerr ("modest: failed to create message\n");
339 /* Add the message to a folder and show its UI for editing: */
340 TnyFolder *folder = modest_tny_account_get_special_folder (account,
341 TNY_FOLDER_TYPE_DRAFTS);
343 g_printerr ("modest: failed to find Drafts folder\n");
346 tny_folder_add_msg (folder, msg, NULL); /* TODO: check err */
348 ModestWindow *win = modest_msg_edit_window_new (msg, account_name);
349 gtk_widget_show_all (GTK_WIDGET (win));
351 g_object_unref (G_OBJECT(folder));
354 g_object_unref (G_OBJECT(msg));
357 g_object_unref (G_OBJECT(account));
361 g_free (account_name);
363 /* Free the list, as required by the uri_parse_mailto() documentation: */
364 if (list_names_and_values)
365 g_slist_foreach (list_names_and_values, (GFunc)g_free, NULL);
366 g_slist_free (list_names_and_values);
372 return FALSE; /* Do not call this callback again. */
375 static gint on_mail_to(GArray * arguments, gpointer data, osso_rpc_t * retval)
377 if (arguments->len != MODEST_DEBUS_MAIL_TO_ARGS_COUNT)
380 /* Use g_idle to context-switch into the application's thread: */
382 /* Get the arguments: */
383 osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_MAIL_TO_ARG_URI);
384 gchar *uri = g_strdup (val.value.s);
386 /* printf(" debug: to=%s\n", idle_data->to); */
387 g_idle_add(on_idle_mail_to, (gpointer)uri);
389 /* Note that we cannot report failures during sending,
390 * because that would be asynchronous. */
396 on_idle_compose_mail(gpointer user_data)
398 ComposeMailIdleData *idle_data = (ComposeMailIdleData*)user_data;
400 /* Get the TnyTransportAccount so we can instantiate a mail operation: */
401 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
402 gchar *account_name = modest_account_mgr_get_default_account (account_mgr);
404 g_printerr ("modest: no account found\n");
407 TnyAccount *account = NULL;
409 account = modest_tny_account_store_get_transport_account_for_open_connection (
410 modest_runtime_get_account_store(), account_name);
414 g_printerr ("modest: failed to get tny account folder'\n", account_name);
416 gchar * from = modest_account_mgr_get_from_string (account_mgr,
419 g_printerr ("modest: no from address for account '%s'\n", account_name);
422 /* Create the message: */
423 TnyMsg *msg = modest_tny_msg_new (idle_data->to, from,
424 idle_data->cc, idle_data->bcc, idle_data->subject, idle_data->body,
425 idle_data->attachments);
428 g_printerr ("modest: failed to create message\n");
431 /* Add the message to a folder and show its UI for editing: */
432 TnyFolder *folder = modest_tny_account_get_special_folder (account,
433 TNY_FOLDER_TYPE_DRAFTS);
435 g_printerr ("modest: failed to find Drafts folder\n");
438 tny_folder_add_msg (folder, msg, NULL); /* TODO: check err */
440 ModestWindow *win = modest_msg_edit_window_new (msg, account_name);
441 gtk_widget_show_all (GTK_WIDGET (win));
443 g_object_unref (G_OBJECT(folder));
446 g_object_unref (G_OBJECT(msg));
449 g_object_unref (G_OBJECT(account));
453 /* Free the idle data: */
454 g_free (idle_data->to);
455 g_free (idle_data->cc);
456 g_free (idle_data->bcc);
457 g_free (idle_data->subject);
458 g_free (idle_data->body);
459 g_free (idle_data->attachments);
462 g_free (account_name);
463 return FALSE; /* Do not call this callback again. */
466 static gint on_compose_mail(GArray * arguments, gpointer data, osso_rpc_t * retval)
471 if (arguments->len != MODEST_DEBUS_COMPOSE_MAIL_ARGS_COUNT)
474 /* Use g_idle to context-switch into the application's thread: */
475 ComposeMailIdleData *idle_data = g_new0(ComposeMailIdleData, 1); /* Freed in the idle callback. */
477 /* Get the arguments: */
478 osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_TO);
479 idle_data->to = g_strdup (val.value.s);
481 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_CC);
482 idle_data->cc = g_strdup (val.value.s);
484 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_BCC);
485 idle_data->bcc = g_strdup (val.value.s);
487 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_SUBJECT);
488 idle_data->subject = g_strdup (val.value.s);
490 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_BODY);
491 idle_data->body = g_strdup (val.value.s);
493 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_ATTACHMENTS);
494 gchar *attachments_str = g_strdup (val.value.s);
496 list = g_strsplit(attachments_str, ",", 0);
497 for (i=0; list[i] != NULL; i++) {
498 idle_data->attachments = g_slist_append(idle_data->attachments, g_strdup(list[i]));
503 /* printf(" debug: to=%s\n", idle_data->to); */
504 g_idle_add(on_idle_compose_mail, (gpointer)idle_data);
506 /* Note that we cannot report failures during sending,
507 * because that would be asynchronous. */
513 find_message_by_url (const char *uri, TnyAccount **ac_out)
516 ModestTnyAccountStore *astore;
525 astore = modest_runtime_get_account_store ();
527 if (astore == NULL) {
531 g_debug ("Got AccountStore, lets go");
533 account = tny_account_store_find_account (TNY_ACCOUNT_STORE (astore),
536 if (account == NULL) {
540 g_debug ("Found account");
542 if ( ! TNY_IS_STORE_ACCOUNT (account)) {
546 g_debug ("Account is store account");
550 folder = tny_store_account_find_folder (TNY_STORE_ACCOUNT (account),
554 if (folder == NULL) {
557 g_debug ("Found folder");
560 msg = tny_folder_find_msg (folder, uri, NULL);
563 if (account && !msg) {
564 g_object_unref (account);
569 g_object_unref (folder);
576 on_idle_open_message (gpointer user_data)
578 ModestWindow *msg_view;
583 const char *account_name;
586 uri = (char *) user_data;
588 g_debug ("Trying to find msg by url: %s", uri);
589 msg = find_message_by_url (uri, &account);
595 g_debug ("Found message");
597 header = tny_msg_get_header (msg);
598 account_name = tny_account_get_name (account);
599 msg_uid = tny_header_get_uid (header);
601 msg_view = modest_msg_view_window_new (msg,
604 /* TODO: does that leak the msg_view ?! */
606 gtk_widget_show_all (GTK_WIDGET (msg_view));
608 g_object_unref (header);
609 g_object_unref (account);
611 return FALSE; /* Do not call this callback again. */
614 static gint on_open_message(GArray * arguments, gpointer data, osso_rpc_t * retval)
616 if (arguments->len != MODEST_DEBUS_OPEN_MESSAGE_ARGS_COUNT)
619 /* Use g_idle to context-switch into the application's thread: */
621 /* Get the arguments: */
622 osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_OPEN_MESSAGE_ARG_URI);
623 gchar *uri = g_strdup (val.value.s);
625 /* printf(" debug: to=%s\n", idle_data->to); */
626 g_idle_add(on_idle_open_message, (gpointer)uri);
628 /* Note that we cannot report failures during sending,
629 * because that would be asynchronous. */
635 on_delete_message (GArray *arguments, gpointer data, osso_rpc_t *retval)
641 TnyHeader *msg_header;
650 if (arguments->len != MODEST_DEBUS_DELETE_MESSAGE_ARGS_COUNT) {
654 val = g_array_index (arguments,
656 MODEST_DEBUS_DELETE_MESSAGE_ARG_URI);
658 uri = (const char *) val.value.s;
660 g_debug ("Searching message (delete message)");
662 msg = find_message_by_url (uri, &account);
668 g_debug ("Found message");
670 msg_header = tny_msg_get_header (msg);
671 uid = tny_header_get_uid (msg_header);
672 folder = tny_msg_get_folder (msg);
675 /* tny_msg_get_header () flaw:
676 * From tinythingy doc: You can't use the returned instance with the
677 * TnyFolder operations
679 * To get a header instance that will work with these folder methods,
680 * you can use tny_folder_get_headers.
682 * Ok, we will do so then. Sigh.
684 headers = tny_simple_list_new ();
686 tny_folder_get_headers (folder, headers, TRUE, NULL);
687 iter = tny_list_create_iterator (headers);
690 g_debug ("Searching header for msg in folder");
691 while (!tny_iterator_is_done (iter)) {
694 header = TNY_HEADER (tny_iterator_get_current (iter));
695 cur_id = tny_header_get_uid (header);
697 if (cur_id && uid && g_str_equal (cur_id, uid)) {
698 g_debug ("Found correspoding header from folder");
703 g_object_unref (header);
704 tny_iterator_next (iter);
707 g_object_unref (iter);
708 g_object_unref (headers);
710 g_object_unref (msg_header);
711 g_object_unref (msg);
713 if (header == NULL) {
714 g_object_unref (folder);
721 tny_folder_remove_msg (folder, header, &error);
725 g_error_free (error);
728 g_object_unref (folder);
733 on_idle_send_receive(gpointer user_data)
737 /* Pick the main window if it exists */
738 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ());
740 /* Send & receive all if "Update automatically" is set */
741 /* TODO: check the auto-update parameter in the configuration */
742 modest_ui_actions_do_send_receive_all (win);
744 return FALSE; /* Do not call this callback again. */
747 static gint on_send_receive(GArray * arguments, gpointer data, osso_rpc_t * retval)
749 /* Use g_idle to context-switch into the application's thread: */
751 /* This method has no arguments. */
753 /* printf(" debug: to=%s\n", idle_data->to); */
754 g_idle_add(on_idle_send_receive, NULL);
756 /* Note that we cannot report failures during send/receive,
757 * because that would be asynchronous. */
761 /* Callback for normal D-BUS messages */
762 gint modest_dbus_req_handler(const gchar * interface, const gchar * method,
763 GArray * arguments, gpointer data,
767 g_debug ("modest_dbus_req_handler()\n");
768 g_debug ("debug: method received: %s\n", method);
770 if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_SEND_MAIL) == 0) {
771 return on_send_mail (arguments, data, retval);
772 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_MAIL_TO) == 0) {
773 return on_mail_to (arguments, data, retval);
774 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_OPEN_MESSAGE) == 0) {
775 return on_open_message (arguments, data, retval);
776 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_SEND_RECEIVE) == 0) {
777 return on_send_receive (arguments, data, retval);
778 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_COMPOSE_MAIL) == 0) {
779 return on_compose_mail (arguments, data, retval);
780 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_DELETE_MESSAGE) == 0) {
781 return on_delete_message (arguments,data, retval);
784 /* We need to return INVALID here so
785 * osso is returning DBUS_HANDLER_RESULT_NOT_YET_HANDLED
786 * so our modest_dbus_req_filter can kick in!
792 #define SEARCH_HIT_DBUS_TYPE \
793 DBUS_STRUCT_BEGIN_CHAR_AS_STRING \
794 DBUS_TYPE_STRING_AS_STRING \
795 DBUS_TYPE_STRING_AS_STRING \
796 DBUS_TYPE_STRING_AS_STRING \
797 DBUS_TYPE_STRING_AS_STRING \
798 DBUS_TYPE_UINT64_AS_STRING \
799 DBUS_TYPE_BOOLEAN_AS_STRING \
800 DBUS_TYPE_BOOLEAN_AS_STRING \
801 DBUS_TYPE_INT64_AS_STRING \
802 DBUS_STRUCT_END_CHAR_AS_STRING
805 search_result_to_messsage (DBusMessage *reply,
808 DBusMessageIter iter;
809 DBusMessageIter array_iter;
812 dbus_message_iter_init_append (reply, &iter);
813 dbus_message_iter_open_container (&iter,
815 SEARCH_HIT_DBUS_TYPE,
818 for (hit_iter = hits; hit_iter; hit_iter = hit_iter->next) {
819 DBusMessageIter struct_iter;
820 ModestSearchHit *hit;
826 gboolean has_attachment;
830 hit = (ModestSearchHit *) hit_iter->data;
832 msg_url = hit->msgid;
833 subject = hit->subject;
834 folder = hit->folder;
835 sender = hit->sender;
837 has_attachment = hit->has_attachment;
838 is_unread = hit->is_unread;
841 g_debug ("Adding hit: %s", msg_url);
843 dbus_message_iter_open_container (&array_iter,
848 dbus_message_iter_append_basic (&struct_iter,
852 dbus_message_iter_append_basic (&struct_iter,
856 dbus_message_iter_append_basic (&struct_iter,
860 dbus_message_iter_append_basic (&struct_iter,
864 dbus_message_iter_append_basic (&struct_iter,
868 dbus_message_iter_append_basic (&struct_iter,
872 dbus_message_iter_append_basic (&struct_iter,
876 dbus_message_iter_append_basic (&struct_iter,
880 dbus_message_iter_close_container (&array_iter,
884 g_free (hit->subject);
885 g_free (hit->folder);
886 g_free (hit->sender);
888 g_slice_free (ModestSearchHit, hit);
891 dbus_message_iter_close_container (&iter, &array_iter);
897 modest_dbus_req_filter (DBusConnection *con,
898 DBusMessage *message,
901 gboolean handled = FALSE;
904 if (dbus_message_is_method_call (message,
906 MODEST_DBUS_METHOD_SEARCH)) {
907 ModestDBusSearchFlags dbus_flags;
909 DBusMessage *reply = NULL;
913 dbus_int32_t flags_v;
914 dbus_uint32_t serial;
915 dbus_uint32_t size_v;
924 dbus_error_init (&error);
929 res = dbus_message_get_args (message,
931 DBUS_TYPE_STRING, &query,
932 DBUS_TYPE_STRING, &folder,
933 DBUS_TYPE_INT64, &sd_v,
934 DBUS_TYPE_INT64, &ed_v,
935 DBUS_TYPE_INT32, &flags_v,
936 DBUS_TYPE_UINT32, &size_v,
939 dbus_flags = (ModestDBusSearchFlags) flags_v;
940 start_date = (time_t) sd_v;
941 end_date = (time_t) ed_v;
943 memset (&search, 0, sizeof (search));
944 #ifdef MODEST_HAVE_OGS
945 search.query = query;
947 search.before = start_date;
948 search.after = end_date;
951 if (dbus_flags & MODEST_DBUS_SEARCH_SUBJECT) {
952 search.flags |= MODEST_SEARCH_SUBJECT;
953 search.subject = query;
956 if (dbus_flags & MODEST_DBUS_SEARCH_SENDER) {
957 search.flags |= MODEST_SEARCH_SENDER;
961 if (dbus_flags & MODEST_DBUS_SEARCH_RECIPIENT) {
962 search.flags |= MODEST_SEARCH_RECIPIENT;
963 search.recipient = query;
966 if (dbus_flags & MODEST_DBUS_SEARCH_BODY) {
967 search.flags |= MODEST_SEARCH_BODY;
968 search.subject = query;
972 search.flags |= MODEST_SEARCH_BEFORE;
973 search.before = start_date;
977 search.flags |= MODEST_SEARCH_AFTER;
978 search.after = end_date;
982 search.flags |= MODEST_SEARCH_SIZE;
983 search.minsize = size_v;
986 #ifdef MODEST_HAVE_OGS
987 search.flags |= MODEST_SEARCH_USE_OGS;
988 g_debug ("Starting search for %s", search.query);
990 hits = modest_search_all_accounts (&search);
992 reply = dbus_message_new_method_return (message);
994 search_result_to_messsage (reply, hits);
997 g_warning ("Could not create reply");
1001 dbus_connection_send (con, reply, &serial);
1002 dbus_connection_flush (con);
1003 dbus_message_unref (reply);
1012 DBUS_HANDLER_RESULT_HANDLED :
1013 DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
1017 modest_osso_cb_hw_state_handler(osso_hw_state_t *state, gpointer data)
1020 /* printf("%s()\n", __PRETTY_FUNCTION__); */
1022 if(state->system_inactivity_ind)
1025 else if(state->save_unsaved_data_ind)
1033 /* printf("debug: %s(): return\n", __PRETTY_FUNCTION__); */