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

Diff of /imapfilter/imapfilter.h

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

revision 1.37.2.12 by lefcha, Mon May 26 08:14:37 2003 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>
 #include <unistd.h>  
 #include <sys/stat.h>  
6  #include <sys/types.h>  #include <sys/types.h>
7  #include <dirent.h>  #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    
 /* Program's version number. */  
 #define IMAPFILTER_VERSION              "0.8.9"  
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_LOCKFILE                  4  #define ERROR_FILEOPEN          4
23  #define ERROR_CONFIG_PARSE              5  #define ERROR_LOCKFILE          5
24  #define ERROR_MEMORY_ALLOCATION         6  #define ERROR_PARSER            6
25  #define ERROR_SETUID                    7  #define ERROR_MEMALLOC          7
26  #define ERROR_TERMIO                    8  #define ERROR_SETUID            8
27  #define ERROR_NETWORK                   9  #define ERROR_TERMIO            9
28  #define ERROR_SSL                       10  #define ERROR_NETWORK           10
29  #define ERROR_PASSPHRASE                11  #define ERROR_SSL               11
30  #define ERROR_ENCRYPT                   12  #define ERROR_PASSPHRASE        12
31  #define ERROR_DECRYPT                   13  #define ERROR_ENCRYPT           13
32  #define ERROR_FORK                      14  #define ERROR_DECRYPT           14
33  #define ERROR_UNDEFINED                 15  #define ERROR_FORK              15
34    
35  /* Flags that control the program's execution options. */  /* SSL/TLS certificate status for the server. */
36  #define OPTION_DETAILS_QUIET            0x0001  #define CERT_OK                 0
37  #define OPTION_DETAILS_NORMAL           0x0002  #define CERT_NONE               1
38  #define OPTION_DETAILS_VERBOSE          0x0004  #define CERT_MISMATCH           2
39  #define OPTION_DETAILS_CLEAR            0xfff8  
40  #define OPTION_ERRORS                   0x0008  /* Action to be applied, concerning the SSL/TLS certificate. */
41  #define OPTION_EXPUNGE                  0x0010  #define CERT_ACTION_ACCEPT      0
42  #define OPTION_HEADERS                  0x0020  #define CERT_ACTION_REJECT      1
43  #define OPTION_NAMESPACE                0x0040  #define CERT_ACTION_CONTINUE    0
44  #define OPTION_SUBSCRIBE                0x0080  #define CERT_ACTION_ABORT       1
 #define OPTION_WARNING                  0x0100  
 #define OPTION_PASSWORD_EDITOR          0x0200  
 #define OPTION_DAEMON_MODE              0x0400  
45    
46  /* Other flags. */  /* Other flags. */
47  #define FLAG_TTY                        0x01  #define FLAG_DAEMON             0x01
48  #define FLAG_TTY_MODIFIED               0x02  #define FLAG_TTY                0x02
49  #define FLAG_BLANK_PASSWORD             0x04  #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_PREAMBLE                    0  #define LOG_PREAMBLE            0
66  #define LOG_ACCOUNT                     1  #define LOG_ACCOUNT             1
67  #define LOG_MAILBOX                     2  #define LOG_MBOX                2
68  #define LOG_FILTER                      3  #define LOG_FILTER              3
69  #define LOG_ACTION                      4  #define LOG_ACTION              4
70  #define LOG_DESTINATION_ACCOUNT         5  #define LOG_DEST_ACCOUNT        5
71  #define LOG_DESTINATION_MAILBOX         6  #define LOG_DEST_MBOX           6
72  #define LOG_HEADER                      7  #define LOG_HEADER              7
   
 /* Buffer size of the IMAP command. */  
 #define SMALL_CMD                       64  
 #define MEDIUM_CMD                      512  
 #define BIG_CMD                         32768  
   
 /* Store IMAP command type may replace,add or remove flags. */  
 #define STORE_FLAG_REPLACE              1  
 #define STORE_FLAG_ADD                  2  
 #define STORE_FLAG_REMOVE               3  
   
 /* Buffer size of server's response. */  
 #define RESPONSE_BUF                    4096  
 #define RESULT_BUF                      512  
