Statistics
| Branch: | Tag: | Revision:

root / src / sylfilter.c @ 4012ec30

History | View | Annotate | Download (2.65 KB)

1
#include <stdio.h>
2

    
3
#include "filter.h"
4
#include "filter-manager.h"
5
#include "textcontent-filter.h"
6
#include "blacklist-filter.h"
7
#include "whitelist-filter.h"
8
#include "wordsep-filter.h"
9
#include "ngram-filter.h"
10
#include "bayes-filter.h"
11

    
12
int main(int argc, char *argv[])
13
{
14
        XFilterManager *mgr;
15
        XFilter *filter;
16
        XMessageData *msgdata;
17
        XMessageData *resdata;
18
        XFilterResult *res;
19
        XFilterStatus status;
20
        int i;
21

    
22
        XFilterConstructorFunc learn_ctors[] = {
23
                xfilter_textcontent_new,
24
                xfilter_wordsep_new,
25
                xfilter_ngram_new,
26
                xfilter_bayes_learn_new,
27
                NULL
28
        };
29

    
30
        XFilterConstructorFunc ctors[] = {
31
                xfilter_textcontent_new,
32
                xfilter_blacklist_new,
33
                xfilter_whitelist_new,
34
                xfilter_wordsep_new,
35
                xfilter_ngram_new,
36
                xfilter_bayes_new,
37
                NULL
38
        };
39

    
40
        const char *rfc822content =
41
                "From: foo@bar\n"
42
                "To: fuga@hoge\n"
43
                "Subject: test message\n"
44
                "\n"
45
                "This is a test message.\n"
46
                "...\n"
47
                "\n"
48
                "-- \n"
49
                "Foo Bar <foo@bar>\n";
50

    
51
        xfilter_init();
52

    
53
        // learning
54
        mgr = xfilter_manager_new();
55

    
56
        for (i = 0; learn_ctors[i] != NULL; i++) {
57
                filter = learn_ctors[i]();
58
                xfilter_manager_filter_add(mgr, filter);
59
        }
60

    
61
        msgdata = xfilter_message_data_new(rfc822content, "message/rfc822");
62

    
63
        res = xfilter_manager_run(mgr, msgdata);
64
        xfilter_result_print(res);
65
        status = xfilter_result_get_status(res);
66

    
67
        resdata = xfiltrer_result_get_message_data(res);
68
        if (resdata) {
69
                const char *content;
70
                content = xfilter_message_data_get_content(resdata);
71
                printf("content: %s\n", content);
72
        }
73

    
74
        xfilter_result_free(res);
75
        xfilter_message_data_free(msgdata);
76
        xfilter_manager_free(mgr);
77

    
78
        printf("--------\n");
79

    
80
        mgr = xfilter_manager_new();
81

    
82
        for (i = 0; ctors[i] != NULL; i++) {
83
                filter = ctors[i]();
84
                xfilter_manager_filter_add(mgr, filter);
85
        }
86

    
87
        // test 1
88
        msgdata = xfilter_message_data_new("test", "text/plain");
89

    
90
        res = xfilter_manager_run(mgr, msgdata);
91
        xfilter_result_print(res);
92
        status = xfilter_result_get_status(res);
93

    
94
        resdata = xfiltrer_result_get_message_data(res);
95
        if (resdata) {
96
                const char *content;
97
                content = xfilter_message_data_get_content(resdata);
98
                printf("content: %s\n", content);
99
        }
100

    
101
        xfilter_result_free(res);
102
        xfilter_message_data_free(msgdata);
103

    
104
        printf("--------\n");
105

    
106
        // test 2
107
        msgdata = xfilter_message_data_new(rfc822content, "message/rfc822");
108

    
109
        res = xfilter_manager_run(mgr, msgdata);
110
        xfilter_result_print(res);
111
        status = xfilter_result_get_status(res);
112

    
113
        resdata = xfiltrer_result_get_message_data(res);
114
        if (resdata) {
115
                const char *content;
116
                content = xfilter_message_data_get_content(resdata);
117
                printf("content: %s\n", content);
118
        }
119

    
120
        xfilter_result_free(res);
121
        xfilter_message_data_free(msgdata);
122

    
123
        xfilter_manager_free(mgr);
124

    
125
        xfilter_done();
126

    
127
        return 0;
128
}