1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
#ifndef IMAPFILTER_H
#define IMAPFILTER_H
#include <stdio.h>
#include <sys/types.h>
#include <limits.h>
#include <lua.h>
#include <lualib.h>
#include "session.h"
#ifndef NO_SSLTLS
#include <openssl/ssl.h>
#endif
/* Fatal error exit codes. */
#define ERROR_SIGNAL 1
#define ERROR_CONFIG 2
#define ERROR_MEMALLOC 3
#define ERROR_PATHNAME 4
/* IMAP protocol supported by the server. */
#define PROTOCOL_NONE 0
#define PROTOCOL_IMAP4REV1 1
#define PROTOCOL_IMAP4 2
/* Capabilities of mail server. */
#define CAPABILITY_NONE 0x00
#define CAPABILITY_NAMESPACE 0x01
#define CAPABILITY_CRAMMD5 0x02
#define CAPABILITY_STARTTLS 0x04
#define CAPABILITY_CHILDREN 0x08
/* Status responses and response codes. */
#define STATUS_RESPONSE_NONE 0
#define STATUS_RESPONSE_OK 1
#define STATUS_RESPONSE_NO 2
#define STATUS_RESPONSE_BAD 3
#define STATUS_RESPONSE_BYE 4
#define STATUS_RESPONSE_PREAUTH 5
#define STATUS_RESPONSE_READONLY 6
#define STATUS_RESPONSE_TRYCREATE 7
#define STATUS_RESPONSE_CONTINUE 8
/* Initial buffer size for input, output and namespace buffers. */
#define INPUT_BUF 4096
#define OUTPUT_BUF 1024
#define NAMESPACE_BUF 128
/* Maximum length, in bytes, of a utility's input line. */
#ifndef LINE_MAX
#define LINE_MAX 2048
#endif
/* Program's options. */
typedef struct options {
int debug; /* Debugging level (0..2). */
int verbose; /* Verbose mode. */
int interactive; /* Act as an interpreter. */
char *log; /* Log file for error messages. */
char *config; /* Configuration file. */
char *oneline; /* One line of program/configuration. */
} options;
/* Environment variables. */
typedef struct environment {
char *home; /* User's home directory. */
long pathmax; /* Maximum pathname. */
} environment;
/* auth.c */
#ifndef NO_CRAMMD5
int auth_cram_md5(session *ssn, const char *user, const char *pass);
#endif
/* cert.c */
#ifndef NO_SSLTLS
int get_cert(session *ssn);
#endif
/* core.c */
LUALIB_API int luaopen_ifcore(lua_State *lua);
/* file.c */
int create_homedir(void);
int exists_file(char *fname);
int exists_dir(char *fname);
int create_file(char *fname, mode_t mode);
int get_pathmax(void);
/* imap.c */
int imap_continuation(session *ssn, const char *cont, size_t len);
int imap_capability(session *ssn);
int imap_noop(session *ssn);
int imap_logout(session *ssn);
#ifndef NO_SSLTLS
int imap_starttls(session *ssn);
#endif
int imap_authenticate(session *ssn, const char *auth);
int imap_login(session *ssn, const char *user, const char *pass);
int imap_select(session *ssn, const char *mbox);
int imap_examine(session *ssn, const char *mbox);
int imap_create(session *ssn, const char *mbox);
int imap_delete(session *ssn, const char *mbox);
int imap_rename(session *ssn, const char *oldmbox, const char *newmbox);
int imap_subscribe(session *ssn, const char *mbox);
int imap_unsubscribe(session *ssn, const char *mbox);
int imap_list(session *ssn, const char *refer, const char *name);
int imap_lsub(session *ssn, const char *refer, const char *name);
int imap_status(session *ssn, const char *mbox, const char *items);
int imap_append(session *ssn, const char *mbox, const char *flags,
const char *date, unsigned int size);
int imap_check(session *ssn);
int imap_close(session *ssn);
int imap_expunge(session *ssn);
int imap_search(session *ssn, const char *charset, const char *criteria);
int imap_fetch(session *ssn, const char *mesg, const char *items);
int imap_store(session *ssn, const char *mesg, const char *mode,
const char *flags);
int imap_copy(session *ssn, const char *mesg, const char *mbox);
int imap_namespace(session *ssn);
/* log.c */
void verbose(const char *info,...);
void debug(const char *debug,...);
void debugc(char c);
void error(const char *errmsg,...);
void fatal(unsigned int errnum, const char *fatal,...);
int open_debug(void);
int close_debug(void);
int open_log(void);
int close_log(void);
/* lua.c */
void start_lua(void);
void stop_lua(void);
int get_option_boolean(const char *opt);
lua_Number get_option_number(const char *opt);
const char *get_option_string(const char *opt);
int get_table_type(const char *key);
lua_Number get_table_number(const char *key);
const char *get_table_string(const char *key);
int set_table_nil(const char *key);
int set_table_boolean(const char *key, int value);
int set_table_number(const char *key, lua_Number value);
int set_table_string(const char *key, const char *value);
/* memory.c */
void *xmalloc(size_t size);
void *xrealloc(void *ptr, size_t size);
void xfree(void *ptr);
char *xstrdup(const char *str);
char *xstrndup(const char *str, size_t len);
/* misc.c */
const char *xstrcasestr(const char *haystack, const char *needle);
char *xstrncpy(char *dest, const char *src, size_t size);
/* namespace.c */
const char *apply_namespace(const char *mbox, char *prefix, char delim);
const char *reverse_namespace(const char *mbox, char *prefix, char delim);
/* pcre.c */
LUALIB_API int luaopen_ifre(lua_State *lua);
/* request.c */
int request_noop(const char *server, const char *port, const char *user);
int request_login(const char *server, const char *port, const char *ssl,
const char *user, const char *pass);
int request_logout(const char *server, const char *port, const char *user);
int request_status(const char *server, const char *port, const char *user,
const char *mbox, unsigned int *exist, unsigned int *recent,
unsigned int *unseen);
int request_select(const char *server, const char *port, const char *user,
const char *mbox);
int request_close(const char *server, const char *port, const char *user);
int request_expunge(const char *server, const char *port, const char *user);
int request_list(const char *server, const char *port, const char *user,
const char *refer, const char *name, char **mboxs, char **folders);
int request_lsub(const char *server, const char *port, const char *user,
const char *refer, const char *name, char **mboxs, char **folders);
int request_search(const char *server, const char *port, const char *user,
const char *criteria, const char *charset, char **mesgs);
int request_fetchfast(const char *server, const char *port, const char *user,
const char *mesg, char **flags, char **date, char **size);
int request_fetchflags(const char *server, const char *port, const char *user,
const char *mesg, char **flags);
int request_fetchdate(const char *server, const char *port, const char *user,
const char *mesg, char **date);
int request_fetchsize(const char *server, const char *port, const char *user,
const char *mesg, char **size);
int request_fetchheader(const char *server, const char *port, const char *user,
const char *mesg, char **header, size_t *len);
int request_fetchtext(const char *server, const char *port, const char *user,
const char *mesg, char **text, size_t *len);
int request_fetchfields(const char *server, const char *port, const char *user,
const char *mesg, const char *headerfields, char **fields, size_t *len);
int request_store(const char *server, const char *port, const char *user,
const char *mesg, const char *mode, const char *flags);
int request_copy(const char *server, const char *port, const char *user,
const char *mesg, const char *mbox);
int request_append(const char *server, const char *port, const char *user,
const char *mbox, const char *mesg, size_t mesglen, const char *flags,
const char *date);
int request_create(const char *server, const char *port, const char *user,
const char *mbox);
int request_delete(const char *server, const char *port, const char *user,
const char *mbox);
int request_rename(const char *server, const char *port, const char *user,
const char *oldmbox, const char *newmbox);
int request_subscribe(const char *server, const char *port, const char *user,
const char *mbox);
int request_unsubscribe(const char *server, const char *port, const char *user,
const char *mbox);
/* response.c */
int response_generic(session *ssn, int tag);
int response_greeting(session *ssn);
int response_capability(session *ssn, int tag);
int response_authenticate(session *ssn, int tag, unsigned char **cont);
int response_namespace(session *ssn, int tag);
int response_status(session *ssn, int tag, unsigned int *exist,
unsigned int *recent, unsigned int *unseen);
int response_examine(session *ssn, int tag, unsigned int *exist,
unsigned int *recent);
int response_select(session *ssn, int tag);
int response_list(session *ssn, int tag, char **mboxs, char **folders);
int response_search(session *ssn, int tag, char **mesgs);
int response_fetchfast(session *ssn, int tag, char **flags, char **date,
char **size);
int response_fetchflags(session *ssn, int tag, char **flags);
int response_fetchdate(session *ssn, int tag, char **date);
int response_fetchsize(session *ssn, int tag, char **size);
int response_fetchbody(session *ssn, int tag, char **body, size_t *len);
/* signal.c */
void catch_signals(void);
void release_signals(void);
/* socket.c */
int open_connection(session *ssn, const char *server, const char *port,
const char *protocol);
int close_connection(session *ssn);
ssize_t socket_read(session *ssn, char *buf, size_t len);
ssize_t socket_write(session *ssn, const char *buf, size_t len);
#ifndef NO_SSLTLS
int open_secure_connection(session *ssn, const char *server, const char *port,
const char *protocol);
int close_secure_connection(session *ssn);
ssize_t socket_secure_read(session *ssn, char *buf, size_t len);
ssize_t socket_secure_write(session *ssn, const char *buf, size_t len);
#endif
/* system.c */
LUALIB_API int luaopen_ifsys(lua_State *lua);
#endif /* IMAPFILTER_H */
|