1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
5 * Authors: Michael Zucchi <notzed@ximian.com>
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.
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.
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.
22 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
23 #error "Only <camel/camel.h> can be included directly."
26 #ifndef CAMEL_FOLDER_SEARCH_H
27 #define CAMEL_FOLDER_SEARCH_H
29 #include <camel/camel-folder.h>
30 #include <camel/camel-index.h>
31 #include <camel/camel-sexp.h>
33 /* Standard GObject macros */
34 #define CAMEL_TYPE_FOLDER_SEARCH \
35 (camel_folder_search_get_type ())
36 #define CAMEL_FOLDER_SEARCH(obj) \
37 (G_TYPE_CHECK_INSTANCE_CAST \
38 ((obj), CAMEL_TYPE_FOLDER_SEARCH, CamelFolderSearch))
39 #define CAMEL_FOLDER_SEARCH_CLASS(cls) \
40 (G_TYPE_CHECK_CLASS_CAST \
41 ((cls), CAMEL_TYPE_FOLDER_SEARCH, CamelFolderSearchClass))
42 #define CAMEL_IS_FOLDER_SEARCH(obj) \
43 (G_TYPE_CHECK_INSTANCE_TYPE \
44 ((obj), CAMEL_TYPE_FOLDER_SEARCH))
45 #define CAMEL_IS_FOLDER_SEARCH_CLASS(cls) \
46 (G_TYPE_CHECK_CLASS_TYPE \
47 ((cls), CAMEL_TYPE_FOLDER_SEARCH))
48 #define CAMEL_FOLDER_SEARCH_GET_CLASS(obj) \
49 (G_TYPE_INSTANCE_GET_CLASS \
50 ((obj), CAMEL_TYPE_FOLDER_SEARCH, CamelFolderSearchClass))
54 typedef struct _CamelFolderSearch CamelFolderSearch;
55 typedef struct _CamelFolderSearchClass CamelFolderSearchClass;
56 typedef struct _CamelFolderSearchPrivate CamelFolderSearchPrivate;
58 struct _CamelFolderSearch {
60 CamelFolderSearchPrivate *priv;
62 CamelSExp *sexp; /* s-exp evaluator */
63 gchar *last_search; /* last searched expression */
65 /* these are only valid during the search, and are reset afterwards */
66 CamelFolder *folder; /* folder for current search */
67 GPtrArray *summary; /* summary array for current search */
68 GPtrArray *summary_set; /* subset of summary to actually include in search */
69 CamelMessageInfo *current; /* current message info, when searching one by one */
70 CamelMimeMessage *current_message; /* cache of current message, if required */
71 CamelIndex *body_index;
74 struct _CamelFolderSearchClass {
75 CamelObjectClass parent_class;
77 /* general bool/comparison options, usually these wont need to be set, unless it is compiling into another language */
78 CamelSExpResult * (*and_)(CamelSExp *f, gint argc, CamelSExpTerm **argv, CamelFolderSearch *s);
79 CamelSExpResult * (*or_)(CamelSExp *f, gint argc, CamelSExpTerm **argv, CamelFolderSearch *s);
80 CamelSExpResult * (*not_)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
81 CamelSExpResult * (*lt)(CamelSExp *f, gint argc, CamelSExpTerm **argv, CamelFolderSearch *s);
82 CamelSExpResult * (*gt)(CamelSExp *f, gint argc, CamelSExpTerm **argv, CamelFolderSearch *s);
83 CamelSExpResult * (*eq)(CamelSExp *f, gint argc, CamelSExpTerm **argv, CamelFolderSearch *s);
86 /* (match-all [boolean expression]) Apply match to all messages */
87 CamelSExpResult * (*match_all)(CamelSExp *f, gint argc, CamelSExpTerm **argv, CamelFolderSearch *s);
89 /* (match-threads "type" [array expression]) add all related threads */
90 CamelSExpResult * (*match_threads)(CamelSExp *f, gint argc, CamelSExpTerm **argv, CamelFolderSearch *s);
92 /* (body-contains "string1" "string2" ...) Returns a list of matches, or true if in single-message mode */
93 CamelSExpResult * (*body_contains)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
95 /* (body-regex "regex") Returns a list of matches, or true if in single-message mode */
96 CamelSExpResult * (*body_regex)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
98 /* (header-contains "headername" "string1" ...) List of matches, or true if in single-message mode */
99 CamelSExpResult * (*header_contains)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
101 /* (header-matches "headername" "string") */
102 CamelSExpResult * (*header_matches)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
104 /* (header-starts-with "headername" "string") */
105 CamelSExpResult * (*header_starts_with)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
107 /* (header-ends-with "headername" "string") */
108 CamelSExpResult * (*header_ends_with)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
110 /* (header-exists "headername") */
111 CamelSExpResult * (*header_exists)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
113 /* (header-soundex "headername" "string") */
114 CamelSExpResult * (*header_soundex)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
116 /* (header-regex "headername" "regex_string") */
117 CamelSExpResult * (*header_regex)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
119 /* (header-full-regex "regex") */
120 CamelSExpResult * (*header_full_regex)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
122 /* (user-flag "flagname" "flagname" ...) If one of user-flag set */
123 CamelSExpResult * (*user_flag)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
125 /* (user-tag "flagname") Returns the value of a user tag. Can only be used in match-all */
126 CamelSExpResult * (*user_tag)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
128 /* (system-flag "flagname") Returns the value of a system flag. Can only be used in match-all */
129 CamelSExpResult * (*system_flag)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
131 /* (get-sent-date) Retrieve the date that the message was sent on as a time_t */
132 CamelSExpResult * (*get_sent_date)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
134 /* (get-received-date) Retrieve the date that the message was received on as a time_t */
135 CamelSExpResult * (*get_received_date)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
137 /* (get-current-date) Retrieve 'now' as a time_t */
138 CamelSExpResult * (*get_current_date)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
140 /* (get-relative-months) Retrieve relative seconds from 'now' and specified number of months as a time_t */
141 CamelSExpResult * (*get_relative_months)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
143 /* (get-size) Retrieve message size as an gint (in kilobytes) */
144 CamelSExpResult * (*get_size)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
146 /* (uid "uid" ...) True if the uid is in the list */
147 CamelSExpResult * (*uid)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
149 /* (message-location "folder_string") True if the message is in the folder's full name "folder_string" */
150 CamelSExpResult * (*message_location)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
154 GType camel_folder_search_get_type (void);
155 CamelFolderSearch *camel_folder_search_new (void);
156 void camel_folder_search_construct (CamelFolderSearch *search);
158 /* This stuff currently gets cleared when you run a search ... what on earth was i thinking ... */
159 void camel_folder_search_set_folder (CamelFolderSearch *search, CamelFolder *folder);
160 void camel_folder_search_set_summary (CamelFolderSearch *search, GPtrArray *summary);
161 void camel_folder_search_set_body_index (CamelFolderSearch *search, CamelIndex *body_index);
163 GPtrArray *camel_folder_search_search (CamelFolderSearch *search, const gchar *expr, GPtrArray *uids, GCancellable *cancellable, GError **error);
164 guint32 camel_folder_search_count (CamelFolderSearch *search, const gchar *expr, GCancellable *cancellable, GError **error);
165 void camel_folder_search_free_result (CamelFolderSearch *search, GPtrArray *);
167 time_t camel_folder_search_util_add_months (time_t t, gint months);
171 #endif /* CAMEL_FOLDER_SEARCH_H */