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

Contents of /imapfilter/imapfilter.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.80 - (show annotations)
Tue Feb 10 22:21:09 2004 UTC (20 years, 1 month ago) by lefcha
Branch: MAIN
Changes since 1.79: +22 -13 lines
File MIME type: text/plain
Replaced integer options and bitwise OPTION_* with an options struct.

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_SIGNAL 2
21 #define ERROR_TRIVIAL 3
22 #define ERROR_FILE_OPEN 4
23 #define ERROR_LOCKFILE 5
24 #define ERROR_CONFIG_PARSE 6
25 #define ERROR_MEMORY_ALLOCATION 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 SSL_CERT_OK 0
37 #define SSL_CERT_NONEXISTENT 1
38 #define SSL_CERT_MISMATCH 2
39
40 /* Action to be applied, concerning the SSL/TLS certificate. */
41 #define SSL_CERT_ACTION_ACCEPT 0
42 #define SSL_CERT_ACTION_REJECT 1
43 #define SSL_CERT_ACTION_CONTINUE 0
44 #define SSL_CERT_ACTION_ABORT 1
45
46 /* Other flags. */
47 #define FLAG_DAEMON_MODE 0x01
48 #define FLAG_TTY 0x02
49 #define FLAG_TTY_MODIFIED 0x04
50 #define FLAG_BLANK_PASSWORD 0x08
51 #define FLAG_SIGUSR1_RECEIVED 0x10
52
53 /* Capabilities of mail server. */
54 #define CAPABILITY_NONE 0x00
55 #define CAPABILITY_NAMESPACE 0x01
56 #define CAPABILITY_AUTH_CRAM_MD5 0x02
57 #define CAPABILITY_STARTTLS 0x04
58
59 /* Flags for logger. */
60 #define LOG_PREAMBLE 0
61 #define LOG_ACCOUNT 1
62 #define LOG_MAILBOX 2
63 #define LOG_FILTER 3
64 #define LOG_ACTION 4
65 #define LOG_DESTINATION_ACCOUNT 5
66 #define LOG_DESTINATION_MAILBOX 6
67 #define LOG_HEADER 7
68
69 /* Store IMAP command type may replace,add or remove flags. */
70 #define STORE_FLAG_REPLACE 1
71 #define STORE_FLAG_ADD 2
72 #define STORE_FLAG_REMOVE 3
73
74 /* Buffer size of server's response. */
75 #define RESPONSE_BUF 4096
76 #define RESULT_BUF 512
77
78 /* Response codes. */
79 #define RESPONSE_NULLBODY -2
80 #define RESPONSE_NONE -1
81 #define RESPONSE_OK 0
82 #define RESPONSE_NO 1
83 #define RESPONSE_BAD 2
84 #define RESPONSE_BYE 3
85 #define RESPONSE_PREAUTH 4
86 #define RESPONSE_READONLY 5
87 #define RESPONSE_TRYCREATE 6
88
89 /* Encryption and decryption buffers. */
90 #define ENCRYPTION_BUF 1024
91 #define DECRYPTION_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 opts {
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 } opts_t;
128
129 /* IMAP connection. */
130 typedef struct conn {
131 int sock; /* Socket. */
132 #ifdef SSL_TLS
133 SSL *ssl; /* SSL socket. */
134 #endif
135 unsigned int caps; /* Capabilities of the mail server. */
136 struct { /* Namespace of the mail server's mailboxes. */
137 char prefix[NAMESPACE_PREFIX_LEN]; /* Namespace prefix. */
138 char delim; /* Namespace delimiter. */
139 } nsp;
140 } conn_t;
141
142
143 /* action.c */
144 int apply_action(char *mbox, char *mesgs, unsigned int *type, account_t * raccount, char *destmbox, unsigned int *msgflags, char *args);
145
146 /* auth.c */
147 #ifdef CRAM_MD5
148 int auth_cram_md5(conn_t * conn, char *user, char *pass);
149 #endif
150
151 /* cert.c */
152 #ifdef SSL_TLS
153 int get_cert(conn_t * conn);
154 #endif
155
156 /* destroy.c */
157 void destroy_all(void);
158 void destroy_unneeded(void);
159
160 /* file.c */
161 int create_homedir(void);
162 int exists_file(char *fname);
163 int exists_dir(char *fname);
164 int create_file(char *fname, mode_t mode);
165 int check_file_perms(char *fname, mode_t mode);
166 int check_dir_perms(char *dname, mode_t mode);
167
168 /* imap.c */
169 int imap_noop(conn_t * conn);
170 int imap_capability(conn_t * conn);
171 int imap_namespace(conn_t * conn);
172 int imap_logout(conn_t * conn);
173 #ifdef SSL_TLS
174 int imap_starttls(conn_t * conn);
175 #endif
176 int imap_authenticate(conn_t * conn, char *auth, int cont);
177 int imap_login(conn_t * conn, char *user, char *pass);
178 /* int imap_list(conn_t *conn, char *refer, char *mbox); */
179 int imap_subscribe(conn_t * conn, char *mbox);
180 /* int imap_examine(conn_t *conn, char *mbox); */
181 int imap_select(conn_t * conn, char *mbox);
182 int imap_status(conn_t * conn, char *mbox, char *items);
183 int imap_create(conn_t * conn, char *mbox);
184 int imap_search(conn_t * conn, char *charset, char *search);
185 int imap_fetch(conn_t * conn, char *mesg, char *items);
186 int imap_store(conn_t * conn, char *mesg, unsigned int mode, char *flags);
187 int imap_copy(conn_t * conn, char *mesg, char *mbox);
188 int imap_append(conn_t * conn, char *mbox, char *flags, char *date, unsigned int size);
189 int imap_close(conn_t * conn);
190 int imap_expunge(conn_t * conn);
191
192 /* lock.c */
193 void lockfile_create(void);
194 void lockfile_check(void);
195 int lockfile_remove(void);
196 void kill_imapfilter(void);
197
198 /* log.c */
199 void info(const char *info,...);
200 void verbose(const char *info,...);
201 void debug(const char *debug,...);
202 void error(const char *errmsg,...);
203 void fatal(unsigned int errnum, const char *fatal,...);
204 void catch_signals(void);
205 int debug_start(void);
206 int debug_stop(void);
207 int log_start(void);
208 int log_stop(void);
209 void log_info(int flag, void *ptr);
210
211 /* match.c */
212 int apply_filters(char *mbox, filter_t ** filters);
213
214 /* memory.c */
215 void *xmalloc(size_t size);
216 void *xrealloc(void *ptr, size_t size);
217 void xfree(void *ptr);
218 char *xstrdup(const char *s);
219
220 void *smalloc(size_t size);
221 void *srealloc(void *ptr, size_t size);
222 void sfree(void *ptr);
223 char *sstrdup(const char *s);
224 void secmem_clear(void);
225
226 void corefile_disable(void);
227
228 /* misc.c */
229 char *strcasestr(const char *haystack, const char *needle);
230 char *ultostr(unsigned long int num, int base);
231 char *xstrncpy(char *dest, const char *src, size_t size);
232
233 /* parse.c */
234 int read_config(char *cfg);
235 void reread_config(char *cfg);
236 int read_passwords(void);
237
238 /* passwd.c */
239 void get_password(char *passwd, size_t pwlen);
240 #ifdef ENCRYPTED_PASSWORDS
241 int encrypt_passwords(FILE * fd, account_t ** accts);
242 int decrypt_passwords(unsigned char **buf, FILE * fd);
243 void password_editor(void);
244 #endif
245
246 /* request.c */
247 int test(conn_t * conn);
248 int check_capabilities(conn_t * conn);
249 int check_namespace(conn_t * conn);
250 #ifdef SSL_TLS
251 int negotiate_tls(conn_t * conn);
252 #endif
253 int login(conn_t * conn, char *user, char *pass);
254 int check_mailbox(conn_t * conn, char *mbox);
255 int select_mailbox(conn_t * conn, char *mbox);
256 int mailbox_status(conn_t * conn, char *mbox);
257 int close_mailbox(conn_t * conn);
258 int logout(conn_t * conn);
259
260 /* response.c */
261 int server_response(conn_t * conn, unsigned int tag);
262 int greeting_response(conn_t * conn);
263 int logout_response(conn_t * conn, unsigned int tag);
264 int capability_response(conn_t * conn, unsigned int tag);
265 int authenticate_response(conn_t * conn, unsigned int tag, unsigned char **cont);
266 int namespace_response(conn_t * conn, unsigned int tag);
267 int status_response(conn_t * conn, unsigned int tag, char *mbox);
268 int select_response(conn_t * conn, unsigned int tag);
269 int search_response(conn_t * conn, unsigned int tag, char **mesgs);
270 int fetch_response(conn_t * conn, unsigned int tag, int reset, char *fetch);
271 int fetchfast_response(conn_t * conn, char **flags, char **date, unsigned int *size, unsigned int tag);
272 int append_response(conn_t * conn, unsigned int tag);
273 int copy_response(conn_t * conn, unsigned int tag);
274
275 /* socket.c */
276 int
277 init_connection(conn_t * conn, char *serv, unsigned short int port, unsigned int protocol);
278 #ifdef SSL_TLS
279 int init_secure_connection(conn_t * conn, unsigned int protocol);
280 #endif
281 int close_connection(conn_t * conn);
282 int socket_read(conn_t * conn, char *buf);
283 int socket_write(conn_t * conn, char *data);
284
285 /* tty.c */
286 int tty_store(void);
287 int tty_disable_echo(void);
288 int tty_restore(void);
289
290
291 #endif /* IMAPFILTER_H */

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26