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

Diff of /imapfilter/imapfilter.h

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

revision 1.24.2.2 by lefcha, Mon Jun 17 12:01:00 2002 UTC revision 1.85 by lefcha, Sun Feb 15 15:31:54 2004 UTC
# Line 1  Line 1 
1  #ifndef IMAPFILTER_H  #ifndef IMAPFILTER_H
2  #define IMAPFILTER_H  #define IMAPFILTER_H
3    
4    
5  #include <stdio.h>  #include <stdio.h>
6    #include <sys/types.h>
7    #include <limits.h>
8    
9    #include "config.h"
10    #include "account.h"
11    #include "filter.h"
12    
13  #ifndef DATA_H  #ifdef SSL_TLS
14  #include "data.h"  #include <openssl/ssl.h>
15  #endif  #endif
16    
17    
18  /* Error codes returned by functions. */  /* Error codes returned by functions. */
19  #define ERROR_SIGNAL                    1  #define ERROR_UNDEFINED         1
20  #define ERROR_TRIVIAL                   2  #define ERROR_TRIVIAL           2
21  #define ERROR_FILE_OPEN                 3  #define ERROR_SIGNAL            3
22  #define ERROR_CONFIG_PARSE              4  #define ERROR_FILEOPEN          4
23  #define ERROR_MEMORY_ALLOCATION         5  #define ERROR_LOCKFILE          5
24  #define ERROR_NETWORK                   6  #define ERROR_PARSER            6
25  #define ERROR_SSL                       7  #define ERROR_MEMALLOC          7
26  #define ERROR_UNDEFINED                 8  #define ERROR_SETUID            8
27    #define ERROR_TERMIO            9
28  /* Flags that control the program's options. */  #define ERROR_NETWORK           10
29  #define OPTION_DETAILS_QUIET            0x01  #define ERROR_SSL               11
30  #define OPTION_DETAILS_NORMAL           0x02  #define ERROR_PASSPHRASE        12
31  #define OPTION_DETAILS_VERBOSE          0x04  #define ERROR_ENCRYPT           13
32  #define OPTION_DETAILS_CLEAR            0xf8  #define ERROR_DECRYPT           14
33  #define OPTION_HEADERS                  0x08  #define ERROR_FORK              15
34  #define OPTION_NAMESPACE                0x10  
35    /* SSL/TLS certificate status for the server. */
36    #define CERT_OK                 0
37    #define CERT_NONE               1
38    #define CERT_MISMATCH           2
39    
40    /* Action to be applied, concerning the SSL/TLS certificate. */
41    #define CERT_ACTION_ACCEPT      0
42    #define CERT_ACTION_REJECT      1
43    #define CERT_ACTION_CONTINUE    0
44    #define CERT_ACTION_ABORT       1
45    
46    /* Other flags. */
47    #define FLAG_DAEMON             0x01
48    #define FLAG_TTY                0x02
49    #define FLAG_TTYMOD             0x04
50    #define FLAG_BLANKPASS          0x08
51    #define FLAG_SIGUSR1            0x10
52    
53    /* IMAP protocol supported by the server. */
54    #define PROTOCOL_NONE           0
55    #define PROTOCOL_IMAP4REV1      1
56    #define PROTOCOL_IMAP4          2
57    
58  /* Capabilities of mail server. */  /* Capabilities of mail server. */
59  #define CAPABILITY_NONE                 0x00  #define CAPABILITY_NONE         0x00
60  #define CAPABILITY_NAMESPACE            0x01  #define CAPABILITY_NAMESPACE    0x01
61    #define CAPABILITY_CRAMMD5      0x02
62    #define CAPABILITY_STARTTLS     0x04
63    
64  /* Flags for logger. */  /* Flags for logger. */
65  #define LOG_WRITE                       0  #define LOG_PREAMBLE            0
66  #define LOG_SERVER                      1  #define LOG_ACCOUNT             1
67  #define LOG_USERNAME                    2  #define LOG_MBOX                2
68  #define LOG_MAILBOX                     3  #define LOG_FILTER              3
69  #define LOG_FILTER                      4  #define LOG_ACTION              4
70  #define LOG_ACTION                      5  #define LOG_DEST_ACCOUNT        5
71  #define LOG_DESTINATION_MAILBOX         6  #define LOG_DEST_MBOX           6
72    #define LOG_HEADER              7
73  /* Buffer size of the IMAP command. */  
74  #define SMALL_CMD                       64  /* Response codes. */
75  #define MEDIUM_CMD                      256  #define RESPONSE_NULLBODY       -2
76  #define BIG_CMD                         8192  #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. */  /* Buffer size of server's response. */
86  #define RESPONSE_BUF                    (4096 + 1)  #define RESPONSE_BUF            4096
87  #define RESULT_BUF                      512  #define RESULT_BUF              512
88    
89  /* Response codes. */  /* Encryption and decryption buffers. */
90  #define RESPONSE_BAD                    -1  #define ENCRYPT_BUF             1024
91  #define RESPONSE_OK                     0  #define DECRYPT_BUF             4096
 #define RESPONSE_NO                     1  
 #define RESPONSE_BYE                    2  
 #define RESPONSE_PREAUTH                3  
 #define RESPONSE_READONLY               4  
 #define RESPONSE_TRYCREATE              5  
