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>
61 } ComposeMailIdleData;
64 on_idle_send_mail(gpointer user_data)
66 SendMailIdleData *idle_data = (SendMailIdleData*)user_data;
68 /* Get the TnyTransportAccount so we can instantiate a mail operation: */
69 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
70 gchar *account_name = modest_account_mgr_get_default_account (account_mgr);
72 g_printerr ("modest: no account found\n");
75 TnyTransportAccount *transport_account = NULL;
77 transport_account = TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
78 (modest_runtime_get_account_store(),
82 if (!transport_account) {
83 g_printerr ("modest: no transport account found for '%s'\n", account_name);
86 /* Create the mail operation: */
87 if (transport_account) {
88 /* Use the mail operation: */
89 gchar * from = modest_account_mgr_get_from_string (account_mgr,
92 g_printerr ("modest: no from address for account '%s'\n", account_name);
94 ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, NULL);
95 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
97 modest_mail_operation_send_new_mail (mail_operation,
100 idle_data->to, idle_data->cc, idle_data->bcc, idle_data->subject,
101 idle_data->body, /* plain_body */
102 NULL, /* html_body */
103 NULL, /* attachments_list, GSList of TnyMimePart. */
107 g_object_unref (G_OBJECT (mail_operation));
110 g_object_unref (G_OBJECT (transport_account));
113 g_free (account_name);
115 /* Free the idle data: */
116 g_free (idle_data->to);
117 g_free (idle_data->cc);
118 g_free (idle_data->bcc);
119 g_free (idle_data->subject);
120 g_free (idle_data->body);
123 return FALSE; /* Do not call this callback again. */
126 static gint on_send_mail(GArray * arguments, gpointer data, osso_rpc_t * retval)
128 if (arguments->len != MODEST_DEBUS_SEND_MAIL_ARGS_COUNT)
131 /* Use g_idle to context-switch into the application's thread: */
132 SendMailIdleData *idle_data = g_new0(SendMailIdleData, 1); /* Freed in the idle callback. */
134 /* Get the arguments: */
135 osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_TO);
136 idle_data->to = g_strdup (val.value.s);
138 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_CC);
139 idle_data->cc = g_strdup (val.value.s);
141 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_BCC);
142 idle_data->bcc = g_strdup (val.value.s);
144 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_SUBJECT);
145 idle_data->subject = g_strdup (val.value.s);
147 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_BODY);
148 idle_data->body = g_strdup (val.value.s);
150 /* printf(" debug: to=%s\n", idle_data->to); */
151 g_idle_add(on_idle_send_mail, (gpointer)idle_data);
153 /* Note that we cannot report failures during sending,
154 * because that would be asynchronous. */
159 * @uri An escaped URI. URIs should always be escaped.
160 * @len The length of the @uri string, or -1 if the string is null terminated.
162 * Decode a URI, or URI fragment, as per RFC 1738.
163 * http://www.ietf.org/rfc/rfc1738.txt
165 * Return value: An unescaped string. This should be freed with g_free().
167 static gchar* uri_unescape(const gchar* uri, size_t len)
175 /* Allocate an extra string so we can be sure that it is null-terminated,
176 * so we can use gnome_vfs_unescape_string().
177 * This is not efficient. */
178 gchar * escaped_nullterminated = g_strndup (uri, len);
179 gchar *result = gnome_vfs_unescape_string (escaped_nullterminated, NULL);
180 g_free (escaped_nullterminated);
185 /** uri_parse_mailto:
186 * @mailto A mailto URI, with the mailto: prefix.
187 * @list_items_and_values: A pointer to a list that should be filled with item namesand value strings,
188 * with each name item being followed by a value item. This list should be freed with g_slist_free) after
189 * all the string items have been freed. This parameter may be NULL.
190 * Parse a mailto URI as per RFC2368.
191 * http://www.ietf.org/rfc/rfc2368.txt
193 * Return value: The to address, unescaped. This should be freed with g_free().
195 static gchar* uri_parse_mailto (const gchar* mailto, GSList** list_items_and_values)
197 const gchar* start_to = NULL;
198 /* Remove the mailto: prefix:
199 * 7 is the length of "mailto:": */
200 if (strncmp (mailto, "mailto:", 7) == 0) {
201 start_to = mailto + 7;
207 /* Look for ?, or the end of the string, marking the end of the to address: */
208 const size_t len_to = strcspn (start_to, "?");
209 gchar* result_to = uri_unescape (start_to, len_to);
210 printf("debug: result_to=%s\n", result_to);
212 /* Get any other items: */
213 const size_t len_mailto = strlen (start_to);
214 const gchar* p = start_to + len_to + 1; /* parsed so far. */
215 const gchar* end = start_to + len_mailto;
216 /* GSList *items = NULL; */
217 const gchar* start_item_name = p;
218 size_t len_item_name = 0;
219 const gchar* start_item_value = NULL;
222 /* Looking for the end of a name; */
223 if (start_item_name) {
224 const size_t len = strcspn (p, "="); /* Returns whole string if none found. */
226 /* This marks the end of a name and the start of the value: */
229 /* Skip over the name and mark the start of the value: */
230 p += (len + 1); /* Skip over the = */
231 start_item_value = p;
235 /* Looking for the end of a value: */
236 if (start_item_value) {
237 const size_t len = strcspn (p, "?"); /* Returns whole string if none found. */
238 /* ? marks the start of a new item: */
240 if (start_item_name && len_item_name) {
241 /* Finish the previously-started item: */
242 gchar *item_value = uri_unescape (start_item_value, len);
243 gchar *item_name = g_strndup (start_item_name, len_item_name);
244 /* printf ("debug: item name=%s, value=%s\n", item_name, item_value); */
246 /* Append the items to the list */
247 if(list_items_and_values) {
248 *list_items_and_values = g_slist_append (*list_items_and_values, item_name);
249 *list_items_and_values = g_slist_append (*list_items_and_values, item_value);
253 /* Skip over the value and mark the start of a possible new name/value pair: */
254 p += (len + 1); /* Skip over the ? */
257 start_item_value = NULL;
268 on_idle_mail_to(gpointer user_data)
270 /* This is based on the implemenation of main.c:start_uil(): */
272 gchar *uri = (gchar*)user_data;
273 GSList *list_names_and_values = NULL;
274 gchar *to = uri_parse_mailto (uri, &list_names_and_values);
276 /* Get the TnyTransportAccount so we can instantiate a mail operation: */
277 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
278 gchar *account_name = modest_account_mgr_get_default_account (account_mgr);
280 g_printerr ("modest: no account found\n");
283 TnyAccount *account = NULL;
285 account = modest_tny_account_store_get_transport_account_for_open_connection (
286 modest_runtime_get_account_store(), account_name);
290 g_printerr ("modest: failed to get tny account folder'\n", account_name);
292 gchar * from = modest_account_mgr_get_from_string (account_mgr,
295 g_printerr ("modest: no from address for account '%s'\n", account_name);
297 const gchar *cc = NULL;
298 const gchar *bcc = NULL;
299 const gchar *subject = NULL;
300 const gchar *body = NULL;
302 /* Get the relevant items from the list: */
303 GSList *list = list_names_and_values;
305 const gchar * name = (const gchar*)list->data;
306 GSList *list_value = g_slist_next (list);
307 const gchar * value = (const gchar*)list_value->data;
309 if (strcmp (name, "cc") == 0) {
311 } else if (strcmp (name, "bcc") == 0) {
313 } else if (strcmp (name, "subject") == 0) {
315 } else if (strcmp (name, "body") == 0) {
319 /* Go to the next pair: */
321 list = g_slist_next (list_value);
326 /* Create the message: */
327 TnyMsg *msg = modest_tny_msg_new (to, from,
328 cc, bcc, subject, body,
329 NULL /* attachments */);
332 g_printerr ("modest: failed to create message\n");
335 /* Add the message to a folder and show its UI for editing: */
336 TnyFolder *folder = modest_tny_account_get_special_folder (account,
337 TNY_FOLDER_TYPE_DRAFTS);
339 g_printerr ("modest: failed to find Drafts folder\n");
342 tny_folder_add_msg (folder, msg, NULL); /* TODO: check err */
344 ModestWindow *win = modest_msg_edit_window_new (msg, account_name);
345 gtk_widget_show_all (GTK_WIDGET (win));
347 g_object_unref (G_OBJECT(folder));
350 g_object_unref (G_OBJECT(msg));
353 g_object_unref (G_OBJECT(account));
357 g_free (account_name);
359 /* Free the list, as required by the uri_parse_mailto() documentation: */
360 if (list_names_and_values)
361 g_slist_foreach (list_names_and_values, (GFunc)g_free, NULL);
362 g_slist_free (list_names_and_values);
368 return FALSE; /* Do not call this callback again. */
371 static gint on_mail_to(GArray * arguments, gpointer data, osso_rpc_t * retval)
373 if (arguments->len != MODEST_DEBUS_MAIL_TO_ARGS_COUNT)
376 /* Use g_idle to context-switch into the application's thread: */
378 /* Get the arguments: */
379 osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_MAIL_TO_ARG_URI);
380 gchar *uri = g_strdup (val.value.s);
382 /* printf(" debug: to=%s\n", idle_data->to); */
383 g_idle_add(on_idle_mail_to, (gpointer)uri);
385 /* Note that we cannot report failures during sending,
386 * because that would be asynchronous. */
392 on_idle_compose_mail(gpointer user_data)
394 ComposeMailIdleData *idle_data = (ComposeMailIdleData*)user_data;
396 /* Get the TnyTransportAccount so we can instantiate a mail operation: */
397 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
398 gchar *account_name = modest_account_mgr_get_default_account (account_mgr);
400 g_printerr ("modest: no account found\n");
403 TnyAccount *account = NULL;
405 account = modest_tny_account_store_get_transport_account_for_open_connection (
406 modest_runtime_get_account_store(), account_name);
410 g_printerr ("modest: failed to get tny account folder'\n", account_name);
412 gchar * from = modest_account_mgr_get_from_string (account_mgr,
415 g_printerr ("modest: no from address for account '%s'\n", account_name);
418 /* Create the message: */
419 TnyMsg *msg = modest_tny_msg_new (idle_data->to, from,
420 idle_data->cc, idle_data->bcc, idle_data->subject, idle_data->body,
421 idle_data->attachments);
424 g_printerr ("modest: failed to create message\n");
427 /* Add the message to a folder and show its UI for editing: */
428 TnyFolder *folder = modest_tny_account_get_special_folder (account,
429 TNY_FOLDER_TYPE_DRAFTS);
431 g_printerr ("modest: failed to find Drafts folder\n");
434 tny_folder_add_msg (folder, msg, NULL); /* TODO: check err */
436 ModestWindow *win = modest_msg_edit_window_new (msg, account_name);
437 gtk_widget_show_all (GTK_WIDGET (win));
439 g_object_unref (G_OBJECT(folder));
442 g_object_unref (G_OBJECT(msg));
445 g_object_unref (G_OBJECT(account));
449 /* Free the idle data: */
450 g_free (idle_data->to);
451 g_free (idle_data->cc);
452 g_free (idle_data->bcc);
453 g_free (idle_data->subject);
454 g_free (idle_data->body);
455 g_free (idle_data->attachments);
458 g_free (account_name);
459 return FALSE; /* Do not call this callback again. */
462 static gint on_compose_mail(GArray * arguments, gpointer data, osso_rpc_t * retval)
467 if (arguments->len != MODEST_DEBUS_COMPOSE_MAIL_ARGS_COUNT)
470 /* Use g_idle to context-switch into the application's thread: */
471 ComposeMailIdleData *idle_data = g_new0(ComposeMailIdleData, 1); /* Freed in the idle callback. */
473 /* Get the arguments: */
474 osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_TO);
475 idle_data->to = g_strdup (val.value.s);
477 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_CC);
478 idle_data->cc = g_strdup (val.value.s);
480 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_BCC);
481 idle_data->bcc = g_strdup (val.value.s);
483 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_SUBJECT);
484 idle_data->subject = g_strdup (val.value.s);
486 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_BODY);
487 idle_data->body = g_strdup (val.value.s);
489 val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_ATTACHMENTS);
490 gchar *attachments_str = g_strdup (val.value.s);
492 list = g_strsplit(attachments_str, ",", 0);
493 for (i=0; list[i] != NULL; i++) {
494 idle_data->attachments = g_slist_append(idle_data->attachments, g_strdup(list[i]));
499 /* printf(" debug: to=%s\n", idle_data->to); */
500 g_idle_add(on_idle_compose_mail, (gpointer)idle_data);
502 /* Note that we cannot report failures during sending,
503 * because that would be asynchronous. */
509 find_message_by_url (const char *uri, TnyAccount **ac_out)
512 ModestTnyAccountStore *astore;
521 astore = modest_runtime_get_account_store ();
523 if (astore == NULL) {
527 g_debug ("Got AccountStore, lets go");
529 account = tny_account_store_find_account (TNY_ACCOUNT_STORE (astore),
532 if (account == NULL) {
536 g_debug ("Found account");
538 if ( ! TNY_IS_STORE_ACCOUNT (account)) {
542 g_debug ("Account is store account");
546 folder = tny_store_account_find_folder (TNY_STORE_ACCOUNT (account),
550 if (folder == NULL) {
553 g_debug ("Found folder");
556 msg = tny_folder_find_msg (folder, uri, NULL);
559 if (account && !msg) {
560 g_object_unref (account);
565 g_object_unref (folder);
572 on_idle_open_message (gpointer user_data)
574 ModestWindow *msg_view;
579 const char *account_name;
582 uri = (char *) user_data;
584 g_debug ("Trying to find msg by url: %s", uri);
585 msg = find_message_by_url (uri, &account);
591 g_debug ("Found message");
593 header = tny_msg_get_header (msg);
594 account_name = tny_account_get_name (account);
595 msg_uid = tny_header_get_uid (header);
597 msg_view = modest_msg_view_window_new (msg,
600 /* TODO: does that leak the msg_view ?! */
602 gtk_widget_show_all (GTK_WIDGET (msg_view));
604 g_object_unref (header);
605 g_object_unref (account);
607 return FALSE; /* Do not call this callback again. */
610 static gint on_open_message(GArray * arguments, gpointer data, osso_rpc_t * retval)
612 if (arguments->len != MODEST_DEBUS_OPEN_MESSAGE_ARGS_COUNT)
615 /* Use g_idle to context-switch into the application's thread: */
617 /* Get the arguments: */
618 osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_OPEN_MESSAGE_ARG_URI);
619 gchar *uri = g_strdup (val.value.s);
621 /* printf(" debug: to=%s\n", idle_data->to); */
622 g_idle_add(on_idle_open_message, (gpointer)uri);
624 /* Note that we cannot report failures during sending,
625 * because that would be asynchronous. */
631 on_idle_send_receive(gpointer user_data)
635 /* Pick the main window if it exists */
636 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ());
638 /* Send & receive all if "Update automatically" is set */
639 /* TODO: check the auto-update parameter in the configuration */
640 modest_ui_actions_do_send_receive_all (win);
642 return FALSE; /* Do not call this callback again. */
645 static gint on_send_receive(GArray * arguments, gpointer data, osso_rpc_t * retval)
647 /* Use g_idle to context-switch into the application's thread: */
649 /* This method has no arguments. */
651 /* printf(" debug: to=%s\n", idle_data->to); */
652 g_idle_add(on_idle_send_receive, NULL);
654 /* Note that we cannot report failures during send/receive,
655 * because that would be asynchronous. */
659 /* Callback for normal D-BUS messages */
660 gint modest_dbus_req_handler(const gchar * interface, const gchar * method,
661 GArray * arguments, gpointer data,
665 printf("debug: modest_dbus_req_handler()\n");
666 printf("debug: method received: %s\n", method);
668 if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_SEND_MAIL) == 0) {
669 return on_send_mail (arguments, data, retval);
670 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_MAIL_TO) == 0) {
671 return on_mail_to (arguments, data, retval);
672 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_OPEN_MESSAGE) == 0) {
673 return on_open_message (arguments, data, retval);
674 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_SEND_RECEIVE) == 0) {
675 return on_send_receive (arguments, data, retval);
676 } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_COMPOSE_MAIL) == 0) {
677 return on_compose_mail (arguments, data, retval);
680 /* We need to return INVALID here so
681 * osso is returning DBUS_HANDLER_RESULT_NOT_YET_HANDLED
682 * so our modest_dbus_req_filter can kick in!
688 #define SEARCH_HIT_DBUS_TYPE \
689 DBUS_STRUCT_BEGIN_CHAR_AS_STRING \
690 DBUS_TYPE_STRING_AS_STRING \
691 DBUS_TYPE_STRING_AS_STRING \
692 DBUS_TYPE_STRING_AS_STRING \
693 DBUS_TYPE_STRING_AS_STRING \
694 DBUS_TYPE_UINT64_AS_STRING \
695 DBUS_TYPE_BOOLEAN_AS_STRING \
696 DBUS_TYPE_BOOLEAN_AS_STRING \
697 DBUS_TYPE_INT64_AS_STRING \
698 DBUS_STRUCT_END_CHAR_AS_STRING
701 search_result_to_messsage (DBusMessage *reply,
704 DBusMessageIter iter;
705 DBusMessageIter array_iter;
708 dbus_message_iter_init_append (reply, &iter);
709 dbus_message_iter_open_container (&iter,
711 SEARCH_HIT_DBUS_TYPE,
714 for (hit_iter = hits; hit_iter; hit_iter = hit_iter->next) {
715 DBusMessageIter struct_iter;
718 TnyHeaderFlags flags;
720 const char *subject = "";
721 const char *folder = "";
722 const char *sender = "";
724 gboolean has_attachemnt = FALSE;
725 gboolean is_unread = FALSE;
730 g_debug ("Marshalling hit ...(%s)",
731 TNY_IS_HEADER (hit_iter->data) ? "yes" : "no");
733 header = TNY_HEADER (hit_iter->data);
734 tf = tny_header_get_folder (header);
735 furl = tny_folder_get_url_string (tf);
737 uid = tny_header_get_uid (header);
738 msg_url = g_strdup_printf ("%s/%s", furl, uid);
740 subject = tny_header_get_subject (header);
742 sender = tny_header_get_from (header);
743 size = tny_header_get_message_size (header);
745 flags = tny_header_get_flags (header);
746 has_attachemnt = flags & TNY_HEADER_FLAG_ATTACHMENTS;
747 is_unread = ! (flags & TNY_HEADER_FLAG_SEEN);
748 ts = tny_header_get_date_received (header);
750 g_debug ("Adding hit: %s", msg_url);
752 dbus_message_iter_open_container (&array_iter,
757 dbus_message_iter_append_basic (&struct_iter,
761 dbus_message_iter_append_basic (&struct_iter,
765 dbus_message_iter_append_basic (&struct_iter,
769 dbus_message_iter_append_basic (&struct_iter,
773 dbus_message_iter_append_basic (&struct_iter,
777 dbus_message_iter_append_basic (&struct_iter,
781 dbus_message_iter_append_basic (&struct_iter,
785 dbus_message_iter_append_basic (&struct_iter,
789 dbus_message_iter_close_container (&array_iter,
796 /* Also unref the header, we don't need it anymore */
797 g_object_unref (header);
800 dbus_message_iter_close_container (&iter, &array_iter);
806 modest_dbus_req_filter (DBusConnection *con,
807 DBusMessage *message,
810 gboolean handled = FALSE;
813 if (dbus_message_is_method_call (message,
815 MODEST_DBUS_METHOD_SEARCH)) {
816 ModestDBusSearchFlags dbus_flags;
818 DBusMessage *reply = NULL;
822 dbus_int32_t flags_v;
823 dbus_uint32_t serial;
824 dbus_uint32_t size_v;
833 dbus_error_init (&error);
838 res = dbus_message_get_args (message,
840 DBUS_TYPE_STRING, &query,
841 DBUS_TYPE_STRING, &folder,
842 DBUS_TYPE_INT64, &sd_v,
843 DBUS_TYPE_INT64, &ed_v,
844 DBUS_TYPE_INT32, &flags_v,
845 DBUS_TYPE_UINT32, &size_v,
848 dbus_flags = (ModestDBusSearchFlags) flags_v;
849 start_date = (time_t) sd_v;
850 end_date = (time_t) ed_v;
852 memset (&search, 0, sizeof (search));
853 search.query = query;
854 search.before = start_date;
855 search.after = end_date;
858 if (dbus_flags & MODEST_DBUS_SEARCH_SUBJECT) {
859 search.flags |= MODEST_SEARCH_SUBJECT;
860 search.subject = query;
863 if (dbus_flags & MODEST_DBUS_SEARCH_SENDER) {
864 search.flags |= MODEST_SEARCH_SENDER;
868 if (dbus_flags & MODEST_DBUS_SEARCH_RECIPIENT) {
869 search.flags |= MODEST_SEARCH_RECIPIENT;
870 search.recipient = query;
873 if (dbus_flags & MODEST_DBUS_SEARCH_BODY) {
874 search.flags |= MODEST_SEARCH_BODY;
875 search.subject = query;
879 search.flags |= MODEST_SEARCH_BEFORE;
880 search.before = start_date;
884 search.flags |= MODEST_SEARCH_AFTER;
885 search.after = end_date;
889 search.flags |= MODEST_SEARCH_SIZE;
890 search.minsize = size_v;
893 #ifdef MODEST_HAVE_OGS
894 search.flags |= MODEST_SEARCH_USE_OGS;
897 g_debug ("Starting search for %s", search.query);
899 hits = modest_search_all_accounts (&search);
901 reply = dbus_message_new_method_return (message);
903 search_result_to_messsage (reply, hits);
906 g_warning ("Could not create reply");
910 dbus_connection_send (con, reply, &serial);
911 dbus_connection_flush (con);
912 dbus_message_unref (reply);
919 DBUS_HANDLER_RESULT_HANDLED :
920 DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
924 modest_osso_cb_hw_state_handler(osso_hw_state_t *state, gpointer data)
927 /* printf("%s()\n", __PRETTY_FUNCTION__); */
929 if(state->system_inactivity_ind)
932 else if(state->save_unsaved_data_ind)
940 /* printf("debug: %s(): return\n", __PRETTY_FUNCTION__); */