1 |
lefcha |
1.9 |
#ifndef IMAPFILTER_H |
2 |
|
|
#define IMAPFILTER_H |
3 |
|
|
|
4 |
|
|
#include <stdio.h> |
5 |
|
|
|
6 |
|
|
#ifndef DATA_H |
7 |
|
|
#include "data.h" |
8 |
|
|
#endif |
9 |
|
|
|
10 |
lefcha |
1.11 |
/* Error codes returned by functions. */ |
11 |
lefcha |
1.22 |
#define ERROR_SIGNAL 1 |
12 |
|
|
#define ERROR_TRIVIAL 2 |
13 |
|
|
#define ERROR_FILE_OPEN 3 |
14 |
|
|
#define ERROR_CONFIG_PARSE 4 |
15 |
|
|
#define ERROR_MEMORY_ALLOCATION 5 |
16 |
|
|
#define ERROR_NETWORK 6 |
17 |
|
|
#define ERROR_SSL 7 |
18 |
|
|
#define ERROR_UNDEFINED 8 |
19 |
lefcha |
1.9 |
|
20 |
|
|
/* Flags that control the program's options. */ |
21 |
lefcha |
1.16 |
#define OPTION_DETAILS_QUIET 0x01 |
22 |
lefcha |
1.9 |
#define OPTION_DETAILS_NORMAL 0x02 |
23 |
|
|
#define OPTION_DETAILS_VERBOSE 0x04 |
24 |
|
|
#define OPTION_DETAILS_CLEAR 0xf8 |
25 |
lefcha |
1.14 |
#define OPTION_HEADERS 0x08 |
26 |
lefcha |
1.9 |
|
27 |
lefcha |
1.12 |
/* Flags for logger. */ |
28 |
|
|
#define LOG_WRITE 0 |
29 |
|
|
#define LOG_SERVER 1 |
30 |
|
|
#define LOG_USERNAME 2 |
31 |
|
|
#define LOG_MAILBOX 3 |
32 |
|
|
#define LOG_FILTER 4 |
33 |
|
|
#define LOG_ACTION 5 |
34 |
|
|
#define LOG_DESTINATION_MAILBOX 6 |
35 |
|
|
|
36 |
lefcha |
1.17 |
/* Buffer size of the IMAP command. */ |
37 |
lefcha |
1.9 |
#define SMALL_CMD 64 |
38 |
|
|
#define MEDIUM_CMD 256 |
39 |
|
|
#define BIG_CMD 8192 |
40 |
|
|
|
41 |
|
|
/* Buffer size of server's response. */ |
42 |
lefcha |
1.21 |
#define RESPONSE_BUF (4096 + 1) |
43 |
lefcha |
1.20 |
#define RESULT_BUF 512 |
44 |
lefcha |
1.9 |
|
45 |
lefcha |
1.16 |
/* Response codes. */ |
46 |
|
|
#define RESPONSE_BAD -1 |
47 |
|
|
#define RESPONSE_OK 0 |
48 |
|
|
#define RESPONSE_NO 1 |
49 |
|
|
#define RESPONSE_BYE 2 |
50 |
lefcha |
1.20 |
#define RESPONSE_PREAUTH 3 |
51 |
|
|
#define RESPONSE_READONLY 4 |
52 |
|
|
#define RESPONSE_TRYCREATE 5 |
53 |
lefcha |
1.16 |
|
54 |
lefcha |
1.9 |
/* Buffer size of message's headers. */ |
55 |
lefcha |
1.19 |
#define HEADERS_BUF 16384 |
56 |
lefcha |
1.9 |
|
57 |
lefcha |
1.1 |
|
58 |
|
|
#define min(A, B) ((A) < (B) ? (A) : (B)) |
59 |
lefcha |
1.15 |
#define plural(A) ((A) == 1 ? "" : "s") |
60 |
lefcha |
1.1 |
|
61 |
|
|
|
62 |
lefcha |
1.17 |
/* socket.c */ |
63 |
|
|
#ifndef SSL_TLS |
64 |
lefcha |
1.9 |
int init_connection(char *serv, unsigned int port); |
65 |
lefcha |
1.17 |
#else |
66 |
|
|
int init_connection(char *serv, unsigned int port, unsigned int protocol); |
67 |
|
|
#endif |
68 |
|
|
int ssl_init(unsigned int protocol); |
69 |
lefcha |
1.9 |
int close_connection(void); |
70 |
lefcha |
1.17 |
int socket_read(char *buf); |
71 |
|
|
int socket_write(char *data); |
72 |
lefcha |
1.9 |
|
73 |
|
|
/* file.c */ |
74 |
|
|
int read_config(char *cfg); |
75 |
|
|
#ifdef CHECK_PERMISSIONS |
76 |
|
|
int check_permissions(char *cfg); |
77 |
|
|
#endif |
78 |
|
|
int parse_config(FILE * fp); |
79 |
lefcha |
1.10 |
void set_options(char *line, regmatch_t * match); |
80 |
lefcha |
1.1 |
|
81 |
lefcha |
1.9 |
/* imapfilter.c */ |
82 |
|
|
void usage(void); |
83 |
lefcha |
1.1 |
|
84 |
lefcha |
1.9 |
/* imap.c */ |
85 |
lefcha |
1.16 |
unsigned int send_command(char *cmd); |
86 |
lefcha |
1.9 |
#ifdef DEBUG |
87 |
|
|
int imap_noop(void); |
88 |
|
|
#endif |
89 |
lefcha |
1.16 |
int imap_capability(void); |
90 |
lefcha |
1.9 |
int imap_logout(void); |
91 |
|
|
int imap_login(char *user, char *pass); |
92 |
lefcha |
1.16 |
/* int imap_examine(char *mbox); */ |
93 |
lefcha |
1.9 |
int imap_select(char *mbox); |
94 |
|
|
int imap_status(char *mbox, char *items); |
95 |
|
|
int imap_create(char *mbox); |
96 |
|
|
int imap_search(char *search); |
97 |
lefcha |
1.16 |
int imap_fetch(char *mesg, char *headers, int peek); |
98 |
lefcha |
1.9 |
int imap_store(char *mesg, char *flags); |
99 |
|
|
int imap_copy(char *mesg, char *mbox); |
100 |
|
|
int imap_close(void); |
101 |
|
|
int imap_expunge(void); |
102 |
|
|
|
103 |
|
|
/* log.c */ |
104 |
lefcha |
1.13 |
void info(const char *info,...); |
105 |
|
|
void verbose(const char *info,...); |
106 |
|
|
void error(const char *errmsg,...); |
107 |
|
|
void fatal(unsigned int errnum, const char *fatal,...); |
108 |
lefcha |
1.22 |
void catch_signals(void); |
109 |
|
|
void signal_handler(int sig); |
110 |
lefcha |
1.9 |
int open_logfile(void); |
111 |
|
|
int create_logfile(void); |
112 |
|
|
int close_logfile(void); |
113 |
lefcha |
1.12 |
void log_info(int flag, void *ptr); |
114 |
lefcha |
1.11 |
char *get_time(void); |
115 |
lefcha |
1.9 |
|
116 |
lefcha |
1.13 |
/* memory.c */ |
117 |
|
|
void *xmalloc(size_t size); |
118 |
lefcha |
1.19 |
void *xrealloc(void *ptr, size_t size); |
119 |
lefcha |
1.13 |
char *xstrdup(const char *s); |
120 |
|
|
|
121 |
lefcha |
1.16 |
/* misc.c */ |
122 |
|
|
char *strcasestr(const char *haystack, const char *needle); |
123 |
|
|
char *ultostr(unsigned long int num, int base); |
124 |
lefcha |
1.20 |
char *xstrncpy(char *dest, char *src, size_t size); |
125 |
lefcha |
1.16 |
|
126 |
lefcha |
1.9 |
/* request.c */ |
127 |
|
|
int test(void); |
128 |
lefcha |
1.16 |
int check_capabilities(void); |
129 |
lefcha |
1.9 |
int login(char *user, char *pass); |
130 |
|
|
int select_mailbox(char *mbox); |
131 |
lefcha |
1.11 |
int mailbox_status(char *mbox); |
132 |
lefcha |
1.9 |
int close_mailbox(void); |
133 |
|
|
int logout(void); |
134 |
|
|
|
135 |
lefcha |
1.16 |
int apply_filters(filter_t ** filters); |
136 |
lefcha |
1.19 |
int match_filter(filter_t * filter, char **mesgs); |
137 |
lefcha |
1.9 |
|
138 |
|
|
void empty_fifo(mask_t ** mfifo); |
139 |
lefcha |
1.11 |
void queue_fifo(mask_t ** mfifo, mask_t * mask); |
140 |
|
|
mask_t *dequeue_fifo(mask_t ** mfifo); |
141 |
lefcha |
1.9 |
|
142 |
lefcha |
1.11 |
char *generate_filter_and(mask_t * mask, unsigned int masknum, unsigned int masklen); |
143 |
|
|
char *generate_filter_or(mask_t * mask, unsigned int masknum, unsigned int masklen); |
144 |
lefcha |
1.9 |
|
145 |
lefcha |
1.11 |
int apply_action(char *mesgs, unsigned int *type, char *destmbox, char *args); |
146 |
lefcha |
1.9 |
int action_delete(char *mesgs, char *args); |
147 |
lefcha |
1.11 |
int action_copy(char *mesgs, char *destmbox, char *args); |
148 |
|
|
int action_move(char *mesgs, char *destmbox, char *args); |
149 |
|
|
int action_list(char *mesgs, char *args); |
150 |
lefcha |
1.9 |
|
151 |
|
|
unsigned int convert_messages(char *mesgs); |
152 |
|
|
|
153 |
lefcha |
1.11 |
/* response.c */ |
154 |
lefcha |
1.20 |
void receive_response(char *buf); |
155 |
lefcha |
1.16 |
int server_response(unsigned int tag); |
156 |
|
|
int greeting_response(void); |
157 |
|
|
int capability_response(unsigned int tag); |
158 |
|
|
int status_response(unsigned int tag); |
159 |
|
|
int select_response(unsigned int tag); |
160 |
lefcha |
1.19 |
int search_response(unsigned int tag, char **mesgs); |
161 |
lefcha |
1.16 |
int fetch_response(unsigned int tag); |
162 |
|
|
int copy_response(unsigned int tag); |
163 |
lefcha |
1.20 |
int analyze_response(char *buf); |
164 |
lefcha |
1.11 |
|
165 |
lefcha |
1.13 |
#endif /* IMAPFILTER_H */ |