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