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