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

Contents of /imapfilter/imapfilter.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.75 - (show annotations)
Mon Feb 9 18:23:49 2004 UTC (20 years, 1 month ago) by lefcha
Branch: MAIN
Changes since 1.74: +1 -1 lines
File MIME type: text/plain
Remove permissions variable and add command line option -w to suppress related warning messages.

1 #ifndef IMAPFILTER_H
2 #define IMAPFILTER_H
3
4
5 #include <stdio.h>
6 #include <sys/types.h>
7
8 #include "config.h"
9 #include "account.h"
10 #include "filter.h"
11
12 #ifdef SSL_TLS
13 #include <openssl/ssl.h>
14 #endif
15
16
17 /* Error codes returned by functions. */
18 #define ERROR_SIGNAL 1
19 #define ERROR_TRIVIAL 2
20 #define ERROR_FILE_OPEN 3
21 #define ERROR_LOCKFILE 4
22 #define ERROR_CONFIG_PARSE 5
23 #define ERROR_MEMORY_ALLOCATION 6
24 #define ERROR_SETUID 7
25 #define ERROR_TERMIO 8
26 #define ERROR_NETWORK 9
27 #define ERROR_SSL 10
28 #define ERROR_PASSPHRASE 11
29 #define ERROR_ENCRYPT 12
30 #define ERROR_DECRYPT 13
31 #define ERROR_FORK 14
32 #define ERROR_UNDEFINED 15
33
34 /* SSL/TLS certificate status for the server. */
35 #define SSL_CERT_OK 0
36 #define SSL_CERT_NONEXISTENT 1
37 #define SSL_CERT_MISMATCH 2
38
39 /* Action to be applied, concerning the SSL/TLS certificate. */
40 #define SSL_CERT_ACTION_ACCEPT 0
41 #define SSL_CERT_ACTION_REJECT 1
42 #define SSL_CERT_ACTION_CONTINUE 0
43 #define SSL_CERT_ACTION_ABORT 1
44
45 /* Flags that control the program's execution options. */
46 #define OPTION_DETAILS_QUIET 0x0001
47 #define OPTION_DETAILS_NORMAL 0x0002
48 #define OPTION_DETAILS_VERBOSE 0x0004
49 #define OPTION_ERRORS 0x0008
50 #define OPTION_EXPUNGE 0x0010
51 #define OPTION_HEADERS 0x0020
52 #define OPTION_NAMESPACE 0x0040
53 #define OPTION_SUBSCRIBE 0x0080
54 #define OPTION_PASSWORD_EDITOR 0x0100
55 #define OPTION_DAEMON_MODE 0x0200
56 #define OPTION_PEEK 0x0400
57 #define OPTION_PERMISSIONS 0x0800
58 #define OPTION_DEBUG 0x1000
59
60 /* Other flags. */
61 #define FLAG_DAEMON_MODE 0x01
62 #define FLAG_TTY 0x02
63 #define FLAG_TTY_MODIFIED 0x04
64 #define FLAG_BLANK_PASSWORD 0x08
65 #define FLAG_SIGUSR1_RECEIVED 0x10
66
67 /* Capabilities of mail server. */
68 #define CAPABILITY_NONE 0x00
69 #define CAPABILITY_NAMESPACE 0x01
70 #define CAPABILITY_AUTH_CRAM_MD5 0x02
71 #define CAPABILITY_STARTTLS 0x04
72
73 /* Flags for logger. */
74 #define LOG_PREAMBLE 0
75 #define LOG_ACCOUNT 1
76 #define LOG_MAILBOX 2
77 #define LOG_FILTER 3
78 #define LOG_ACTION 4
79 #define LOG_DESTINATION_ACCOUNT 5
80 #define LOG_DESTINATION_MAILBOX 6
81 #define LOG_HEADER 7
82
83 /* Store IMAP command type may replace,add or remove flags. */
84 #define STORE_FLAG_REPLACE 1
85 #define STORE_FLAG_ADD 2
86 #define STORE_FLAG_REMOVE 3
87
88 /* Buffer size of server's response. */
89 #define RESPONSE_BUF 4096
90 #define RESULT_BUF 512
91
92 /* Response codes. */
93 #define RESPONSE_NULLBODY -2
94 #define RESPONSE_NONE -1
95 #define RESPONSE_OK 0
96 #define RESPONSE_NO 1
97 #define RESPONSE_BAD 2
98 #define RESPONSE_BYE 3
99 #define RESPONSE_PREAUTH 4
100 #define RESPONSE_READONLY 5
101 #define RESPONSE_TRYCREATE 6
102
103 /* Encryption and decryption buffers. */
104 #define ENCRYPTION_BUF 1024
105 #define DECRYPTION_BUF 4096
106
107 /* Buffer to save flags of the store IMAP command. */
108 #define STORE_FLAGS_BUF 64
109
110 /* Length of charset for IMAP SEARCH requests. */
111 #define CHARSET_LEN 64
112
113 /* String lengths of master password and encrypted passwords. */
114 #define PASSPHRASE_LEN 256
115
116 /* Length of mailbox namespace prefix. */
117 #define NAMESPACE_PREFIX_LEN 64
118
119
120 #define min(A, B) ((A) < (B) ? (A) : (B))
121 #define plural(A) ((A) == 1 ? "" : "s")
122
123
124 /* IMAP connection. */
125 typedef struct conn {
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 } nsp;
135 } conn_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(conn_t * conn, char *user, char *pass);
144 #endif
145
146 /* cert.c */
147 #ifdef SSL_TLS
148 int get_cert(conn_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(conn_t * conn);
165 int imap_capability(conn_t * conn);
166 int imap_namespace(conn_t * conn);
167 int imap_logout(conn_t * conn);
168 #ifdef SSL_TLS
169 int imap_starttls(conn_t * conn);
170 #endif
171 int imap_authenticate(conn_t * conn, char *auth, int cont);
172 int imap_login(conn_t * conn, char *user, char *pass);
173 /* int imap_list(conn_t *conn, char *refer, char *mbox); */
174 int imap_subscribe(conn_t * conn, char *mbox);
175 /* int imap_examine(conn_t *conn, char *mbox); */
176 int imap_select(conn_t * conn, char *mbox);
177 int imap_status(conn_t * conn, char *mbox, char *items);
178 int imap_create(conn_t * conn, char *mbox);
179 int imap_search(conn_t * conn, char *charset, char *search);
180 int imap_fetch(conn_t * conn, char *mesg, char *items);
181 int imap_store(conn_t * conn, char *mesg, unsigned int mode, char *flags);
182 int imap_copy(conn_t * conn, char *mesg, char *mbox);
183 int imap_append(conn_t * conn, char *mbox, char *flags, char *date, unsigned int size);
184 int imap_close(conn_t * conn);
185 int imap_expunge(conn_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 void secmem_clear(void);
220
221 void corefile_disable(void);
222
223 /* misc.c */
224 char *strcasestr(const char *haystack, const char *needle);
225 char *ultostr(unsigned long int num, int base);
226 char *xstrncpy(char *dest, const char *src, size_t size);
227
228 /* parse.c */
229 int read_config(char *cfg);
230 void reread_config(char *cfg);
231 int read_passwords(void);
232
233 /* passwd.c */
234 void get_password(char *passwd, size_t pwlen);
235 #ifdef ENCRYPTED_PASSWORDS
236 int encrypt_passwords(FILE * fd, account_t ** accts);
237 int decrypt_passwords(unsigned char **buf, FILE * fd);
238 void password_editor(void);
239 #endif
240
241 /* request.c */
242 int test(conn_t * conn);
243 int check_capabilities(conn_t * conn);
244 int check_namespace(conn_t * conn);
245 #ifdef SSL_TLS
246 int negotiate_tls(conn_t * conn);
247 #endif
248 int login(conn_t * conn, char *user, char *pass);
249 int check_mailbox(conn_t * conn, char *mbox);
250 int select_mailbox(conn_t * conn, char *mbox);
251 int mailbox_status(conn_t * conn, char *mbox);
252 int close_mailbox(conn_t * conn);
253 int logout(conn_t * conn);
254
255 /* response.c */
256 int server_response(conn_t * conn, unsigned int tag);
257 int greeting_response(conn_t * conn);
258 int logout_response(conn_t * conn, unsigned int tag);
259 int capability_response(conn_t * conn, unsigned int tag);
260 int authenticate_response(conn_t * conn, unsigned int tag, unsigned char **cont);
261 int namespace_response(conn_t * conn, unsigned int tag);
262 int status_response(conn_t * conn, unsigned int tag, char *mbox);
263 int select_response(conn_t * conn, unsigned int tag);
264 int search_response(conn_t * conn, unsigned int tag, char **mesgs);
265 int fetch_response(conn_t * conn, unsigned int tag, int reset, char *fetch);
266 int fetchfast_response(conn_t * conn, char **flags, char **date, unsigned int *size, unsigned int tag);
267 int append_response(conn_t * conn, unsigned int tag);
268 int copy_response(conn_t * conn, unsigned int tag);
269
270 /* socket.c */
271 int init_connection(conn_t * conn, char *serv, unsigned short int port, unsigned int protocol);
272 #ifdef SSL_TLS
273 int init_secure_connection(conn_t * conn, unsigned int protocol);
274 #endif
275 int close_connection(conn_t * conn);
276 int socket_read(conn_t * conn, char *buf);
277 int socket_write(conn_t * conn, char *data);
278
279 /* tty.c */
280 int tty_store(void);
281 int tty_disable_echo(void);
282 int tty_restore(void);
283
284
285 #endif /* IMAPFILTER_H */

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26