Statistics
| Revision:

root / libsylph / filter.h @ 2427

History | View | Annotate | Download (5.1 kB)

1
/*
2
 * LibSylph -- E-Mail client library
3
 * Copyright (C) 1999-2007 Hiroyuki Yamamoto
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
20
#ifndef __FILTER_H__
21
#define __FILTER_H__
22
23
#include <glib.h>
24
25
#include "folder.h"
26
#include "procmsg.h"
27
#include "utils.h"
28
29
typedef struct _FilterCond        FilterCond;
30
typedef struct _FilterAction        FilterAction;
31
typedef struct _FilterRule        FilterRule;
32
typedef struct _FilterInfo        FilterInfo;
33
34
typedef enum
35
{
36
        FLT_TIMING_ANY,
37
        FLT_TIMING_ON_RECEIVE,
38
        FLT_TIMING_MANUAL
39
} FilterTiming;
40
41
typedef enum
42
{
43
        FLT_COND_HEADER,
44
        FLT_COND_ANY_HEADER,
45
        FLT_COND_TO_OR_CC,
46
        FLT_COND_BODY,
47
        FLT_COND_CMD_TEST,
48
        FLT_COND_SIZE_GREATER,
49
        FLT_COND_AGE_GREATER,
50
        FLT_COND_UNREAD,
51
        FLT_COND_MARK,
52
        FLT_COND_COLOR_LABEL,
53
        FLT_COND_MIME,
54
        FLT_COND_ACCOUNT
55
} FilterCondType;
56
57
typedef enum
58
{
59
        FLT_CONTAIN,
60
        FLT_EQUAL,
61
        FLT_REGEX
62
} FilterMatchType;
63
64
typedef enum
65
{
66
        FLT_NOT_MATCH        = 1 << 0,
67
        FLT_CASE_SENS        = 1 << 1
68
} FilterMatchFlag;
69
70
typedef enum
71
{
72
        FLT_OR,
73
        FLT_AND
74
} FilterBoolOp;
75
76
typedef enum
77
{
78
        FLT_ACTION_MOVE,
79
        FLT_ACTION_COPY,
80
        FLT_ACTION_NOT_RECEIVE,
81
        FLT_ACTION_DELETE,
82
        FLT_ACTION_EXEC,
83
        FLT_ACTION_EXEC_ASYNC,
84
        FLT_ACTION_MARK,
85
        FLT_ACTION_COLOR_LABEL,
86
        FLT_ACTION_MARK_READ,
87
        FLT_ACTION_FORWARD,
88
        FLT_ACTION_FORWARD_AS_ATTACHMENT,
89
        FLT_ACTION_REDIRECT,
90
        FLT_ACTION_STOP_EVAL,
91
        FLT_ACTION_NONE
92
} FilterActionType;
93
94
typedef enum
95
{
96
        FLT_BY_NONE,
97
        FLT_BY_AUTO,
98
        FLT_BY_FROM,
99
        FLT_BY_TO,
100
        FLT_BY_SUBJECT
101
} FilterCreateType;
102
103
typedef enum
104
{
105
        FLT_ERROR_OK,
106
        FLT_ERROR_ERROR,
107
        FLT_ERROR_EXEC_FAILED
108
} FilterErrorValue;
109
110
#define FLT_IS_NOT_MATCH(flag)        ((flag & FLT_NOT_MATCH) != 0)
111
#define FLT_IS_CASE_SENS(flag)        ((flag & FLT_CASE_SENS) != 0)
112
113
struct _FilterCond
114
{
115
        FilterCondType type;
116
117
        gchar *header_name;
118
119
        gchar *str_value;
120
        gint int_value;
121
122
        FilterMatchType match_type;
123
        FilterMatchFlag match_flag;
124
125
        StrFindFunc match_func;
126
};
127
128
struct _FilterAction
129
{
130
        FilterActionType type;
131
132
        gchar *str_value;
133
        gint int_value;
134
};
135
136
struct _FilterRule
137
{
138
        gchar *name;
139
140
        FilterBoolOp bool_op;
141
142
        GSList *cond_list;
143
        GSList *action_list;
144
145
        FilterTiming timing;
146
        gboolean enabled;
147
148
        gchar *target_folder;
149
        gboolean recursive;
150
};
151
152
struct _FilterInfo
153
{
154
        PrefsAccount *account;
155
        MsgFlags flags;
156
157
        gboolean actions[FLT_ACTION_NONE];
158
        GSList *dest_list;
159
        FolderItem *move_dest;
160
        gboolean drop_done;
161
162
        FilterErrorValue error;
163
};
164
165
gint filter_apply                        (GSList                        *fltlist,
166
                                         const gchar                *file,
167
                                         FilterInfo                *fltinfo);
168
gint filter_apply_msginfo                (GSList                        *fltlist,
169
                                         MsgInfo                *msginfo,
170
                                         FilterInfo                *fltinfo);
171
172
gint filter_action_exec                        (FilterRule                *rule,
173
                                         MsgInfo                *msginfo,
174
                                         const gchar                *file,
175
                                         FilterInfo                *fltinfo);
176
177
gboolean filter_match_rule                (FilterRule                *rule,
178
                                         MsgInfo                *msginfo,
179
                                         GSList                        *hlist,
180
                                         FilterInfo                *fltinfo);
181
182
gboolean filter_rule_requires_full_headers        (FilterRule        *rule);
183
184
/* read / write config */
185
GSList *filter_xml_node_to_filter_list        (GNode                        *node);
186
GSList *filter_read_file                (const gchar                *file);
187
void filter_read_config                        (void);
188
void filter_write_file                        (GSList                        *list,
189
                                         const gchar                *file);
190
void filter_write_config                (void);
191
192
/* for old filterrc */
193
gchar *filter_get_str                        (FilterRule                *rule);
194
FilterRule *filter_read_str                (const gchar                *str);
195
196
FilterRule *filter_rule_new                (const gchar                *name,
197
                                         FilterBoolOp                 bool_op,
198
                                         GSList                        *cond_list,
199
                                         GSList                        *action_list);
200
FilterCond *filter_cond_new                (FilterCondType                 type,
201
                                         FilterMatchType         match_type,
202
                                         FilterMatchFlag         match_flag,
203
                                         const gchar                *header,
204
                                         const gchar                *value);
205
FilterAction *filter_action_new                (FilterActionType         type,
206
                                         const gchar                *str);
207
FilterInfo *filter_info_new                (void);
208
209
void filter_rule_rename_dest_path        (FilterRule                *rule,
210
                                         const gchar                *old_path,
211
                                         const gchar                *new_path);
212
void filter_rule_delete_action_by_dest_path
213
                                        (FilterRule                *rule,
214
                                         const gchar                *path);
215
216
void filter_list_rename_path                (const gchar                *old_path,
217
                                         const gchar                *new_path);
218
void filter_list_delete_path                (const gchar                *path);
219
220
void filter_rule_match_type_str_to_enum        (const gchar                *type_str,
221
                                         FilterMatchType        *type,
222
                                         FilterMatchFlag        *flag);
223
224
void filter_get_keyword_from_msg        (MsgInfo                *msginfo,
225
                                         gchar                       **header,
226
                                         gchar                       **key,
227
                                         FilterCreateType         type);
228
229
void filter_rule_list_free                (GSList                        *fltlist);
230
void filter_rule_free                        (FilterRule                *rule);
231
void filter_cond_list_free                (GSList                        *cond_list);
232
void filter_action_list_free                (GSList                        *action_list);
233
void filter_info_free                        (FilterInfo                *info);
234
235
#endif /* __FILTER_H__ */