73    
74  /* Response codes. */  /* Response codes. */
75  #define RESPONSE_NULLBODY               -2  #define RESPONSE_NULLBODY       -2
76  #define RESPONSE_NONE                   -1  #define RESPONSE_NONE           -1
77  #define RESPONSE_OK                     0  #define RESPONSE_OK             0
78  #define RESPONSE_NO                     1  #define RESPONSE_NO             1
79  #define RESPONSE_BAD                    2  #define RESPONSE_BAD            2
80  #define RESPONSE_BYE                    3  #define RESPONSE_BYE            3
81  #define RESPONSE_PREAUTH                4  #define RESPONSE_PREAUTH        4
82  #define RESPONSE_READONLY               5  #define RESPONSE_READONLY       5
83  #define RESPONSE_TRYCREATE              6  #define RESPONSE_TRYCREATE      6
84    
85  /* Size virtual buffer. */  /* Buffer size of server's response. */
86  #define VIRTUAL_BUF                     4096  #define RESPONSE_BUF            4096
87    #define RESULT_BUF              512
 /* Length of mailbox namespace prefix. */  
 #define NAMESPACE_PREFIX_LEN            64  
88    
89  /* Encryption and decryption buffers. */  /* Encryption and decryption buffers. */
90  #define ENCRYPTION_BUF                  1024  #define ENCRYPT_BUF             1024
91  #define DECRYPTION_BUF                  4096  #define DECRYPT_BUF             4096
92    
93  /* Buffer to save flags of the store IMAP command. */  /* Buffer to save flags of the store IMAP command. */
94  #define STORE_FLAGS_BUF                 64  #define STORE_FLAGS_BUF         64
95    
96  /* Maximum passwords the password editor can handle. */  /* Length of charset for IMAP SEARCH requests. */
97  #define EDITOR_PASSWORDS_MAX            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    
 /* Secure memory information. */  
 typedef struct secmem {  
     void *buf;                  /* Allocated memory buffer. */  
     size_t size;                /* Size of the buffer. */  
     struct secmem *prev, *next; /* Previous/next node of doubly linked list. */  
 } secmem_t;  
105    
106    #define min(A, B)               ((A) < (B) ? (A) : (B))
107    #define plural(A)               ((A) == 1 ? "" : "s")
108    
 /* Namespace of IMAP mailboxes. */  
 typedef struct namesp {  
     char prefix[NAMESPACE_PREFIX_LEN];  
     char delim;  
 } namesp_t;  
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  /*      file.c          */  /*      cert.c          */
155  int read_config(char *cfg);  #ifdef SSL_TLS
156  int parse_config(FILE * fd);  int get_cert(connection_t * conn);
157  void set_options(char *line, regmatch_t * match);  #endif
158    
159  int read_passwords(void);  /*      destroy.c       */
160  int parse_passwords(FILE * fd);  void destroy_all(void);
161  int store_passwords(account_t * accts[]);  void destroy_unneeded(void);
162    
163    /*      file.c          */
164  int create_homedir(void);  int create_homedir(void);
165  int exists_file(char *fname);  int exists_file(char *fname);
166  int exists_dir(char *fname);  int exists_dir(char *fname);
167  int create_file(char *fname, mode_t mode);  int create_file(char *fname, mode_t mode);
 #ifdef CHECK_PERMISSIONS  
168  int check_file_perms(char *fname, mode_t mode);  int check_file_perms(char *fname, mode_t mode);
169  int check_dir_perms(char *dname, mode_t mode);  int check_dir_perms(char *dname, mode_t mode);
 #endif  
   
 /*      imapfilter.c    */  
 void usage(void);  
 void version(void);  
