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