* Fixes NB#86176, do not remove own address when it's the only one and "reply to...
[modest] / src / modest-search.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
16  *
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.
28  */
29
30 #ifndef _GNU_SOURCE
31 #define _GNU_SOURCE
32 #endif
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 #include <string.h>
39
40 #include <tny-shared.h>
41 #include <tny-folder.h>
42 #include <tny-folder-store.h>
43 #include <tny-list.h>
44 #include <tny-iterator.h>
45 #include <tny-simple-list.h>
46 #include <tny-camel-imap-store-account.h>
47 #include <tny-camel-pop-store-account.h>
48
49 #include "modest-text-utils.h"
50 #include "modest-account-mgr.h"
51 #include "modest-tny-account-store.h"
52 #include "modest-tny-account.h"
53 #include "modest-tny-mime-part.h"
54 #include "modest-tny-folder.h"
55 #include "modest-search.h"
56 #include "modest-runtime.h"
57 #include "modest-platform.h"
58
59 typedef struct 
60 {
61         guint pending_calls;
62         GList *msg_hits;
63         ModestSearch *search;
64         ModestSearchCallback callback;
65         gpointer user_data;
66         TnyList *all_folders;
67 } SearchHelper;
68
69 static SearchHelper *create_helper (ModestSearchCallback callback, 
70                                     ModestSearch *search,
71                                     gpointer user_data);
72
73 static void          _search_folder (TnyFolder *folder, 
74                                      SearchHelper *helper);
75
76 static gchar *
77 g_strdup_or_null (const gchar *str)
78 {
79         gchar *string = NULL;
80
81         if  (str != NULL) {
82                 string = g_strdup (str);
83         }
84
85         return string;
86 }
87
88 static GList*
89 add_hit (GList *list, TnyHeader *header, TnyFolder *folder)
90 {
91         ModestSearchResultHit *hit;
92         TnyHeaderFlags   flags;
93         char            *furl;
94         char            *msg_url;
95         char      *uid;
96         char      *subject;
97         char      *sender;
98
99         hit = g_slice_new0 (ModestSearchResultHit);
100
101         furl = tny_folder_get_url_string (folder);
102         g_debug ("%s: folder URL=%s\n", __FUNCTION__, furl);
103         if (!furl) {
104                 g_warning ("%s: tny_folder_get_url_string(): returned NULL for folder. Folder name=%s\n", __FUNCTION__, tny_folder_get_name (folder));
105         }
106         
107         /* Make sure that we use the short UID instead of the long UID,
108          * and/or find out what UID form is used when finding, in camel_data_cache_get().
109          * so we can find what we get. Philip is working on this.
110          */
111         uid = tny_header_dup_uid (header);
112         if (!furl) {
113                 gchar *subject = tny_header_dup_subject (header);
114                 g_warning ("%s: tny_header_get_uid(): returned NULL for message with subject=%s\n", __FUNCTION__, subject);
115                 g_free (subject);
116         }
117         
118         msg_url = g_strdup_printf ("%s/%s", furl, uid);
119         g_free (furl);
120         g_free (uid);
121         
122         subject = tny_header_dup_subject (header);
123         sender = tny_header_dup_from (header);
124         
125         flags = tny_header_get_flags (header);
126
127         hit->msgid = msg_url;
128         hit->subject = subject;
129         hit->sender = sender;
130         hit->folder = g_strdup_or_null (tny_folder_get_name (folder));
131         hit->msize = tny_header_get_message_size (header);
132         hit->has_attachment = flags & TNY_HEADER_FLAG_ATTACHMENTS;
133         hit->is_unread = ! (flags & TNY_HEADER_FLAG_SEEN);
134         hit->timestamp = MIN (tny_header_get_date_received (header), tny_header_get_date_sent (header));
135         
136         return g_list_prepend (list, hit);
137 }
138
139 /** Call this until it returns FALSE or nread is set to 0.
140  * 
141  * @result: FALSE is something failed. */
142 static gboolean
143 read_chunk (TnyStream *stream, char *buffer, gsize count, gsize *nread)
144 {
145         gsize _nread = 0;
146         gssize res = 0;
147
148         while (_nread < count) {
149                 res = tny_stream_read (stream,
150                                        buffer + _nread, 
151                                        count - _nread);
152                 if (res == -1) { /* error */
153                         *nread = _nread;
154                         return FALSE;
155                 }
156
157                 _nread += res;
158                 
159                 if (res == 0) { /* no more bytes read. */
160                         *nread = _nread;
161                         return TRUE;
162                 }
163         }
164
165         *nread = _nread;
166         return TRUE;
167 }
168
169 #ifdef MODEST_HAVE_OGS
170 /*
171  * This function assumes that the mime part is of type "text / *"
172  */
173 static gboolean
174 search_mime_part_ogs (TnyMimePart *part, ModestSearch *search)
175 {
176         TnyStream *stream = NULL;
177         char       buffer[4096];
178         const gsize len = sizeof (buffer);
179         gsize      nread = 0;
180         gboolean   is_text_html = FALSE;
181         gboolean   found = FALSE;
182         gboolean   res = FALSE;
183         
184         is_text_html = tny_mime_part_content_type_is (part, "text/html");
185
186         stream = tny_mime_part_get_stream (part);
187
188         res = read_chunk (stream, buffer, len, &nread);
189         while (res && (nread > 0)) {
190                 /* search->text_searcher was instantiated in modest_search_folder(). */
191                 
192                 if (is_text_html) {
193                         found = ogs_text_searcher_search_html (search->text_searcher,
194                                                                buffer,
195                                                                nread,
196                                                                nread < len);
197                 } else {
198                         found = ogs_text_searcher_search_text (search->text_searcher,
199                                                                buffer,
200                                                                nread);
201                 }
202
203                 /* HACK: this helps UI refreshes because the search
204                    operations could be heavy */
205                 while (gtk_events_pending ())
206                         gtk_main_iteration ();
207
208                 if (found) {
209                         break;
210                 }
211                 
212                 nread = 0;
213                 res = read_chunk (stream, buffer, len, &nread);
214         }
215         g_object_unref (stream);
216
217         if (!found) {
218                 found = ogs_text_searcher_search_done (search->text_searcher);
219         }
220
221         ogs_text_searcher_reset (search->text_searcher);
222
223         return found;
224 }
225
226 #else
227
228 /*
229  * This function assumes that the mime part is of type "text / *"
230  */
231 static gboolean
232 search_mime_part_strcmp (TnyMimePart *part, ModestSearch *search)
233 {
234         TnyStream *stream;
235         char       buffer[8193];
236         char      *chunk[2];
237         gssize     len;
238         gsize     nread;
239         gboolean   found;
240         gboolean   res;
241
242         found = FALSE;
243         len = (sizeof (buffer) - 1) / 2;
244
245         if (strlen (search->body) > len) {
246                 g_warning ("Search term bigger then chunk."
247                            "We might not find everything");     
248         }
249
250         stream = tny_mime_part_get_stream (part);
251
252         memset (buffer, 0, sizeof (buffer));
253         chunk[0] = buffer;
254         chunk[1] = buffer + len;
255
256         res = read_chunk (stream, chunk[0], len, &nread);
257
258         if (res == FALSE) {
259                 goto done;
260         }
261
262         found = !modest_text_utils_utf8_strcmp (search->body,
263                                                 buffer,
264                                                 TRUE);
265         if (found) {
266                 goto done;
267         }
268
269         /* This works like this:
270          * buffer: [ooooooooooo|xxxxxxxxxxxx|\0] 
271          *          ^chunk[0]  ^chunk[1]
272          * we have prefilled chunk[0] now we always read into chunk[1]
273          * and then move the content of chunk[1] to chunk[0].
274          * The idea is to prevent not finding search terms that are
275          * spread across 2 reads:        
276          * buffer: [ooooooooTES|Txxxxxxxxxxx|\0] 
277          * We should catch that because we always search the whole
278          * buffer not only the chunks.
279          *
280          * Of course that breaks for search terms > sizeof (chunk)
281          * but sizeof (chunk) should be big enough I guess (see
282          * the g_warning in this function)
283          * */   
284         while ((res = read_chunk (stream, chunk[1], len, &nread))) {
285                 buffer[len + nread] = '\0';
286
287                 found = !modest_text_utils_utf8_strcmp (search->body,
288                                                         buffer,
289                                                         TRUE);
290
291                 /* HACK: this helps UI refreshes because the search
292                    operations could be heavy */
293                 while (gtk_events_pending ())
294                         gtk_main_iteration ();
295
296                 if ((found)||(nread == 0)) {
297                         break;
298                 }
299
300                 /* also move the \0 */
301                 g_memmove (chunk[0], chunk[1], len + 1);
302         }
303
304 done:
305         g_object_unref (stream);
306         return found;
307 }
308 #endif /*MODEST_HAVE_OGS*/
309
310 static gboolean
311 search_string (const char      *what,
312                const char      *where,
313                ModestSearch    *search)
314 {
315         gboolean found = FALSE;
316 #ifdef MODEST_HAVE_OGS
317         if (search->flags & MODEST_SEARCH_USE_OGS) {
318                 found = ogs_text_searcher_search_text (search->text_searcher,
319                                                        where,
320                                                        strlen (where));
321
322                 ogs_text_searcher_reset (search->text_searcher);
323         } else {
324 #endif
325                 if (what == NULL || where == NULL) {
326                         return FALSE;
327                 }
328
329                 found = !modest_text_utils_utf8_strcmp (what, where, TRUE);
330 #ifdef MODEST_HAVE_OGS
331         }
332 #endif
333
334         /* HACK: this helps UI refreshes because the search
335            operations could be heavy */
336         while (gtk_events_pending ())
337                 gtk_main_iteration ();
338
339         return found;
340 }
341
342
343 static gboolean 
344 search_mime_part_and_child_parts (TnyMimePart *part, ModestSearch *search)
345 {
346         gboolean found = FALSE;
347
348         /* Do not search into attachments */
349         if (modest_tny_mime_part_is_attachment_for_modest (part) && !TNY_IS_MSG (part))
350                 return FALSE;
351
352         #ifdef MODEST_HAVE_OGS
353         found = search_mime_part_ogs (part, search);
354         #else
355         found = search_mime_part_strcmp (part, search);
356         #endif
357
358         if (found) {    
359                 return found;           
360         }
361         
362         /* Check the child part too, recursively: */
363         TnyList *child_parts = tny_simple_list_new ();
364         tny_mime_part_get_parts (TNY_MIME_PART (part), child_parts);
365
366         TnyIterator *piter = tny_list_create_iterator (child_parts);
367         while (!found && !tny_iterator_is_done (piter)) {
368                 TnyMimePart *pcur = (TnyMimePart *) tny_iterator_get_current (piter);
369                 if (pcur) {
370                         found = search_mime_part_and_child_parts (pcur, search);
371
372                         g_object_unref (pcur);
373                 }
374
375                 tny_iterator_next (piter);
376         }
377
378         g_object_unref (piter);
379         g_object_unref (child_parts);
380         
381         return found;
382 }
383
384 static void
385 search_next_folder (SearchHelper *helper) 
386 {
387         TnyIterator *iter = tny_list_create_iterator (helper->all_folders);
388         TnyFolder *first = TNY_FOLDER (tny_iterator_get_current (iter));
389         
390         _search_folder (first, helper);
391
392         g_object_unref (first);
393         g_object_unref (iter);
394 }
395
396 static void 
397 modest_search_folder_get_headers_cb (TnyFolder *folder, 
398                                      gboolean cancelled, 
399                                      TnyList *headers, 
400                                      GError *err, 
401                                      gpointer user_data)
402 {
403         TnyIterator *iter = NULL;
404         SearchHelper *helper;
405
406         helper = (SearchHelper *) user_data;
407
408         if (err || cancelled) {
409                 goto end;
410         }
411
412         iter = tny_list_create_iterator (headers);
413
414         while (!tny_iterator_is_done (iter)) {
415
416                 TnyHeader *cur = (TnyHeader *) tny_iterator_get_current (iter);
417                 const time_t t = tny_header_get_date_sent (cur);
418                 gboolean found = FALSE;
419                 
420                 /* Ignore deleted (not yet expunged) emails: */
421                 if (tny_header_get_flags(cur) & TNY_HEADER_FLAG_DELETED)
422                         goto go_next;
423                         
424                 if (helper->search->flags & MODEST_SEARCH_BEFORE)
425                         if (!(t <= helper->search->end_date))
426                                 goto go_next;
427
428                 if (helper->search->flags & MODEST_SEARCH_AFTER)
429                         if (!(t >= helper->search->start_date))
430                                 goto go_next;
431
432                 if (helper->search->flags & MODEST_SEARCH_SIZE)
433                         if (tny_header_get_message_size (cur) < helper->search->minsize)
434                                 goto go_next;
435
436                 if (helper->search->flags & MODEST_SEARCH_SUBJECT) {
437                         char *str = tny_header_dup_subject (cur);
438
439                         if ((found = search_string (helper->search->subject, str, helper->search))) {
440                             helper->msg_hits = add_hit (helper->msg_hits, cur, folder);
441                         }
442                         g_free (str);
443                 }
444                 
445                 if (!found && helper->search->flags & MODEST_SEARCH_SENDER) {
446                         char *str = tny_header_dup_from (cur);
447
448                         if ((found = search_string (helper->search->from, (const gchar *) str, helper->search))) {
449                                 helper->msg_hits = add_hit (helper->msg_hits, cur, folder);
450                         }
451                         g_free (str);
452                 }
453                 
454                 if (!found && helper->search->flags & MODEST_SEARCH_RECIPIENT) {
455                         char *str = tny_header_dup_to (cur);
456
457                         if ((found = search_string (helper->search->recipient, str, helper->search))) {
458                                 helper->msg_hits = add_hit (helper->msg_hits, cur, folder);
459                         }
460                         g_free (str);
461                 }
462         
463                 if (!found && helper->search->flags & MODEST_SEARCH_BODY) {
464                         TnyHeaderFlags flags;
465                         GError      *err = NULL;
466                         TnyMsg      *msg = NULL;
467
468                         flags = tny_header_get_flags (cur);
469
470                         if (!(flags & TNY_HEADER_FLAG_CACHED)) {
471                                 goto go_next;
472                         }
473
474                         msg = tny_folder_get_msg (folder, cur, &err);
475
476                         if (err != NULL || msg == NULL) {
477                                 g_warning ("%s: Could not get message.\n", __FUNCTION__);
478                                 g_error_free (err);
479
480                                 if (msg) {
481                                         g_object_unref (msg);
482                                 }
483                         } else {        
484                                 gchar *str;
485                                 str = tny_header_dup_subject (cur);
486                                 g_debug ("Searching in %s\n", str);
487                                 g_free (str);
488                         
489                                 found = search_mime_part_and_child_parts (TNY_MIME_PART (msg),
490                                                                           helper->search);
491                                 if (found) {
492                                         helper->msg_hits = add_hit (helper->msg_hits, cur, folder);
493                                 }
494                         }
495                         
496                         if (msg)
497                                 g_object_unref (msg);
498                 }
499         go_next:
500                 g_object_unref (cur);
501                 tny_iterator_next (iter);
502         }
503
504         /* Frees */
505         g_object_unref (iter);
506  end:
507         if (headers)
508                 g_object_unref (headers);
509
510         /* Check search finished */
511         tny_list_remove (helper->all_folders, G_OBJECT (folder));
512         if (tny_list_get_length (helper->all_folders) == 0) {
513                 /* callback */
514                 helper->callback (helper->msg_hits, helper->user_data);
515                 
516                 /* free helper */
517                 g_object_unref (helper->all_folders);
518                 g_list_free (helper->msg_hits);
519                 g_slice_free (SearchHelper, helper);
520         } else {
521                 search_next_folder (helper);
522         }
523 }
524
525 static void
526 _search_folder (TnyFolder *folder, 
527                 SearchHelper *helper)
528 {
529         TnyList *list = NULL;
530
531         g_debug ("%s: searching folder %s.", __FUNCTION__, tny_folder_get_name (folder));
532         
533         /* Check that we should be searching this folder. */
534         /* Note that we don't try to search sub-folders. 
535          * Maybe we should, but that should be specified. */
536         if (helper->search->folder && strlen (helper->search->folder)) {
537                 if (!strcmp (helper->search->folder, "outbox")) {
538                         if (modest_tny_folder_guess_folder_type (folder) != TNY_FOLDER_TYPE_OUTBOX) {
539                                 modest_search_folder_get_headers_cb (folder, TRUE, NULL, NULL, helper); 
540                                 return;
541                         }
542                 } else if (strcmp (tny_folder_get_id (folder), helper->search->folder) != 0) {
543                         modest_search_folder_get_headers_cb (folder, TRUE, NULL, NULL, helper); 
544                         return;
545                 }
546         }
547         
548 #ifdef MODEST_HAVE_OGS
549         if (helper->search->flags & MODEST_SEARCH_USE_OGS) {
550         
551                 if (helper->search->text_searcher == NULL && helper->search->query != NULL) {
552                         OgsTextSearcher *text_searcher; 
553
554                         text_searcher = ogs_text_searcher_new (FALSE);
555                         ogs_text_searcher_parse_query (text_searcher, helper->search->query);
556                         helper->search->text_searcher = text_searcher;
557                 }
558         }
559 #endif
560         list = tny_simple_list_new ();
561         /* Get the headers */
562         tny_folder_get_headers_async (folder, list, FALSE, 
563                                       modest_search_folder_get_headers_cb, 
564                                       NULL, helper);
565 }
566
567 void
568 modest_search_folder (TnyFolder *folder, 
569                       ModestSearch *search,
570                       ModestSearchCallback callback,
571                       gpointer user_data)
572 {
573         SearchHelper *helper;
574
575         /* Create the helper */
576         helper = create_helper (callback, search, user_data);
577
578         /* Search */
579         _search_folder (folder, helper);
580 }
581
582 static void
583 modest_search_account_get_folders_cb (TnyFolderStore *self, 
584                                       gboolean cancelled, 
585                                       TnyList *folders, 
586                                       GError *err, 
587                                       gpointer user_data)
588 {
589         TnyIterator *iter;
590         SearchHelper *helper;
591
592         helper = (SearchHelper *) user_data;
593
594         if (err || cancelled) {
595                 goto end;
596         }
597
598         /* IMPORTANT: We need to get the headers of the folders one by
599            one, because otherwise the get_headers_async calls are
600            often canceled. That's why we firstly retrieve all folders,
601            and then we search inside them one by one. sergio */
602         iter = tny_list_create_iterator (folders);
603         while (!tny_iterator_is_done (iter)) {
604                 TnyFolder *folder = NULL;
605
606                 /* Search into folder */
607                 folder = TNY_FOLDER (tny_iterator_get_current (iter));  
608                 tny_list_append (helper->all_folders, G_OBJECT (folder));
609
610                 /* Search into children. Could be a merge folder */
611                 if (TNY_IS_FOLDER_STORE (folder)) {
612                         TnyList *children = tny_simple_list_new ();
613                         helper->pending_calls++;
614                         tny_folder_store_get_folders_async (TNY_FOLDER_STORE (folder), children, NULL, 
615                                                             modest_search_account_get_folders_cb, 
616                                                             NULL, helper);
617                 }
618
619                 g_object_unref (folder);
620                 tny_iterator_next (iter);
621         }
622         g_object_unref (iter);
623  end:
624         /* Remove the "account" reference */
625         helper->pending_calls--;
626
627         if (folders)
628                 g_object_unref (folders);
629
630         /* If there are not more folders, begin to search from the first one */
631         if (helper->pending_calls == 0) {
632                 TnyIterator *iter = tny_list_create_iterator (helper->all_folders);
633                 TnyFolder *first = TNY_FOLDER (tny_iterator_get_current (iter));
634
635                 _search_folder (first, helper);
636
637                 g_object_unref (first);
638                 g_object_unref (iter);
639         }
640 }
641
642 static void
643 _search_account (TnyAccount *account, 
644                  SearchHelper *helper)
645 {
646         TnyList *folders = tny_simple_list_new ();
647
648         g_debug ("%s: Searching account %s", __FUNCTION__, tny_account_get_name (account));
649
650         /* Add a "reference" to the folder total. This allows the code
651            not to finalize the helper if an account is fully refreshed
652            before we get the folders of the others */
653         helper->pending_calls++;
654
655         /* Get folders */
656         tny_folder_store_get_folders_async (TNY_FOLDER_STORE (account), folders, NULL, 
657                                             modest_search_account_get_folders_cb, 
658                                             NULL, helper);
659 }
660
661 void
662 modest_search_account (TnyAccount *account, 
663                        ModestSearch *search,
664                        ModestSearchCallback callback,
665                        gpointer user_data)
666 {
667         SearchHelper *helper;
668
669         /* Create the helper */
670         helper = create_helper (callback, search, user_data);
671
672         /* Search */
673         _search_account (account, helper);
674 }
675
676 void
677 modest_search_all_accounts (ModestSearch *search,
678                             ModestSearchCallback callback,
679                             gpointer user_data)
680 {
681         ModestTnyAccountStore *astore;
682         TnyList *accounts;
683         TnyIterator *iter;
684         GList *hits;
685         SearchHelper *helper;
686
687         hits = NULL;
688         astore = modest_runtime_get_account_store ();
689
690         accounts = tny_simple_list_new ();
691         tny_account_store_get_accounts (TNY_ACCOUNT_STORE (astore),
692                                         accounts,
693                                         TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
694
695         /* Create the helper */
696         helper = create_helper (callback, search, user_data);
697
698         /* Search through all accounts */
699         iter = tny_list_create_iterator (accounts);
700         while (!tny_iterator_is_done (iter)) {
701                 TnyAccount *account = NULL;
702
703                 account = TNY_ACCOUNT (tny_iterator_get_current (iter));
704                 _search_account (account, helper);
705                 g_object_unref (account);
706
707                 tny_iterator_next (iter);
708         }
709         g_object_unref (iter);
710         g_object_unref (accounts);
711 }
712
713 static SearchHelper *
714 create_helper (ModestSearchCallback callback, 
715                ModestSearch *search,
716                gpointer user_data)
717 {
718         SearchHelper *helper;
719
720         helper = g_slice_new0 (SearchHelper);
721         helper->pending_calls = 0;
722         helper->search = search;
723         helper->callback = callback;
724         helper->user_data = user_data;
725         helper->msg_hits = NULL;
726         helper->all_folders = tny_simple_list_new ();
727
728         return helper;
729 }
730
731 void 
732 modest_search_free (ModestSearch *search)
733 {
734         if (search->folder)
735                 g_free (search->folder);
736         if (search->subject)
737                 g_free (search->subject);
738         if (search->from)
739                 g_free (search->from);
740         if (search->recipient)
741                 g_free (search->recipient);
742         if (search->body)
743                 g_free (search->body);
744
745 #ifdef MODEST_HAVE_OGS
746         if (search->query)
747                 g_free (search->query);
748         if (search->text_searcher)
749                 ogs_text_searcher_free (search->text_searcher); 
750 #endif
751 }