92    
93  /* Buffer size of message's headers. */  /* Buffer to save flags of the store IMAP command. */
94  #define HEADERS_BUF                     16384  #define STORE_FLAGS_BUF         64
95    
96  /* Length of mailbox namespace prefix. */  /* Length of charset for IMAP SEARCH requests. */
97  #define NAMESPACE_PREFIX_LEN            64  #define CHARSET_LEN             64
98    
99    /* String lengths of master password and encrypted passwords. */
100    #define PASSPHRASE_LEN          256
101    
102  #define min(A, B)                       ((A) < (B) ? (A) : (B))  /* Length of mailbox namespace prefix. */
103  #define plural(A)                       ((A) == 1 ? "" : "s")  #define NAMESPACE_PREFIX_LEN    64
104    
105    
106  /* Namespace of mailboxes residing on mail server. */  #define min(A, B)               ((A) < (B) ? (A) : (B))
107  struct namespace_t {  #define plural(A)               ((A) == 1 ? "" : "s")
     char prefix[NAMESPACE_PREFIX_LEN];  
     char delim;  
 };  
108    
109    
110  /*      file.c          */  /* Program's options. */
111  int read_config(char *cfg);  typedef struct options {
112  #ifdef CHECK_PERMISSIONS          int debug;              /* Debugging level (1..2). */
113  int check_permissions(char *cfg);          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  #endif
 int parse_config(FILE * fp);  
 void set_options(char *line, regmatch_t * match);  
153    
154  /*      imapfilter.c    */  /*      cert.c          */
155  void usage(void);  #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          */  /*      imap.c          */
172  unsigned int send_command(char *cmd);  int imap_noop(connection_t * conn);
173  #ifdef DEBUG  int imap_capability(connection_t * conn);
174  int imap_noop(void);  int imap_namespace(connection_t * conn);
175  #endif  int imap_logout(connection_t * conn);
176  int imap_capability(void);  #ifdef SSL_TLS
177  int imap_namespace(void);  int imap_starttls(connection_t * conn);
178  int imap_logout(void);  #endif
179  int imap_login(char *user, char *pass);  int imap_authenticate(connection_t * conn, char *auth, int cont);
180  /* int imap_examine(char *mbox); */  int imap_login(connection_t * conn, char *user, char *pass);
181  int imap_select(char *mbox);  /* int imap_list(connection_t *conn, char *refer, char *mbox); */
182  int imap_status(char *mbox, char *items);  int imap_subscribe(connection_t * conn, char *mbox);
183  int imap_create(char *mbox);  int imap_examine(connection_t * conn, char *mbox);
184  int imap_search(char *search);  int imap_select(connection_t * conn, char *mbox);
185  int imap_fetch(char *mesg, char *headers, int peek);  int imap_status(connection_t * conn, char *mbox, char *items);
186  int imap_store(char *mesg, char *flags);  int imap_create(connection_t * conn, char *mbox);
187  int imap_copy(char *mesg, char *mbox);  int imap_search(connection_t * conn, char *charset, char *search);
188  int imap_close(void);  int imap_fetch(connection_t * conn, char *mesg, char *items);
189  /* int imap_expunge(void); */  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           */  /*      log.c           */
202  void info(const char *info,...);  void info(const char *info,...);
203  void verbose(const char *info,...);  void verbose(const char *info,...);
204    void debug(const char *debug,...);
205  void error(const char *errmsg,...);  void error(const char *errmsg,...);
206  void fatal(unsigned int errnum, const char *fatal,...);  void fatal(unsigned int errnum, const char *fatal,...);
207  void catch_signals(void);  void catch_signals(void);
208  void signal_handler(int sig);  int debug_start(void);
209  int open_logfile(void);  int debug_stop(void);
210  int create_logfile(void);  int log_start(void);
211  int close_logfile(void);  int log_stop(void);
212  void log_info(int flag, void *ptr);  void log_info(int flag, void *ptr);
213  char *get_time(void);  
214    /*      match.c         */
215    int apply_filters(char *mbox, filter_t ** filters);
216    
217  /*      memory.c        */  /*      memory.c        */
218  void *xmalloc(size_t size);  void *xmalloc(size_t size);
219  void *xrealloc(void *ptr, size_t size);  void *xrealloc(void *ptr, size_t size);
220    void xfree(void *ptr);
221  char *xstrdup(const char *s);  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          */  /*      misc.c          */
233  char *strcasestr(const char *haystack, const char *needle);  char *strcasestr(const char *haystack, const char *needle);
234  char *ultostr(unsigned long int num, int base);  char *ultostr(unsigned long int num, int base);
235  char *xstrncpy(char *dest, const char *src, size_t size);  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       */  /*      request.c       */
251  int test(void);  int test(connection_t * conn);
252  int check_capabilities(void);  int check_capabilities(connection_t * conn);
253  int check_namespace(void);  int check_namespace(connection_t * conn);
254  int login(char *user, char *pass);  #ifdef SSL_TLS
255  int select_mailbox(char *mbox);  int negotiate_tls(connection_t * conn);
256  int mailbox_status(char *mbox);  #endif
257  int close_mailbox(void);  int login(connection_t * conn, char *user, char *pass);
258  int logout(void);  int check_mailbox(connection_t * conn, char *mbox);
259    int select_mailbox(connection_t * conn, char *mbox);
260  int apply_filters(filter_t ** filters);  int mailbox_status(connection_t * conn, char *mbox);
261  int match_filter(filter_t * filter, char **mesgs);  int close_mailbox(connection_t * conn);
262    int logout(connection_t * conn);
263  void empty_fifo(mask_t ** mfifo);  
264  void queue_fifo(mask_t ** mfifo, mask_t * mask);  /*      response.c      */
265  mask_t *dequeue_fifo(mask_t ** mfifo);  int response_generic(connection_t * conn, unsigned int tag);
266    int response_greeting(connection_t * conn);
267  char *generate_filter_and(mask_t * mask, unsigned int masknum, unsigned int masklen);  int response_logout(connection_t * conn, unsigned int tag);
268  char *generate_filter_or(mask_t * mask, unsigned int masknum, unsigned int masklen);  int response_capability(connection_t * conn, unsigned int tag);
269    int response_authenticate(connection_t * conn, unsigned int tag, unsigned char **cont);
270  int apply_action(char *mesgs, unsigned int *type, char *destmbox, char *args);  int response_namespace(connection_t * conn, unsigned int tag);
271  int action_delete(char *mesgs, char *args);  int response_status(connection_t * conn, unsigned int tag, char *mbox);
272  int action_copy(char *mesgs, char *destmbox, char *args);  int response_examine(connection_t * conn, unsigned int tag, char *mbox);
273  int action_move(char *mesgs, char *destmbox, char *args);  int response_select(connection_t * conn, unsigned int tag);
274  int action_list(char *mesgs, char *args);  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  unsigned int convert_messages(char *mesgs);  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  /*      response.c      */  int response_copy(connection_t * conn, unsigned int tag);
 void receive_response(char *buf);  
 int server_response(unsigned int tag);  
 int greeting_response(void);  
 int capability_response(unsigned int tag);  
 int namespace_response(unsigned int tag, struct namespace_t * namesp);  
 int status_response(unsigned int tag, char *mbox);  
 int select_response(unsigned int tag);  
 int search_response(unsigned int tag, char **mesgs);  
 int fetch_response(unsigned int tag);  
 int copy_response(unsigned int tag);  
 int analyze_response(char *buf);  
 void init_vbuf(void);  
 void reset_vbuf(void);  
 void check_vbuf(size_t s);  
279    
280  /*      socket.c        */  /*      socket.c        */
281  #ifndef SSL_TLS  int
282  int init_connection(char *serv, unsigned short int port);   init_connection(connection_t * conn, char *serv, unsigned short int port, unsigned int protocol);
283  #else  #ifdef SSL_TLS
284  int init_connection(char *serv, unsigned short int port,  int init_secure_connection(connection_t * conn, unsigned int protocol);
285                       unsigned int protocol);  #endif
286  #endif  int close_connection(connection_t * conn);
287  int ssl_init(unsigned int protocol);  int socket_read(connection_t * conn, char *buf);
288  int close_connection(void);  int socket_write(connection_t * conn, char *data);
289  int socket_read(char *buf);  
290  int socket_write(char *data);  /*      tty.c           */
291    int tty_store(void);
292    int tty_noecho(void);
293    int tty_restore(void);
294    
295    
296  #endif                          /* IMAPFILTER_H */  #endif                          /* IMAPFILTER_H */

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26