1 |
lefcha |
1.9 |
#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 |
lefcha |
1.11 |
/* Error codes returned by functions. */ |
11 |
|
|
#define ERROR_TRIVIAL 1 |
12 |
|
|
#define ERROR_FILE_OPEN 2 |
13 |
|
|
#define ERROR_CONFIG_PARSE 3 |
14 |
|
|
#define ERROR_MEMORY_ALLOCATION 4 |
15 |
|
|
#define ERROR_NETWORK 5 |
16 |
lefcha |
1.17 |
#define ERROR_SSL 6 |
17 |
|
|
#define ERROR_UNDEFINED 7 |
18 |
lefcha |
1.9 |
|
19 |
|
|
/* Flags that control the program's options. */ |
20 |
lefcha |
1.16 |
#define OPTION_DETAILS_QUIET 0x01 |
21 |
lefcha |
1.9 |
#define OPTION_DETAILS_NORMAL 0x02 |
22 |
|
|
#define OPTION_DETAILS_VERBOSE 0x04 |
23 |
|
|
#define OPTION_DETAILS_CLEAR 0xf8 |
24 |
lefcha |
1.14 |
#define OPTION_HEADERS 0x08 |
25 |
lefcha |
1.9 |
|
26 |
lefcha |
1.12 |
/* Flags for logger. */ |
27 |
|
|
#define LOG_WRITE 0 |
28 |
|
|
#define LOG_SERVER 1 |
29 |
|
|
#define LOG_USERNAME 2 |
30 |
|
|
#define LOG_MAILBOX 3 |
31 |
|
|
#define LOG_FILTER 4 |
32 |
|
|
#define LOG_ACTION 5 |
33 |
|
|
#define LOG_DESTINATION_MAILBOX 6 |
34 |
|
|
|
35 |
lefcha |
1.17 |
/* Buffer size of the IMAP command. */ |
36 |
lefcha |
1.9 |
#define SMALL_CMD 64 |
37 |
|
|
#define MEDIUM_CMD 256 |
38 |
|
|
#define BIG_CMD 8192 |
39 |
|
|
|
40 |
lefcha |
1.19 |
/* Buffer size of a packet server sends. */ |
41 |
|
|
#define SOCKET_READ_BUF 4096 |
42 |
|
|
|
43 |
|
|
/* Memory size added each time dynamically to packet buffer. */ |
44 |
|
|
#define PACKET_SIZE 8096 |
45 |
|
|
|
46 |
lefcha |
1.9 |
/* Buffer size of server's response. */ |
47 |
lefcha |
1.19 |
#define RESPONSE_BUF 512 |
48 |
lefcha |
1.9 |
|
49 |
lefcha |
1.16 |
/* Response codes. */ |
50 |
|
|
#define RESPONSE_BAD -1 |
51 |
|
|
#define RESPONSE_OK 0 |
52 |
|
|
#define RESPONSE_NO 1 |
53 |
|
|
#define RESPONSE_BYE 2 |
54 |
|
|
#define RESPONSE_READONLY 3 |
55 |
|
|
#define RESPONSE_TRYCREATE 4 |
56 |
|
|
|
57 |
lefcha |
1.9 |
/* Buffer size of message's headers. */ |
58 |
lefcha |
1.19 |
#define HEADERS_BUF 16384 |
59 |
lefcha |
1.9 |
|
60 |
lefcha |
1.1 |
|
61 |
|
|
#define min(A, B) ((A) < (B) ? (A) : (B)) |
62 |
lefcha |
1.15 |
#define plural(A) ((A) == 1 ? "" : "s") |
63 |
lefcha |
1.1 |
|
64 |
|
|
|
65 |
lefcha |
1.17 |
/* socket.c */ |
66 |
|
|
#ifndef SSL_TLS |
67 |
lefcha |
1.9 |
int init_connection(char *serv, unsigned int port); |
68 |
lefcha |
1.17 |
#else |
69 |
|
|
int init_connection(char *serv, unsigned int port, unsigned int protocol); |
70 |
|
|
#endif |
71 |
|
|
int ssl_init(unsigned int protocol); |
72 |
lefcha |
1.9 |
int close_connection(void); |
73 |
lefcha |
1.17 |
int socket_read(char *buf); |
74 |
|
|
int socket_write(char *data); |
75 |
lefcha |
1.9 |
|
76 |
|
|
/* file.c */ |
77 |
|
|
int read_config(char *cfg); |
78 |
|
|
#ifdef CHECK_PERMISSIONS |
79 |
|
|
int check_permissions(char *cfg); |
80 |
|
|
#endif |
81 |
|
|
int parse_config(FILE * fp); |
82 |
lefcha |
1.10 |
void set_options(char *line, regmatch_t * match); |
83 |
lefcha |
1.1 |
|
84 |
lefcha |
1.9 |
/* imapfilter.c */ |
85 |
|
|
void usage(void); |
86 |
lefcha |
1.1 |
|
87 |
lefcha |
1.9 |
/* imap.c */ |
88 |
lefcha |
1.16 |
unsigned int send_command(char *cmd); |
89 |
lefcha |
1.9 |
#ifdef DEBUG |
90 |
|
|
int imap_noop(void); |
91 |
|
|
#endif |
92 |
lefcha |
1.16 |
int imap_capability(void); |
93 |
lefcha |
1.9 |
int imap_logout(void); |
94 |
|
|
int imap_login(char *user, char *pass); |
95 |
lefcha |
1.16 |
/* int imap_examine(char *mbox); */ |
96 |
lefcha |
1.9 |
int imap_select(char *mbox); |
97 |
|
|
int imap_status(char *mbox, char *items); |
98 |
|
|
int imap_create(char *mbox); |
99 |
|
|
int imap_search(char *search); |
100 |
lefcha |
1.16 |
int imap_fetch(char *mesg, char *headers, int peek); |
101 |
lefcha |
1.9 |
int imap_store(char *mesg, char *flags); |
102 |
|
|
int imap_copy(char *mesg, char *mbox); |
103 |
|
|
int imap_close(void); |
104 |
|
|
int imap_expunge(void); |
105 |
|
|
|
106 |
|
|
/* log.c */ |
107 |
lefcha |
1.13 |
void info(const char *info,...); |
108 |
|
|
void verbose(const char *info,...); |
109 |
|
|
void error(const char *errmsg,...); |
110 |
|
|
void fatal(unsigned int errnum, const char *fatal,...); |
111 |
lefcha |
1.9 |
int open_logfile(void); |
112 |
|
|
int create_logfile(void); |
113 |
|
|
int close_logfile(void); |
114 |
lefcha |
1.12 |
void log_info(int flag, void *ptr); |
115 |
lefcha |
1.11 |
char *get_time(void); |
116 |
lefcha |
1.9 |
|
117 |
lefcha |
1.13 |
/* memory.c */ |
118 |
|
|
void *xmalloc(size_t size); |
119 |
lefcha |
1.19 |
void *xrealloc(void *ptr, size_t size); |
120 |
lefcha |
1.13 |
char *xstrdup(const char *s); |
121 |
|
|
|
122 |
lefcha |
1.16 |
/* misc.c */ |
123 |
|
|
char *strcasestr(const char *haystack, const char *needle); |
124 |
|
|
char *ultostr(unsigned long int num, int base); |
125 |
|
|
|
126 |
lefcha |
1.9 |
/* request.c */ |
127 |
|
|
int test(void); |
128 |
lefcha |
1.16 |
int check_capabilities(void); |
129 |
lefcha |
1.9 |
int login(char *user, char *pass); |
130 |
|
|
int select_mailbox(char *mbox); |
131 |
lefcha |
1.11 |
int mailbox_status(char *mbox); |
132 |
lefcha |
1.9 |
int close_mailbox(void); |
133 |
|
|
int logout(void); |
134 |
|
|
|
135 |
lefcha |
1.16 |
int apply_filters(filter_t ** filters); |
136 |
lefcha |
1.19 |
int match_filter(filter_t * filter, char **mesgs); |
137 |
lefcha |
1.9 |
|
138 |
|
|
void empty_fifo(mask_t ** mfifo); |
139 |
lefcha |
1.11 |
void queue_fifo(mask_t ** mfifo, mask_t * mask); |
140 |
|
|
mask_t *dequeue_fifo(mask_t ** mfifo); |
141 |
lefcha |
1.9 |
|
142 |
lefcha |
1.11 |
char *generate_filter_and(mask_t * mask, unsigned int masknum, unsigned int masklen); |
143 |
|
|
char *generate_filter_or(mask_t * mask, unsigned int masknum, unsigned int masklen); |
144 |
lefcha |
1.9 |
|
145 |
lefcha |
1.11 |
int apply_action(char *mesgs, unsigned int *type, char *destmbox, char *args); |
146 |
lefcha |
1.9 |
int action_delete(char *mesgs, char *args); |
147 |
lefcha |
1.11 |
int action_copy(char *mesgs, char *destmbox, char *args); |
148 |
|
|
int action_move(char *mesgs, char *destmbox, char *args); |
149 |
|
|
int action_list(char *mesgs, char *args); |
150 |
lefcha |
1.9 |
|
151 |
|
|
unsigned int convert_messages(char *mesgs); |
152 |
|
|
|
153 |
lefcha |
1.11 |
/* response.c */ |
154 |
lefcha |
1.19 |
void packet_alloc(void); |
155 |
|
|
void packet_realloc(void); |
156 |
|
|
void packet_clear(void); |
157 |
|
|
|
158 |
|
|
void receive_response(void); |
159 |
lefcha |
1.16 |
int server_response(unsigned int tag); |
160 |
|
|
int greeting_response(void); |
161 |
|
|
int capability_response(unsigned int tag); |
162 |
|
|
int status_response(unsigned int tag); |
163 |
|
|
int select_response(unsigned int tag); |
164 |
lefcha |
1.19 |
int search_response(unsigned int tag, char **mesgs); |
165 |
lefcha |
1.16 |
int fetch_response(unsigned int tag); |
166 |
|
|
int copy_response(unsigned int tag); |
167 |
lefcha |
1.19 |
int analyze_response(void); |
168 |
lefcha |
1.11 |
|
169 |
lefcha |
1.13 |
#endif /* IMAPFILTER_H */ |