Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / camel-folder-search.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  *  Copyright (C) 2000 Ximian Inc.
4  *
5  *  Authors: Michael Zucchi <notzed@ximian.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of version 2 of the GNU Lesser General Public
9  * License as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #ifndef _CAMEL_FOLDER_SEARCH_H
23 #define _CAMEL_FOLDER_SEARCH_H
24
25 #include <libedataserver/e-sexp.h>
26 #include <camel/camel-folder.h>
27 #include <camel/camel-object.h>
28 #include <camel/camel-index.h>
29
30 #define CAMEL_FOLDER_SEARCH_TYPE         (camel_folder_search_get_type ())
31 #define CAMEL_FOLDER_SEARCH(obj)         CAMEL_CHECK_CAST (obj, camel_folder_search_get_type (), CamelFolderSearch)
32 #define CAMEL_FOLDER_SEARCH_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_folder_search_get_type (), CamelFolderSearchClass)
33 #define CAMEL_IS_FOLDER_SEARCH(obj)      CAMEL_CHECK_TYPE (obj, camel_folder_search_get_type ())
34
35 G_BEGIN_DECLS
36
37 typedef struct _CamelFolderSearchClass CamelFolderSearchClass;
38
39 struct _CamelFolderSearch {
40         CamelObject parent;
41
42         struct _CamelFolderSearchPrivate *priv;
43
44         ESExp *sexp;            /* s-exp evaluator */
45         char *last_search;      /* last searched expression */
46
47         /* these are only valid during the search, and are reset afterwards */
48         CamelFolder *folder;    /* folder for current search */
49         GPtrArray *summary;     /* summary array for current search */
50         GPtrArray *summary_set; /* subset of summary to actually include in search */
51         GHashTable *summary_hash; /* hashtable of summary items */
52         CamelMessageInfo *current; /* current message info, when searching one by one */
53         CamelMimeMessage *current_message; /* cache of current message, if required */
54         CamelIndex *body_index;
55 };
56
57 struct _CamelFolderSearchClass {
58         CamelObjectClass parent_class;
59
60         /* general bool/comparison options, usually these wont need to be set, unless it is compiling into another language */
61         ESExpResult * (*and)(struct _ESExp *f, int argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
62         ESExpResult * (*or)(struct _ESExp *f, int argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
63         ESExpResult * (*not)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
64         ESExpResult * (*lt)(struct _ESExp *f, int argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
65         ESExpResult * (*gt)(struct _ESExp *f, int argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
66         ESExpResult * (*eq)(struct _ESExp *f, int argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
67
68         /* search options */
69         /* (match-all [boolean expression]) Apply match to all messages */
70         ESExpResult * (*match_all)(struct _ESExp *f, int argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
71
72         /* (match-threads "type" [array expression]) add all related threads */
73         ESExpResult * (*match_threads)(struct _ESExp *f, int argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
74
75         /* (body-contains "string1" "string2" ...) Returns a list of matches, or true if in single-message mode */
76         ESExpResult * (*body_contains)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
77
78         /* (header-contains "headername" "string1" ...) List of matches, or true if in single-message mode */
79         ESExpResult * (*header_contains)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
80         
81         /* (header-matches "headername" "string") */
82         ESExpResult * (*header_matches)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
83         
84         /* (header-starts-with "headername" "string") */
85         ESExpResult * (*header_starts_with)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
86         
87         /* (header-ends-with "headername" "string") */
88         ESExpResult * (*header_ends_with)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
89         
90         /* (header-exists "headername") */
91         ESExpResult * (*header_exists)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
92         
93         /* (user-flag "flagname" "flagname" ...) If one of user-flag set */
94         ESExpResult * (*user_flag)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
95
96         /* (user-tag "flagname") Returns the value of a user tag.  Can only be used in match-all */
97         ESExpResult * (*user_tag)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
98         
99         /* (system-flag "flagname") Returns the value of a system flag.  Can only be used in match-all */
100         ESExpResult * (*system_flag)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
101         
102         /* (get-sent-date) Retrieve the date that the message was sent on as a time_t */
103         ESExpResult * (*get_sent_date)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
104
105         /* (get-received-date) Retrieve the date that the message was received on as a time_t */
106         ESExpResult * (*get_received_date)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
107
108         /* (get-current-date) Retrieve 'now' as a time_t */
109         ESExpResult * (*get_current_date)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
110
111         /* (get-size) Retrieve message size as an int (in kilobytes) */
112         ESExpResult * (*get_size)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
113
114         /* (uid "uid" ...) True if the uid is in the list */
115         ESExpResult * (*uid)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
116 };
117
118 CamelType               camel_folder_search_get_type    (void);
119 CamelFolderSearch      *camel_folder_search_new (void);
120 void camel_folder_search_construct (CamelFolderSearch *search);
121
122 /* This stuff currently gets cleared when you run a search ... what on earth was i thinking ... */
123 void camel_folder_search_set_folder(CamelFolderSearch *search, CamelFolder *folder);
124 void camel_folder_search_set_summary(CamelFolderSearch *search, GPtrArray *summary);
125 void camel_folder_search_set_body_index(CamelFolderSearch *search, CamelIndex *index);
126 /* this interface is deprecated */
127 GPtrArray *camel_folder_search_execute_expression(CamelFolderSearch *search, const char *expr, CamelException *ex);
128
129 GPtrArray *camel_folder_search_search(CamelFolderSearch *search, const char *expr, GPtrArray *uids, CamelException *ex);
130 void camel_folder_search_free_result(CamelFolderSearch *search, GPtrArray *);
131
132 G_END_DECLS
133
134 #endif /* ! _CAMEL_FOLDER_SEARCH_H */