]> Pileus Git - ~andy/fetchmail/blob - fetchmail.h
682dfff482ed47bcca5941b54b709c73bf89eb0d
[~andy/fetchmail] / fetchmail.h
1 #ifndef _FETCHMAIL_H
2 #define _FETCHMAIL_H
3 /*
4  * For license terms, see the file COPYING in this directory.
5  */
6
7 /* We need this for HAVE_STDARG_H, etc */
8 #include "config.h"
9
10 /* We need this for size_t */
11 #include <sys/types.h>
12
13 /* We need this for time_t */
14 #if TIME_WITH_SYS_TIME
15 # include <sys/time.h>
16 # include <time.h>
17 #else
18 # if HAVE_SYS_TIME_H
19 #  include <sys/time.h>
20 # else
21 #  include <time.h>
22 # endif
23 #endif
24
25 #include <stdio.h>
26
27 /* Import Trio if needed */
28 #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
29 #  include "trio/trio.h"
30 #endif
31
32 /* We need this for strstr */
33 #if !defined(HAVE_STRSTR) && !defined(strstr)
34 char *strstr(const char *, const char *);
35 #endif
36
37 /* constants designating the various supported protocols */
38 #define         P_AUTO          1
39 #define         P_POP2          2
40 #define         P_POP3          3
41 #define         P_APOP          4
42 #define         P_RPOP          5
43 #define         P_IMAP          6
44 #define         P_ETRN          7
45 #define         P_ODMR          8
46
47 #define         SMTP_PORT       "smtp"
48 #define         SMTP_PORT_NUM   25
49 #define         KPOP_PORT       "kpop"
50
51 #ifdef SSL_ENABLE
52 #define         SIMAP_PORT      993
53 #define         SPOP3_PORT      995
54 #endif
55
56 /* 
57  * We need to distinguish between mailbox and mailbag protocols.
58  * Under a mailbox protocol wwe're pulling mail for a speecific user.
59  * Under a mailbag protocol we're fetching mail for an entire domain.
60  */
61 #define MAILBOX_PROTOCOL(ctl)   ((ctl)->server.protocol < P_ETRN)
62
63 /* authentication types */
64 #define         A_ANY           0       /* use the first method that works */
65 #define         A_PASSWORD      1       /* password authentication */
66 #define         A_NTLM          2       /* Microsoft NTLM protocol */
67 #define         A_CRAM_MD5      3       /* CRAM-MD5 shrouding (RFC2195) */
68 #define         A_OTP           4       /* One-time password (RFC1508) */
69 #define         A_KERBEROS_V4   5       /* authenticate w/ Kerberos V4 */
70 #define         A_KERBEROS_V5   6       /* authenticate w/ Kerberos V5 */
71 #define         A_GSSAPI        7       /* authenticate with GSSAPI */
72 #define         A_SSH           8       /* authentication at session level */
73
74 /* some protocols (KERBEROS, GSSAPI, SSH) don't require a password */
75 #define NO_PASSWORD(ctl)        ((ctl)->server.authenticate > A_OTP || (ctl)->server.protocol == P_ETRN)
76
77 /*
78  * Definitions for buffer sizes.  We get little help on setting maxima
79  * from IMAP RFCs up to 2060, so these are mostly from POP3.
80  */
81 #define         HOSTLEN         635     /* max hostname length (RFC1123) */
82 #define         POPBUFSIZE      512     /* max length of response (RFC1939) */
83 #define         IDLEN           128     /* max length of UID (RFC1939) */
84
85 /* per RFC1939 this should be 40, but Microsoft Exchange ignores that limit */
86 #define         USERNAMELEN     128     /* max POP3 arg length */
87
88 /* clear a netBSD kernel parameter out of the way */ 
89 #undef          MSGBUFSIZE
90
91 /*
92  * The RFC822 limit on message line size is just 998.  But
93  * make this *way* oversized; idiot DOS-world mailers that
94  * don't line-wrap properly often ship entire paragraphs as
95  * lines.
96  */
97 #define         MSGBUFSIZE      8192
98
99 #define         NAMELEN         64      /* max username length */
100 #define         PASSWORDLEN     64      /* max password length */
101 #define         DIGESTLEN       33      /* length of MD5 digest */
102
103 /* exit code values */
104 #define         PS_SUCCESS      0       /* successful receipt of messages */
105 #define         PS_NOMAIL       1       /* no mail available */
106 #define         PS_SOCKET       2       /* socket I/O woes */
107 #define         PS_AUTHFAIL     3       /* user authorization failed */
108 #define         PS_PROTOCOL     4       /* protocol violation */
109 #define         PS_SYNTAX       5       /* command-line syntax error */
110 #define         PS_IOERR        6       /* bad permissions on rc file */
111 #define         PS_ERROR        7       /* protocol error */
112 #define         PS_EXCLUDE      8       /* client-side exclusion error */
113 #define         PS_LOCKBUSY     9       /* server responded lock busy */
114 #define         PS_SMTP         10      /* SMTP error */
115 #define         PS_DNS          11      /* fatal DNS error */
116 #define         PS_BSMTP        12      /* output batch could not be opened */
117 #define         PS_MAXFETCH     13      /* poll ended by fetch limit */
118 #define         PS_SERVBUSY     14      /* server is busy */
119 /* leave space for more codes */
120 #define         PS_UNDEFINED    23      /* something I hadn't thought of */
121 #define         PS_TRANSIENT    24      /* transient failure (internal use) */
122 #define         PS_REFUSED      25      /* mail refused (internal use) */
123 #define         PS_RETAINED     26      /* message retained (internal use) */
124 #define         PS_TRUNCATED    27      /* headers incomplete (internal use) */
125 #define         PS_REPOLL       28      /* repoll immediately with changed parameters (internal use) */
126 #define         PS_IDLETIMEOUT  29      /* timeout on imap IDLE (internal use) */
127
128 /* output noise level */
129 #define         O_SILENT        0       /* mute, max squelch, etc. */
130 #define         O_NORMAL        1       /* user-friendly */
131 #define         O_VERBOSE       2       /* chatty */
132 #define         O_DEBUG         3       /* prolix */
133 #define         O_MONITOR       O_VERBOSE
134
135 #define         SIZETICKER      1024    /* print 1 dot per this many bytes */
136
137 /*
138  * We #ifdef this and use flag rather than bool
139  * to avoid a type clash with curses.h
140  */
141 #ifndef TRUE
142 #define FALSE   0
143 #define TRUE    1
144 #endif /* TRUE */
145 typedef char    flag;
146
147 /* we need to use zero as a flag-uninitialized value */
148 #define FLAG_TRUE       2
149 #define FLAG_FALSE      1
150
151 struct runctl
152 {
153     char        *logfile;
154     char        *idfile;
155     int         poll_interval;
156     char        *postmaster;
157     flag        bouncemail;
158     flag        spambounce;
159     char        *properties;
160     flag        use_syslog;
161     flag        invisible;
162     flag        showdots;
163 };
164
165 struct idlist
166 {
167     unsigned char *id;
168     union
169     {
170         struct
171         {
172             int         num;
173             flag        mark;           /* UID-index information */
174 #define UID_UNSEEN      0               /* hasn't been seen */
175 #define UID_SEEN        1               /* seen, but not deleted */
176 #define UID_DELETED     2               /* this message has been deleted */
177 #define UID_EXPUNGED    3               /* this message has been expunged */ 
178         }
179         status;
180         unsigned char *id2;
181     } val;
182     struct idlist *next;
183 };
184
185 struct query;
186
187 struct method           /* describe methods for protocol state machine */
188 {
189     const char *name;           /* protocol name */
190     const char *service;        /* service port (unencrypted) */
191     const char *sslservice;     /* service port (SSL) */
192     flag tagged;                /* if true, generate & expect command tags */
193     flag delimited;             /* if true, accept "." message delimiter */
194     int (*parse_response)(int, char *);
195                                 /* response_parsing function */
196     int (*getauth)(int, struct query *, char *);
197                                 /* authorization fetcher */
198     int (*getrange)(int, struct query *, const char *, int *, int *, int *);
199                                 /* get message range to fetch */
200     int (*getsizes)(int, int, int *);
201                                 /* get sizes of messages */
202     int (*getpartialsizes)(int, int, int, int *);
203                                 /* get sizes of subset of messages */
204     int (*is_old)(int, struct query *, int);
205                                 /* check for old message */
206     int (*fetch_headers)(int, struct query *, int, int *);
207                                 /* fetch FROM headera given message */
208     int (*fetch_body)(int, struct query *, int, int *);
209                                 /* fetch a given message */
210     int (*trail)(int, struct query *, int);
211                                 /* eat trailer of a message */
212     int (*delete)(int, struct query *, int);
213                                 /* delete method */
214     int (*mark_seen)(int, struct query *, int);
215                                 /* mark as seen method */
216     int (*logout_cmd)(int, struct query *);
217                                 /* logout command */
218     flag retry;                 /* can getrange poll for new messages? */
219 };
220
221 struct hostdata         /* shared among all user connections to given server */
222 {
223     /* rc file data */
224     char *pollname;                     /* poll label of host */
225     char *via;                          /* "true" server name if non-NULL */
226     struct idlist *akalist;             /* server name first, then akas */
227     struct idlist *localdomains;        /* list of pass-through domains */
228     int protocol;                       /* protocol type */
229     char *service;                      /* service name */
230     int interval;                       /* # cycles to skip between polls */
231     int authenticate;                   /* authentication mode to try */
232     int timeout;                        /* inactivity timout in seconds */
233     char *envelope;                     /* envelope address list header */
234     int envskip;                        /* skip to numbered envelope header */
235     char *qvirtual;                     /* prefix removed from local user id */
236     flag skip;                          /* suppress poll in implicit mode? */
237     flag dns;                           /* do DNS lookup on multidrop? */
238     flag uidl;                          /* use RFC1725 UIDLs? */
239 #ifdef SDPS_ENABLE
240     flag sdps;                          /* use Demon Internet SDPS *ENV */
241 #endif /* SDPS_ENABLE */
242     flag checkalias;                    /* resolve aliases by comparing IPs? */
243     flag tracepolls;                    /* if TRUE, add poll trace info to Received */
244     char *principal;                    /* Kerberos principal for mail service */
245     char *esmtp_name, *esmtp_password;  /* ESMTP AUTH information */
246
247 #if defined(linux) || defined(__FreeBSD__)
248 #define CAN_MONITOR
249 #endif
250
251 #ifdef CAN_MONITOR
252     char *interface;
253     char *monitor;
254     int  monitor_io;
255     struct interface_pair_s *interface_pair;
256 #endif
257
258     char *plugin,*plugout;
259
260     /* computed for internal use */
261     const struct method *base_protocol; /* relevant protocol method table */
262     int poll_count;                     /* count of polls so far */
263     char *queryname;                    /* name to attempt DNS lookup on */
264     char *truename;                     /* "true name" of server host */
265     struct sockaddr *trueaddr;          /* IP address of truename */
266     size_t trueaddr_len;                /* size of trueaddr data */
267     struct hostdata *lead_server;       /* ptr to lead query for this server */
268     int esmtp_options;
269 };
270
271 struct query
272 {
273     /* mailserver connection controls */
274     struct hostdata server;
275
276     /* per-user data */
277     struct idlist *localnames;  /* including calling user's name */
278     int wildcard;               /* should unmatched names be passed through */
279     char *remotename;           /* remote login name to use */
280     char *password;             /* remote password to use */
281     struct idlist *mailboxes;   /* list of mailboxes to check */
282
283     /* per-forwarding-target data */
284     struct idlist *smtphunt;    /* list of SMTP hosts to try forwarding to */
285     struct idlist *domainlist;  /* domainlist to fetch from */
286     char *smtpaddress;          /* address to force in RCPT TO */ 
287     char *smtpname;             /* full RCPT TO name, including domain */
288     struct idlist *antispam;    /* list of listener's antispam response */
289     char *mda;                  /* local MDA to pass mail to */
290     char *bsmtp;                /* BSMTP output file */
291     char listener;              /* what's the listener's wire protocol? */
292 #define SMTP_MODE       'S'
293 #define LMTP_MODE       'L'
294     char *preconnect;           /* pre-connection command to execute */
295     char *postconnect;          /* post-connection command to execute */
296
297     /* per-user control flags */
298     flag keep;                  /* if TRUE, leave messages undeleted */
299     flag fetchall;              /* if TRUE, fetch all (not just unseen) */
300     flag flush;                 /* if TRUE, delete messages already seen */
301     flag limitflush;            /* if TRUE, delete oversized mails */
302     flag rewrite;               /* if TRUE, canonicalize recipient addresses */
303     flag stripcr;               /* if TRUE, strip CRs in text */
304     flag forcecr;               /* if TRUE, force CRs before LFs in text */
305     flag pass8bits;             /* if TRUE, ignore Content-Transfer-Encoding */
306     flag dropstatus;            /* if TRUE, drop Status lines in mail */
307     flag dropdelivered;         /* if TRUE, drop Delivered-To lines in mail */
308     flag mimedecode;            /* if TRUE, decode MIME-armored messages */
309     flag idle;                  /* if TRUE, idle after each poll */
310     int limit;                  /* limit size of retrieved messages */
311     int warnings;               /* size warning interval */
312     int fetchlimit;             /* max # msgs to get in single poll */
313     int fetchsizelimit;         /* max # msg sizes to get in a request */
314     int fastuidl;               /* do binary search for new UIDLs? */
315     int fastuidlcount;          /* internal count for frequency of binary search */
316     int batchlimit;             /* max # msgs to pass in single SMTP session */
317     int expunge;                /* max # msgs to pass between expunges */
318     flag use_ssl;               /* use SSL encrypted session */
319     char *sslkey;               /* optional SSL private key file */
320     char *sslcert;              /* optional SSL certificate file */
321         char *sslproto;         /* force usage of protocol (ssl2|ssl3|tls1) - defaults to ssl23 */
322     char *sslcertpath;          /* Trusted certificate directory for checking the server cert */
323     flag sslcertck;             /* Strictly check the server cert. */
324     char *sslfingerprint;       /* Fingerprint to check against */
325     char *properties;           /* passthrough properties for extensions */
326
327     /* internal use -- per-poll state */
328     flag active;                /* should we actually poll this server? */
329     const char *destaddr;       /* destination host for this query */
330     int errcount;               /* count transient errors in last pass */
331     int authfailcount;          /* count of authorization failures */
332     int wehaveauthed;           /* We've managed to logon at least once! */
333     int wehavesentauthnote;     /* We've sent an authorization failure note */
334     int wedged;                 /* wedged by auth failures or timeouts? */
335     char *smtphost;             /* actual SMTP host we connected to */
336     int smtp_socket;            /* socket descriptor for SMTP connection */
337     unsigned int uid;           /* UID of user to deliver to */
338     struct idlist *skipped;     /* messages skipped on the mail server */
339     struct idlist *oldsaved, *newsaved;
340     struct idlist **oldsavedend;
341     char lastdigest[DIGESTLEN]; /* last MD5 hash seen on this connection */
342
343     /* internal use -- per-message state */
344     int mimemsg;                /* bitmask indicating MIME body-type */
345     char digest[DIGESTLEN];     /* md5 digest buffer */
346
347     /* internal use -- housekeeping */
348     struct query *next;         /* next query control block in chain */
349 };
350
351 struct msgblk                   /* message header parsed for open_sink() */
352 {
353     char                *headers;       /* raw message headers */
354     struct idlist       *recipients;    /* addressees */
355     char                return_path[HOSTLEN + USERNAMELEN + 4]; 
356     int                 msglen;
357     int                 reallen;
358 };
359
360
361 /*
362  * Numeric option handling.  Numeric option value of zero actually means
363  * it's unspecified.  Value less than zero is zero.  The reason for this
364  * screwy encoding is so we can zero out an option block in order to set the
365  * numeric flags in it to unspecified.
366  */
367 #define NUM_VALUE_IN(n)         (((n) == 0) ? -1 : (n))
368 #define NUM_VALUE_OUT(n)        (((n) < 0) ? 0 : (n))
369 #define NUM_NONZERO(n)          ((n) > 0)
370 #define NUM_ZERO(n)             ((n) < 0)
371 #define NUM_SPECIFIED(n)        ((n) != 0)
372
373 #define MULTIDROP(ctl)  (ctl->wildcard || \
374                                 ((ctl)->localnames && (ctl)->localnames->next))
375
376 /*
377  * Note: tags are generated with an a%04d format from a 1-origin
378  * integer sequence number.  Length 4 permits transaction numbers
379  * up to 9999, so we force rollover with % 10000.  There's no special
380  * reason for this format other than to look like the exmples in the
381  * IMAP RFCs.
382  */
383 #define TAGLEN  6               /* 'a' + 4 digits + NUL */
384 extern char tag[TAGLEN];
385 #define TAGMOD  10000
386
387 /* list of hosts assembled from run control file and command line */
388 extern struct query cmd_opts, *querylist;
389
390 /* what's returned by envquery */
391 extern void envquery(int, char **);
392
393 /* controls the detail level of status/progress messages written to stderr */
394 extern int outlevel;            /* see the O_.* constants above */
395 extern int yydebug;             /* enable parse debugging */
396
397 /* these get computed */
398 extern int batchcount;          /* count of messages sent in current batch */
399 extern flag peek_capable;       /* can we read msgs without setting seen? */
400
401 /* miscellaneous global controls */
402 extern struct runctl run;       /* global controls for this run */
403 extern flag nodetach;           /* if TRUE, don't detach daemon process */
404 extern flag quitmode;           /* if --quit was set */
405 extern flag check_only;         /* if --check was set */
406 extern char *rcfile;            /* path name of rc file */
407 extern int linelimit;           /* limit # lines retrieved per site */
408 extern flag versioninfo;        /* emit only version info */
409 extern char *user;              /* name of invoking user */
410 extern char *home;              /* home directory of invoking user */
411 extern char *fmhome;            /* fetchmail home directory */
412 extern int pass;                /* number of re-polling pass */
413 extern flag configdump;         /* dump control blocks as Python dictionary */
414 extern char *fetchmailhost;     /* either "localhost" or an FQDN */
415 extern int suppress_tags;       /* suppress tags in tagged protocols? */
416 extern char shroud[PASSWORDLEN*2+3];    /* string to shroud in debug output */
417 #ifdef SDPS_ENABLE
418 extern char *sdps_envfrom;
419 extern char *sdps_envto;
420 #endif /* SDPS_ENABLE */
421
422 extern const char *iana_charset;        /* IANA assigned charset name */
423
424 /* from ucs/norm_charmap.c */
425 const char *norm_charmap(const char *name);
426
427 /* prototypes for globally callable functions */
428
429 /* from /usr/include/sys/cdefs.h */
430 #if !defined __GNUC__ || __GNUC__ < 2
431 # define __attribute__(xyz)    /* Ignore. */
432 #endif
433
434 /* error.c: Error reporting */
435 #if defined(HAVE_STDARG_H)
436 void report_init(int foreground);
437 void report (FILE *fp, const char *format, ...)
438     __attribute__ ((format (printf, 2, 3)))
439     ;
440 void report_build (FILE *fp, const char *format, ...)
441     __attribute__ ((format (printf, 2, 3)))
442     ;
443 void report_complete (FILE *fp, const char *format, ...)
444     __attribute__ ((format (printf, 2, 3)))
445     ;
446 void report_at_line (FILE *fp, int, const char *, unsigned int, const char *, ...)
447     __attribute__ ((format (printf, 5, 6)))
448     ;
449 #else
450 void report ();
451 void report_build ();
452 void report_complete ();
453 void report_at_line ();
454 #endif
455
456 /* driver.c -- main driver loop */
457 void set_timeout(int);
458 int isidletimeout(void);
459 void resetidletimeout(void);
460 int do_protocol(struct query *, const struct method *);
461
462 /* transact.c: transaction support */
463 void init_transact(const struct method *);
464 int readheaders(int sock,
465                        long fetchlen,
466                        long reallen,
467                        struct query *ctl,
468                        int num,
469                        flag *suppress_readbody);
470 int readbody(int sock, struct query *ctl, flag forward, int len);
471 #if defined(HAVE_STDARG_H)
472 void gen_send(int sock, const char *, ... )
473     __attribute__ ((format (printf, 2, 3)))
474     ;
475 int gen_recv(int sock, char *buf, int size);
476 int gen_transact(int sock, const char *, ... )
477     __attribute__ ((format (printf, 2, 3)))
478     ;
479 #else
480 void gen_send();
481 int gen_recv();
482 int gen_transact();
483 #endif
484 extern struct msgblk msgblk;
485
486 /* lock.c: concurrency locking */
487 void lock_setup(void);
488 void lock_assert(void);
489 void lock_or_die(void);
490 void fm_lock_release(void);
491 int lock_state(void);
492 void lock_dispose(void);
493
494 /* use these to track what was happening when the nonresponse timer fired */
495 #define GENERAL_WAIT    0       /* unknown wait type */
496 #define OPEN_WAIT       1       /* waiting from mailserver open */
497 #define SERVER_WAIT     2       /* waiting for mailserver response */
498 #define LISTENER_WAIT   3       /* waiting for listener initialization */
499 #define FORWARDING_WAIT 4       /* waiting for listener response */
500 extern int phase;
501
502 /* response hooks can use this to identify the query stage */
503 #define STAGE_GETAUTH   0
504 #define STAGE_GETRANGE  1
505 #define STAGE_GETSIZES  2
506 #define STAGE_FETCH     3
507 #define STAGE_IDLE      4
508 #define STAGE_LOGOUT    5
509 extern int stage;
510
511 extern int mytimeout;
512
513 /* mark values for name lists */
514 #define XMIT_ACCEPT     1       /* accepted; matches local domain or name */
515 #define XMIT_REJECT     2       /* rejected; no match */
516 #define XMIT_RCPTBAD    3       /* SMTP listener rejected the name */ 
517
518 /* idle.c */
519 int interruptible_idle(int interval);
520 extern volatile int lastsig;
521
522 /* sink.c: forwarding */
523 void smtp_close(struct query *, int);
524 int smtp_open(struct query *);
525 char *rcpt_address(struct query *, const char *, int);
526 int stuffline(struct query *, char *);
527 int open_sink(struct query*, struct msgblk *, int*, int*);
528 void release_sink(struct query *);
529 int close_sink(struct query *, struct msgblk *, flag);
530 int open_warning_by_mail(struct query *, struct msgblk *);
531 #if defined(HAVE_STDARG_H)
532 void stuff_warning(const char *, struct query *, const char *, ... )
533     __attribute__ ((format (printf, 3, 4)))
534     ;
535 #else
536 void stuff_warning();
537 #endif
538 void close_warning_by_mail(struct query *, struct msgblk *);
539
540 /* rfc822.c: RFC822 header parsing */
541 unsigned char *reply_hack(unsigned char *, const unsigned char *, size_t *);
542 unsigned char *nxtaddr(const unsigned char *);
543
544 /* uid.c: UID support */
545 extern int dofastuidl;
546
547 void initialize_saved_lists(struct query *, const char *);
548 struct idlist *save_str(struct idlist **, const char *, flag);
549 void free_str_list(struct idlist **);
550 struct idlist *copy_str_list(struct idlist *idl);
551 void save_str_pair(struct idlist **, const char *, const char *);
552 void free_str_pair_list(struct idlist **);
553 int delete_str(struct idlist **, long);
554 struct idlist *str_in_list(struct idlist **, const char *, const flag);
555 int str_nr_in_list(struct idlist **, const char *);
556 int str_nr_last_in_list(struct idlist **, const char *);
557 void str_set_mark( struct idlist **, const char *, const flag);
558 int count_list( struct idlist **idl );
559 char *str_from_nr_list( struct idlist **idl, long number );
560 char *str_find(struct idlist **, long);
561 struct idlist *id_find(struct idlist **idl, long);
562 char *idpair_find(struct idlist **, const char *);
563 void append_str_list(struct idlist **, struct idlist **);
564 void expunge_uids(struct query *);
565 void uid_swap_lists(struct query *);
566 void uid_discard_new_list(struct query *ctl);
567 void uid_reset_num(struct query *ctl);
568 void write_saved_lists(struct query *, const char *);
569
570 /* rcfile_y.y */
571 int prc_parse_file(const char *, const flag);
572 int prc_filecheck(const char *, const flag);
573
574 /* base64.c */
575 void to64frombits(unsigned char *, const unsigned char *, int);
576 int from64tobits(char *, const char *, int maxlen);
577
578 /* unmime.c */
579 /* Bit-mask returned by MimeBodyType */
580 #define MSG_IS_7BIT       0x01
581 #define MSG_IS_8BIT       0x02
582 #define MSG_NEEDS_DECODE  0x80
583 extern void UnMimeHeader(unsigned char *buf);
584 extern int  MimeBodyType(unsigned char *hdrs, int WantDecode);
585 extern int  UnMimeBodyline(unsigned char **buf, flag delimited, flag issoftline);
586
587 /* interface.c */
588 void interface_init(void);
589 void interface_parse(char *, struct hostdata *);
590 void interface_note_activity(struct hostdata *);
591 int interface_approve(struct hostdata *, flag domonitor);
592
593 /* xmalloc.c */
594 #if defined(HAVE_VOIDPOINTER)
595 #define XMALLOCTYPE void
596 #else
597 #define XMALLOCTYPE char
598 #endif
599 XMALLOCTYPE *xmalloc(size_t);
600 XMALLOCTYPE *xrealloc(/*@null@*/ XMALLOCTYPE *, size_t);
601 #define xfree(p) { if (p) { free(p); } (p) = 0; }
602 char *xstrdup(const char *);
603
604 /* protocol driver and methods */
605 int doPOP2 (struct query *); 
606 int doPOP3 (struct query *);
607 int doIMAP (struct query *);
608 int doETRN (struct query *);
609 int doODMR (struct query *);
610
611 /* authentication functions */
612 int do_cram_md5(int sock, char *command, struct query *ctl, char *strip);
613 int do_rfc1731(int sock, char *command, char *truename);
614 int do_gssauth(int sock, char *command, char *service, char *hostname, char *username);
615 int do_otp(int sock, char *command, struct query *ctl);
616
617 /* miscellanea */
618
619 /* these should be of size PATH_MAX */
620 extern char currentwd[1024], rcfiledir[1024];
621
622 struct query *hostalloc(struct query *); 
623 int parsecmdline (int, char **, struct runctl *, struct query *);
624 char *prependdir (const char *, const char *);
625 char *MD5Digest (unsigned char *);
626 void hmac_md5 (unsigned char *, size_t, unsigned char *, size_t, unsigned char *, size_t);
627 int POP3_auth_rpa(unsigned char *, unsigned char *, int socket);
628 typedef RETSIGTYPE (*SIGHANDLERTYPE) (int);
629 void deal_with_sigchld(void);
630 RETSIGTYPE null_signal_handler(int sig);
631 SIGHANDLERTYPE set_signal_handler(int sig, SIGHANDLERTYPE handler);
632 int daemonize(const char *, void (*)(int));
633 char *fm_getpassword(char *);
634 void escapes(const char *, char *);
635 char *visbuf(const char *);
636 const char *showproto(int);
637 void dump_config(struct runctl *runp, struct query *querylist);
638 int is_host_alias(const char *, struct query *);
639 char *host_fqdn(void);
640 char *rfc822timestamp(void);
641 flag isafile(int);
642 char *rfc2047e(const char*, const char *);
643
644 void yyerror(const char *);
645 int yylex(void);
646
647 #ifdef __EMX__
648 void itimerthread(void*);
649 /* Have to include these first to avoid errors from redefining getcwd
650    and chdir.  They're re-include protected in EMX, so it's okay, I
651    guess.  */
652 #include <stdlib.h>
653 #include <unistd.h>
654 /* Redefine getcwd and chdir to get drive-letter support so we can
655    find all of our lock files and stuff. */
656 #define getcwd _getcwd2
657 #define chdir _chdir2
658 #endif /* _EMX_ */
659
660 # if HAVE_STRERROR
661 #  ifndef strerror              /* On some systems, strerror is a macro */
662 char *strerror (int);
663 #  endif
664 # endif /* HAVE_STRERROR */
665
666 #define STRING_DISABLED (char *)-1
667 #define STRING_DUMMY    ""
668
669 #ifdef NeXT
670 #ifndef S_IXGRP
671 #define S_IXGRP 0000010
672 #endif
673 #endif
674
675 #ifndef HAVE_STPCPY
676 char *stpcpy(char *, const char*);
677 #endif
678
679 #ifdef FETCHMAIL_DEBUG
680 #define exit(e) do { \
681        FILE *out; \
682        out = fopen("/tmp/fetchmail.log", "a"); \
683        fprintf(out, \
684                "Exiting fetchmail from file %s, line %d with status %d\n", \
685                __FILE__, __LINE__, e); \
686        fclose(out); \
687        _exit(e); \
688        } while(0)
689 #endif /* FETCHMAIL_DEBUG */
690
691 #ifdef __CYGWIN__
692 #define ROOT_UID 18
693 #else /* !__CYGWIN__ */
694 #define ROOT_UID 0
695 #endif /* __CYGWIN__ */
696
697 extern int mailserver_socket_temp;
698 extern char *program_name;
699
700 /* POSIX space characters,
701  * <tab>;<newline>;<vertical-tab>;<form-feed>;<carriage-return>;<space> */
702 #define POSIX_space "\t\n\v\f\r "
703
704 /* strlcpy/strlcat prototypes */
705 #ifndef HAVE_STRLCAT
706 size_t
707 strlcat(char *dst, const char *src, size_t siz);
708 #endif
709 #ifndef HAVE_STRLCPY
710 size_t
711 strlcpy(char *dst, const char *src, size_t siz);
712 #endif
713
714 /** Resolve the a TCP service name or a string containing only a decimal
715  * positive integer to a port number. Returns -1 for error. */
716 int servport(const char *service);
717
718 #ifndef HAVE_GETNAMEINFO
719 # define NI_NUMERICHOST 1
720 # define NI_NUMERICSERV 2
721 # define NI_NOFQDN      4
722 # define NI_NAMEREQD    8
723 # define NI_DGRAM       16
724 #endif
725
726 #endif
727 /* fetchmail.h ends here */