Statistics
| Revision:

root / libsylph / filter.h @ 836

History | View | Annotate | Download (4.9 kB)

1
/*
2
 * LibSylph -- E-Mail client library
3
 * Copyright (C) 1999-2005 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_ACCOUNT
51
} FilterCondType;
52
53
typedef enum
54
{
55
        FLT_CONTAIN,
56
        FLT_EQUAL,
57
        FLT_REGEX
58
} FilterMatchType;
59
60
typedef enum
61
{
62
        FLT_NOT_MATCH        = 1 << 0,
63
        FLT_CASE_SENS        = 1 << 1
64
} FilterMatchFlag;
65
66
typedef enum
67
{
68
        FLT_OR,
69
        FLT_AND
70
} FilterBoolOp;
71
72
typedef enum
73
{
74
        FLT_ACTION_MOVE,
75
        FLT_ACTION_COPY,
76
        FLT_ACTION_NOT_RECEIVE,
77
        FLT_ACTION_DELETE,
78
        FLT_ACTION_EXEC,
79
        FLT_ACTION_EXEC_ASYNC,
80
        FLT_ACTION_MARK,
81
        FLT_ACTION_COLOR_LABEL,
82
        FLT_ACTION_MARK_READ,
83
        FLT_ACTION_FORWARD,
84
        FLT_ACTION_FORWARD_AS_ATTACHMENT,
85
        FLT_ACTION_REDIRECT,
86
        FLT_ACTION_STOP_EVAL,
87
        FLT_ACTION_NONE
88
} FilterActionType;
89
90
typedef enum
91
{
92
        FLT_BY_NONE,
93
        FLT_BY_AUTO,
94
        FLT_BY_FROM,
95
        FLT_BY_TO,
96
        FLT_BY_SUBJECT
97
} FilterCreateType;
98
99
#define FLT_IS_NOT_MATCH(flag)        ((flag & FLT_NOT_MATCH) != 0)
100
#define FLT_IS_CASE_SENS(flag)        ((flag & FLT_CASE_SENS) != 0)
101
102
struct _FilterCond
103
{
104
        FilterCondType type;
105
106
        gchar *header_name;
107
108
        gchar *str_value;
109
        gint int_value;
110
111
        FilterMatchType match_type;
112
        FilterMatchFlag match_flag;
113
114
        StrFindFunc match_func;
115
};
116
117
struct _FilterAction
118
{
119
        FilterActionType type;
120
121
        gchar *str_value;
122
        gint int_value;
123
};
124
125
struct _FilterRule
126
{
127
        gchar *name;
128
129
        FilterBoolOp bool_op;
130
131
        GSList *cond_list;
132
        GSList *action_list;
133
134
        FilterTiming timing;
135
        gboolean enabled;
136
137
        gchar *target_folder;
138
        gboolean recursive;
139
};
140
141
struct _FilterInfo
142
{
143
        PrefsAccount *account;
144
        MsgFlags flags;
145
146
        gboolean actions[FLT_ACTION_NONE];
147
        GSList *dest_list;
148
        FolderItem *move_dest;
149
        gboolean drop_done;
150
};
151
152
gint filter_apply                        (GSList                        *fltlist,
153
                                         const gchar                *file,
154
                                         FilterInfo                *fltinfo);
155
gint filter_apply_msginfo                (GSList                        *fltlist,
156
                                         MsgInfo                *msginfo,
157
                                         FilterInfo                *fltinfo);
158
159
gint filter_action_exec                        (FilterRule                *rule,
160
                                         MsgInfo                *msginfo,
161
                                         const gchar                *file,
162
                                         FilterInfo                *fltinfo);
163
164
gboolean filter_match_rule                (FilterRule                *rule,
165
                                         MsgInfo                *msginfo,
166
                                         GSList                        *hlist,
167
                                         FilterInfo                *fltinfo);
168
169
gboolean filter_rule_requires_full_headers        (FilterRule        *rule);
170
171
/* read / write config */
172
GSList *filter_xml_node_to_filter_list        (GNode                        *node);
173
GSList *filter_read_file                (const gchar                *file);
174
void filter_read_config                        (void);
175
void filter_write_file                        (GSList                        *list,
176
                                         const gchar                *file);
177
void filter_write_config                (void);
178
179
/* for old filterrc */
180
gchar *filter_get_str                        (FilterRule                *rule);
181
FilterRule *filter_read_str                (const gchar                *str);
182
183
FilterRule *filter_rule_new                (const gchar                *name,
184
                                         FilterBoolOp                 bool_op,
185
                                         GSList                        *cond_list,
186
                                         GSList                        *action_list);
187
FilterCond *filter_cond_new                (FilterCondType                 type,
188
                                         FilterMatchType         match_type,
189
                                         FilterMatchFlag         match_flag,
190
                                         const gchar                *header,
191
                                         const gchar                *body);
192
FilterAction *filter_action_new                (FilterActionType         type,
193
                                         const gchar                *str);
194
FilterInfo *filter_info_new                (void);
195
196
void filter_rule_rename_dest_path        (FilterRule                *rule,
197
                                         const gchar                *old_path,
198
                                         const gchar                *new_path);
199
void filter_rule_delete_action_by_dest_path
200
                                        (FilterRule                *rule,
201
                                         const gchar                *path);
202
203
void filter_list_rename_path                (const gchar                *old_path,
204
                                         const gchar                *new_path);
205
void filter_list_delete_path                (const gchar                *path);
206
207
void filter_rule_match_type_str_to_enum        (const gchar                *type_str,
208
                                         FilterMatchType        *type,
209
                                         FilterMatchFlag        *flag);
210
211
void filter_get_keyword_from_msg        (MsgInfo                *msginfo,
212
                                         gchar                       **header,
213
                                         gchar                       **key,
214
                                         FilterCreateType         type);
215
216
void filter_rule_list_free                (GSList                        *fltlist);
217
void filter_rule_free                        (FilterRule                *rule);
218
void filter_cond_list_free                (GSList                        *cond_list);
219
void filter_action_list_free                (GSList                        *action_list);
220
void filter_info_free                        (FilterInfo                *info);
221
222
#endif /* __FILTER_H__ */