Statistics
| Branch: | Tag: | Revision:

root / lib / filters / ngram-filter.c @ aebfd4cc

History | View | Annotate | Download (1.4 KB)

1
/* SylFilter - a message filter
2
 *
3
 * Copyright (C) 2011 Hiroyuki Yamamoto
4
 * Copyright (C) 2011 Sylpheed Development Team
5
 */
6

    
7
#include <glib.h>
8

    
9
#include "filter.h"
10
#include "ngram-filter.h"
11

    
12

    
13
static char *do_ngram(const char *content)
14
{
15
        return g_strdup(content);
16
}
17

    
18
static XFilterStatus xfilter_ngram_func(XFilter *filter, const XMessageData *data, XFilterResult *result)
19
{
20
        const char *mime_type;
21
        const char *content = NULL;
22
        char *processed_content;
23
        XMessageData *msgdata;
24

    
25
        g_return_val_if_fail(result != NULL, XF_ERROR);
26

    
27
        mime_type = xfilter_message_data_get_mime_type(data);
28
        if (!mime_type) {
29
                xfilter_result_set_status(result, XF_UNSUPPORTED_TYPE);
30
                return XF_UNSUPPORTED_TYPE;
31
        }
32

    
33
        if (!g_strncasecmp(mime_type, "text/", 5))
34
                content = xfilter_message_data_get_content(data);
35
        else {
36
                xfilter_result_set_status(result, XF_UNSUPPORTED_TYPE);
37
                return XF_UNSUPPORTED_TYPE;
38
        }
39

    
40
        processed_content = do_ngram(content);
41

    
42
        msgdata = xfilter_message_data_new(NULL, mime_type);
43
        xfilter_message_data_set_content(msgdata, processed_content);
44
        xfilter_message_data_copy_attributes(msgdata, data);
45
        xfilter_result_set_message_data(result, msgdata);
46

    
47
        xfilter_result_set_status(result, XF_REWRITTEN);
48

    
49
        return XF_REWRITTEN;
50
}
51

    
52
XFilter *xfilter_ngram_new(void)
53
{
54
        XFilter *filter;
55

    
56
        filter = xfilter_new(XF_CONTENT, "ngram");
57
        xfilter_set_content_filter_func(X_CONTENT_FILTER(filter),
58
                                        xfilter_ngram_func);
59

    
60
        return filter;
61
}