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