/[imapfilter]/imapfilter/imapfilter.h
ViewVC logotype

Diff of /imapfilter/imapfilter.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by lefcha, Sat Aug 11 15:52:52 2001 UTC revision 1.85 by lefcha, Sun Feb 15 15:31:54 2004 UTC
# Line 1  Line 1 
1  #include <limits.h>  #ifndef IMAPFILTER_H
2    #define IMAPFILTER_H
3    
4    
5    #include <stdio.h>
6    #include <sys/types.h>
7    #include <limits.h>
8    
9  /* Return values of functions. */  #include "config.h"
10  #define FAILURE                         1  #include "account.h"
11  #define SUCCESS                         0  #include "filter.h"
12    
13  /* Flags that control the program options that have been selected. */  #ifdef SSL_TLS
14  #define OPTION_TEST_MODE                0x00000001  #include <openssl/ssl.h>
15  #define OPTION_DETAILS_QUITE            0x00000002  #endif
16  #define OPTION_DETAILS_NORMAL           0x00000004  
17  #define OPTION_DETAILS_VERBOSE          0x00000008  
18  #define OPTION_LOGGING_DISABLED         0x00000010  /* Error codes returned by functions. */
19  #define OPTION_DETAILS_CLEAR            0xFFFFFFF1  #define ERROR_UNDEFINED         1
20    #define ERROR_TRIVIAL           2
21  /* Lengths of strings to save account settings. */  #define ERROR_SIGNAL            3
22  #define SERVER_MAX                      128  #define ERROR_FILEOPEN          4
23  #define USERNAME_MAX                    64  #define ERROR_LOCKFILE          5
24  #define PASSWORD_MAX                    32  #define ERROR_PARSER            6
25    #define ERROR_MEMALLOC          7
26  /* Lengths of strings that comprise the HEADER of a filter. */  #define ERROR_SETUID            8
27  #define FIELD_NAME_MAX                  64  #define ERROR_TERMIO            9
28  #define FIELD_BODY_MAX                  512  #define ERROR_NETWORK           10
29    #define ERROR_SSL               11
30  /* Size of buffer that holds the results of the searching and matching  #define ERROR_PASSPHRASE        12
31     of filters. */  #define ERROR_ENCRYPT           13
32  #define SEARCH_RESULTS_MAX              512  #define ERROR_DECRYPT           14
33    #define ERROR_FORK              15
34  /* Every how many filter entries found in the configuration file will  
35     be space in memory will be allocated. */  /* SSL/TLS certificate status for the server. */
36  #define FILTER_ENTRIES_MAX              8  #define CERT_OK                 0
37    #define CERT_NONE               1
38  #define min(A, B)                       ((A) < (B) ? (A) : (B))  #define CERT_MISMATCH           2
39    
40    /* Action to be applied, concerning the SSL/TLS certificate. */
41  /* Account settings. */  #define CERT_ACTION_ACCEPT      0
42  typedef struct {  #define CERT_ACTION_REJECT      1
43      char server[SERVER_MAX];    /* Hostname of mail server. */  #define CERT_ACTION_CONTINUE    0
44      unsigned short int port;    /* Port to connect. */  #define CERT_ACTION_ABORT       1
45      char username[USERNAME_MAX];  
46      char password[PASSWORD_MAX];  /* Other flags. */
47      char logfile[PATH_MAX];  #define FLAG_DAEMON             0x01
48  } account_data;  #define FLAG_TTY                0x02
49    #define FLAG_TTYMOD             0x04
50  /* A header filter entry. */  #define FLAG_BLANKPASS          0x08
51  typedef struct {  #define FLAG_SIGUSR1            0x10
52      char name[FIELD_NAME_MAX];  /* Header field name. */  
53      int explicit;               /* If field name one of FROM, TO, CC, BCC,  /* IMAP protocol supported by the server. */
54                                     SUBJECT then zero. */  #define PROTOCOL_NONE           0
55      char body[FIELD_BODY_MAX];  /* Header field body. */  #define PROTOCOL_IMAP4REV1      1
56  } filter_entry;  #define PROTOCOL_IMAP4          2
57    
58    /* Capabilities of mail server. */
59    #define CAPABILITY_NONE         0x00
60    #define CAPABILITY_NAMESPACE    0x01
61    #define CAPABILITY_CRAMMD5      0x02
62    #define CAPABILITY_STARTTLS     0x04
63    
64    /* Flags for logger. */
65    #define LOG_PREAMBLE            0
66    #define LOG_ACCOUNT             1
67    #define LOG_MBOX                2
68    #define LOG_FILTER              3
69    #define LOG_ACTION              4
70    #define LOG_DEST_ACCOUNT        5
71    #define LOG_DEST_MBOX           6
72    #define LOG_HEADER              7
73    
74    /* Response codes. */
75    #define RESPONSE_NULLBODY       -2
76    #define RESPONSE_NONE           -1
77    #define RESPONSE_OK             0
78    #define RESPONSE_NO             1
79    #define RESPONSE_BAD            2
80    #define RESPONSE_BYE            3
81    #define RESPONSE_PREAUTH        4
82    #define RESPONSE_READONLY       5
83    #define RESPONSE_TRYCREATE      6
84    
85    /* Buffer size of server's response. */
86    #define RESPONSE_BUF            4096
87    #define RESULT_BUF              512
88    
89    /* Encryption and decryption buffers. */
90    #define ENCRYPT_BUF             1024
91    #define DECRYPT_BUF             4096
92    
93    /* Buffer to save flags of the store IMAP command. */
94    #define STORE_FLAGS_BUF         64
95    
96    /* Length of charset for IMAP SEARCH requests. */
97    #define CHARSET_LEN             64
98    
99    /* String lengths of master password and encrypted passwords. */
100    #define PASSPHRASE_LEN          256
101    
102    /* Length of mailbox namespace prefix. */
103    #define NAMESPACE_PREFIX_LEN    64
104    
105    
106    #define min(A, B)               ((A) < (B) ? (A) : (B))
107    #define plural(A)               ((A) == 1 ? "" : "s")
108    
109    
110    /* Program's options. */
111    typedef struct options {
112            int debug;              /* Debugging level (1..2). */
113            int verbosity;          /* Verbosity level (-2..2). */
114            int timeout;            /* Server non-response timeout in seconds. */
115            int daemon;             /* Daemon mode interval. */
116            int headers;            /* Print messages headers to stdout. */
117            int errors;             /* Errors appended to logfile. */
118            int namespace;          /* Apply mailbox namespace automatically. */
119            int expunge;            /* Expunge messages after they are marked
120                                     * deleted. */
121            int subscribe;          /* Subscribe newly created mailboxes. */
122            int peek;               /* Do not mark messages seen when their
123                                     * headers are received. */
124            int passwd_editor;      /* Enter interactive password editor. */
125            char charset[CHARSET_LEN];      /* Search criteria character set. */
126            char logfile[PATH_MAX]; /* Log file for filtering information. */
127            int force_protocol;     /* Protocol version to assume. */
128    } options_t;
129    
130    /* IMAP connection. */
131    typedef struct connection {
132            int sock;               /* Socket. */
133    #ifdef SSL_TLS
134            SSL *ssl;               /* SSL socket. */
135    #endif
136            unsigned int proto;     /* IMAP protocol.  Currently IMAP4rev1 and
137                                     * IMAP4 are supported. */
138            unsigned int caps;      /* Capabilities of the mail server. */
139            struct {                /* Namespace of the mail server's mailboxes. */
140                    char prefix[NAMESPACE_PREFIX_LEN];      /* Namespace prefix. */
141                    char delim;     /* Namespace delimiter. */
142            } ns;
143    } connection_t;
144    
145    
146    /*      action.c        */
147    int apply_action(char *mbox, char *mesgs, unsigned int *type, account_t * destacct, char *destmbox, unsigned int *msgflags, char *args);
148    
149    /*      auth.c          */
150    #ifdef CRAM_MD5
151    int auth_cram_md5(connection_t * conn, char *user, char *pass);
152    #endif
153    
154    /*      cert.c          */
155    #ifdef SSL_TLS
156    int get_cert(connection_t * conn);
157    #endif
158    
159    /*      destroy.c       */
160    void destroy_all(void);
161    void destroy_unneeded(void);
162    
163    /*      file.c          */
164    int create_homedir(void);
165    int exists_file(char *fname);
166    int exists_dir(char *fname);
167    int create_file(char *fname, mode_t mode);
168    int check_file_perms(char *fname, mode_t mode);
169    int check_dir_perms(char *dname, mode_t mode);
170    
171    /*      imap.c          */
172    int imap_noop(connection_t * conn);
173    int imap_capability(connection_t * conn);
174    int imap_namespace(connection_t * conn);
175    int imap_logout(connection_t * conn);
176    #ifdef SSL_TLS
177    int imap_starttls(connection_t * conn);
178    #endif
179    int imap_authenticate(connection_t * conn, char *auth, int cont);
180    int imap_login(connection_t * conn, char *user, char *pass);
181    /* int imap_list(connection_t *conn, char *refer, char *mbox); */
182    int imap_subscribe(connection_t * conn, char *mbox);
183    int imap_examine(connection_t * conn, char *mbox);
184    int imap_select(connection_t * conn, char *mbox);
185    int imap_status(connection_t * conn, char *mbox, char *items);
186    int imap_create(connection_t * conn, char *mbox);
187    int imap_search(connection_t * conn, char *charset, char *search);
188    int imap_fetch(connection_t * conn, char *mesg, char *items);
189    int imap_store(connection_t * conn, char *mesg, unsigned int mode, char *flags);
190    int imap_copy(connection_t * conn, char *mesg, char *mbox);
191    int imap_append(connection_t * conn, char *mbox, char *flags, char *date, unsigned int size);
192    int imap_close(connection_t * conn);
193    int imap_expunge(connection_t * conn);
194    
195    /*      lock.c          */
196    void lockfile_create(void);
197    void lockfile_check(void);
198    int lockfile_remove(void);
199    void kill_imapfilter(void);
200    
201    /*      log.c           */
202    void info(const char *info,...);
203    void verbose(const char *info,...);
204    void debug(const char *debug,...);
205    void error(const char *errmsg,...);
206    void fatal(unsigned int errnum, const char *fatal,...);
207    void catch_signals(void);
208    int debug_start(void);
209    int debug_stop(void);
210    int log_start(void);
211    int log_stop(void);
212    void log_info(int flag, void *ptr);
213    
214    /*      match.c         */
215    int apply_filters(char *mbox, filter_t ** filters);
216    
217    /*      memory.c        */
218    void *xmalloc(size_t size);
219    void *xrealloc(void *ptr, size_t size);
220    void xfree(void *ptr);
221    char *xstrdup(const char *s);
222    
223    void *smalloc(size_t size);
224    void *srealloc(void *ptr, size_t size);
225    void sfree(void *ptr);
226    char *sstrdup(const char *s);
227    
228    void secmem_clear(void);
229    
230    void corefile_disable(void);
231    
232    /*      misc.c          */
233    char *strcasestr(const char *haystack, const char *needle);
234    char *ultostr(unsigned long int num, int base);
235    char *xstrncpy(char *dest, const char *src, size_t size);
236    
237    /*      parse.c         */
238    int read_config(char *cfg);
239    void reread_config(char *cfg);
240    int read_passwords(void);
241    
242    /*      passwd.c        */
243    void get_password(char *passwd, size_t pwlen);
244    #ifdef ENCRYPTED_PASSWORDS
245    int encrypt_passwords(FILE * fd, account_t ** accts);
246    int decrypt_passwords(unsigned char **buf, FILE * fd);
247    void password_editor(void);
248    #endif
249    
250    /*      request.c       */
251    int test(connection_t * conn);
252    int check_capabilities(connection_t * conn);
253    int check_namespace(connection_t * conn);
254    #ifdef SSL_TLS
255    int negotiate_tls(connection_t * conn);
256    #endif
257    int login(connection_t * conn, char *user, char *pass);
258    int check_mailbox(connection_t * conn, char *mbox);
259    int select_mailbox(connection_t * conn, char *mbox);
260    int mailbox_status(connection_t * conn, char *mbox);
261    int close_mailbox(connection_t * conn);
262    int logout(connection_t * conn);
263    
264    /*      response.c      */
265    int response_generic(connection_t * conn, unsigned int tag);
266    int response_greeting(connection_t * conn);
267    int response_logout(connection_t * conn, unsigned int tag);
268    int response_capability(connection_t * conn, unsigned int tag);
269    int response_authenticate(connection_t * conn, unsigned int tag, unsigned char **cont);
270    int response_namespace(connection_t * conn, unsigned int tag);
271    int response_status(connection_t * conn, unsigned int tag, char *mbox);
272    int response_examine(connection_t * conn, unsigned int tag, char *mbox);
273    int response_select(connection_t * conn, unsigned int tag);
274    int response_search(connection_t * conn, unsigned int tag, char **mesgs);
275    int response_fetch(connection_t * conn, unsigned int tag, int reset, char *fetch);
276    int response_fetchfast(connection_t * conn, char **flags, char **date, unsigned int *size, unsigned int tag);
277    int response_append(connection_t * conn, unsigned int tag);
278    int response_copy(connection_t * conn, unsigned int tag);
279    
280    /*      socket.c        */
281    int
282     init_connection(connection_t * conn, char *serv, unsigned short int port, unsigned int protocol);
283    #ifdef SSL_TLS
284    int init_secure_connection(connection_t * conn, unsigned int protocol);
285    #endif
286    int close_connection(connection_t * conn);
287    int socket_read(connection_t * conn, char *buf);
288    int socket_write(connection_t * conn, char *data);
289    
290    /*      tty.c           */
291    int tty_store(void);
292    int tty_noecho(void);
293    int tty_restore(void);
294    
295    
296  void apply_filters(void);  #endif                          /* IMAPFILTER_H */

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.85

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26