camel-folder-search.h 6.18 KB
Newer Older
Michael Zucci's avatar
Michael Zucci committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 *  Copyright (C) 2000 Helix Code Inc.
 *
 *  Authors: Michael Zucchi <notzed@helixcode.com>
 *
 *  This program is free software; you can redistribute it and/or 
 *  modify it under the terms of the GNU General Public License as 
 *  published by the Free Software Foundation; either version 2 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 *  USA
 */

#ifndef _CAMEL_FOLDER_SEARCH_H
#define _CAMEL_FOLDER_SEARCH_H

25
#include <camel/camel-object.h>
Michael Zucci's avatar
Michael Zucci committed
26
#include <e-util/e-sexp.h>
27
#include <gal/util/e-util.h>
Michael Zucci's avatar
Michael Zucci committed
28 29 30
#include <libibex/ibex.h>
#include <camel/camel-folder.h>

31
#define CAMEL_FOLDER_SEARCH_TYPE         (camel_folder_search_get_type ())
Peter Williams's avatar
Peter Williams committed
32 33
#define CAMEL_FOLDER_SEARCH(obj)         CAMEL_CHECK_CAST (obj, camel_folder_search_get_type (), CamelFolderSearch)
#define CAMEL_FOLDER_SEARCH_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_folder_search_get_type (), CamelFolderSearchClass)
34
#define CAMEL_IS_FOLDER_SEARCH(obj)      CAMEL_CHECK_TYPE (obj, camel_folder_search_get_type ())
Michael Zucci's avatar
Michael Zucci committed
35 36 37 38

typedef struct _CamelFolderSearchClass CamelFolderSearchClass;

struct _CamelFolderSearch {
39
	CamelObject parent;
Michael Zucci's avatar
Michael Zucci committed
40 41 42 43 44 45 46 47 48 49

	struct _CamelFolderSearchPrivate *priv;

	ESExp *sexp;		/* s-exp evaluator */
	char *last_search;	/* last searched expression */

	/* these are only valid during the search, and are reset afterwards */
	CamelFolder *folder;	/* folder for current search */
	GPtrArray *summary;	/* summary array for current search */
	CamelMessageInfo *current; /* current message info, when searching one by one */
50
	CamelMessageInfo *match1; /* message info, when searching a single message only */
51
	CamelMimeMessage *current_message; /* cache of current message, if required */
Michael Zucci's avatar
Michael Zucci committed
52 53 54 55
	ibex *body_index;
};

struct _CamelFolderSearchClass {
56
	CamelObjectClass parent_class;
Michael Zucci's avatar
Michael Zucci committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

	/* general bool/comparison options, usually these wont need to be set, unless it is compiling into another language */
	ESExpResult * (*and)(struct _ESExp *f, int argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
	ESExpResult * (*or)(struct _ESExp *f, int argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
	ESExpResult * (*not)(struct _ESExp *f, int argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
	ESExpResult * (*lt)(struct _ESExp *f, int argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
	ESExpResult * (*gt)(struct _ESExp *f, int argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
	ESExpResult * (*eq)(struct _ESExp *f, int argc, struct _ESExpTerm **argv, CamelFolderSearch *s);

	/* search options */
	/* (match-all [boolean expression]) Apply match to all messages */
	ESExpResult * (*match_all)(struct _ESExp *f, int argc, struct _ESExpTerm **argv, CamelFolderSearch *s);

	/* (body-contains "string1" "string2" ...) Returns a list of matches, or true if in single-message mode */
	ESExpResult * (*body_contains)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);

	/* (header-contains "headername" "string1" ...) List of matches, or true if in single-message mode */
	ESExpResult * (*header_contains)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
75 76 77 78 79 80 81 82 83 84 85 86 87
	
	/* (header-matches "headername" "string") */
	ESExpResult * (*header_matches)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
	
	/* (header-starts-with "headername" "string") */
	ESExpResult * (*header_starts_with)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
	
	/* (header-ends-with "headername" "string") */
	ESExpResult * (*header_ends_with)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
	
	/* (header-exists "headername") */
	ESExpResult * (*header_exists)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
	
NotZed's avatar
NotZed committed
88 89
	/* (user-flag "flagname" "flagname" ...) If one of user-flag set */
	ESExpResult * (*user_flag)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
90 91 92

	/* (user-tag "flagname") Returns the value of a user tag.  Can only be used in match-all */
	ESExpResult * (*user_tag)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
93 94 95 96
	
	/* (system-flag "flagname") Returns the value of a system flag.  Can only be used in match-all */
	ESExpResult * (*system_flag)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
	
97 98 99 100 101 102 103 104
	/* (get-sent-date) Retrieve the date that the message was sent on as a time_t */
	ESExpResult * (*get_sent_date)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);

	/* (get-received-date) Retrieve the date that the message was received on as a time_t */
	ESExpResult * (*get_received_date)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);

	/* (get-current-date) Retrieve 'now' as a time_t */
	ESExpResult * (*get_current_date)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
105

106 107
	/* (uid "uid" ...) True if the uid is in the list */
	ESExpResult * (*uid)(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *s);
Michael Zucci's avatar
Michael Zucci committed
108 109 110 111 112 113 114 115 116
};

guint		camel_folder_search_get_type	(void);
CamelFolderSearch      *camel_folder_search_new	(void);
void camel_folder_search_construct (CamelFolderSearch *search);

void camel_folder_search_set_folder(CamelFolderSearch *search, CamelFolder *folder);
void camel_folder_search_set_summary(CamelFolderSearch *search, GPtrArray *summary);
void camel_folder_search_set_body_index(CamelFolderSearch *search, ibex *index);
117
GPtrArray *camel_folder_search_execute_expression(CamelFolderSearch *search, const char *expr, CamelException *ex);
118 119
gboolean camel_folder_search_match_expression(CamelFolderSearch *search, const char *expr,
					      const CamelMessageInfo *info, CamelException *ex);
120
void camel_folder_search_free_result(CamelFolderSearch *search, GPtrArray *);
Michael Zucci's avatar
Michael Zucci committed
121 122

#endif /* ! _CAMEL_FOLDER_SEARCH_H */