1 |
#ifndef IMAPFILTER_H |
2 |
#define IMAPFILTER_H |
3 |
|
4 |
#include <stdio.h> |
5 |
|
6 |
#ifndef DATA_H |
7 |
#include "data.h" |
8 |
#endif |
9 |
|
10 |
/* Error codes returned by functions. */ |
11 |
#define ERROR_SIGNAL 1 |
12 |
#define ERROR_TRIVIAL 2 |
13 |
#define ERROR_FILE_OPEN 3 |
14 |
#define ERROR_CONFIG_PARSE 4 |
15 |
#define ERROR_MEMORY_ALLOCATION 5 |
16 |
#define ERROR_NETWORK 6 |
17 |
#define ERROR_SSL 7 |
18 |
#define ERROR_UNDEFINED 8 |
19 |
|
20 |
/* Flags that control the program's options. */ |
21 |
#define OPTION_DETAILS_QUIET 0x01 |
22 |
#define OPTION_DETAILS_NORMAL 0x02 |
23 |
#define OPTION_DETAILS_VERBOSE 0x04 |
24 |
#define OPTION_DETAILS_CLEAR 0xf8 |
25 |
#define OPTION_HEADERS 0x08 |
26 |
#define OPTION_NAMESPACE 0x10 |
27 |
|
28 |
/* Capabilities of mail server. */ |
29 |
#define CAPABILITY_NONE 0x00 |
30 |
#define CAPABILITY_NAMESPACE 0x01 |
31 |
|
32 |
/* Flags for logger. */ |
33 |
#define LOG_WRITE 0 |
34 |
#define LOG_SERVER 1 |
35 |
#define LOG_USERNAME 2 |
36 |
#define LOG_MAILBOX 3 |
37 |
#define LOG_FILTER 4 |
38 |
#define LOG_ACTION 5 |
39 |
#define LOG_DESTINATION_MAILBOX 6 |
40 |
|
41 |
/* Buffer size of the IMAP command. */ |
42 |
#define SMALL_CMD 64 |
43 |
#define MEDIUM_CMD 256 |
44 |
#define BIG_CMD 8192 |
45 |
|
46 |
/* Buffer size of server's response. */ |
47 |
#define RESPONSE_BUF (4096 + 1) |
48 |
#define RESULT_BUF 512 |
49 |
|
50 |
/* Response codes. */ |
51 |
#define RESPONSE_BAD -1 |
52 |
#define RESPONSE_OK 0 |
53 |
#define RESPONSE_NO 1 |
54 |
#define RESPONSE_BYE 2 |
55 |
#define RESPONSE_PREAUTH 3 |
56 |
#define RESPONSE_READONLY 4 |
57 |
#define RESPONSE_TRYCREATE 5 |
58 |
|
59 |
/* Buffer size of message's headers. */ |
60 |
#define HEADERS_BUF 16384 |
61 |
|
62 |
/* Length of mailbox namespace prefix. */ |
63 |
#define NAMESPACE_PREFIX_LEN 64 |
64 |
|
65 |
|
66 |
#define min(A, B) ((A) < (B) ? (A) : (B)) |
67 |
#define plural(A) ((A) == 1 ? "" : "s") |
68 |
|
69 |
|
70 |
/* Namespace of mailboxes residing on mail server. */ |
71 |
struct namespace_t { |
72 |
char prefix[NAMESPACE_PREFIX_LEN]; |
73 |
char delim; |
74 |
}; |
75 |
|
76 |
|
77 |
/* file.c */ |
78 |
int read_config(char *cfg); |
79 |
#ifdef CHECK_PERMISSIONS |
80 |
int check_permissions(char *cfg); |
81 |
#endif |
82 |
int parse_config(FILE * fp); |
83 |
void set_options(char *line, regmatch_t * match); |
84 |
|
85 |
/* imapfilter.c */ |
86 |
void usage(void); |
87 |
|
88 |
/* imap.c */ |
89 |
unsigned int send_command(char *cmd); |
90 |
#ifdef DEBUG |
91 |
int imap_noop(void); |
92 |
#endif |
93 |
int imap_capability(void); |
94 |
int imap_namespace(void); |
95 |
int imap_logout(void); |
96 |
int imap_login(char *user, char *pass); |
97 |
/* int imap_examine(char *mbox); */ |
98 |
int imap_select(char *mbox); |
99 |
int imap_status(char *mbox, char *items); |
100 |
int imap_create(char *mbox); |
101 |
int imap_search(char *search); |
102 |
int imap_fetch(char *mesg, char *headers, int peek); |
103 |
int imap_store(char *mesg, char *flags); |
104 |
int imap_copy(char *mesg, char *mbox); |
105 |
int imap_close(void); |
106 |
/* int imap_expunge(void); */ |
107 |
|
108 |
/* log.c */ |
109 |
void info(const char *info,...); |
110 |
void verbose(const char *info,...); |
111 |
void error(const char *errmsg,...); |
112 |
void fatal(unsigned int errnum, const char *fatal,...); |
113 |
void catch_signals(void); |
114 |
void signal_handler(int sig); |
115 |
int open_logfile(void); |
116 |
int create_logfile(void); |
117 |
int close_logfile(void); |
118 |
void log_info(int flag, void *ptr); |
119 |
char *get_time(void); |
120 |
|
121 |
/* memory.c */ |
122 |
void *xmalloc(size_t size); |
123 |
void *xrealloc(void *ptr, size_t size); |
124 |
char *xstrdup(const char *s); |
125 |
|
126 |
/* misc.c */ |
127 |
char *strcasestr(const char *haystack, const char *needle); |
128 |
char *ultostr(unsigned long int num, int base); |
129 |
char *xstrncpy(char *dest, const char *src, size_t size); |
130 |
|
131 |
/* request.c */ |
132 |
int test(void); |
133 |
int check_capabilities(void); |
134 |
int check_namespace(void); |
135 |
int login(char *user, char *pass); |
136 |
int select_mailbox(char *mbox); |
137 |
int mailbox_status(char *mbox); |
138 |
int close_mailbox(void); |
139 |
int logout(void); |
140 |
|
141 |
int apply_filters(filter_t ** filters); |
142 |
int match_filter(filter_t * filter, char **mesgs); |
143 |
|
144 |
void empty_fifo(mask_t ** mfifo); |
145 |
void queue_fifo(mask_t ** mfifo, mask_t * mask); |
146 |
mask_t *dequeue_fifo(mask_t ** mfifo); |
147 |
|
148 |
char *generate_filter_and(mask_t * mask, unsigned int masknum, unsigned int masklen); |
149 |
char *generate_filter_or(mask_t * mask, unsigned int masknum, unsigned int masklen); |
150 |
|
151 |
int apply_action(char *mesgs, unsigned int *type, char *destmbox, char *args); |
152 |
int action_delete(char *mesgs, char *args); |
153 |
int action_copy(char *mesgs, char *destmbox, char *args); |
154 |
int action_move(char *mesgs, char *destmbox, char *args); |
155 |
int action_list(char *mesgs, char *args); |
156 |
|
157 |
unsigned int convert_messages(char *mesgs); |
158 |
|
159 |
/* response.c */ |
160 |
void receive_response(char *buf); |
161 |
int server_response(unsigned int tag); |
162 |
int greeting_response(void); |
163 |
int capability_response(unsigned int tag); |
164 |
int namespace_response(unsigned int tag, struct namespace_t * namesp); |
165 |
int status_response(unsigned int tag, char *mbox); |
166 |
int select_response(unsigned int tag); |
167 |
int search_response(unsigned int tag, char **mesgs); |
168 |
int fetch_response(unsigned int tag); |
169 |
int copy_response(unsigned int tag); |
170 |
int analyze_response(char *buf); |
171 |
void init_vbuf(void); |
172 |
void reset_vbuf(void); |
173 |
void check_vbuf(size_t s); |
174 |
|
175 |
/* socket.c */ |
176 |
#ifndef SSL_TLS |
177 |
int init_connection(char *serv, unsigned short int port); |
178 |
#else |
179 |
int init_connection(char *serv, unsigned short int port, |
180 |
unsigned int protocol); |
181 |
#endif |
182 |
int ssl_init(unsigned int protocol); |
183 |
int close_connection(void); |
184 |
int socket_read(char *buf); |
185 |
int socket_write(char *data); |
186 |
|
187 |
#endif /* IMAPFILTER_H */ |