~ubuntu-branches/ubuntu/saucy/evolution-data-server/saucy

« back to all changes in this revision

Viewing changes to camel/camel-folder-search.c

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-10-08 12:58:16 UTC
  • mfrom: (181.1.7 quantal)
  • Revision ID: package-import@ubuntu.com-20121008125816-i3n76e8c0m64e7xp
Tags: 3.6.0-0ubuntu2
* Fix LP: #1038047 part 1 - Don't abort in e_source_registry_new* when a
  problem occurs connecting to the Dbus service
  - add debian/patches/dont-abort-in-e_source_registry_new.patch
  - update debian/patches/series
* Fix LP: #1038047 part 2 - libedataserver depends on
  evolution-data-server-common to ensure that the GSettings schemas are
  present
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
173
173
        gint flags;             /* 0x02 = immediate, 0x01 = always enter */
174
174
} builtins[] = {
175
175
        /* these have default implementations in e-sexp */
176
 
        { "and", G_STRUCT_OFFSET(CamelFolderSearchClass, and_), 2 },
177
 
        { "or", G_STRUCT_OFFSET(CamelFolderSearchClass, or_), 2 },
 
176
        { "and", G_STRUCT_OFFSET (CamelFolderSearchClass, and_), 2 },
 
177
        { "or", G_STRUCT_OFFSET (CamelFolderSearchClass, or_), 2 },
178
178
        /* we need to override this one though to implement an 'array not' */
179
 
        { "not", G_STRUCT_OFFSET(CamelFolderSearchClass, not_), 0 },
180
 
        { "<", G_STRUCT_OFFSET(CamelFolderSearchClass, lt), 2 },
181
 
        { ">", G_STRUCT_OFFSET(CamelFolderSearchClass, gt), 2 },
182
 
        { "=", G_STRUCT_OFFSET(CamelFolderSearchClass, eq), 2 },
 
179
        { "not", G_STRUCT_OFFSET (CamelFolderSearchClass, not_), 0 },
 
180
        { "<", G_STRUCT_OFFSET (CamelFolderSearchClass, lt), 2 },
 
181
        { ">", G_STRUCT_OFFSET (CamelFolderSearchClass, gt), 2 },
 
182
        { "=", G_STRUCT_OFFSET (CamelFolderSearchClass, eq), 2 },
183
183
 
184
184
        /* these we have to use our own default if there is none */
185
185
        /* they should all be defined in the language? so it parses, or should they not?? */
186
 
        { "match-all", G_STRUCT_OFFSET(CamelFolderSearchClass, match_all), 3 },
187
 
        { "match-threads", G_STRUCT_OFFSET(CamelFolderSearchClass, match_threads), 3 },
188
 
        { "body-contains", G_STRUCT_OFFSET(CamelFolderSearchClass, body_contains), 1 },
189
 
        { "body-regex",  G_STRUCT_OFFSET(CamelFolderSearchClass, body_regex), 1  },
190
 
        { "header-contains", G_STRUCT_OFFSET(CamelFolderSearchClass, header_contains), 1 },
191
 
        { "header-matches", G_STRUCT_OFFSET(CamelFolderSearchClass, header_matches), 1 },
192
 
        { "header-starts-with", G_STRUCT_OFFSET(CamelFolderSearchClass, header_starts_with), 1 },
193
 
        { "header-ends-with", G_STRUCT_OFFSET(CamelFolderSearchClass, header_ends_with), 1 },
194
 
        { "header-exists", G_STRUCT_OFFSET(CamelFolderSearchClass, header_exists), 1 },
195
 
        { "header-soundex", G_STRUCT_OFFSET(CamelFolderSearchClass, header_soundex), 1 },
196
 
        { "header-regex", G_STRUCT_OFFSET(CamelFolderSearchClass, header_regex), 1 },
197
 
        { "header-full-regex", G_STRUCT_OFFSET(CamelFolderSearchClass, header_full_regex), 1 },
198
 
        { "user-tag", G_STRUCT_OFFSET(CamelFolderSearchClass, user_tag), 1 },
199
 
        { "user-flag", G_STRUCT_OFFSET(CamelFolderSearchClass, user_flag), 1 },
200
 
        { "system-flag", G_STRUCT_OFFSET(CamelFolderSearchClass, system_flag), 1 },
201
 
        { "get-sent-date", G_STRUCT_OFFSET(CamelFolderSearchClass, get_sent_date), 1 },
202
 
        { "get-received-date", G_STRUCT_OFFSET(CamelFolderSearchClass, get_received_date), 1 },
203
 
        { "get-current-date", G_STRUCT_OFFSET(CamelFolderSearchClass, get_current_date), 1 },
204
 
        { "get-relative-months", G_STRUCT_OFFSET(CamelFolderSearchClass, get_relative_months), 1 },
205
 
        { "get-size", G_STRUCT_OFFSET(CamelFolderSearchClass, get_size), 1 },
206
 
        { "uid", G_STRUCT_OFFSET(CamelFolderSearchClass, uid), 1 },
207
 
        { "message-location", G_STRUCT_OFFSET(CamelFolderSearchClass, message_location), 1 },
 
186
        { "match-all", G_STRUCT_OFFSET (CamelFolderSearchClass, match_all), 3 },
 
187
        { "match-threads", G_STRUCT_OFFSET (CamelFolderSearchClass, match_threads), 3 },
 
188
        { "body-contains", G_STRUCT_OFFSET (CamelFolderSearchClass, body_contains), 1 },
 
189
        { "body-regex",  G_STRUCT_OFFSET (CamelFolderSearchClass, body_regex), 1  },
 
190
        { "header-contains", G_STRUCT_OFFSET (CamelFolderSearchClass, header_contains), 1 },
 
191
        { "header-matches", G_STRUCT_OFFSET (CamelFolderSearchClass, header_matches), 1 },
 
192
        { "header-starts-with", G_STRUCT_OFFSET (CamelFolderSearchClass, header_starts_with), 1 },
 
193
        { "header-ends-with", G_STRUCT_OFFSET (CamelFolderSearchClass, header_ends_with), 1 },
 
194
        { "header-exists", G_STRUCT_OFFSET (CamelFolderSearchClass, header_exists), 1 },
 
195
        { "header-soundex", G_STRUCT_OFFSET (CamelFolderSearchClass, header_soundex), 1 },
 
196
        { "header-regex", G_STRUCT_OFFSET (CamelFolderSearchClass, header_regex), 1 },
 
197
        { "header-full-regex", G_STRUCT_OFFSET (CamelFolderSearchClass, header_full_regex), 1 },
 
198
        { "user-tag", G_STRUCT_OFFSET (CamelFolderSearchClass, user_tag), 1 },
 
199
        { "user-flag", G_STRUCT_OFFSET (CamelFolderSearchClass, user_flag), 1 },
 
200
        { "system-flag", G_STRUCT_OFFSET (CamelFolderSearchClass, system_flag), 1 },
 
201
        { "get-sent-date", G_STRUCT_OFFSET (CamelFolderSearchClass, get_sent_date), 1 },
 
202
        { "get-received-date", G_STRUCT_OFFSET (CamelFolderSearchClass, get_received_date), 1 },
 
203
        { "get-current-date", G_STRUCT_OFFSET (CamelFolderSearchClass, get_current_date), 1 },
 
204
        { "get-relative-months", G_STRUCT_OFFSET (CamelFolderSearchClass, get_relative_months), 1 },
 
205
        { "get-size", G_STRUCT_OFFSET (CamelFolderSearchClass, get_size), 1 },
 
206
        { "uid", G_STRUCT_OFFSET (CamelFolderSearchClass, uid), 1 },
 
207
        { "message-location", G_STRUCT_OFFSET (CamelFolderSearchClass, message_location), 1 },
208
208
};
209
209
 
