1 |
lefcha |
1.9 |
#ifndef IMAPFILTER_H |
2 |
|
|
#define IMAPFILTER_H |
3 |
|
|
|
4 |
|
|
|
5 |
lefcha |
1.68 |
#include <stdio.h> |
6 |
|
|
#include <sys/types.h> |
7 |
|
|
|
8 |
lefcha |
1.54 |
#include "config.h" |
9 |
lefcha |
1.65 |
#include "account.h" |
10 |
|
|
#include "filter.h" |
11 |
lefcha |
1.54 |
|
12 |
|
|
#ifdef SSL_TLS |
13 |
|
|
#include <openssl/ssl.h> |
14 |
|
|
#endif |
15 |
|
|
|
16 |
lefcha |
1.43 |
|
17 |
lefcha |
1.11 |
/* Error codes returned by functions. */ |
18 |
lefcha |
1.22 |
#define ERROR_SIGNAL 1 |
19 |
|
|
#define ERROR_TRIVIAL 2 |
20 |
|
|
#define ERROR_FILE_OPEN 3 |
21 |
lefcha |
1.32 |
#define ERROR_LOCKFILE 4 |
22 |
lefcha |
1.29 |
#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 |
lefcha |
1.30 |
#define ERROR_FORK 14 |
32 |
|
|
#define ERROR_UNDEFINED 15 |
33 |
lefcha |
1.9 |
|
34 |
lefcha |
1.54 |
/* 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 |
lefcha |
1.30 |
/* Flags that control the program's execution options. */ |
46 |
lefcha |
1.76 |
#define OPTION_DEBUG 0x0001 |
47 |
|
|
#define OPTION_ERRORS 0x0002 |
48 |
|
|
#define OPTION_EXPUNGE 0x0004 |
49 |
|
|
#define OPTION_HEADERS 0x0008 |
50 |
|
|
#define OPTION_NAMESPACE 0x0010 |
51 |
|
|
#define OPTION_SUBSCRIBE 0x0020 |
52 |
|
|
#define OPTION_PASSWORD_EDITOR 0x0040 |
53 |
|
|
#define OPTION_DAEMON_MODE 0x0080 |
54 |
|
|
#define OPTION_PEEK 0x0100 |
55 |
lefcha |
1.30 |
|
56 |
|
|
/* Other flags. */ |
57 |
lefcha |
1.54 |
#define FLAG_DAEMON_MODE 0x01 |
58 |
|
|
#define FLAG_TTY 0x02 |
59 |
|
|
#define FLAG_TTY_MODIFIED 0x04 |
60 |
|
|
#define FLAG_BLANK_PASSWORD 0x08 |
61 |
lefcha |
1.67 |
#define FLAG_SIGUSR1_RECEIVED 0x10 |
62 |
lefcha |
1.25 |
|
63 |
|
|
/* Capabilities of mail server. */ |
64 |
|
|
#define CAPABILITY_NONE 0x00 |
65 |
|
|
#define CAPABILITY_NAMESPACE 0x01 |
66 |
lefcha |
1.61 |
#define CAPABILITY_AUTH_CRAM_MD5 0x02 |
67 |
lefcha |
1.62 |
#define CAPABILITY_STARTTLS 0x04 |
68 |
lefcha |
1.9 |
|
69 |
lefcha |
1.12 |
/* Flags for logger. */ |
70 |
lefcha |
1.55 |
#define LOG_PREAMBLE 0 |
71 |
lefcha |
1.49 |
#define LOG_ACCOUNT 1 |
72 |
|
|
#define LOG_MAILBOX 2 |
73 |
|
|
#define LOG_FILTER 3 |
74 |
|
|
#define LOG_ACTION 4 |
75 |
|
|
#define LOG_DESTINATION_ACCOUNT 5 |
76 |
lefcha |
1.12 |
#define LOG_DESTINATION_MAILBOX 6 |
77 |
lefcha |
1.55 |
#define LOG_HEADER 7 |
78 |
lefcha |
1.12 |
|
79 |
lefcha |
1.35 |
/* Store IMAP command type may replace,add or remove flags. */ |
80 |
|
|
#define STORE_FLAG_REPLACE 1 |
81 |
|
|
#define STORE_FLAG_ADD 2 |
82 |
|
|
#define STORE_FLAG_REMOVE 3 |
83 |
|
|
|
84 |
lefcha |
1.9 |
/* Buffer size of server's response. */ |
85 |
lefcha |
1.55 |
#define RESPONSE_BUF 4096 |
86 |
lefcha |
1.20 |
#define RESULT_BUF 512 |
87 |
lefcha |
1.9 |
|
88 |
lefcha |
1.16 |
/* Response codes. */ |
89 |
lefcha |
1.44 |
#define RESPONSE_NULLBODY -2 |
90 |
|
|
#define RESPONSE_NONE -1 |
91 |
lefcha |
1.16 |
#define RESPONSE_OK 0 |
92 |
|
|
#define RESPONSE_NO 1 |
93 |
lefcha |
1.44 |
#define RESPONSE_BAD 2 |
94 |
|
|
#define RESPONSE_BYE 3 |
95 |
|
|
#define RESPONSE_PREAUTH 4 |
96 |
|
|
#define RESPONSE_READONLY 5 |
97 |
|
|
#define RESPONSE_TRYCREATE 6 |
98 |
lefcha |
1.16 |
|
99 |
lefcha |
1.26 |
/* Encryption and decryption buffers. */ |
100 |
|
|
#define ENCRYPTION_BUF 1024 |
101 |
|
|
#define DECRYPTION_BUF 4096 |
102 |
|
|
|
103 |
lefcha |
1.35 |
/* Buffer to save flags of the store IMAP command. */ |
104 |
|
|
#define STORE_FLAGS_BUF 64 |
105 |
|
|
|
106 |
lefcha |
1.69 |
/* Length of charset for IMAP SEARCH requests. */ |
107 |
lefcha |
1.47 |
#define CHARSET_LEN 64 |
108 |
|
|
|
109 |
lefcha |
1.65 |
/* String lengths of master password and encrypted passwords. */ |
110 |
|
|
#define PASSPHRASE_LEN 256 |
111 |
|
|
|
112 |
|
|
/* Length of mailbox namespace prefix. */ |
113 |
|
|
#define NAMESPACE_PREFIX_LEN 64 |
114 |
|
|
|
115 |
lefcha |
1.1 |
|
116 |
|
|
#define min(A, B) ((A) < (B) ? (A) : (B)) |
117 |
lefcha |
1.15 |
#define plural(A) ((A) == 1 ? "" : "s") |
118 |
lefcha |
1.1 |
|
119 |
|
|
|
120 |
lefcha |
1.64 |
/* IMAP connection. */ |
121 |
|
|
typedef struct conn { |
122 |
|
|
int sock; /* Socket. */ |
123 |
|
|
#ifdef SSL_TLS |
124 |
|
|
SSL *ssl; /* SSL socket. */ |
125 |
|
|
#endif |
126 |
|
|
unsigned int caps; /* Capabilities of the mail server. */ |
127 |
lefcha |
1.65 |
struct { /* Namespace of the mail server's mailboxes. */ |
128 |
|
|
char prefix[NAMESPACE_PREFIX_LEN]; /* Namespace prefix. */ |
129 |
|
|
char delim; /* Namespace delimiter. */ |
130 |
|
|
} nsp; |
131 |
lefcha |
1.64 |
} conn_t; |
132 |
|
|
|
133 |
|
|
|
134 |
lefcha |
1.65 |
/* action.c */ |
135 |
|
|
int apply_action(char *mbox, char *mesgs, unsigned int *type, account_t * raccount, char *destmbox, unsigned int *msgflags, char *args); |
136 |
|
|
|
137 |
lefcha |
1.61 |
/* auth.c */ |
138 |
lefcha |
1.62 |
#ifdef CRAM_MD5 |
139 |
lefcha |
1.65 |
int auth_cram_md5(conn_t * conn, char *user, char *pass); |
140 |
|
|
#endif |
141 |
lefcha |
1.61 |
|
142 |
lefcha |
1.65 |
/* cert.c */ |
143 |
|
|
#ifdef SSL_TLS |
144 |
|
|
int get_cert(conn_t * conn); |
145 |
lefcha |
1.62 |
#endif |
146 |
|
|
|
147 |
lefcha |
1.65 |
/* destroy.c */ |
148 |
|
|
void destroy_all(void); |
149 |
|
|
void destroy_unneeded(void); |
150 |
lefcha |
1.63 |
|
151 |
lefcha |
1.9 |
/* file.c */ |
152 |
lefcha |
1.25 |
int create_homedir(void); |
153 |
lefcha |
1.26 |
int exists_file(char *fname); |
154 |
|
|
int exists_dir(char *fname); |
155 |
lefcha |
1.25 |
int create_file(char *fname, mode_t mode); |
156 |
|
|
int check_file_perms(char *fname, mode_t mode); |
157 |
lefcha |
1.75 |
int check_dir_perms(char *dname, mode_t mode); |
158 |
lefcha |
1.54 |
|
159 |
lefcha |
1.9 |
/* imap.c */ |
160 |
lefcha |
1.64 |
int imap_noop(conn_t * conn); |
161 |
|
|
int imap_capability(conn_t * conn); |
162 |
|
|
int imap_namespace(conn_t * conn); |
163 |
|
|
int imap_logout(conn_t * conn); |
164 |
lefcha |
1.62 |
#ifdef SSL_TLS |
165 |
lefcha |
1.64 |
int imap_starttls(conn_t * conn); |
166 |
lefcha |
1.62 |
#endif |
167 |
lefcha |
1.64 |
int imap_authenticate(conn_t * conn, char *auth, int cont); |
168 |
|
|
int imap_login(conn_t * conn, char *user, char *pass); |
169 |
|
|
/* int imap_list(conn_t *conn, char *refer, char *mbox); */ |
170 |
|
|
int imap_subscribe(conn_t * conn, char *mbox); |
171 |
|
|
/* int imap_examine(conn_t *conn, char *mbox); */ |
172 |
|
|
int imap_select(conn_t * conn, char *mbox); |
173 |
|
|
int imap_status(conn_t * conn, char *mbox, char *items); |
174 |
|
|
int imap_create(conn_t * conn, char *mbox); |
175 |
|
|
int imap_search(conn_t * conn, char *charset, char *search); |
176 |
|
|
int imap_fetch(conn_t * conn, char *mesg, char *items); |
177 |
|
|
int imap_store(conn_t * conn, char *mesg, unsigned int mode, char *flags); |
178 |
|
|
int imap_copy(conn_t * conn, char *mesg, char *mbox); |
179 |
lefcha |
1.71 |
int imap_append(conn_t * conn, char *mbox, char *flags, char *date, unsigned int size); |
180 |
lefcha |
1.64 |
int imap_close(conn_t * conn); |
181 |
|
|
int imap_expunge(conn_t * conn); |
182 |
lefcha |
1.29 |
|
183 |
|
|
/* lock.c */ |
184 |
|
|
void lockfile_create(void); |
185 |
|
|
void lockfile_check(void); |
186 |
|
|
int lockfile_remove(void); |
187 |
lefcha |
1.30 |
void kill_imapfilter(void); |
188 |
lefcha |
1.9 |
|
189 |
|
|
/* log.c */ |
190 |
lefcha |
1.13 |
void info(const char *info,...); |
191 |
|
|
void verbose(const char *info,...); |
192 |
lefcha |
1.74 |
void debug(const char *debug,...); |
193 |
lefcha |
1.13 |
void error(const char *errmsg,...); |
194 |
|
|
void fatal(unsigned int errnum, const char *fatal,...); |
195 |
lefcha |
1.22 |
void catch_signals(void); |
196 |
lefcha |
1.74 |
int debug_start(void); |
197 |
|
|
int debug_stop(void); |
198 |
|
|
int log_start(void); |
199 |
|
|
int log_stop(void); |
200 |
lefcha |
1.12 |
void log_info(int flag, void *ptr); |
201 |
lefcha |
1.65 |
|
202 |
|
|
/* match.c */ |
203 |
|
|
int apply_filters(char *mbox, filter_t ** filters); |
204 |
lefcha |
1.9 |
|
205 |
lefcha |
1.13 |
/* memory.c */ |
206 |
|
|
void *xmalloc(size_t size); |
207 |
lefcha |
1.19 |
void *xrealloc(void *ptr, size_t size); |
208 |
lefcha |
1.26 |
void xfree(void *ptr); |
209 |
lefcha |
1.13 |
char *xstrdup(const char *s); |
210 |
|
|
|
211 |
lefcha |
1.27 |
void *smalloc(size_t size); |
212 |
|
|
void *srealloc(void *ptr, size_t size); |
213 |
|
|
void sfree(void *ptr); |
214 |
|
|
char *sstrdup(const char *s); |
215 |
|
|
void secmem_clear(void); |
216 |
lefcha |
1.49 |
|
217 |
lefcha |
1.27 |
void corefile_disable(void); |
218 |
|
|
|
219 |
lefcha |
1.16 |
/* misc.c */ |
220 |
|
|
char *strcasestr(const char *haystack, const char *needle); |
221 |
|
|
char *ultostr(unsigned long int num, int base); |
222 |
lefcha |
1.24 |
char *xstrncpy(char *dest, const char *src, size_t size); |
223 |
lefcha |
1.16 |
|
224 |
lefcha |
1.65 |
/* parse.c */ |
225 |
|
|
int read_config(char *cfg); |
226 |
|
|
void reread_config(char *cfg); |
227 |
|
|
int read_passwords(void); |
228 |
|
|
|
229 |
lefcha |
1.25 |
/* passwd.c */ |
230 |
lefcha |
1.26 |
void get_password(char *passwd, size_t pwlen); |
231 |
|
|
#ifdef ENCRYPTED_PASSWORDS |
232 |
lefcha |
1.60 |
int encrypt_passwords(FILE * fd, account_t ** accts); |
233 |
lefcha |
1.34 |
int decrypt_passwords(unsigned char **buf, FILE * fd); |
234 |
lefcha |
1.26 |
void password_editor(void); |
235 |
|
|
#endif |
236 |
lefcha |
1.25 |
|
237 |
lefcha |
1.9 |
/* request.c */ |
238 |
lefcha |
1.64 |
int test(conn_t * conn); |
239 |
|
|
int check_capabilities(conn_t * conn); |
240 |
|
|
int check_namespace(conn_t * conn); |
241 |
lefcha |
1.62 |
#ifdef SSL_TLS |
242 |
lefcha |
1.65 |
int negotiate_tls(conn_t * conn); |
243 |
lefcha |
1.62 |
#endif |
244 |
lefcha |
1.64 |
int login(conn_t * conn, char *user, char *pass); |
245 |
|
|
int check_mailbox(conn_t * conn, char *mbox); |
246 |
|
|
int select_mailbox(conn_t * conn, char *mbox); |
247 |
|
|
int mailbox_status(conn_t * conn, char *mbox); |
248 |
|
|
int close_mailbox(conn_t * conn); |
249 |
|
|
int logout(conn_t * conn); |
250 |
lefcha |
1.9 |
|
251 |
lefcha |
1.65 |
/* response.c */ |
252 |
lefcha |
1.64 |
int server_response(conn_t * conn, unsigned int tag); |
253 |
|
|
int greeting_response(conn_t * conn); |
254 |
|
|
int logout_response(conn_t * conn, unsigned int tag); |
255 |
|
|
int capability_response(conn_t * conn, unsigned int tag); |
256 |
|
|
int authenticate_response(conn_t * conn, unsigned int tag, unsigned char **cont); |
257 |
|
|
int namespace_response(conn_t * conn, unsigned int tag); |
258 |
|
|
int status_response(conn_t * conn, unsigned int tag, char *mbox); |
259 |
|
|
int select_response(conn_t * conn, unsigned int tag); |
260 |
|
|
int search_response(conn_t * conn, unsigned int tag, char **mesgs); |
261 |
|
|
int fetch_response(conn_t * conn, unsigned int tag, int reset, char *fetch); |
262 |
lefcha |
1.71 |
int fetchfast_response(conn_t * conn, char **flags, char **date, unsigned int *size, unsigned int tag); |
263 |
lefcha |
1.64 |
int append_response(conn_t * conn, unsigned int tag); |
264 |
|
|
int copy_response(conn_t * conn, unsigned int tag); |
265 |
lefcha |
1.25 |
|
266 |
|
|
/* socket.c */ |
267 |
lefcha |
1.64 |
int init_connection(conn_t * conn, char *serv, unsigned short int port, unsigned int protocol); |
268 |
lefcha |
1.62 |
#ifdef SSL_TLS |
269 |
lefcha |
1.65 |
int init_secure_connection(conn_t * conn, unsigned int protocol); |
270 |
lefcha |
1.62 |
#endif |
271 |
lefcha |
1.64 |
int close_connection(conn_t * conn); |
272 |
|
|
int socket_read(conn_t * conn, char *buf); |
273 |
|
|
int socket_write(conn_t * conn, char *data); |
274 |
lefcha |
1.25 |
|
275 |
|
|
/* tty.c */ |
276 |
|
|
int tty_store(void); |
277 |
|
|
int tty_disable_echo(void); |
278 |
|
|
int tty_restore(void); |
279 |
lefcha |
1.65 |
|
280 |
lefcha |
1.11 |
|
281 |
lefcha |
1.13 |
#endif /* IMAPFILTER_H */ |