1 |
#ifndef IMAPFILTER_H |
2 |
#define IMAPFILTER_H |
3 |
|
4 |
#include <stdio.h> |
5 |
#include <unistd.h> |
6 |
#include <sys/stat.h> |
7 |
#include <sys/types.h> |
8 |
#include <dirent.h> |
9 |
|
10 |
#ifndef DATA_H |
11 |
#include "data.h" |
12 |
#endif |
13 |
|
14 |
/* Error codes returned by functions. */ |
15 |
#define ERROR_SIGNAL 1 |
16 |
#define ERROR_TRIVIAL 2 |
17 |
#define ERROR_FILE_OPEN 3 |
18 |
#define ERROR_LOCK_FILE 4 |
19 |
#define ERROR_CONFIG_PARSE 5 |
20 |
#define ERROR_MEMORY_ALLOCATION 6 |
21 |
#define ERROR_SETUID 7 |
22 |
#define ERROR_TERMIO 8 |
23 |
#define ERROR_NETWORK 9 |
24 |
#define ERROR_SSL 10 |
25 |
#define ERROR_PASSPHRASE 11 |
26 |
#define ERROR_ENCRYPT 12 |
27 |
#define ERROR_DECRYPT 13 |
28 |
#define ERROR_UNDEFINED 14 |
29 |
|
30 |
/* Flags that control the program's options. */ |
31 |
#define OPTION_DETAILS_QUIET 0x01 |
32 |
#define OPTION_DETAILS_NORMAL 0x02 |
33 |
#define OPTION_DETAILS_VERBOSE 0x04 |
34 |
#define OPTION_DETAILS_CLEAR 0xf8 |
35 |
#define OPTION_HEADERS 0x08 |
36 |
#define OPTION_NAMESPACE 0x10 |
37 |
#define OPTION_PASSWORD_EDITOR 0x20 |
38 |
|
39 |
/* Capabilities of mail server. */ |
40 |
#define CAPABILITY_NONE 0x00 |
41 |
#define CAPABILITY_NAMESPACE 0x01 |
42 |
|
43 |
/* Flags for logger. */ |
44 |
#define LOG_WRITE 0 |
45 |
#define LOG_SERVER 1 |
46 |
#define LOG_USERNAME 2 |
47 |
#define LOG_MAILBOX 3 |
48 |
#define LOG_FILTER 4 |
49 |
#define LOG_ACTION 5 |
50 |
#define LOG_DESTINATION_MAILBOX 6 |
51 |
|
52 |
/* Buffer size of the IMAP command. */ |
53 |
#define SMALL_CMD 64 |
54 |
#define MEDIUM_CMD 256 |
55 |
#define BIG_CMD 8192 |
56 |
|
57 |
/* Buffer size of server's response. */ |
58 |
#define RESPONSE_BUF (4096 + 1) |
59 |
#define RESULT_BUF 512 |
60 |
|
61 |
/* Response codes. */ |
62 |
#define RESPONSE_BAD -1 |
63 |
#define RESPONSE_OK 0 |
64 |
#define RESPONSE_NO 1 |
65 |
#define RESPONSE_BYE 2 |
66 |
#define RESPONSE_PREAUTH 3 |
67 |
#define RESPONSE_READONLY 4 |
68 |
#define RESPONSE_TRYCREATE 5 |
69 |
|
70 |
/* Buffer size of message's headers. */ |
71 |
#define HEADERS_BUF 16384 |
72 |
|
73 |
/* Length of mailbox namespace prefix. */ |
74 |
#define NAMESPACE_PREFIX_LEN 64 |
75 |
|
76 |
/* Encryption and decryption buffers. */ |
77 |
#define ENCRYPTION_BUF 1024 |
78 |
#define DECRYPTION_BUF 4096 |
79 |
|
80 |
/* Maximum passwords the password editor can handle. */ |
81 |
#define EDITOR_PASSWORDS_MAX 64 |
82 |
|
83 |
|
84 |
#define min(A, B) ((A) < (B) ? (A) : (B)) |
85 |
#define plural(A) ((A) == 1 ? "" : "s") |
86 |
|
87 |
|
88 |
/* Secure memory information. */ |
89 |
typedef struct secmem { |
90 |
void *buf; /* Allocated memory buffer. */ |
91 |
size_t size; /* Size of the buffer. */ |
92 |
struct secmem *prev, *next; /* Previous/next node of doubly linked list. */ |
93 |
} secmem_t; |
94 |
|
95 |
|
96 |
/* file.c */ |
97 |
int read_config(char *cfg); |
98 |
int parse_config(FILE * fd); |
99 |
void set_options(char *line, regmatch_t * match); |
100 |
|
101 |
int read_passwords(void); |
102 |
int parse_passwords(FILE * fd); |
103 |
int store_passwords(account_t * accts[]); |
104 |
|
105 |
int create_homedir(void); |
106 |
int exists_file(char *fname); |
107 |
int exists_dir(char *fname); |
108 |
int create_file(char *fname, mode_t mode); |
109 |
int create_dir(char *dname, mode_t mode); |
110 |
#ifdef CHECK_PERMISSIONS |
111 |
int check_file_perms(char *fname, mode_t mode); |
112 |
int check_dir_perms(char *dname, mode_t mode); |
113 |
#endif |
114 |
|
115 |
/* imapfilter.c */ |
116 |
void usage(void); |
117 |
|
118 |
/* imap.c */ |
119 |
unsigned int send_command(char *cmd); |
120 |
#ifdef DEBUG |
121 |
int imap_noop(void); |
122 |
#endif |
123 |
int imap_capability(void); |
124 |
int imap_namespace(void); |
125 |
int imap_logout(void); |
126 |
int imap_login(char *user, char *pass); |
127 |
/* int imap_examine(char *mbox); */ |
128 |
int imap_select(char *mbox); |
129 |
int imap_status(char *mbox, char *items); |
130 |
int imap_create(char *mbox); |
131 |
int imap_search(char *search); |
132 |
int imap_fetch(char *mesg, char *headers, int peek); |
133 |
int imap_store(char *mesg, char *flags); |
134 |
int imap_copy(char *mesg, char *mbox); |
135 |
int imap_close(void); |
136 |
/* int imap_expunge(void); */ |
137 |
|
138 |
/* lock.c */ |
139 |
void lockfile_create(void); |
140 |
void lockfile_check(void); |
141 |
int lockfile_remove(void); |
142 |
|
143 |
/* log.c */ |
144 |
void info(const char *info,...); |
145 |
void verbose(const char *info,...); |
146 |
void error(const char *errmsg,...); |
147 |
void fatal(unsigned int errnum, const char *fatal,...); |
148 |
void catch_signals(void); |
149 |
void signal_handler(int sig); |
150 |
int open_logfile(void); |
151 |
int create_logfile(void); |
152 |
int close_logfile(void); |
153 |
void log_info(int flag, void *ptr); |
154 |
char *get_time(void); |
155 |
|
156 |
/* memory.c */ |
157 |
void *xmalloc(size_t size); |
158 |
void *xrealloc(void *ptr, size_t size); |
159 |
void xfree(void *ptr); |
160 |
char *xstrdup(const char *s); |
161 |
|
162 |
void *smalloc(size_t size); |
163 |
void *srealloc(void *ptr, size_t size); |
164 |
void sfree(void *ptr); |
165 |
char *sstrdup(const char *s); |
166 |
void secmem_append(secmem_t *node); |
167 |
secmem_t *secmem_find(void *ptr); |
168 |
void secmem_remove(secmem_t *node); |
169 |
void secmem_clear(void); |
170 |
|
171 |
void corefile_disable(void); |
172 |
|
173 |
/* misc.c */ |
174 |
char *strcasestr(const char *haystack, const char *needle); |
175 |
char *ultostr(unsigned long int num, int base); |
176 |
char *xstrncpy(char *dest, const char *src, size_t size); |
177 |
|
178 |
/* passwd.c */ |
179 |
void get_password(char *passwd, size_t pwlen); |
180 |
#ifdef ENCRYPTED_PASSWORDS |
181 |
int encrypt_passwords(FILE *fd, account_t *accts[]); |
182 |
int decrypt_passwords(unsigned char **buf, FILE *fd); |
183 |
void password_editor(void); |
184 |
#endif |
185 |
|
186 |
/* request.c */ |
187 |
int test(void); |
188 |
int check_capabilities(void); |
189 |
int check_namespace(void); |
190 |
int login(char *user, char *pass); |
191 |
int select_mailbox(char *mbox); |
192 |
int mailbox_status(char *mbox); |
193 |
int close_mailbox(void); |
194 |
int logout(void); |
195 |
|
196 |
int apply_filters(filter_t ** filters); |
197 |
int match_filter(filter_t * filter, char **mesgs); |
198 |
|
199 |
void empty_fifo(mask_t ** mfifo); |
200 |
void queue_fifo(mask_t ** mfifo, mask_t * mask); |
201 |
mask_t *dequeue_fifo(mask_t ** mfifo); |
202 |
|
203 |
char *generate_filter_and(mask_t * mask, unsigned int masknum, unsigned int masklen); |
204 |
char *generate_filter_or(mask_t * mask, unsigned int masknum, unsigned int masklen); |
205 |
|
206 |
int apply_action(char *mesgs, unsigned int *type, char *destmbox, char *args); |
207 |
int action_delete(char *mesgs, char *args); |
208 |
int action_copy(char *mesgs, char *destmbox, char *args); |
209 |
int action_move(char *mesgs, char *destmbox, char *args); |
210 |
int action_list(char *mesgs, char *args); |
211 |
|
212 |
unsigned int convert_messages(char *mesgs); |
213 |
|
214 |
/* response.c */ |
215 |
void receive_response(char *buf); |
216 |
int server_response(unsigned int tag); |
217 |
int greeting_response(void); |
218 |
int capability_response(unsigned int tag); |
219 |
int namespace_response(unsigned int tag, char *prefix, char delim); |
220 |
int status_response(unsigned int tag, char *mbox); |
221 |
int select_response(unsigned int tag); |
222 |
int search_response(unsigned int tag, char **mesgs); |
223 |
int fetch_response(unsigned int tag); |
224 |
int copy_response(unsigned int tag); |
225 |
int analyze_response(char *buf); |
226 |
|
227 |
/* socket.c */ |
228 |
#ifndef SSL_TLS |
229 |
int init_connection(char *serv, unsigned short int port); |
230 |
#else |
231 |
int init_connection(char *serv, unsigned short int port, unsigned int protocol); |
232 |
#endif |
233 |
int ssl_init(unsigned int protocol); |
234 |
int close_connection(void); |
235 |
int socket_read(char *buf); |
236 |
int socket_write(char *data); |
237 |
|
238 |
/* tty.c */ |
239 |
int tty_store(void); |
240 |
int tty_disable_echo(void); |
241 |
int tty_restore(void); |
242 |
|
243 |
#endif /* IMAPFILTER_H */ |