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

Contents of /imapfilter/imapfilter.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.81 - (show annotations)
Fri Feb 13 12:17:16 2004 UTC (20 years, 1 month ago) by lefcha
Branch: MAIN
Changes since 1.80: +119 -123 lines
File MIME type: text/plain
Stylistic changes.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26