File: filter.h

package info (click to toggle)
balsa 0.4.6.2-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 2,264 kB
  • ctags: 2,404
  • sloc: ansic: 26,471; sh: 4,773; makefile: 345; sed: 93
file content (117 lines) | stat: -rw-r--r-- 2,433 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* -*- C -*-
 * filter.h
 * 
 * Header for libfilter, the mail filtering porting of balsa
 *
 * Author:  Joel Becker
 */

#ifndef _FILTER_H
#define _FILTER_H

#include <sys/types.h>
#include <regex.h>
#include <glib.h>
#include "mailbox.h"


/* filter match types */
typedef enum
{
    FILTER_NONE = 0,
    FILTER_SIMPLE,
    FILTER_REGEX,
    FILTER_EXEC
} filter_match_type;

typedef enum
{
    FILTER_MATCHES,
    FILTER_NOMATCH,
    FILTER_ALWAYS,
} filter_when_type;
	

/* filter_run_dialog() modes */
#define FILTER_RUN_SINGLE    0
#define FILTER_RUN_MULTIPLE  1

/*
 * filter error codes
 * (not an enum cause they *have* to match filter_errlist
 */
#define FILTER_NOERR         0
#define FILTER_ENOFILE       1
#define FILTER_ENOREAD       2
#define FILTER_EFILESYN      3
#define FILTER_ENOMSG        4
#define FILTER_ENOMEM        5
#define FILTER_EREGSYN       6


/*
 * Filter errors set the variable filter_errno (like errno)
 */
gint filter_errno;

/* filters */
typedef struct _filter
{
    gint group;
    gchar *name;
    filter_match_type type;
    filter_when_type match_when;
    guint flags;

    /*
     * This should perhaps be a union, especially to 
     * share the string areas.
     * Also, I am tempted to provide limits for match_string
     * and exec_command, sort of like this:
     * union
     * {
     *     gchar match_string[1024];
     *     gchar exec_command[1024];
     * } _filter_strings;
     */
    guint match_fields; /* for FILTER_SIMPLE filters */
    gchar *match_string; /* for FILTER_SIMPLE filters */

    gchar *exec_command; /* for FILTER_EXEC filters */

    /* other options I haven't thought of yet */

    GList *regex;
} filter;

/*
 * Exported filter functions
 */
GList *filter_init(gchar *filter_file);
gint filter_load(GList *filter_list,
		 gchar *filter_file);
gint filter_save(GList *filter_list,
		 gchar *filter_file);
gint filter_run_all(GList *filter_list,
		    Message *message);
gint filter_run_group(GList *filter_list,
		      Message *message, gint group);
gint filter_run_nth(GList *filter_list,
		    Message *message, gint n);
gint filter_run_single(filter *filt,
		       Message *message);

/*
 * Dialog calls
 */
void filter_edit_dialog(GList *filter_list);
void filter_run_dialog(GList *filter_list,
		       guint mode);

/*
 * Error calls
 */
gchar *filter_strerror(gint filter_errnum);
void filter_perror(const gchar *s);

#endif /* _FILTER_H */