for (hit_iter = hits; hit_iter; hit_iter = hit_iter->next) {
DBusMessageIter struct_iter;
- TnyFolder *tf;
- TnyHeader *header;
- TnyHeaderFlags flags;
- char *msg_url = "";
- const char *subject = "";
- const char *folder = "";
- const char *sender = "";
- guint64 size = 0;
- gboolean has_attachemnt = FALSE;
- gboolean is_unread = FALSE;
- gint64 ts = 0;
- char *furl;
- const char *uid;
-
- g_debug ("Marshalling hit ...(%s)",
- TNY_IS_HEADER (hit_iter->data) ? "yes" : "no");
-
- header = TNY_HEADER (hit_iter->data);
- tf = tny_header_get_folder (header);
- furl = tny_folder_get_url_string (tf);
-
- uid = tny_header_get_uid (header);
- msg_url = g_strdup_printf ("%s/%s", furl, uid);
-
- subject = tny_header_get_subject (header);
- folder = furl;
- sender = tny_header_get_from (header);
- size = tny_header_get_message_size (header);
-
- flags = tny_header_get_flags (header);
- has_attachemnt = flags & TNY_HEADER_FLAG_ATTACHMENTS;
- is_unread = ! (flags & TNY_HEADER_FLAG_SEEN);
- ts = tny_header_get_date_received (header);
+ ModestSearchHit *hit;
+ char *msg_url;
+ const char *subject;
+ const char *folder;
+ const char *sender;
+ guint64 size;
+ gboolean has_attachment;
+ gboolean is_unread;
+ gint64 ts;
+
+ hit = (ModestSearchHit *) hit_iter->data;
+
+ msg_url = hit->msgid;
+ subject = hit->subject;
+ folder = hit->folder;
+ sender = hit->sender;
+ size = hit->msize;
+ has_attachment = hit->has_attachment;
+ is_unread = hit->is_unread;
+ ts = hit->timestamp;
g_debug ("Adding hit: %s", msg_url);
dbus_message_iter_append_basic (&struct_iter,
DBUS_TYPE_BOOLEAN,
- &has_attachemnt);
+ &has_attachment);
dbus_message_iter_append_basic (&struct_iter,
DBUS_TYPE_BOOLEAN,
dbus_message_iter_close_container (&array_iter,
&struct_iter);
+ g_free (hit->msgid);
+ g_free (hit->subject);
+ g_free (hit->folder);
+ g_free (hit->sender);
- g_free (msg_url);
- g_free (furl);
-
- /* Also unref the header, we don't need it anymore */
- g_object_unref (header);
+ g_slice_free (ModestSearchHit, hit);
}
dbus_message_iter_close_container (&iter, &array_iter);
reply = dbus_message_new_method_return (message);
search_result_to_messsage (reply, hits);
-
+
if (reply == NULL) {
g_warning ("Could not create reply");
}
dbus_message_unref (reply);
}
+ g_list_free (hits);
+
}
#include <tny-iterator.h>
#include <tny-simple-list.h>
+#include <libmodest-dbus-client/libmodest-dbus-client.h>
+
#include "modest-text-utils.h"
#include "modest-account-mgr.h"
#include "modest-tny-account-store.h"
#include "modest-search.h"
#include "modest-runtime.h"
+static char *
+g_strdup_or_null (const char *str)
+{
+ char *string = NULL;
+
+ if (str != NULL) {
+ string = g_strdup (str);
+ }
+
+ return string;
+}
+
static GList*
-add_header (GList *list, TnyHeader *header, TnyFolder *folder)
+add_hit (GList *list, TnyHeader *header, TnyFolder *folder)
{
- TnyFolder *f;
-
- /* TODO: we need this call otherwise it will crash later
- * when we try to do that call again without having the
- * folder around, I guess that is a bug in TinyThingy */
- f = tny_header_get_folder (header);
-
- return g_list_prepend (list, g_object_ref (header));
+ ModestSearchHit *hit;
+ TnyHeaderFlags flags;
+ char *furl;
+ char *msg_url;
+ const char *uid;
+ const char *subject;
+ const char *sender;
+
+ hit = g_slice_new0 (ModestSearchHit);
+
+ furl = tny_folder_get_url_string (folder);
+ uid = tny_header_get_uid (header);
+ msg_url = g_strdup_printf ("%s/%s", furl, uid);
+ subject = tny_header_get_subject (header);
+ sender = tny_header_get_from (header);
+
+ flags = tny_header_get_flags (header);
+
+ hit->msgid = msg_url;
+ hit->subject = g_strdup_or_null (subject);
+ hit->sender = g_strdup_or_null (sender);
+ hit->folder = furl;
+ hit->msize = tny_header_get_message_size (header);
+ hit->has_attachment = flags & TNY_HEADER_FLAG_ATTACHMENTS;
+ hit->is_unread = ! (flags & TNY_HEADER_FLAG_SEEN);
+ hit->timestamp = tny_header_get_date_received (header);
+
+ return g_list_prepend (list, hit);
}
static gboolean
const char *str = tny_header_get_subject (cur);
if ((found = search_string (search->subject, str, search))) {
- retval = add_header (retval, cur, folder);
+ retval = add_hit (retval, cur, folder);
}
}
const char *str = tny_header_get_from (cur);
if ((found = search_string (search->from, str, search))) {
- retval = add_header (retval, cur, folder);
+ retval = add_hit (retval, cur, folder);
}
}
const char *str = tny_header_get_to (cur);
if ((found = search_string (search->recipient, str, search))) {
- retval = add_header (retval, cur, folder);
+ retval = add_hit (retval, cur, folder);
}
}
TnyMimePart *pcur = (TnyMimePart *) tny_iterator_get_current (piter);
if ((found = part_search_func (pcur, search))) {
- retval = add_header (retval, cur, folder);
+ retval = add_hit (retval, cur, folder);
}
g_object_unref (pcur);