root / lib / filter.h @ aebfd4cc
History | View | Annotate | Download (3.4 kB)
| 1 | /* SylFilter - a message filter
|
|---|---|
| 2 | * |
| 3 | * Copyright (C) 2011 Hiroyuki Yamamoto |
| 4 | * Copyright (C) 2011 Sylpheed Development Team |
| 5 | */ |
| 6 | |
| 7 | /* filter.h */
|
| 8 | |
| 9 | #ifndef __FILTER_H__
|
| 10 | #define __FILTER_H__
|
| 11 | |
| 12 | typedef enum { |
| 13 | XF_CONTENT, |
| 14 | XF_TEST |
| 15 | } XFilterType; |
| 16 | |
| 17 | typedef enum { |
| 18 | XF_NOJUNK, |
| 19 | XF_JUNK, |
| 20 | XF_UNCERTAIN, |
| 21 | XF_REWRITTEN, |
| 22 | XF_NONE, |
| 23 | XF_UNSUPPORTED_TYPE, |
| 24 | XF_ERROR |
| 25 | } XFilterStatus; |
| 26 | |
| 27 | typedef enum { |
| 28 | XM_FROM, |
| 29 | XM_TO, |
| 30 | XM_CC, |
| 31 | XM_SUBJECT, |
| 32 | } XMessageAttr; |
| 33 | |
| 34 | typedef struct _XFilterManager XFilterManager; |
| 35 | typedef struct _XFilter XFilter; |
| 36 | typedef struct _XContentFilter XContentFilter; |
| 37 | typedef struct _XTestFilter XTestFilter; |
| 38 | typedef struct _XMessageData XMessageData; |
| 39 | typedef struct _XFilterResult XFilterResult; |
| 40 | |
| 41 | #define XFILTER(f) ((XFilter *)f)
|
| 42 | #define X_CONTENT_FILTER(f) ((XContentFilter *)f)
|
| 43 | #define X_TEST_FILTER(f) ((XTestFilter *)f)
|
| 44 | |
| 45 | typedef XFilter * (*XFilterConstructorFunc) (void); |
| 46 | |
| 47 | typedef XFilterStatus (*XContentFilterFunc) (XFilter *filter,
|
| 48 | const XMessageData *data,
|
| 49 | XFilterResult *result); |
| 50 | typedef XFilterStatus (*XTestFilterFunc) (XFilter *filter,
|
| 51 | const XMessageData *data,
|
| 52 | XFilterResult *result); |
| 53 | |
| 54 | |
| 55 | int xfilter_init (void); |
| 56 | void xfilter_done (void); |
| 57 | |
| 58 | /* XFilter */
|
| 59 | |
| 60 | XFilter *xfilter_new (XFilterType type, const char *name); |
| 61 | void xfilter_free (XFilter *filter);
|
| 62 | |
| 63 | XFilterType xfilter_get_type(XFilter *filter); |
| 64 | const char *xfilter_get_name(XFilter *filter); |
| 65 | |
| 66 | void xfilter_set_input_mime_types(XFilter *filter, const char **types); |
| 67 | void xfilter_set_output_mime_type(XFilter *filter, const char *type); |
| 68 | |
| 69 | /* XMessageData */
|
| 70 | |
| 71 | XMessageData *xfilter_message_data_new(const char *src, const char *mime_type); |
| 72 | XMessageData *xfilter_message_data_read_file(const char *file, const char *mime_type); |
| 73 | void xfilter_message_data_free(XMessageData *msgdata);
|
| 74 | void xfilter_message_data_set_file(XMessageData *msgdata, const char *file); |
| 75 | void xfilter_message_data_set_content(XMessageData *msgdata, char *content); |
| 76 | void xfilter_message_data_set_attribute(XMessageData *msgdata, XMessageAttr attr, const char *value, int append); |
| 77 | void xfilter_message_data_copy_attributes(XMessageData *msgdata, const XMessageData *srcdata); |
| 78 | const char *xfilter_message_data_get_mime_type(const XMessageData *msgdata); |
| 79 | const char *xfilter_message_data_get_file(const XMessageData *msgdata); |
| 80 | const char *xfilter_message_data_get_content(const XMessageData *msgdata); |
| 81 | const char *xfilter_message_data_get_attribute(const XMessageData *msgdata, XMessageAttr); |
| 82 | |
| 83 | /* X*Filter */
|
| 84 | |
| 85 | void xfilter_set_content_filter_func(XContentFilter *filter, XContentFilterFunc func);
|
| 86 | void xfilter_set_test_filter_func(XTestFilter *filter, XTestFilterFunc func);
|
| 87 | |
| 88 | XFilterStatus xfilter_exec(XFilter *filter, const XMessageData *msgdata, XFilterResult *result);
|
| 89 | |
| 90 | /* XFilterResult */
|
| 91 | |
| 92 | void xfilter_result_print(XFilterResult *result);
|
| 93 | |
| 94 | XFilterResult *xfilter_result_new(void);
|
| 95 | void xfilter_result_set_status(XFilterResult *result, XFilterStatus status);
|
| 96 | void xfilter_result_set_message_data(XFilterResult *result, XMessageData *msgdata);
|
| 97 | void xfilter_result_set_probability(XFilterResult *result, double prob); |
| 98 | XFilterStatus xfilter_result_get_status(XFilterResult *result); |
| 99 | XMessageData *xfilter_result_get_message_data(XFilterResult *result); |
| 100 | double xfilter_result_get_probability(XFilterResult *result);
|
| 101 | void xfilter_result_free(XFilterResult *result);
|
| 102 | |
| 103 | /* Utility functions */
|
| 104 | |
| 105 | void xfilter_set_debug_mode(int mode); |
| 106 | int xfilter_get_debug_mode(void); |
| 107 | void xfilter_debug_print(const char *format, ...); |
| 108 | |
| 109 | #endif /* __FILTER_H__ */ |