210
210
void
220
220
                /* c is sure messy sometimes */
221
221
                func = *((gpointer *)(((gchar *) class) + builtins[i].offset));
222
222
                if (func == NULL && builtins[i].flags&1) {
223
 
                        g_warning("Search class doesn't implement '%s' method: %s", builtins[i].name, G_OBJECT_TYPE_NAME (search));
 
223
                        g_warning ("Search class doesn't implement '%s' method: %s", builtins[i].name, G_OBJECT_TYPE_NAME (search));
224
224
                        func = (gpointer) search_dummy;
225
225
                }
226
226
                if (func != NULL) {
390
390
 
391
391
        p = search->priv;
392
392
 
 
393
        if (g_cancellable_set_error_if_cancelled (cancellable, error))
 
394
                goto fail;
 
395
 
 
396
        if (!expr || !*expr)
 
397
                expr = "(match-all)";
 
398
 
393
399
        g_assert (search->folder);
394
400
 
395
401
        p->cancellable = cancellable;
430
436
 
431
437
                /* now create a folder summary to return?? */
432
438
                if (r->type == CAMEL_SEXP_RES_ARRAY_PTR) {
433
 
                        d(printf("got result\n"));
 
439
                        d (printf ("got result\n"));
434
440
 
435
441
                        /* reorder result in summary order */
436
442
                        results = g_hash_table_new (g_str_hash, g_str_equal);
437
443
                        for (i = 0; i < r->value.ptrarray->len; i++) {
438
 
                                d(printf("adding match: %s\n", (gchar *)g_ptr_array_index(r->value.ptrarray, i)));
 
444
                                d (printf ("adding match: %s\n", (gchar *) g_ptr_array_index (r->value.ptrarray, i)));
439
445
                                g_hash_table_insert (results, g_ptr_array_index (r->value.ptrarray, i), GINT_TO_POINTER (1));
440
446
                        }
441
447
 
460
466
                /* Sync the db, so that we search the db for changes */
461
467
                camel_folder_summary_save_to_db (search->folder->summary, error);
462
468
 
463
 
                dd(printf ("sexp is : [%s]\n", expr));
 
469
                dd (printf ("sexp is : [%s]\n", expr));
464
470
                sql_query = camel_sexp_to_sql_sexp (expr);
465
471
                tmp1 = camel_db_sqlize_string (full_name);
466
 
                tmp = g_strdup_printf ("SELECT COUNT (*) FROM %s %s %s", tmp1, sql_query ? "WHERE":"", sql_query?sql_query:"");
 
472
                tmp = g_strdup_printf ("SELECT COUNT (*) FROM %s %s %s", tmp1, sql_query ? "WHERE":"", sql_query ? sql_query:"");
467
473
                camel_db_free_sqlized_string (tmp1);
468
474
                g_free (sql_query);
469
 
                dd(printf("Equivalent sql %s\n", tmp));
 
475
                dd (printf ("Equivalent sql %s\n", tmp));
470
476
 
471
477
                cdb = (CamelDB *) (parent_store->cdb_r);
472
478
                camel_db_count_message_info  (cdb, tmp, &count, &local_error);
473
479
                if (local_error != NULL) {
474
480
                        const gchar *message = local_error->message;
475
 
                        if (strncmp(message, "no such table", 13) == 0) {
476
 
                                d(g_warning ("Error during searching %s: %s\n", tmp, message));
 
481
                        if (strncmp (message, "no such table", 13) == 0) {
 
482
                                d (g_warning ("Error during searching %s: %s\n", tmp, message));
477
483
                                /* Suppress no such table */
478
484
                                g_clear_error (&local_error);
479
485
                        }
539
545
 
540
546
        p = search->priv;
541
547
 
 
548
        if (g_cancellable_set_error_if_cancelled (cancellable, error))
 
549
                goto fail;
 
550
 
 
551
        if (!expr || !*expr)
 
552
                expr = "(match-all)";
 
553
 
542
554
        g_assert (search->folder);
543
555
 
544
556
        p->cancellable = cancellable;
593
605
 
594
606
                /* now create a folder summary to return?? */
595
607
                if (r->type == CAMEL_SEXP_RES_ARRAY_PTR) {
596
 
                        d(printf("got result\n"));
 
608
                        d (printf ("got result\n"));
597
609
 
598
610
                        /* reorder result in summary order */
599
611
                        results = g_hash_table_new (g_str_hash, g_str_equal);
600
612
                        for (i = 0; i < r->value.ptrarray->len; i++) {
601
 
                                d(printf("adding match: %s\n", (gchar *)g_ptr_array_index(r->value.ptrarray, i)));
 
613
                                d (printf ("adding match: %s\n", (gchar *) g_ptr_array_index (r->value.ptrarray, i)));
602
614
                                g_hash_table_insert (results, g_ptr_array_index (r->value.ptrarray, i), GINT_TO_POINTER (1));
603
615
                        }
604
616
 
623
635
                /* Sync the db, so that we search the db for changes */
624
636
                camel_folder_summary_save_to_db (search->folder->summary, error);
625
637
 
626
 
                dd(printf ("sexp is : [%s]\n", expr));
 
638
                dd (printf ("sexp is : [%s]\n", expr));
627
639
                sql_query = camel_sexp_to_sql_sexp (expr);
628
640
                tmp1 = camel_db_sqlize_string (full_name);
629
 
                tmp = g_strdup_printf ("SELECT uid FROM %s %s %s", tmp1, sql_query ? "WHERE":"", sql_query?sql_query:"");
 
641
                tmp = g_strdup_printf ("SELECT uid FROM %s %s %s", tmp1, sql_query ? "WHERE":"", sql_query ? sql_query:"");
630
642
                camel_db_free_sqlized_string (tmp1);
631
643
                g_free (sql_query);
632
 
                dd(printf("Equivalent sql %s\n", tmp));
 
644
                dd (printf ("Equivalent sql %s\n", tmp));
633
645
 
634
646
                matches = g_ptr_array_new ();
635
647
                cdb = (CamelDB *) (parent_store->cdb_r);
638
650
                        read_uid_callback, matches, &local_error);
639
651
                if (local_error != NULL) {
640
652
                        const gchar *message = local_error->message;
641
 
                        if (strncmp(message, "no such table", 13) == 0) {
642
 
                                d(g_warning ("Error during searching %s: %s\n", tmp, message));
 
653
                        if (strncmp (message, "no such table", 13) == 0) {
 
654
                                d (g_warning ("Error during searching %s: %s\n", tmp, message));
643
655
                                /* Suppress no such table */
644
656
                                g_clear_error (&local_error);
645
657
                        } else
670
682
        search->current = NULL;
671
683
        search->body_index = NULL;
672
684
 
 
685
        if (error && *error) {
 
686
                camel_folder_search_free_result (search, matches);
 
687
                matches = NULL;
 
688
        }
 
689
 
673
690
        return matches;
674
691
}
675
692
 
676
 
void camel_folder_search_free_result (CamelFolderSearch *search, GPtrArray *result)
 
693
void
 
694
camel_folder_search_free_result (CamelFolderSearch *search,
 
695
                                 GPtrArray *result)
677
696
{
 
697
        if (!result)
 
698
                return;
 
699
 
678
700
        g_ptr_array_foreach (result, (GFunc) camel_pstring_free, NULL);
679
701
        g_ptr_array_free (result, TRUE);
680
702
}
730
752
                                if (!found)
731
753
                                        g_ptr_array_add (r->value.ptrarray, (gchar *) uid);
732
754
                        } else if (search->summary == NULL) {
733
 
                                g_warning("No summary set, 'not' against an array requires a summary");
 
755
                                g_warning ("No summary set, 'not' against an array requires a summary");
734
756
                        } else {
735
757
                                /* 'not' against the whole summary */
736
758
                                GHashTable *have = g_hash_table_new (g_str_hash, g_str_equal);
780
802
        GPtrArray *v;
781
803
 
782
804
        if (argc > 1) {
783
 
                g_warning("match-all only takes a single argument, other arguments ignored");
 
805
                g_warning ("match-all only takes a single argument, other arguments ignored");
784
806
        }
785
807
 
786
808
        /* we are only matching a single message?  or already inside a match-all? */
787
809
        if (search->current) {
788
 
                d(printf("matching against 1 message: %s\n", camel_message_info_subject(search->current)));
 
810
                d (printf ("matching against 1 message: %s\n", camel_message_info_subject (search->current)));
789
811
 
790
812
                r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
791
813
                r->value.boolean = FALSE;
795
817
                        if (r1->type == CAMEL_SEXP_RES_BOOL) {
796
818
                                r->value.boolean = r1->value.boolean;
797
819
                        } else {
798
 
                                g_warning("invalid syntax, matches require a single bool result");
 
820
                                g_warning ("invalid syntax, matches require a single bool result");
799
821
                                /* Translators: The '%s' is an element type name, part of an expressing language */
800
 
                                error_msg = g_strdup_printf(_("(%s) requires a single bool result"), "match-all");
 
822
                                error_msg = g_strdup_printf (_("(%s) requires a single bool result"), "match-all");
801
823
                                camel_sexp_fatal_error (f, error_msg);
802
824
                                g_free (error_msg);
803
825
                        }
813
835
 
814
836
        if (search->summary == NULL) {
815
837
                /* TODO: make it work - e.g. use the folder and so forth for a slower search */
816
 
                g_warning("No summary supplied, match-all doesn't work with no summary");
 
838
                g_warning ("No summary supplied, match-all doesn't work with no summary");
817
839
                g_assert (0);
818
840
                return r;
819
841
        }
838
860
                                if (r1->value.boolean)
839
861
                                        g_ptr_array_add (r->value.ptrarray, (gchar *) uid);
840
862
                        } else {
841
 
                                g_warning("invalid syntax, matches require a single bool result");
 
863
                                g_warning ("invalid syntax, matches require a single bool result");
842
864
                                /* Translators: The '%s' is an element type name, part of an expressing language */
843
 
                                error_msg = g_strdup_printf(_("(%s) requires a single bool result"), "match-all");
 
865
                                error_msg = g_strdup_printf (_("(%s) requires a single bool result"), "match-all");
844
866
                                camel_sexp_fatal_error (f, error_msg);
845
867
                                g_free (error_msg);
846
868
                        }
898
920
        GHashTable *results;
899
921
        gchar *error_msg;
900
922
 
 
923
        if (g_cancellable_is_cancelled (search->priv->cancellable)) {
 
924
                r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
 
925
                r->value.ptrarray = g_ptr_array_new ();
 
926
                return r;
 
927
        }
 
928
 
901
929
        /* not supported in match-all */
902
930
        if (search->current) {
903
931
                /* Translators: Each '%s' is an element type name, part of an expressing language */
904
 
                error_msg = g_strdup_printf(_("(%s) not allowed inside %s"), "match-threads", "match-all");
 
932
                error_msg = g_strdup_printf (_("(%s) not allowed inside %s"), "match-threads", "match-all");
905
933
                camel_sexp_fatal_error (f, error_msg);
906
934
                g_free (error_msg);
907
935
        }
908
936
 
909
937
        if (argc == 0) {
910
938
                /* Translators: The '%s' is an element type name, part of an expressing language */
911
 
                error_msg = g_strdup_printf(_("(%s) requires a match type string"), "match-threads");
 
939
                error_msg = g_strdup_printf (_("(%s) requires a match type string"), "match-threads");
912
940
                camel_sexp_fatal_error (f, error_msg);
913
941
                g_free (error_msg);
914
942
        }
916
944
        r = camel_sexp_term_eval (f, argv[0]);
917
945
        if (r->type != CAMEL_SEXP_RES_STRING) {
918
946
                /* Translators: The '%s' is an element type name, part of an expressing language */
919
 
                error_msg = g_strdup_printf(_("(%s) requires a match type string"), "match-threads");
 
947
                error_msg = g_strdup_printf (_("(%s) requires a match type string"), "match-threads");
920
948
                camel_sexp_fatal_error (f, error_msg);
921
949
                g_free (error_msg);
922
950
        }
923
951
 
924
952
        type = 0;
925
 
        if (!strcmp(r->value.string, "none"))
 
953
        if (!strcmp (r->value.string, "none"))
926
954
                type = 0;
927
 
        else if (!strcmp(r->value.string, "all"))
 
955
        else if (!strcmp (r->value.string, "all"))
928
956
                type = 1;
929
 
        else if (!strcmp(r->value.string, "replies"))
 
957
        else if (!strcmp (r->value.string, "replies"))
930
958
                type = 2;
931
 
        else if (!strcmp(r->value.string, "replies_parents"))
 
959
        else if (!strcmp (r->value.string, "replies_parents"))
932
960
                type = 3;
933
 
        else if (!strcmp(r->value.string, "single"))
 
961
        else if (!strcmp (r->value.string, "single"))
934
962
                type = 4;
935
963
        camel_sexp_result_free (f, r);
936
964
 
944
972
 
945
973
        if (r == NULL || r->type != CAMEL_SEXP_RES_ARRAY_PTR) {
946
974
                /* Translators: The '%s' is an element type name, part of an expressing language */
947
 
                error_msg = g_strdup_printf(_("(%s) expects an array result"), "match-threads");
 
975
                error_msg = g_strdup_printf (_("(%s) expects an array result"), "match-threads");
948
976
                camel_sexp_fatal_error (f, error_msg);
949
977
                g_free (error_msg);
950
978
        }
954
982
 
955
983
        if (search->folder == NULL) {
956
984
                /* Translators: The '%s' is an element type name, part of an expressing language */
957
 
                error_msg = g_strdup_printf(_("(%s) requires the folder set"), "match-threads");
 
985
                error_msg = g_strdup_printf (_("(%s) requires the folder set"), "match-threads");
958
986
                camel_sexp_fatal_error (f, error_msg);
959
987
                g_free (error_msg);
960
988
        }
968
996
        }
969
997
 
970
998
        results = g_hash_table_new (g_str_hash, g_str_equal);
971
 
        for (i = 0; i < r->value.ptrarray->len; i++) {
 
999
        for (i = 0; i < r->value.ptrarray->len && !g_cancellable_is_cancelled (search->priv->cancellable); i++) {
972
1000
                struct _CamelFolderThreadNode *node, *scan;
973
1001
 
974
1002
                if (type != 4)
1029
1057
        CamelSExpResult *r;
1030
1058
        gint truth = FALSE;
1031
1059
 
1032
 
        r(printf("executing check-header %d\n", how));
 
1060
        r (printf ("executing check-header %d\n", how));
1033
1061
 
1034
1062
        /* are we inside a match-all? */
1035
1063
        if (search->current && argc > 1
1036
 
            && argv[0]->type == CAMEL_SEXP_RES_STRING) {
 
1064
            && argv[0]->type == CAMEL_SEXP_RES_STRING
 
1065
            && !g_cancellable_is_cancelled (search->priv->cancellable)) {
1037
1066
                gchar *headername;
1038
1067
                const gchar *header = NULL, *charset = NULL;
1039
1068
                gchar strbuf[32];
1045
1074
 
1046
1075
                /* only a subset of headers are supported .. */
1047
1076
                headername = argv[0]->value.string;
1048
 
                if (!g_ascii_strcasecmp(headername, "subject")) {
 
1077
                if (!g_ascii_strcasecmp (headername, "subject")) {
1049
1078
                        header = camel_message_info_subject (search->current);
1050
 
                } else if (!g_ascii_strcasecmp(headername, "date")) {
 
1079
                } else if (!g_ascii_strcasecmp (headername, "date")) {
1051
1080
                        /* FIXME: not a very useful form of the date */
1052
 
                        sprintf(strbuf, "%d", (gint)camel_message_info_date_sent(search->current));
 
1081
                        sprintf (strbuf, "%d", (gint) camel_message_info_date_sent (search->current));
1053
1082
                        header = strbuf;
1054
 
                } else if (!g_ascii_strcasecmp(headername, "from")) {
 
1083
                } else if (!g_ascii_strcasecmp (headername, "from")) {
1055
1084
                        header = camel_message_info_from (search->current);
1056
1085
                        type = CAMEL_SEARCH_TYPE_ADDRESS;
1057
 
                } else if (!g_ascii_strcasecmp(headername, "to")) {
 
1086
                } else if (!g_ascii_strcasecmp (headername, "to")) {
1058
1087
                        header = camel_message_info_to (search->current);
1059
1088
                        type = CAMEL_SEARCH_TYPE_ADDRESS;
1060
 
                } else if (!g_ascii_strcasecmp(headername, "cc")) {
 
1089
                } else if (!g_ascii_strcasecmp (headername, "cc")) {
1061
1090
                        header = camel_message_info_cc (search->current);
1062
1091
                        type = CAMEL_SEARCH_TYPE_ADDRESS;
1063
 
                } else if (!g_ascii_strcasecmp(headername, "x-camel-mlist")) {
 
1092
                } else if (!g_ascii_strcasecmp (headername, "x-camel-mlist")) {
1064
1093
                        header = camel_message_info_mlist (search->current);
1065
1094
                        type = CAMEL_SEARCH_TYPE_MLIST;
1066
1095
                } else {
1129
1158
static void
1130
1159
l_printf (gchar *node)
1131
1160
{
1132
 
printf("%s\t", node);
 
1161
printf ("%s\t", node);
1133
1162
}
1134
1163
*/
1135
1164
 
1177
1206
{
1178
1207
        CamelSExpResult *r;
1179
1208
 
1180
 
        r(printf ("executing header-exists\n"));
 
1209
        r (printf ("executing header-exists\n"));
1181
1210
 
1182
1211
        if (search->current) {
1183
1212
                r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
1361
1390
static GPtrArray *
1362
1391
match_words_index (CamelFolderSearch *search,
1363
1392
                   struct _camel_search_words *words,
 
1393
                   GCancellable *cancellable,
1364
1394
                   GError **error)
1365
1395
{
1366
1396
        GPtrArray *result = g_ptr_array_new ();
1367
 
        GHashTable *ht = g_hash_table_new (g_str_hash, g_str_equal);
1368
1397
        struct IterData lambdafoo;
1369
1398
        CamelIndexCursor *wc, *nc;
1370
1399
        const gchar *word, *name;
1371
1400
        gint i;
1372
1401
 
 
1402
        if (g_cancellable_set_error_if_cancelled (cancellable, error))
 
1403
                return result;
 
1404
 
1373
1405
        /* we can have a maximum of 32 words, as we use it as the AND mask */
1374
1406
 
1375
1407
        wc = camel_index_words (search->body_index);
1376
1408
        if (wc) {
 
1409
                GHashTable *ht = g_hash_table_new (g_str_hash, g_str_equal);
 
1410
 
1377
1411
                while ((word = camel_index_cursor_next (wc))) {
1378
1412
                        for (i = 0; i < words->len; i++) {
1379
1413
                                if (camel_ustrstrcase (word, words->words[i]->word) != NULL) {
1412
1446
        gint truth = FALSE;
1413
1447
        gint parts, i;
1414
1448
 
 
1449
        if (g_cancellable_is_cancelled (cancellable))
 
1450
                return FALSE;
 
1451
 
1415
1452
        containee = camel_medium_get_content (CAMEL_MEDIUM (object));
1416
1453
 
1417
1454
        if (containee == NULL)
1428
1465
        } else if (CAMEL_IS_MIME_MESSAGE (containee)) {
1429
1466
                /* for messages we only look at its contents */
1430
1467
                truth = match_words_1message ((CamelDataWrapper *) containee, words, mask, cancellable);
1431
 
        } else if (camel_content_type_is(CAMEL_DATA_WRAPPER (containee)->mime_type, "text", "*")) {
 
1468
        } else if (camel_content_type_is (CAMEL_DATA_WRAPPER (containee)->mime_type, "text", "*")) {
1432
1469
                /* for all other text parts, we look inside, otherwise we dont care */
1433
1470
                CamelStream *stream;
1434
1471
                GByteArray *byte_array;
1467
1504
        CamelMimeMessage *msg;
1468
1505
        gint truth = FALSE;
1469
1506
 
 
1507
        if (g_cancellable_set_error_if_cancelled (cancellable, error))
 
1508
                return truth;
 
1509
 
1470
1510
        msg = camel_folder_get_message_sync (folder, uid, cancellable, error);
1471
1511
        if (msg) {
1472
1512
                mask = 0;
1486
1526
        gint i;
1487
1527
        GPtrArray *matches = g_ptr_array_new ();
1488
1528
 
 
1529
        if (g_cancellable_set_error_if_cancelled (cancellable, error))
 
1530
                return matches;
 
1531
 
1489
1532
        if (search->body_index) {
1490
1533
                GPtrArray *indexed;
1491
1534
                struct _camel_search_words *simple;
1492
1535
 
1493
1536
                simple = camel_search_words_simple (words);
1494
 
                indexed = match_words_index (search, simple, error);
 
1537
                indexed = match_words_index (search, simple, cancellable, error);
1495
1538
                camel_search_words_free (simple);
1496
1539
 
1497
 
                for (i = 0; i < indexed->len; i++) {
 
1540
                for (i = 0; i < indexed->len && !g_cancellable_is_cancelled (cancellable); i++) {
1498
1541
                        const gchar *uid = g_ptr_array_index (indexed, i);
1499
1542
 
1500
1543
                        if (match_words_message (
1507
1550
        } else {
1508
1551
                GPtrArray *v = search->summary_set ? search->summary_set : search->summary;
1509
1552
 
1510
 
                for (i = 0; i < v->len; i++) {
 
1553
                for (i = 0; i < v->len && !g_cancellable_is_cancelled (cancellable); i++) {
1511
1554
                        gchar *uid  = g_ptr_array_index (v, i);
1512
1555
 
1513
1556
                        if (match_words_message (
1538
1581
                if (argc == 1 && argv[0]->value.string[0] == 0) {
1539
1582
                        truth = TRUE;
1540
1583
                } else {
1541
 
                        for (i = 0; i < argc && !truth; i++) {
 
1584
                        for (i = 0; i < argc && !truth && !g_cancellable_is_cancelled (search->priv->cancellable); i++) {
1542
1585
                                if (argv[i]->type == CAMEL_SEXP_RES_STRING) {
1543
1586
                                        words = camel_search_words_split ((const guchar *) argv[i]->value.string);
1544
1587
                                        truth = TRUE;
1562
1605
                if (argc == 1 && argv[0]->value.string[0] == 0) {
1563
1606
                        GPtrArray *v = search->summary_set ? search->summary_set : search->summary;
1564
1607
 
1565
 
                        for (i = 0; i < v->len; i++) {
 
1608
                        for (i = 0; i < v->len && !g_cancellable_is_cancelled (search->priv->cancellable); i++) {
1566
1609
                                gchar *uid = g_ptr_array_index (v, i);
1567
1610
 
1568
1611
                                g_ptr_array_add (r->value.ptrarray, uid);
1571
1614
                        GHashTable *ht = g_hash_table_new (g_str_hash, g_str_equal);
1572
1615
                        GPtrArray *matches;
1573
1616
 
1574
 
                        for (i = 0; i < argc; i++) {
 
1617
                        for (i = 0; i < argc && !g_cancellable_is_cancelled (search->priv->cancellable); i++) {
1575
1618
                                if (argv[i]->type == CAMEL_SEXP_RES_STRING) {
1576
1619
                                        words = camel_search_words_split ((const guchar *) argv[i]->value.string);
1577
1620
                                        if ((words->type & CAMEL_SEARCH_WORD_COMPLEX) == 0 && search->body_index) {
1578
 
                                                matches = match_words_index (search, words, error);
 
1621
                                                matches = match_words_index (search, words, search->priv->cancellable, error);
1579
1622
                                        } else {
1580
1623
                                                matches = match_words_messages (search, words, search->priv->cancellable, error);
1581
1624
                                        }
1609
1652
 
1610
1653
                r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
1611
1654
 
1612
 
                if (camel_search_build_match_regex (&pattern, CAMEL_SEARCH_MATCH_ICASE | CAMEL_SEARCH_MATCH_REGEX | CAMEL_SEARCH_MATCH_NEWLINE, argc, argv, search->priv->error) == 0) {
 
1655
                if (!g_cancellable_is_cancelled (search->priv->cancellable) &&
 
1656
                    camel_search_build_match_regex (&pattern, CAMEL_SEARCH_MATCH_ICASE | CAMEL_SEARCH_MATCH_REGEX | CAMEL_SEARCH_MATCH_NEWLINE, argc, argv, search->priv->error) == 0) {
1613
1657
                        r->value.boolean = camel_search_message_body_contains ((CamelDataWrapper *) msg, &pattern);
1614
1658
                        regfree (&pattern);
1615
1659
                } else
1622
1666
                r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
1623
1667
                r->value.ptrarray = g_ptr_array_new ();
1624
1668
 
1625
 
                if (camel_search_build_match_regex (&pattern, CAMEL_SEARCH_MATCH_ICASE | CAMEL_SEARCH_MATCH_REGEX | CAMEL_SEARCH_MATCH_NEWLINE, argc, argv, search->priv->error) == 0) {
 
1669
                if (!g_cancellable_is_cancelled (search->priv->cancellable) &&
 
1670
                    camel_search_build_match_regex (&pattern, CAMEL_SEARCH_MATCH_ICASE | CAMEL_SEARCH_MATCH_REGEX | CAMEL_SEARCH_MATCH_NEWLINE, argc, argv, search->priv->error) == 0) {
1626
1671
                        gint i;
1627
1672
                        GPtrArray *v = search->summary_set ? search->summary_set : search->summary;
1628
1673
                        CamelMimeMessage *message;
1657
1702
        CamelSExpResult *r;
1658
1703
        gint i;
1659
1704
 
1660
 
        r(printf("executing user-flag\n"));
 
1705
        r (printf ("executing user-flag\n"));
1661
1706
 
1662
1707
        /* are we inside a match-all? */
1663
1708
        if (search->current) {
1688
1733
{
1689
1734
        CamelSExpResult *r;
1690
1735
 
1691
 
        r(printf ("executing system-flag\n"));
 
1736
        r (printf ("executing system-flag\n"));
1692
1737
 
1693
1738
        if (search->current) {
1694
1739
                gboolean truth = FALSE;
1715
1760
        const gchar *value = NULL;
1716
1761
        CamelSExpResult *r;
1717
1762
 
1718
 
        r(printf("executing user-tag\n"));
 
1763
        r (printf ("executing user-tag\n"));
1719
1764
 
1720
1765
        if (search->current && argc == 1)
1721
1766
                value = camel_message_info_user_tag (search->current, argv[0]->value.string);
1734
1779
{
1735
1780
        CamelSExpResult *r;
1736
1781
 
1737
 
        r(printf("executing get-sent-date\n"));
 
1782
        r (printf ("executing get-sent-date\n"));
1738
1783
 
1739
1784
        /* are we inside a match-all? */
1740
1785
        if (s->current) {
1757
1802
{
1758
1803
        CamelSExpResult *r;
1759
1804
 
1760
 
        r(printf("executing get-received-date\n"));
 
1805
        r (printf ("executing get-received-date\n"));
1761
1806
 
1762
1807
        /* are we inside a match-all? */
1763
1808
        if (s->current) {
1780
1825
{
1781
1826
        CamelSExpResult *r;
1782
1827
 
1783
 
        r(printf("executing get-current-date\n"));
 
1828
        r (printf ("executing get-current-date\n"));
1784
1829
 
1785
1830
        r = camel_sexp_result_new (f, CAMEL_SEXP_RES_INT);
1786
1831
        r->value.number = time (NULL);
1795
1840
{
1796
1841
        CamelSExpResult *r;
1797
1842
 
1798
 
        r(printf("executing get-relative-months\n"));
 
1843
        r (printf ("executing get-relative-months\n"));
1799
1844
 
1800
1845
        if (argc != 1 || argv[0]->type != CAMEL_SEXP_RES_INT) {
1801
1846
                r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
1818
1863
{
1819
1864
        CamelSExpResult *r;
1820
1865
 
1821
 
        r(printf("executing get-size\n"));
 
1866
        r (printf ("executing get-size\n"));
1822
1867
 
1823
1868
        /* are we inside a match-all? */
1824
1869
        if (s->current) {
1841
1886
        CamelSExpResult *r;
1842
1887
        gint i;
1843
1888
 
1844
 
        r(printf("executing uid\n"));
 
1889
        r (printf ("executing uid\n"));
1845
1890
 
1846
1891
        /* are we inside a match-all? */
1847
1892
        if (search->current) {