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