summaryrefslogtreecommitdiff
path: root/pith/rules.h
blob: 39fda491de5e23c1b24aff35074abf18d757ec17 (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* Included file rules.h */

#ifndef PITH_RULES_INCLUDED
#define PITH_RULES_INCLUDED

#include "../pith/conftype.h"
#include "../pith/detoken.h"
#include "../pith/indxtype.h"
#include "../pith/rulestype.h"

/* Exported prototypes */

void  create_rule_list (struct variable *);
SPAREP_S *get_sparep_for_rule(char *, int);
void  free_sparep_for_rule(void **);
void  free_parsed_rule_list (PRULELIST_S **);
RULE_RESULT *get_result_rule (int, int, ENVELOPE *);
char  *get_rule_result (int , char *, int);
char  *process_rule   (RULE_S *, int, ENVELOPE *);
char  **functions_for_token (char *);
RULELIST *get_rulelist_from_code (int, PRULELIST_S *);
RULE_S   *get_rule  (RULELIST *, int);
int   condition_contains_token (CONDITION_S *, char *);
int   context_for_function (char *);
ENVELOPE *rules_fetchenvelope(INDEXDATA_S *idata, int *we_clear);

/* Separators:
 *
 * A separator is a string that separates the rule condition with the rule
 * action. Below is the list of separators
 *
 */

#define  SAVE_TO_SEP  "->"
#define  APPLY_SEP    "=>"

/*------- Definitions of tokens -------*/
/*------ Keep the list alphabetically sorted, thanks -------*/

#define ADDR_TOKEN	"_ADDRESS_"
#define ADDCC_TOKEN	"_ADDRESSCC_"
#define ADDRECIP_TOKEN	"_ADDRESSRECIPS_"
#define ADDTO_TOKEN	"_ADDRESSTO_"
#define BCC_TOKEN	"_BCC_"
#define CC_TOKEN	"_CC_"
#define COLLECT_TOKEN	"_COLLECTION_"
#define FCCF_TOKEN	"_FCCFROM_"
#define FCCS_TOKEN	"_FCCSENDER_"
#define FLAG_TOKEN	"_FLAG_"
#define FOLDER_TOKEN	"_FOLDER_"
#define FADDRESS_TOKEN	"_FORWARDADDRESS_"
#define FFROM_TOKEN	"_FORWARDFROM_"
#define FROM_TOKEN	"_FROM_"
#define KEY_TOKEN	"_PKEY_"
#define LCC_TOKEN	"_LCC_"
#define NICK_TOKEN	"_NICK_"
#define OTEXT_TOKEN	"_OPENINGTEXT_"
#define OTEXTNQ_TOKEN	"_OPENINGTEXTNQ_"
#define PROCID_TOKEN	"_PROCID_"
#define ROLE_TOKEN	"_ROLE_"
#define SCREEN_TOKEN	"_SCREEN_"
#define SEND_TOKEN	"_SENDER_"
#define SUBJ_TOKEN	"_SUBJECT_"
#define THDDSPSTY_TOKEN	"_THREADSTYLE_"
#define THDNDXSTY_TOKEN	"_THREADINDEX_"
#define TO_TOKEN	"_TO_"

/*------ Definitions of relational operands -------------*/

typedef struct {
        char       *value;
	TestType    ttype;
        int        (*execute)();
} REL_TOKEN;

/* Relational Operands */
#define AND_REL     "&&"        /* For putting more than one condition  */
#define IN_REL      "<<"        /* For belonging relation */
#define NI_REL      ">>"        /* For contain relation   */
#define NOT_IN_REL  "!<"        /* Negation of IN_REL   */
#define NOT_NI_REL  "!>"        /* Negation of NI_REL   */
#define EQ_REL      "=="        /* Test of equality     */
#define NOT_EQ_REL  "!="        /* Test of inequality   */
#define OPEN_SET    "{"         /* Braces to open a set */
#define CLOSE_SET   "}"         /* Braces to close a set*/

/*--- Context in which these variables can be used ---*/

typedef struct use_context {
    char        *name;
    int          what_for;
} USE_IN_CONTEXT;


static USE_IN_CONTEXT tokens_use[] = {
    {NICK_TOKEN,	FOR_SAVE},
    {FROM_TOKEN,	FOR_SAVE},
    {OTEXT_TOKEN,	FOR_SAVE|FOR_FOLDER},
    {OTEXTNQ_TOKEN,	FOR_SAVE|FOR_FOLDER},
    {ROLE_TOKEN,	FOR_COMPOSE},
    {FOLDER_TOKEN,	FOR_SAVE|FOR_FOLDER|FOR_THREAD|FOR_COMPOSE},
    {SUBJ_TOKEN,	FOR_SAVE|FOR_FOLDER|FOR_COMPOSE},
    {FLAG_TOKEN,	FOR_SAVE|FOR_FLAG},
    {COLLECT_TOKEN,	FOR_SAVE|FOR_COMPOSE|FOR_FOLDER|FOR_THREAD},
    {THDDSPSTY_TOKEN,	FOR_THREAD},
    {THDNDXSTY_TOKEN,	FOR_THREAD},
    {ADDR_TOKEN,	FOR_SAVE|FOR_FOLDER},
    {TO_TOKEN,		FOR_SAVE},
    {ADDTO_TOKEN,	FOR_SAVE|FOR_COMPOSE},
    {ADDCC_TOKEN,	FOR_SAVE|FOR_COMPOSE},
    {ADDRECIP_TOKEN,	FOR_SAVE|FOR_COMPOSE},
    {SCREEN_TOKEN,	FOR_KEY},
    {KEY_TOKEN,		FOR_KEY},
    {SEND_TOKEN,	FOR_SAVE},
    {CC_TOKEN,		FOR_SAVE},
    {BCC_TOKEN,		FOR_COMPOSE},
    {LCC_TOKEN,		FOR_COMPOSE},
    {FFROM_TOKEN,	FOR_COMPOSE},
    {FADDRESS_TOKEN,	FOR_COMPOSE},
    {NULL,		FOR_NOTHING}
};


typedef struct {
        char         *name;
        char*        (*execute)();
        int          what_for;
} RULE_FCN;

#define COMMAND_FCN	"_COMMAND_"
#define COPY_FCN	"_COPY_"
#define EXEC_FCN	"_EXEC_"
#define INDEX_FCN       "_INDEX_"
#define REPLACE_FCN     "_REPLACE_"
#define REPLYSTR_FCN    "_RESTR_"
#define REPLY_FCN       "_REPLY_"
#define RESUB_FCN       "_RESUB_"
#define REXTRIM_FCN	"_REXTRIM_"
#define SAVE_FCN        "_SAVE_"
#define SIGNATURE_FCN   "_SIGNATURE_"
#define SMTP_FCN        "_SMTP_"
#define SORT_FCN        "_SORT_"
#define STARTUP_FCN     "_STARTUP_"
#define THRDSTYLE_FCN   "_THREADSTYLE_"
#define THRDINDEX_FCN   "_THREADINDEX_"
#define TRIM_FCN        "_TRIM_"

#define STRICTLY  0x1
#define RELAXED 0x2

#endif 	/* PITH_RULES_INCLUDED */