1 |
lefcha |
1.9 |
#ifndef IMAPFILTER_H |
2 |
|
|
#define IMAPFILTER_H |
3 |
|
|
|
4 |
|
|
#include <stdio.h> |
5 |
lefcha |
1.25 |
#include <unistd.h> |
6 |
|
|
#include <sys/stat.h> |
7 |
|
|
#include <sys/types.h> |
8 |
lefcha |
1.9 |
|
9 |
|
|
#ifndef DATA_H |
10 |
|
|
#include "data.h" |
11 |
|
|
#endif |
12 |
|
|
|
13 |
lefcha |
1.11 |
/* Error codes returned by functions. */ |
14 |
lefcha |
1.22 |
#define ERROR_SIGNAL 1 |
15 |
|
|
#define ERROR_TRIVIAL 2 |
16 |
|
|
#define ERROR_FILE_OPEN 3 |
17 |
|
|
#define ERROR_CONFIG_PARSE 4 |
18 |
|
|
#define ERROR_MEMORY_ALLOCATION 5 |
19 |
lefcha |
1.25 |
#define ERROR_TERMIO 6 |
20 |
|
|
#define ERROR_NETWORK 7 |
21 |
|
|
#define ERROR_SSL 8 |
22 |
lefcha |
1.26 |
#define ERROR_PASSPHRASE 9 |
23 |
|
|
#define ERROR_ENCRYPT 10 |
24 |
|
|
#define ERROR_DECRYPT 11 |
25 |
|
|
#define ERROR_UNDEFINED 12 |
26 |
lefcha |
1.9 |
|
27 |
|
|
/* Flags that control the program's options. */ |
28 |
lefcha |
1.16 |
#define OPTION_DETAILS_QUIET 0x01 |
29 |
lefcha |
1.9 |
#define OPTION_DETAILS_NORMAL 0x02 |
30 |
|
|
#define OPTION_DETAILS_VERBOSE 0x04 |
31 |
|
|
#define OPTION_DETAILS_CLEAR 0xf8 |
32 |
lefcha |
1.14 |
#define OPTION_HEADERS 0x08 |
33 |
lefcha |
1.25 |
#define OPTION_NAMESPACE 0x10 |
34 |
lefcha |
1.26 |
#define OPTION_PASSWORD_EDITOR 0x20 |
35 |
lefcha |
1.25 |
|
36 |
|
|
/* Capabilities of mail server. */ |
37 |
|
|
#define CAPABILITY_NONE 0x00 |
38 |
|
|
#define CAPABILITY_NAMESPACE 0x01 |
39 |
lefcha |
1.9 |
|
40 |
lefcha |
1.12 |
/* Flags for logger. */ |
41 |
|
|
#define LOG_WRITE 0 |
42 |
|
|
#define LOG_SERVER 1 |
43 |
|
|
#define LOG_USERNAME 2 |
44 |
|
|
#define LOG_MAILBOX 3 |
45 |
|
|
#define LOG_FILTER 4 |
46 |
|
|
#define LOG_ACTION 5 |
47 |
|
|
#define LOG_DESTINATION_MAILBOX 6 |
48 |
|
|
|
49 |
lefcha |
1.17 |
/* Buffer size of the IMAP command. */ |
50 |
lefcha |
1.9 |
#define SMALL_CMD 64 |
51 |
|
|
#define MEDIUM_CMD 256 |
52 |
|
|
#define BIG_CMD 8192 |
53 |
|
|
|
54 |
|
|
/* Buffer size of server's response. */ |
55 |
lefcha |
1.21 |
#define RESPONSE_BUF (4096 + 1) |
56 |
lefcha |
1.20 |
#define RESULT_BUF 512 |
57 |
lefcha |
1.9 |
|
58 |
lefcha |
1.16 |
/* Response codes. */ |
59 |
|
|
#define RESPONSE_BAD -1 |
60 |
|
|
#define RESPONSE_OK 0 |
61 |
|
|
#define RESPONSE_NO 1 |
62 |
|
|
#define RESPONSE_BYE 2 |
63 |
lefcha |
1.20 |
#define RESPONSE_PREAUTH 3 |
64 |
|
|
#define RESPONSE_READONLY 4 |
65 |
|
|
#define RESPONSE_TRYCREATE 5 |
66 |
lefcha |
1.16 |
|
67 |
lefcha |
1.9 |
/* Buffer size of message's headers. */ |
68 |
lefcha |
1.19 |
#define HEADERS_BUF 16384 |
69 |
lefcha |
1.9 |
|
70 |
lefcha |
1.25 |
/* Length of mailbox namespace prefix. */ |
71 |
|
|
#define NAMESPACE_PREFIX_LEN 64 |
72 |
|
|
|
73 |
lefcha |
1.26 |
/* Encryption and decryption buffers. */ |
74 |
|
|
#define ENCRYPTION_BUF 1024 |
75 |
|
|
#define DECRYPTION_BUF 4096 |
76 |
|
|
|
77 |
lefcha |
1.1 |
|
78 |
|
|
#define min(A, B) ((A) < (B) ? (A) : (B)) |
79 |
lefcha |
1.15 |
#define plural(A) ((A) == 1 ? "" : "s") |
80 |
lefcha |
1.1 |
|
81 |
|
|
|
82 |
lefcha |
1.9 |
/* file.c */ |
83 |
lefcha |
1.25 |
int create_homedir(void); |
84 |
lefcha |
1.26 |
int exists_file(char *fname); |
85 |
|
|
int exists_dir(char *fname); |
86 |
lefcha |
1.25 |
int create_file(char *fname, mode_t mode); |
87 |
|
|
int create_dir(char *dname, mode_t mode); |
88 |
lefcha |
1.9 |
#ifdef CHECK_PERMISSIONS |
89 |
lefcha |
1.25 |
int check_file_perms(char *fname, mode_t mode); |
90 |
|
|
int check_dir_perms(char *dname, mode_t mode); |
91 |
lefcha |
1.9 |
#endif |
92 |
lefcha |
1.25 |
int read_config(char *cfg); |
93 |
lefcha |
1.26 |
int parse_config(FILE * fd); |
94 |
lefcha |
1.10 |
void set_options(char *line, regmatch_t * match); |
95 |
lefcha |
1.26 |
int read_passwords(void); |
96 |
|
|
int parse_passwords(FILE * fd); |
97 |
|
|
int store_passwords(account_t * accts[]); |
98 |
lefcha |
1.1 |
|
99 |
lefcha |
1.9 |
/* imapfilter.c */ |
100 |
|
|
void usage(void); |
101 |
lefcha |
1.1 |
|
102 |
lefcha |
1.9 |
/* imap.c */ |
103 |
lefcha |
1.16 |
unsigned int send_command(char *cmd); |
104 |
lefcha |
1.9 |
#ifdef DEBUG |
105 |
|
|
int imap_noop(void); |
106 |
|
|
#endif |
107 |
lefcha |
1.16 |
int imap_capability(void); |
108 |
lefcha |
1.25 |
int imap_namespace(void); |
109 |
lefcha |
1.9 |
int imap_logout(void); |
110 |
|
|
int imap_login(char *user, char *pass); |
111 |
lefcha |
1.16 |
/* int imap_examine(char *mbox); */ |
112 |
lefcha |
1.9 |
int imap_select(char *mbox); |
113 |
|
|
int imap_status(char *mbox, char *items); |
114 |
|
|
int imap_create(char *mbox); |
115 |
|
|
int imap_search(char *search); |
116 |
lefcha |
1.16 |
int imap_fetch(char *mesg, char *headers, int peek); |
117 |
lefcha |
1.9 |
int imap_store(char *mesg, char *flags); |
118 |
|
|
int imap_copy(char *mesg, char *mbox); |
119 |
|
|
int imap_close(void); |
120 |
lefcha |
1.23 |
/* int imap_expunge(void); */ |
121 |
lefcha |
1.9 |
|
122 |
|
|
/* log.c */ |
123 |
lefcha |
1.13 |
void info(const char *info,...); |
124 |
|
|
void verbose(const char *info,...); |
125 |
|
|
void error(const char *errmsg,...); |
126 |
|
|
void fatal(unsigned int errnum, const char *fatal,...); |
127 |
lefcha |
1.22 |
void catch_signals(void); |
128 |
|
|
void signal_handler(int sig); |
129 |
lefcha |
1.9 |
int open_logfile(void); |
130 |
|
|
int create_logfile(void); |
131 |
|
|
int close_logfile(void); |
132 |
lefcha |
1.12 |
void log_info(int flag, void *ptr); |
133 |
lefcha |
1.11 |
char *get_time(void); |
134 |
lefcha |
1.9 |
|
135 |
lefcha |
1.13 |
/* memory.c */ |
136 |
|
|
void *xmalloc(size_t size); |
137 |
lefcha |
1.19 |
void *xrealloc(void *ptr, size_t size); |
138 |
lefcha |
1.26 |
void xfree(void *ptr); |
139 |
lefcha |
1.13 |
char *xstrdup(const char *s); |
140 |
|
|
|
141 |
lefcha |
1.16 |
/* misc.c */ |
142 |
|
|
char *strcasestr(const char *haystack, const char *needle); |
143 |
|
|
char *ultostr(unsigned long int num, int base); |
144 |
lefcha |
1.24 |
char *xstrncpy(char *dest, const char *src, size_t size); |
145 |
lefcha |
1.16 |
|
146 |
lefcha |
1.25 |
/* passwd.c */ |
147 |
lefcha |
1.26 |
void get_password(char *passwd, size_t pwlen); |
148 |
|
|
#ifdef ENCRYPTED_PASSWORDS |
149 |
|
|
int encrypt_passwords(FILE *fd, account_t *accts[]); |
150 |
|
|
int decrypt_passwords(unsigned char *buf, FILE *fd); |
151 |
|
|
void password_editor(void); |
152 |
|
|
#endif |
153 |
lefcha |
1.25 |
|
154 |
lefcha |
1.9 |
/* request.c */ |
155 |
|
|
int test(void); |
156 |
lefcha |
1.16 |
int check_capabilities(void); |
157 |
lefcha |
1.25 |
int check_namespace(void); |
158 |
lefcha |
1.9 |
int login(char *user, char *pass); |
159 |
|
|
int select_mailbox(char *mbox); |
160 |
lefcha |
1.11 |
int mailbox_status(char *mbox); |
161 |
lefcha |
1.9 |
int close_mailbox(void); |
162 |
|
|
int logout(void); |
163 |
|
|
|
164 |
lefcha |
1.16 |
int apply_filters(filter_t ** filters); |
165 |
lefcha |
1.19 |
int match_filter(filter_t * filter, char **mesgs); |
166 |
lefcha |
1.9 |
|
167 |
|
|
void empty_fifo(mask_t ** mfifo); |
168 |
lefcha |
1.11 |
void queue_fifo(mask_t ** mfifo, mask_t * mask); |
169 |
|
|
mask_t *dequeue_fifo(mask_t ** mfifo); |
170 |
lefcha |
1.9 |
|
171 |
lefcha |
1.11 |
char *generate_filter_and(mask_t * mask, unsigned int masknum, unsigned int masklen); |
172 |
|
|
char *generate_filter_or(mask_t * mask, unsigned int masknum, unsigned int masklen); |
173 |
lefcha |
1.9 |
|
174 |
lefcha |
1.11 |
int apply_action(char *mesgs, unsigned int *type, char *destmbox, char *args); |
175 |
lefcha |
1.9 |
int action_delete(char *mesgs, char *args); |
176 |
lefcha |
1.11 |
int action_copy(char *mesgs, char *destmbox, char *args); |
177 |
|
|
int action_move(char *mesgs, char *destmbox, char *args); |
178 |
|
|
int action_list(char *mesgs, char *args); |
179 |
lefcha |
1.9 |
|
180 |
|
|
unsigned int convert_messages(char *mesgs); |
181 |
|
|
|
182 |
lefcha |
1.11 |
/* response.c */ |
183 |
lefcha |
1.20 |
void receive_response(char *buf); |
184 |
lefcha |
1.16 |
int server_response(unsigned int tag); |
185 |
|
|
int greeting_response(void); |
186 |
|
|
int capability_response(unsigned int tag); |
187 |
lefcha |
1.25 |
int namespace_response(unsigned int tag, char *prefix, char delim); |
188 |
lefcha |
1.23 |
int status_response(unsigned int tag, char *mbox); |
189 |
lefcha |
1.16 |
int select_response(unsigned int tag); |
190 |
lefcha |
1.19 |
int search_response(unsigned int tag, char **mesgs); |
191 |
lefcha |
1.16 |
int fetch_response(unsigned int tag); |
192 |
|
|
int copy_response(unsigned int tag); |
193 |
lefcha |
1.20 |
int analyze_response(char *buf); |
194 |
lefcha |
1.25 |
|
195 |
|
|
/* socket.c */ |
196 |
|
|
#ifndef SSL_TLS |
197 |
|
|
int init_connection(char *serv, unsigned short int port); |
198 |
|
|
#else |
199 |
|
|
int init_connection(char *serv, unsigned short int port, unsigned int protocol); |
200 |
|
|
#endif |
201 |
|
|
int ssl_init(unsigned int protocol); |
202 |
|
|
int close_connection(void); |
203 |
|
|
int socket_read(char *buf); |
204 |
|
|
int socket_write(char *data); |
205 |
|
|
|
206 |
|
|
/* tty.c */ |
207 |
|
|
int tty_store(void); |
208 |
|
|
int tty_disable_echo(void); |
209 |
|
|
int tty_restore(void); |
210 |
lefcha |
1.11 |
|
211 |
lefcha |
1.13 |
#endif /* IMAPFILTER_H */ |