root / src / filter.h @ 22
History | View | Annotate | Download (4.3 kB)
| 1 | /*
|
|---|---|
| 2 | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client |
| 3 | * Copyright (C) 1999-2004 Hiroyuki Yamamoto |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program 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 |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 | #define FLT_IS_NOT_MATCH(flag) ((flag & FLT_NOT_MATCH) != 0) |
| 91 | #define FLT_IS_CASE_SENS(flag) ((flag & FLT_CASE_SENS) != 0) |
| 92 | |
| 93 | struct _FilterCond
|
| 94 | {
|
| 95 | FilterCondType type; |
| 96 | |
| 97 | gchar *header_name; |
| 98 | |
| 99 | gchar *str_value; |
| 100 | gint int_value; |
| 101 | |
| 102 | FilterMatchType match_type; |
| 103 | FilterMatchFlag match_flag; |
| 104 | |
| 105 | StrFindFunc match_func; |
| 106 | }; |
| 107 | |
| 108 | struct _FilterAction
|
| 109 | {
|
| 110 | FilterActionType type; |
| 111 | |
| 112 | gchar *str_value; |
| 113 | gint int_value; |
| 114 | }; |
| 115 | |
| 116 | struct _FilterRule
|
| 117 | {
|
| 118 | gchar *name; |
| 119 | |
| 120 | FilterBoolOp bool_op; |
| 121 | |
| 122 | GSList *cond_list; |
| 123 | GSList *action_list; |
| 124 | |
| 125 | FilterTiming timing; |
| 126 | gboolean enabled; |
| 127 | }; |
| 128 | |
| 129 | struct _FilterInfo
|
| 130 | {
|
| 131 | PrefsAccount *account; |
| 132 | MsgFlags flags; |
| 133 | |
| 134 | gboolean actions[FLT_ACTION_NONE]; |
| 135 | GSList *dest_list; |
| 136 | FolderItem *move_dest; |
| 137 | gboolean drop_done; |
| 138 | }; |
| 139 | |
| 140 | gint filter_apply (GSList *fltlist, |
| 141 | const gchar *file,
|
| 142 | FilterInfo *fltinfo); |
| 143 | gint filter_apply_msginfo (GSList *fltlist, |
| 144 | MsgInfo *msginfo, |
| 145 | FilterInfo *fltinfo); |
| 146 | |
| 147 | gint filter_action_exec (FilterRule *rule, |
| 148 | MsgInfo *msginfo, |
| 149 | const gchar *file,
|
| 150 | FilterInfo *fltinfo); |
| 151 | |
| 152 | gboolean filter_match_rule (FilterRule *rule, |
| 153 | MsgInfo *msginfo, |
| 154 | GSList *hlist, |
| 155 | FilterInfo *fltinfo); |
| 156 | |
| 157 | /* read / write config */
|
| 158 | GSList *filter_xml_node_to_filter_list (GNode *node); |
| 159 | void filter_write_config (GSList *fltlist);
|
| 160 | |
| 161 | /* for old filterrc */
|
| 162 | gchar *filter_get_str (FilterRule *rule); |
| 163 | FilterRule *filter_read_str (const gchar *str);
|
| 164 | |
| 165 | FilterRule *filter_rule_new (const gchar *name,
|
| 166 | FilterBoolOp bool_op, |
| 167 | GSList *cond_list, |
| 168 | GSList *action_list); |
| 169 | FilterCond *filter_cond_new (FilterCondType type, |
| 170 | FilterMatchType match_type, |
| 171 | FilterMatchFlag match_flag, |
| 172 | const gchar *header,
|
| 173 | const gchar *body);
|
| 174 | FilterAction *filter_action_new (FilterActionType type, |
| 175 | const gchar *str);
|
| 176 | FilterInfo *filter_info_new (void);
|
| 177 | |
| 178 | void filter_rule_rename_dest_path (FilterRule *rule,
|
| 179 | const gchar *old_path,
|
| 180 | const gchar *new_path);
|
| 181 | void filter_rule_delete_action_by_dest_path
|
| 182 | (FilterRule *rule, |
| 183 | const gchar *path);
|
| 184 | |
| 185 | void filter_rule_match_type_str_to_enum (const gchar *type_str, |
| 186 | FilterMatchType *type, |
| 187 | FilterMatchFlag *flag); |
| 188 | |
| 189 | void filter_rule_free (FilterRule *rule);
|
| 190 | void filter_cond_list_free (GSList *cond_list);
|
| 191 | void filter_action_list_free (GSList *action_list);
|
| 192 | void filter_info_free (FilterInfo *info);
|
| 193 | |
| 194 | #endif /* __FILTER_H__ */ |