170    
171  /*      imap.c          */  /*      imap.c          */
172  unsigned int send_command(int *sock, char *cmd);  int imap_noop(connection_t * conn);
173  #ifdef DEBUG  int imap_capability(connection_t * conn);
174  int imap_noop(int *sock);  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  #endif
179  int imap_capability(int *sock);  int imap_authenticate(connection_t * conn, char *auth, int cont);
180  int imap_namespace(int *sock);  int imap_login(connection_t * conn, char *user, char *pass);
181  int imap_logout(int *sock);  /* int imap_list(connection_t *conn, char *refer, char *mbox); */
182  int imap_login(int *sock, char *user, char *pass);  int imap_subscribe(connection_t * conn, char *mbox);
183  /* int imap_list(int *sock, char *refer, char *mbox); */  int imap_examine(connection_t * conn, char *mbox);
184  int imap_subscribe(int *sock, char *mbox);  int imap_select(connection_t * conn, char *mbox);
185  int imap_examine(int *sock, char *mbox);  int imap_status(connection_t * conn, char *mbox, char *items);
186  int imap_select(int *sock, char *mbox);  int imap_create(connection_t * conn, char *mbox);
187  int imap_status(int *sock, char *mbox, char *items);  int imap_search(connection_t * conn, char *charset, char *search);
188  int imap_create(int *sock, char *mbox);  int imap_fetch(connection_t * conn, char *mesg, char *items);
189  int imap_search(int *sock, char *search);  int imap_store(connection_t * conn, char *mesg, unsigned int mode, char *flags);
190  int imap_fetch(int *sock, char *mesg, char *items);  int imap_copy(connection_t * conn, char *mesg, char *mbox);
191  int imap_store(int *sock, char *mesg, unsigned int mode, char *flags);  int imap_append(connection_t * conn, char *mbox, char *flags, char *date, unsigned int size);
192  int imap_copy(int *sock, char *mesg, char *mbox);  int imap_close(connection_t * conn);
193  int imap_append(int *sock, char *mbox, unsigned int size);  int imap_expunge(connection_t * conn);
 int imap_close(int *sock);  
 int imap_expunge(int *sock);  
194    
195  /*      lock.c          */  /*      lock.c          */
196  void lockfile_create(void);  void lockfile_create(void);
197  void lockfile_check(void);  void lockfile_check(void);
 pid_t lockfile_pid(void);  
198  int lockfile_remove(void);  int lockfile_remove(void);
199  void kill_imapfilter(void);  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);
# Line 200  void *smalloc(size_t size); Line 224  void *smalloc(size_t size);
224  void *srealloc(void *ptr, size_t size);  void *srealloc(void *ptr, size_t size);
225  void sfree(void *ptr);  void sfree(void *ptr);
226  char *sstrdup(const char *s);  char *sstrdup(const char *s);
227  void secmem_append(secmem_t * node);  
 secmem_t *secmem_find(void *ptr);  
 void secmem_remove(secmem_t * node);  
228  void secmem_clear(void);  void secmem_clear(void);
229  #ifdef MEMORY_LOCK  
 void secmem_lock(void);  
 #endif  
