]> Pileus Git - ~andy/fetchmail/blob - fetchmail.h
Rationalized timestamps.
[~andy/fetchmail] / fetchmail.h
1 /*
2  * For license terms, see the file COPYING in this directory.
3  */
4
5 /* We need this for HAVE_STDARG_H, etc */
6 #include "config.h"
7
8 /* constants designating the various supported protocols */
9 #define         P_AUTO          1
10 #define         P_POP2          2
11 #define         P_POP3          3
12 #define         P_IMAP          4
13 #define         P_IMAP_K4       5
14 #define         P_IMAP_GSS      6
15 #define         P_APOP          7
16 #define         P_RPOP          8
17 #define         P_ETRN          9
18
19 #if INET6
20 #define         KPOP_PORT       "kpop"
21 #else /* INET6 */
22 #define         KPOP_PORT       1109
23 #endif /* INET6 */
24
25 /* preauthentication types */
26 #define         A_PASSWORD      0       /* password or inline authentication */
27 #define         A_KERBEROS_V4   1       /* preauthenticate w/ Kerberos V4 */
28 #define         A_KERBEROS_V5   2       /* preauthenticate w/ Kerberos V5 */
29
30 /*
31  * Definitions for buffer sizes.  We get little help on setting maxima
32  * from IMAP RFCs up to 2060, so these are mostly from POP3.
33  */
34 #define         HOSTLEN         635     /* max hostname length (RFC1123) */
35 #define         POPBUFSIZE      512     /* max length of response (RFC1939) */
36 #define         IDLEN           128     /* max length of UID (RFC1939) */
37
38 /* per RFC1939 this should be 40, but Microsoft Exchange ignores that limit */
39 #define         USERNAMELEN     128     /* max POP3 arg length */
40
41 /* clear a netBSD kernel parameter out of the way */ 
42 #undef          MSGBUFSIZE
43
44 /*
45  * The RFC822 limit on message line size is just 998.  But
46  * make this *way* oversized; idiot DOS-world mailers that
47  * don't line-wrap properly often ship entire paragraphs as
48  * lines.
49  */
50 #define         MSGBUFSIZE      8192
51
52 #define         PASSWORDLEN     64      /* max password length */
53 #define         DIGESTLEN       33      /* length of MD5 digest */
54
55 /* exit code values */
56 #define         PS_SUCCESS      0       /* successful receipt of messages */
57 #define         PS_NOMAIL       1       /* no mail available */
58 #define         PS_SOCKET       2       /* socket I/O woes */
59 #define         PS_AUTHFAIL     3       /* user authorization failed */
60 #define         PS_PROTOCOL     4       /* protocol violation */
61 #define         PS_SYNTAX       5       /* command-line syntax error */
62 #define         PS_IOERR        6       /* bad permissions on rc file */
63 #define         PS_ERROR        7       /* protocol error */
64 #define         PS_EXCLUDE      8       /* client-side exclusion error */
65 #define         PS_LOCKBUSY     9       /* server responded lock busy */
66 #define         PS_SMTP         10      /* SMTP error */
67 #define         PS_DNS          11      /* fatal DNS error */
68 #define         PS_BSMTP        12      /* output batch could not be opened */
69 /* leave space for more codes */
70 #define         PS_UNDEFINED    23      /* something I hadn't thought of */
71 #define         PS_TRANSIENT    24      /* transient failure (internal use) */
72 #define         PS_REFUSED      25      /* mail refused (internal use) */
73 #define         PS_RETAINED     26      /* message retained (internal use) */
74 #define         PS_TRUNCATED    27      /* headers incomplete (internal use) */
75
76 /* output noise level */
77 #define         O_SILENT        0       /* mute, max squelch, etc. */
78 #define         O_NORMAL        1       /* user-friendly */
79 #define         O_VERBOSE       2       /* chatty */
80 #define         O_DEBUG         3       /* prolix */
81 #define         O_MONITOR       O_VERBOSE
82
83 #define         SIZETICKER      1024    /* print 1 dot per this many bytes */
84
85 /*
86  * We #ifdef this and use flag rather than bool
87  * to avoid a type clash with curses.h
88  */
89 #ifndef TRUE
90 #define FALSE   0
91 #define TRUE    1
92 #endif /* TRUE */
93 typedef char    flag;
94
95 /* we need to use zero as a flag-uninitialized value */
96 #define FLAG_TRUE       2
97 #define FLAG_FALSE      1
98
99 struct runctl
100 {
101     char        *logfile;
102     char        *idfile;
103     int         poll_interval;
104     flag        use_syslog;
105     flag        invisible;
106     const char  *postmaster;
107 };
108
109 struct idlist
110 {
111     char *id;
112     union
113     {
114         struct
115         {
116             short       num;
117             flag        mark;           /* UID-index information */
118 #define UID_UNSEEN      0               /* hasn't been seen */
119 #define UID_SEEN        1               /* seen, but not deleted */
120 #define UID_DELETED     2               /* this message has been deleted */
121 #define UID_EXPUNGED    3               /* this message has been expunged */ 
122         }
123         status;
124         char *id2;
125     } val;
126     struct idlist *next;
127 };
128
129 struct query;
130
131 struct method           /* describe methods for protocol state machine */
132 {
133     const char *name;           /* protocol name */
134 #if INET6
135     const char *service;
136 #else /* INET6 */
137     int port;                   /* service port */
138 #endif /* INET6 */
139     flag tagged;                /* if true, generate & expect command tags */
140     flag delimited;             /* if true, accept "." message delimiter */
141     int (*parse_response)(int, char *);
142                                 /* response_parsing function */
143     int (*password_canonify)(char *, char *);
144                                 /* canonicalize password */
145     int (*getauth)(int, struct query *, char *);
146                                 /* authorization fetcher */
147     int (*getrange)(int, struct query *, const char *, int *, int *, int *);
148                                 /* get message range to fetch */
149     int (*getsizes)(int, int, int *);
150                                 /* get sizes of messages */
151     int (*is_old)(int, struct query *, int);
152                                 /* check for old message */
153     int (*fetch_headers)(int, struct query *, int, int *);
154                                 /* fetch FROM headera given message */
155     int (*fetch_body)(int, struct query *, int, int *);
156                                 /* fetch a given message */
157     int (*trail)(int, struct query *, int);
158                                 /* eat trailer of a message */
159     int (*delete)(int, struct query *, int);
160                                 /* delete method */
161     int (*logout_cmd)(int, struct query *);
162                                 /* logout command */
163     flag retry;                 /* can getrange poll for new messages? */
164 };
165
166 struct hostdata         /* shared among all user connections to given server */
167 {
168     /* rc file data */
169     char *pollname;                     /* poll label of host */
170     char *via;                          /* "true" server name if non-NULL */
171     struct idlist *akalist;             /* server name first, then akas */
172     struct idlist *localdomains;        /* list of pass-through domains */
173     int protocol;                       /* protocol type */
174 #if INET6
175     char *service;                      /* IPv6 service name */
176     void *netsec;                       /* IPv6 security request */
177 #else /* INET6 */
178     int port;                           /* TCP/IP service port number */
179 #endif /* INET6 */
180     int interval;                       /* # cycles to skip between polls */
181     int preauthenticate;                /* preauthentication mode to try */
182     int timeout;                        /* inactivity timout in seconds */
183     char *envelope;                     /* envelope address list header */
184     int envskip;                        /* skip to numbered envelope header */
185     char *qvirtual;                     /* prefix removed from local user id */
186     flag skip;                          /* suppress poll in implicit mode? */
187     flag dns;                           /* do DNS lookup on multidrop? */
188     flag uidl;                          /* use RFC1725 UIDLs? */
189 #ifdef SDPS_ENABLE
190     flag sdps;                          /* use Demon Internet SDPS *ENV */
191 #endif /* SDPS_ENABLE */
192     flag checkalias;                    /* resolve aliases by comparing IPs? */
193
194
195 #ifdef linux
196     char *interface;
197     char *monitor;
198     int  monitor_io;
199     struct interface_pair_s *interface_pair;
200 #endif /* linux */
201
202     /* computed for internal use */
203     const struct method *base_protocol; /* relevant protocol method table */
204     int poll_count;                     /* count of polls so far */
205     char *queryname;                    /* name to attempt DNS lookup on */
206     char *truename;                     /* "true name" of server host */
207     struct hostdata *lead_server;       /* ptr to lead query for this server */
208     int esmtp_options;
209 };
210
211 struct query
212 {
213     /* mailserver connection controls */
214     struct hostdata server;
215
216     /* per-user data */
217     struct idlist *localnames;  /* including calling user's name */
218     int wildcard;               /* should unmatched names be passed through */
219     char *remotename;           /* remote login name to use */
220     char *password;             /* remote password to use */
221     struct idlist *mailboxes;   /* list of mailboxes to check */
222     struct idlist *smtphunt;    /* list of SMTP hosts to try forwarding to */
223     char *smtphost;             /* actual SMTP host to point to */
224     char *smtpaddress;          /* address we want to force in the delivery messages */ 
225     struct idlist *antispam;    /* list of listener's antispam response */
226     char *mda;                  /* local MDA to pass mail to */
227     char *bsmtp;                /* BSMTP output file */
228     char *preconnect;           /* pre-connection command to execute */
229     char *postconnect;          /* post-connection command to execute */
230
231     /* per-user control flags */
232     flag keep;                  /* if TRUE, leave messages undeleted */
233     flag fetchall;              /* if TRUE, fetch all (not just unseen) */
234     flag flush;                 /* if TRUE, delete messages already seen */
235     flag rewrite;               /* if TRUE, canonicalize recipient addresses */
236     flag stripcr;               /* if TRUE, strip CRs in text */
237     flag forcecr;               /* if TRUE, force CRs before LFs in text */
238     flag pass8bits;             /* if TRUE, ignore Content-Transfer-Encoding */
239     flag dropstatus;            /* if TRUE, drop Status lines in mail */
240     flag mimedecode;            /* if TRUE, decode MIME-coded headers/coded printable*/
241     int limit;                  /* limit size of retrieved messages */
242     int warnings;               /* size warning interval */
243     int fetchlimit;             /* max # msgs to get in single poll */
244     int batchlimit;             /* max # msgs to pass in single SMTP session */
245     int expunge;                /* max # msgs to pass between expunges */
246     char *properties;           /* passthrough properties for extensions */
247
248     struct idlist *oldsaved, *newsaved;
249
250     /* internal use -- per-poll state */
251     flag active;                /* should we actually poll this server? */
252     const char *destaddr;       /* destination host for this query */
253     int errcount;               /* count transient errors in last pass */
254     int authfailcount;          /* count authentication failures this run */
255     int smtp_socket;            /* socket descriptor for SMTP connection */
256     unsigned int uid;           /* UID of user to deliver to */
257     struct idlist *skipped;     /* messages skipped on the mail server */
258
259     /* internal use -- per-message state */
260     int mimemsg;                /* bitmask indicating MIME body-type */
261     char digest [DIGESTLEN];    /* md5 digest buffer */
262
263     /* internal use -- housekeeping */
264     struct query *next;         /* next query control block in chain */
265 };
266
267 /*
268  * Numeric option handling.  Numeric option value of zero actually means
269  * it's unspecified.  Value less than zero is zero.
270  */
271 #define NUM_VALUE(n)            (((n) == 0) ? -1 : (n))
272 #define NUM_NONZERO(n)          ((n) > 0)
273 #define NUM_ZERO(n)             ((n) < 0)
274 #define NUM_SPECIFIED(n)        ((n) != 0)
275
276 #define MULTIDROP(ctl)  (ctl->wildcard || \
277                                 ((ctl)->localnames && (ctl)->localnames->next))
278
279 /*
280  * Note: tags are generated with an a%04d format from a 1-origin
281  * integer sequence number.  Length 4 permits transaction numbers
282  * up to 9999, so we force rollover with % 10000.  There's no special
283  * reason for this format other than to look like the exmples in the
284  * IMAP RFCs.
285  */
286 #define TAGLEN  6               /* 'a' + 4 digits + NUL */
287 extern char tag[TAGLEN];
288 #define TAGMOD  10000
289
290 /* list of hosts assembled from run control file and command line */
291 extern struct query cmd_opts, *querylist;
292
293 /* what's returned by envquery */
294 extern void envquery(int, char **);
295
296 /* controls the detail level of status/progress messages written to stderr */
297 extern int outlevel;            /* see the O_.* constants above */
298 extern int yydebug;             /* enable parse debugging */
299
300 /* these get computed */
301 extern int batchcount;          /* count of messages sent in current batch */
302 extern flag peek_capable;       /* can we read msgs without setting seen? */
303
304 /* miscellaneous global controls */
305 extern struct runctl run;       /* global controls for this run */
306 extern flag nodetach;           /* if TRUE, don't detach daemon process */
307 extern flag quitmode;           /* if --quit was set */
308 extern flag check_only;         /* if --check was set */
309 extern char *rcfile;            /* path name of rc file */
310 extern int linelimit;           /* limit # lines retrieved per site */
311 extern flag versioninfo;        /* emit only version info */
312 extern char *user;              /* name of invoking user */
313 extern char *home;              /* home directory of invoking user */
314 extern int pass;                /* number of re-polling pass */
315 extern flag configdump;         /* dump control blocks as Python dictionary */
316 extern const char *fetchmailhost;
317                                 /* either "localhost" or an FQDN */
318
319 /* prototypes for globally callable functions */
320
321 /* error.c: Error reporting */
322 #if defined(HAVE_STDARG_H)
323 void error_init(int foreground);
324 void error (int status, int errnum, const char *format, ...);
325 void error_build (const char *format, ...);
326 void error_complete (int status, int errnum, const char *format, ...);
327 void error_at_line (int, int, const char *, unsigned int, const char *, ...);
328 #else
329 void error ();
330 void error_build ();
331 void error_complete ();
332 void error_at_line ();
333 #endif
334
335 /* driver.c: transaction support */
336 void set_timeout(int);
337 #if defined(HAVE_STDARG_H)
338 void gen_send (int sock, const char *, ... );
339 int gen_recv(int sock, char *buf, int size);
340 int gen_transact (int sock, const char *, ... );
341 #else
342 void gen_send ();
343 int gen_recv();
344 int gen_transact ();
345 #endif
346
347 /* use these to track what was happening when the nonresponse timer fired */
348 #define GENERAL_WAIT    0       /* unknown wait type */
349 #define OPEN_WAIT       1       /* waiting from mailserver open */
350 #define SERVER_WAIT     2       /* waiting for mailserver response */
351 #define LISTENER_WAIT   3       /* waiting for listener initialization */
352 #define FORWARDING_WAIT 4       /* waiting for listener response */
353 extern int phase;
354
355 /* mark values for name lists */
356 #define XMIT_ACCEPT             1
357 #define XMIT_REJECT             2
358 #define XMIT_ANTISPAM           3
359
360 /* sink.c: forwarding */
361 int stuffline(struct query *, char *);
362 int open_sink(struct query*, const char*, struct idlist*, long reallen, int*, int*);
363 void release_sink(struct query *);
364 int close_sink(struct query *, flag);
365
366 /* rfc822.c: RFC822 header parsing */
367 char *reply_hack(char *, const char *);
368 char *nxtaddr(const char *);
369
370 /* uid.c: UID support */
371 void initialize_saved_lists(struct query *, const char *);
372 struct idlist *save_str(struct idlist **, const char *, flag);
373 void free_str_list(struct idlist **);
374 void save_str_pair(struct idlist **, const char *, const char *);
375 void free_str_pair_list(struct idlist **);
376 int delete_str(struct idlist **, int);
377 int str_in_list(struct idlist **, const char *, const flag);
378 int str_nr_in_list(struct idlist **, const char *);
379 int str_nr_last_in_list(struct idlist **, const char *);
380 void str_set_mark( struct idlist **, const char *, const flag);
381 int count_list( struct idlist **idl );
382 char *str_from_nr_list( struct idlist **idl, int number );
383 char *str_find(struct idlist **, int);
384 char *idpair_find(struct idlist **, const char *);
385 void append_str_list(struct idlist **, struct idlist **);
386 void expunge_uids(struct query *);
387 void update_str_lists(struct query *);
388 void write_saved_lists(struct query *, const char *);
389
390 /* rcfile_y.y */
391 int prc_parse_file(const char *, const flag);
392 int prc_filecheck(const char *, const flag);
393
394 /* base64.c */
395 void to64frombits(unsigned char *, const unsigned char *, int);
396 int from64tobits(char *, const char *);
397
398 /* unmime.c */
399 /* Bit-mask returned by MimeBodyType */
400 #define MSG_IS_7BIT       0x01
401 #define MSG_IS_8BIT       0x02
402 #define MSG_NEEDS_DECODE  0x80
403 extern void UnMimeHeader(unsigned char *buf);
404 extern int  MimeBodyType(unsigned char *hdrs, int WantDecode);
405 extern int  UnMimeBodyline(unsigned char **buf, int collapsedoubledot);
406
407 /* interface.c */
408 void interface_parse(char *, struct hostdata *);
409 void interface_note_activity(struct hostdata *);
410 int interface_approve(struct hostdata *);
411
412 /* xmalloc.c */
413 #if defined(HAVE_VOIDPOINTER)
414 #define XMALLOCTYPE void
415 #else
416 #define XMALLOCTYPE char
417 #endif
418 XMALLOCTYPE *xmalloc(int);
419 XMALLOCTYPE *xrealloc(XMALLOCTYPE *, int);
420 char *xstrdup(const char *);
421 #if defined(HAVE_ALLOCA_H)
422 #include <alloca.h>
423 #else
424 #ifdef _AIX
425  #pragma alloca
426 #endif
427 #endif
428 #define xalloca(ptr, t, n)      if (!(ptr = (t) alloca(n))) error(PS_UNDEFINED, 0, "alloca failed")
429
430 /* protocol driver and methods */
431 int do_protocol(struct query *, const struct method *);
432 int doPOP2 (struct query *); 
433 int doPOP3 (struct query *);
434 int doIMAP (struct query *);
435 int doETRN (struct query *);
436
437 /* miscellanea */
438 struct query *hostalloc(struct query *); 
439 int parsecmdline (int, char **, struct runctl *, struct query *);
440 char *MD5Digest (unsigned char *);
441 int POP3_auth_rpa(unsigned char *, unsigned char *, int socket);
442 int daemonize(const char *, void (*)(int));
443 char *getpassword(char *);
444 void escapes(const char *, char *);
445 char *visbuf(const char *);
446 const char *showproto(int);
447 void dump_config(struct runctl *runp, struct query *querylist);
448 int is_host_alias(const char *, struct query *);
449 char *host_fqdn(void);
450 char *rfc822timestamp(void);
451 #ifdef SDPS_ENABLE
452 char *sdps_envto;
453 #endif /* SDPS_ENABLE */
454
455 void yyerror(const char *);
456 int yylex(void);
457
458 #ifdef __EMX__
459 void itimerthread(void*);
460 /* Have to include these first to avoid errors from redefining getcwd
461    and chdir.  They're re-include protected in EMX, so it's okay, I
462    guess.  */
463 #include <stdlib.h>
464 #include <unistd.h>
465 /* Redefine getcwd and chdir to get drive-letter support so we can
466    find all of our lock files and stuff. */
467 #define getcwd _getcwd2
468 #define chdir _chdir2
469 #endif
470
471 #define STRING_DISABLED (char *)-1
472 #define STRING_DUMMY    ""
473
474 /* fetchmail.h ends here */