/[imapfilter]/imapfilter/imapfilter.h
ViewVC logotype

Contents of /imapfilter/imapfilter.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.83 - (show annotations)
Sat Feb 14 22:48:04 2004 UTC (20 years, 2 months ago) by lefcha
Branch: MAIN
Changes since 1.82: +13 -5 lines
File MIME type: text/plain
Added IMAP4 protocol support.

1 #ifndef IMAPFILTER_H
2 #define IMAPFILTER_H
3
4
5 #include <stdio.h>
6 #include <sys/types.h>
7 #include <limits.h>
8
9 #include "config.h"
10 #include "account.h"
11 #include "filter.h"
12
13 #ifdef SSL_TLS
14 #include <openssl/ssl.h>
15 #endif
16
17
18 /* Error codes returned by functions. */
19 #define ERROR_UNDEFINED 1
20 #define ERROR_TRIVIAL 2
21 #define ERROR_SIGNAL 3
22 #define ERROR_FILEOPEN 4
23 #define ERROR_LOCKFILE 5
24 #define ERROR_PARSER 6
25 #define ERROR_MEMALLOC 7
26 #define ERROR_SETUID 8
27 #define ERROR_TERMIO 9
28 #define ERROR_NETWORK 10
29 #define ERROR_SSL 11
30 #define ERROR_PASSPHRASE 12
31 #define ERROR_ENCRYPT 13
32 #define ERROR_DECRYPT 14
33 #define ERROR_FORK 15
34
35 /* SSL/TLS certificate status for the server. */
36 #define CERT_OK 0
37 #define CERT_NONE 1
38 #define CERT_MISMATCH 2
39
40 /* Action to be applied, concerning the SSL/TLS certificate. */
41 #define CERT_ACTION_ACCEPT 0
42 #define CERT_ACTION_REJECT 1
43 #define CERT_ACTION_CONTINUE 0
44 #define CERT_ACTION_ABORT 1
45
46 /* Other flags. */
47 #define FLAG_DAEMON 0x01
48 #define FLAG_TTY 0x02
49 #define FLAG_TTYMOD 0x04
50 #define FLAG_BLANKPASS 0x08
51 #define FLAG_SIGUSR1 0x10
52
53 /* IMAP protocol supported by the server. */
54 #define PROTOCOL_NONE 0x00
55 #define PROTOCOL_IMAP4REV1 0x01
56 #define PROTOCOL_IMAP4 0x02
57
58 /* Capabilities of mail server. */
59 #define CAPABILITY_NONE 0x00
60 #define CAPABILITY_NAMESPACE 0x01
61 #define CAPABILITY_CRAMMD5 0x02
62 #define CAPABILITY_STARTTLS 0x04
63
64 /* Flags for logger. */
65 #define LOG_PREAMBLE 0
66 #define LOG_ACCOUNT 1
67 #define LOG_MBOX 2
68 #define LOG_FILTER 3
69 #define LOG_ACTION 4
70 #define LOG_DEST_ACCOUNT 5
71 #define LOG_DEST_MBOX 6
72 #define LOG_HEADER 7
73
74 /* Response codes. */
75 #define RESPONSE_NULLBODY -2
76 #define RESPONSE_NONE -1
77 #define RESPONSE_OK 0
78 #define RESPONSE_NO 1
79 #define RESPONSE_BAD 2
80 #define RESPONSE_BYE 3
81 #define RESPONSE_PREAUTH 4
82 #define RESPONSE_READONLY 5
83 #define RESPONSE_TRYCREATE 6
84
85 /* Buffer size of server's response. */
86 #define RESPONSE_BUF 4096
87 #define RESULT_BUF 512
88
89 /* Encryption and decryption buffers. */
90 #define ENCRYPT_BUF 1024
91 #define DECRYPT_BUF 4096
92
93 /* Buffer to save flags of the store IMAP command. */
94 #define STORE_FLAGS_BUF 64
95
96 /* Length of charset for IMAP SEARCH requests. */
97 #define CHARSET_LEN 64
98
99 /* String lengths of master password and encrypted passwords. */
100 #define PASSPHRASE_LEN 256
101
102 /* Length of mailbox namespace prefix. */
103 #define NAMESPACE_PREFIX_LEN 64
104
105
106 #define min(A, B) ((A) < (B) ? (A) : (B))
107 #define plural(A) ((A) == 1 ? "" : "s")
108
109
110 /* Program's options. */
111 typedef struct options {
112 int debug; /* Debugging level (1..2). */
113 int verbosity; /* Verbosity level (-2..2). */
114 int timeout; /* Server non-response timeout in seconds. */
115 int daemon; /* Daemon mode interval. */
116 int headers; /* Print messages headers to stdout. */
117 int errors; /* Errors appended to logfile. */
118 int namespace; /* Apply mailbox namespace automatically. */
119 int expunge; /* Expunge messages after they are marked
120 * deleted. */
121 int subscribe; /* Subscribe newly created mailboxes. */
122 int peek; /* Do not mark messages seen when their
123 * headers are received. */
124 int passwd_editor; /* Enter interactive password editor. */
125 char charset[CHARSET_LEN]; /* Search criteria character set. */
126 char logfile[PATH_MAX]; /* Log file for filtering information. */
127 } options_t;
128
129 /* IMAP connection. */
130 typedef struct connection {
131 int sock; /* Socket. */
132 #ifdef SSL_TLS
133 SSL *ssl; /* SSL socket. */
134 #endif
135 unsigned int prot; /* IMAP protocol. Currently IMAP4rev1 and
136 * IMAP4 are supported. */
137 unsigned int caps; /* Capabilities of the mail server. */
138 struct { /* Namespace of the mail server's mailboxes. */
139 char prefix[NAMESPACE_PREFIX_LEN]; /* Namespace prefix. */
140 char delim; /* Namespace delimiter. */
141 } ns;
142 } connection_t;
143
144
145 /* action.c */
146 int apply_action(char *mbox, char *mesgs, unsigned int *type, account_t * destacct, char *destmbox, unsigned int *msgflags, char *args);
147
148 /* auth.c */
149 #ifdef CRAM_MD5
150 int auth_cram_md5(connection_t * conn, char *user, char *pass);
151 #endif
152
153 /* cert.c */
154 #ifdef SSL_TLS
155 int get_cert(connection_t * conn);
156 #endif
157
158 /* destroy.c */
159 void destroy_all(void);
160 void destroy_unneeded(void);
161
162 /* file.c */
163 int create_homedir(void);
164 int exists_file(char *fname);
165 int exists_dir(char *fname);
166 int create_file(char *fname, mode_t mode);
167 int check_file_perms(char *fname, mode_t mode);
168 int check_dir_perms(char *dname, mode_t mode);
169
170 /* imap.c */
171 int imap_noop(connection_t * conn);
172 int imap_capability(connection_t * conn);
173 int imap_namespace(connection_t * conn);
174 int imap_logout(connection_t * conn);
175 #ifdef SSL_TLS
176 int imap_starttls(connection_t * conn);
177 #endif
178 int imap_authenticate(connection_t * conn, char *auth, int cont);
179 int imap_login(connection_t * conn, char *user, char *pass);
180 /* int imap_list(connection_t *conn, char *refer, char *mbox); */
181 int imap_subscribe(connection_t * conn, char *mbox);
182 int imap_examine(connection_t * conn, char *mbox);
183 int imap_select(connection_t * conn, char *mbox);
184 int imap_status(connection_t * conn, char *mbox, char *items);
185 int imap_create(connection_t * conn, char *mbox);
186 int imap_search(connection_t * conn, char *charset, char *search);
187 int imap_fetch(connection_t * conn, char *mesg, char *items);
188 int imap_store(connection_t * conn, char *mesg, unsigned int mode, char *flags);
189 int imap_copy(connection_t * conn, char *mesg, char *mbox);
190 int imap_append(connection_t * conn, char *mbox, char *flags, char *date, unsigned int size);
191 int imap_close(connection_t * conn);
192 int imap_expunge(connection_t * conn);
193
194 /* lock.c */
195 void lockfile_create(void);
196 void lockfile_check(void);
197 int lockfile_remove(void);
198 void kill_imapfilter(void);
199
200 /* log.c */
201 void info(const char *info,...);
202 void verbose(const char *info,...);
203 void debug(const char *debug,...);
204 void error(const char *errmsg,...);
205 void fatal(unsigned int errnum, const char *fatal,...);
206 void catch_signals(void);
207 int debug_start(void);
208 int debug_stop(void);
209 int log_start(void);
210 int log_stop(void);
211 void log_info(int flag, void *ptr);
212
213 /* match.c */
214 int apply_filters(char *mbox, filter_t ** filters);
215
216 /* memory.c */
217 void *xmalloc(size_t size);
218 void *xrealloc(void *ptr, size_t size);
219 void xfree(void *ptr);
220 char *xstrdup(const char *s);
221
222 void *smalloc(size_t size);
223 void *srealloc(void *ptr, size_t size);
224 void sfree(void *ptr);
225 char *sstrdup(const char *s);
226
227 void secmem_clear(void);
228
229 void corefile_disable(void);
230
231 /* misc.c */
232 char *strcasestr(const char *haystack, const char *needle);
233 char *ultostr(unsigned long int num, int base);
234 char *xstrncpy(char *dest, const char *src, size_t size);
235
236 /* parse.c */
237 int read_config(char *cfg);
238 void reread_config(char *cfg);
239 int read_passwords(void);
240
241 /* passwd.c */
242 void get_password(char *passwd, size_t pwlen);
243 #ifdef ENCRYPTED_PASSWORDS
244 int encrypt_passwords(FILE * fd, account_t ** accts);
245 int decrypt_passwords(unsigned char **buf, FILE * fd);
246 void password_editor(void);
247 #endif
248
249 /* request.c */
250 int test(connection_t * conn);
251 int check_capabilities(connection_t * conn);
252 int check_namespace(connection_t * conn);
253 #ifdef SSL_TLS
254 int negotiate_tls(connection_t * conn);
255 #endif
256 int login(connection_t * conn, char *user, char *pass);
257 int check_mailbox(connection_t * conn, char *mbox);
258 int select_mailbox(connection_t * conn, char *mbox);
259 int mailbox_status(connection_t * conn, char *mbox);
260 int close_mailbox(connection_t * conn);
261 int logout(connection_t * conn);
262
263 /* response.c */
264 int response_generic(connection_t * conn, unsigned int tag);
265 int response_greeting(connection_t * conn);
266 int response_logout(connection_t * conn, unsigned int tag);
267 int response_capability(connection_t * conn, unsigned int tag);
268 int response_authenticate(connection_t * conn, unsigned int tag, unsigned char **cont);
269 int response_namespace(connection_t * conn, unsigned int tag);
270 int response_status(connection_t * conn, unsigned int tag, char *mbox);
271 int response_examine(connection_t * conn, unsigned int tag, char *mbox);
272 int response_select(connection_t * conn, unsigned int tag);
273 int response_search(connection_t * conn, unsigned int tag, char **mesgs);
274 int response_fetch(connection_t * conn, unsigned int tag, int reset, char *fetch);
275 int response_fetchfast(connection_t * conn, char **flags, char **date, unsigned int *size, unsigned int tag);
276 int response_append(connection_t * conn, unsigned int tag);
277 int response_copy(connection_t * conn, unsigned int tag);
278
279 /* socket.c */
280 int
281 init_connection(connection_t * conn, char *serv, unsigned short int port, unsigned int protocol);
282 #ifdef SSL_TLS
283 int init_secure_connection(connection_t * conn, unsigned int protocol);
284 #endif
285 int close_connection(connection_t * conn);
286 int socket_read(connection_t * conn, char *buf);
287 int socket_write(connection_t * conn, char *data);
288
289 /* tty.c */
290 int tty_store(void);
291 int tty_noecho(void);
292 int tty_restore(void);
293
294
295 #endif /* IMAPFILTER_H */

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26