230  void corefile_disable(void);  void corefile_disable(void);
231    
232  /*      misc.c          */  /*      misc.c          */
# Line 214  char *strcasestr(const char *haystack, c Line 234  char *strcasestr(const char *haystack, c
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        */  /*      passwd.c        */
243  void get_password(char *passwd, size_t pwlen);  void get_password(char *passwd, size_t pwlen);
244  #ifdef ENCRYPTED_PASSWORDS  #ifdef ENCRYPTED_PASSWORDS
245  int encrypt_passwords(FILE * fd, account_t * accts[]);  int encrypt_passwords(FILE * fd, account_t ** accts);
246  int decrypt_passwords(unsigned char **buf, FILE * fd);  int decrypt_passwords(unsigned char **buf, FILE * fd);
247  void password_editor(void);  void password_editor(void);
248  #endif  #endif
249    
250  /*      request.c       */  /*      request.c       */
251  int test(int *sock);  int test(connection_t * conn);
252  int check_capabilities(int *sock);  int check_capabilities(connection_t * conn);
253  int check_namespace(int *sock, namesp_t * nsp);  int check_namespace(connection_t * conn);
254  int login(int *sock, char *user, char *pass);  #ifdef SSL_TLS
255  int check_mailbox(int *sock, char *mbox, namesp_t * nsp);  int negotiate_tls(connection_t * conn);
256  int select_mailbox(int *sock, char *mbox, namesp_t * nsp);  #endif
257  int mailbox_status(int *sock, char *mbox, namesp_t * nsp);  int login(connection_t * conn, char *user, char *pass);
258  int close_mailbox(int *sock);  int check_mailbox(connection_t * conn, char *mbox);
259  int logout(int *sock);  int select_mailbox(connection_t * conn, char *mbox);
260    int mailbox_status(connection_t * conn, char *mbox);
261  int apply_filters(filter_t ** filters);  int close_mailbox(connection_t * conn);
262  int match_filter(filter_t * filter, char **mesgs);  int logout(connection_t * conn);
263    
264  void empty_fifo(mask_t ** mfifo);  /*      response.c      */
265  void queue_fifo(mask_t ** mfifo, mask_t * mask);  int response_generic(connection_t * conn, unsigned int tag);
266  mask_t *dequeue_fifo(mask_t ** mfifo);  int response_greeting(connection_t * conn);
267    int response_logout(connection_t * conn, unsigned int tag);
268  char *generate_filter_and(mask_t * mask, unsigned int masknum,  int response_capability(connection_t * conn, unsigned int tag);
269                             unsigned int masklen);  int response_authenticate(connection_t * conn, unsigned int tag, unsigned char **cont);
270  char *generate_filter_or(mask_t * mask, unsigned int masknum,  int response_namespace(connection_t * conn, unsigned int tag);
271                            unsigned int masklen);  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 apply_action(char *mesgs, unsigned int *type, account_t * raccount,  int response_select(connection_t * conn, unsigned int tag);
274                    char *destmbox, unsigned int *msgflags, char *args);  int response_search(connection_t * conn, unsigned int tag, char **mesgs);
275  int action_delete(char *mesgs, char *args);  int response_fetch(connection_t * conn, unsigned int tag, int reset, char *fetch);
276  int action_copy(char *mesgs, char *destmbox, char *args);  int response_fetchfast(connection_t * conn, char **flags, char **date, unsigned int *size, unsigned int tag);
277  int action_move(char *mesgs, char *destmbox, char *args);  int response_append(connection_t * conn, unsigned int tag);
278  int action_rcopy(char *mesgs, account_t * destacc, char *destmbox, char *args);  int response_copy(connection_t * conn, unsigned int tag);
 int action_rmove(char *mesgs, account_t * destacc, char *destmbox, char *args);  
 int action_flag(char *mesgs, unsigned int *type, unsigned int *msgflags, char *args);  
 int action_list(char *mesgs, char *args);  
   
 unsigned int count_messages(char *mesgs);  
 char *convert_messages(char *mesgs);  
   
   
 /*      response.c      */  
 void receive_response(int *sock, char *buf);  
 int server_response(int *sock, unsigned int tag);  
 void bye_response(char *buf);  
 int greeting_response(int *sock);  
 int logout_response(int *sock, unsigned int tag);  
 int capability_response(int *sock, unsigned int tag);  
 int namespace_response(int *sock, unsigned int tag, namesp_t * nsp);  
 int status_response(int *sock, unsigned int tag, char *mbox);  
 int select_response(int *sock, unsigned int tag);  
 int search_response(int *sock, unsigned int tag, char **mesgs);  
 int fetch_response(int *sock, unsigned int tag, int reset, char *fetch);  
 int fetchsize_response(int *sock, unsigned int *size, unsigned int tag);  
 int append_response(int *sock, unsigned int tag);  
 int copy_response(int *sock, unsigned int tag);  
 int analyze_response(char *buf);  
 void init_vbuf(void);  
 void reset_vbuf(void);  
 void check_vbuf(size_t n);  
279    
280  /*      socket.c        */  /*      socket.c        */
281  int init_connection(int *sock, char *serv, unsigned short int port,  int
282                       unsigned int protocol);   init_connection(connection_t * conn, char *serv, unsigned short int port, unsigned int protocol);
283  int ssl_init(int *sock, unsigned int protocol);  #ifdef SSL_TLS
284  int close_connection(int *sock);  int init_secure_connection(connection_t * conn, unsigned int protocol);
285  int socket_read(int *sock, char *buf);  #endif
286  int socket_write(int *sock, char *data);  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           */  /*      tty.c           */
291  int tty_store(void);  int tty_store(void);
292  int tty_disable_echo(void);  int tty_noecho(void);
293  int tty_restore(void);  int tty_restore(void);
294    
295    
296  #endif                          /* IMAPFILTER_H */  #endif                          /* IMAPFILTER_H */

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26