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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
|
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef FETCH_H
#define FETCH_H
/* Fetch return codes. */
#define FETCH_AGAIN 1
#define FETCH_BLOCK 2
#define FETCH_ERROR 3
#define FETCH_MAIL 4
#define FETCH_EXIT 5
/* Fetch flags. */
#define FETCH_PURGE 0x1
#define FETCH_EMPTY 0x2
#define FETCH_POLL 0x4
/* Fetch context. */
struct fetch_ctx {
int (*state)(struct account *, struct fetch_ctx *);
int flags;
struct mail *mail;
size_t llen;
char *lbuf;
};
/* Fetch functions. */
struct fetch {
const char *name;
int (*first)(struct account *, struct fetch_ctx *);
void (*fill)(struct account *, struct iolist *);
int (*commit)(struct account *, struct mail *);
void (*abort)(struct account *);
u_int (*total)(struct account *);
void (*desc)(struct account *, char *, size_t);
};
/* Ranges of mail. */
enum fetch_only {
FETCH_ONLY_NEW,
FETCH_ONLY_OLD,
FETCH_ONLY_ALL
};
/* Fetch maildir data. */
struct fetch_maildir_data {
struct strings *maildirs;
u_int total;
struct strings unlinklist;
struct strings *paths;
u_int index;
DIR *dirp;
};
struct fetch_maildir_mail {
char path[MAXPATHLEN];
};
/* Fetch mbox data. */
struct fetch_mbox_data {
struct strings *mboxes;
ARRAY_DECL(, struct fetch_mbox_mbox *) fmboxes;
u_int index;
size_t off;
TAILQ_HEAD(, fetch_mbox_mail) kept;
};
struct fetch_mbox_mbox {
char *path;
u_int reference;
u_int total;
int fd;
char *base;
size_t size;
};
struct fetch_mbox_mail {
size_t off;
size_t size;
struct fetch_mbox_mbox *fmbox;
TAILQ_ENTRY(fetch_mbox_mail) entry;
};
/* NNTP group entry. */
struct fetch_nntp_group {
char *name;
int ignore;
u_int size;
u_int last;
char *id;
};
/* Fetch nntp data. */
struct fetch_nntp_data {
char *path;
char *user;
char *pass;
struct server server;
struct strings *names;
u_int group;
ARRAY_DECL(, struct fetch_nntp_group *) groups;
int flushing;
struct io *io;
};
/* Fetch pop3 queues and trees. */
TAILQ_HEAD(fetch_pop3_queue, fetch_pop3_mail);
RB_HEAD(fetch_pop3_tree, fetch_pop3_mail);
/* Fetch pop3 data. */
struct fetch_pop3_data {
char *path;
enum fetch_only only;
char *user;
char *pass;
struct server server;
char *pipecmd;
int starttls;
int apop;
int uidl;
u_int cur;
u_int num;
u_int total;
u_int committed;
/* Mails on the server. */
struct fetch_pop3_tree serverq;
/* Mails in the cache file. */
struct fetch_pop3_tree cacheq;
/* Mails to fetch from the server. */
struct fetch_pop3_queue wantq;
/* Mails ready to be dropped. */
struct fetch_pop3_queue dropq;
int flushing;
size_t size;
struct io *io;
struct cmd *cmd;
char *src;
int (*connect)(struct account *);
void (*disconnect)(struct account *);
int (*getln)(
struct account *, struct fetch_ctx *, char **);
int (*putln)(struct account *, const char *, va_list);
};
struct fetch_pop3_mail {
char *uid;
u_int idx;
TAILQ_ENTRY(fetch_pop3_mail) qentry;
RB_ENTRY(fetch_pop3_mail) tentry;
};
/* Fetch imap data. */
struct fetch_imap_data {
enum fetch_only only;
char *user;
char *pass;
struct server server;
char *pipecmd;
int starttls;
int nocrammd5;
int noplain;
int nologin;
int oauthbearer;
int xoauth2;
u_int folder;
struct strings *folders;
u_int folders_total; /* total mail count */
int capa;
int tag;
ARRAY_DECL(, u_int) wanted;
ARRAY_DECL(, u_int) dropped;
ARRAY_DECL(, u_int) kept;
u_int total;
u_int committed;
int flushing;
size_t size;
u_int lines;
struct io *io;
struct cmd *cmd;
char *src;
int (*connect)(struct account *);
void (*disconnect)(struct account *);
int (*getln)(
struct account *, struct fetch_ctx *, char **);
int (*putln)(struct account *, const char *, va_list);
int (*putn)(struct account *, const char *, size_t);
};
struct fetch_imap_mail {
u_int uid;
};
#define IMAP_TAG_NONE -1
#define IMAP_TAG_CONTINUE -2
#define IMAP_TAG_ERROR -3
#define IMAP_TAGGED 0
#define IMAP_CONTINUE 1
#define IMAP_UNTAGGED 2
#define IMAP_RAW 3
#define IMAP_CAPA_AUTH_CRAM_MD5 0x1
#define IMAP_CAPA_XYZZY 0x2
#define IMAP_CAPA_STARTTLS 0x4
#define IMAP_CAPA_NOSPACE 0x8
#define IMAP_CAPA_GMEXT 0x10
#define IMAP_CAPA_AUTH_OAUTHBEARER 0x20
#define IMAP_CAPA_AUTH_XOAUTH2 0x40
#define IMAP_CAPA_AUTH_PLAIN 0x80
/* fetch-maildir.c */
extern struct fetch fetch_maildir;
/* fetch-mbx.c */
extern struct fetch fetch_mbox;
/* fetch-stdin.c */
extern struct fetch fetch_stdin;
/* fetch-nntp.c */
extern struct fetch fetch_nntp;
/* fetch-pop3.c */
extern struct fetch fetch_pop3;
/* fetch-pop3pipe.c */
extern struct fetch fetch_pop3pipe;
/* fetch-imap.c */
extern struct fetch fetch_imap;
int fetch_imap_putln(struct account *, const char *, va_list);
int fetch_imap_getln(struct account *, struct fetch_ctx *, char **);
int fetch_imap_state_init(struct account *, struct fetch_ctx *);
/* fetch-imappipe.c */
extern struct fetch fetch_imappipe;
/* imap-common.c */
int imap_not_clean(const char *);
int imap_tag(char *);
int imap_putln(struct account *, const char *, ...);
int imap_getln(struct account *, struct fetch_ctx *, int, char **);
int imap_okay(char *);
int imap_no(char *);
int imap_bad(struct account *, const char *);
int imap_invalid(struct account *, const char *);
int imap_state_init(struct account *, struct fetch_ctx *);
int imap_state_connected(struct account *, struct fetch_ctx *);
int imap_state_select1(struct account *, struct fetch_ctx *);
int imap_commit(struct account *, struct mail *);
void imap_abort(struct account *);
u_int imap_total(struct account *);
/* pop3-common.c */
int pop3_state_init(struct account *, struct fetch_ctx *);
int pop3_commit(struct account *, struct mail *);
void pop3_abort(struct account *);
u_int pop3_total(struct account *);
#endif
|