]> Pileus Git - ~andy/fetchmail/blob - fetchmail.h
Add prototypes for strlc?? functions.
[~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     void *netsec;                       /* IPv6 security request */
239 #else /* INET6_ENABLE */
240     int port;                           /* TCP/IP service port number */
241 #endif /* INET6_ENABLE */
242     int interval;                       /* # cycles to skip between polls */
243     int authenticate;                   /* authentication mode to try */
244     int timeout;                        /* inactivity timout in seconds */
245     char *envelope;                     /* envelope address list header */
246     int envskip;                        /* skip to numbered envelope header */
247     char *qvirtual;                     /* prefix removed from local user id */
248     flag skip;                          /* suppress poll in implicit mode? */
249     flag dns;                           /* do DNS lookup on multidrop? */
250     flag uidl;                          /* use RFC1725 UIDLs? */
251 #ifdef SDPS_ENABLE
252     flag sdps;                          /* use Demon Internet SDPS *ENV */
253 #endif /* SDPS_ENABLE */
254     flag checkalias;                    /* resolve aliases by comparing IPs? */
255     flag tracepolls;                    /* if TRUE, add poll trace info to Received */
256     char *principal;                    /* Kerberos principal for mail service */
257     char *esmtp_name, *esmtp_password;  /* ESMTP AUTH information */
258
259 #if defined(linux) || defined(__FreeBSD__)
260     char *interface;
261     char *monitor;
262     int  monitor_io;
263     struct interface_pair_s *interface_pair;
264 #endif /* linux */
265
266     char *plugin,*plugout;
267
268     /* computed for internal use */
269     const struct method *base_protocol; /* relevant protocol method table */
270     int poll_count;                     /* count of polls so far */
271     char *queryname;                    /* name to attempt DNS lookup on */
272     char *truename;                     /* "true name" of server host */
273     char *trueaddr;                     /* IP address of truename, as char */
274     struct hostdata *lead_server;       /* ptr to lead query for this server */
275     int esmtp_options;
276 };
277
278 struct query
279 {
280     /* mailserver connection controls */
281     struct hostdata server;
282
283     /* per-user data */
284     struct idlist *localnames;  /* including calling user's name */
285     int wildcard;               /* should unmatched names be passed through */
286     char *remotename;           /* remote login name to use */
287     char *password;             /* remote password to use */
288     struct idlist *mailboxes;   /* list of mailboxes to check */
289
290     /* per-forwarding-target data */
291     struct idlist *smtphunt;    /* list of SMTP hosts to try forwarding to */
292     struct idlist *domainlist;  /* domainlist to fetch from */
293     char *smtpaddress;          /* address to force in RCPT TO */ 
294     char *smtpname;             /* full RCPT TO name, including domain */
295     struct idlist *antispam;    /* list of listener's antispam response */
296     char *mda;                  /* local MDA to pass mail to */
297     char *bsmtp;                /* BSMTP output file */
298     char listener;              /* what's the listener's wire protocol? */
299 #define SMTP_MODE       'S'
300 #define LMTP_MODE       'L'
301     char *preconnect;           /* pre-connection command to execute */
302     char *postconnect;          /* post-connection command to execute */
303
304     /* per-user control flags */
305     flag keep;                  /* if TRUE, leave messages undeleted */
306     flag fetchall;              /* if TRUE, fetch all (not just unseen) */
307     flag flush;                 /* if TRUE, delete messages already seen */
308     flag rewrite;               /* if TRUE, canonicalize recipient addresses */
309     flag stripcr;               /* if TRUE, strip CRs in text */
310     flag forcecr;               /* if TRUE, force CRs before LFs in text */
311     flag pass8bits;             /* if TRUE, ignore Content-Transfer-Encoding */
312     flag dropstatus;            /* if TRUE, drop Status lines in mail */
313     flag dropdelivered;         /* if TRUE, drop Delivered-To lines in mail */
314     flag mimedecode;            /* if TRUE, decode MIME-armored messages */
315     flag idle;                  /* if TRUE, idle after each poll */
316     int limit;                  /* limit size of retrieved messages */
317     int warnings;               /* size warning interval */
318     int fetchlimit;             /* max # msgs to get in single poll */
319     int fetchsizelimit;         /* max # msg sizes to get in a request */
320     int fastuidl;               /* do binary search for new UIDLs? */
321     int fastuidlcount;          /* internal count for frequency of binary search */
322     int batchlimit;             /* max # msgs to pass in single SMTP session */
323     int expunge;                /* max # msgs to pass between expunges */
324     flag use_ssl;               /* use SSL encrypted session */
325     char *sslkey;               /* optional SSL private key file */
326     char *sslcert;              /* optional SSL certificate file */
327         char *sslproto;         /* force usage of protocol (ssl2|ssl3|tls1) - defaults to ssl23 */
328     char *sslcertpath;          /* Trusted certificate directory for checking the server cert */
329     flag sslcertck;             /* Strictly check the server cert. */
330     char *sslfingerprint;       /* Fingerprint to check against */
331     char *properties;           /* passthrough properties for extensions */
332
333     /* internal use -- per-poll state */
334     flag active;                /* should we actually poll this server? */
335     const char *destaddr;       /* destination host for this query */
336     int errcount;               /* count transient errors in last pass */
337     int authfailcount;          /* count of authorization failures */
338     int wehaveauthed;           /* We've managed to logon at least once! */
339     int wehavesentauthnote;     /* We've sent an authorization failure note */
340     int wedged;                 /* wedged by auth failures or timeouts? */
341     char *smtphost;             /* actual SMTP host we connected to */
342     int smtp_socket;            /* socket descriptor for SMTP connection */
343     unsigned int uid;           /* UID of user to deliver to */
344     struct idlist *skipped;     /* messages skipped on the mail server */
345     struct idlist *oldsaved, *newsaved;
346     struct idlist **oldsavedend;
347     char lastdigest[DIGESTLEN]; /* last MD5 hash seen on this connection */
348
349     /* internal use -- per-message state */
350     int mimemsg;                /* bitmask indicating MIME body-type */
351     char digest[DIGESTLEN];     /* md5 digest buffer */
352
353     /* internal use -- housekeeping */
354     struct query *next;         /* next query control block in chain */
355 };
356
357 struct msgblk                   /* message header parsed for open_sink() */
358 {
359     char                *headers;       /* raw message headers */
360     struct idlist       *recipients;    /* addressees */
361     char                return_path[HOSTLEN + USERNAMELEN + 4]; 
362     int                 msglen;
363     int                 reallen;
364 };
365
366
367 /*
368  * Numeric option handling.  Numeric option value of zero actually means
369  * it's unspecified.  Value less than zero is zero.  The reason for this
370  * screwy encoding is so we can zero out an option block in order to set the
371  * numeric flags in it to unspecified.
372  */
373 #define NUM_VALUE_IN(n)         (((n) == 0) ? -1 : (n))
374 #define NUM_VALUE_OUT(n)        (((n) < 0) ? 0 : (n))
375 #define NUM_NONZERO(n)          ((n) > 0)
376 #define NUM_ZERO(n)             ((n) < 0)
377 #define NUM_SPECIFIED(n)        ((n) != 0)
378
379 #define MULTIDROP(ctl)  (ctl->wildcard || \
380                                 ((ctl)->localnames && (ctl)->localnames->next))
381
382 /*
383  * Note: tags are generated with an a%04d format from a 1-origin
384  * integer sequence number.  Length 4 permits transaction numbers
385  * up to 9999, so we force rollover with % 10000.  There's no special
386  * reason for this format other than to look like the exmples in the
387  * IMAP RFCs.
388  */
389 #define TAGLEN  6               /* 'a' + 4 digits + NUL */
390 extern char tag[TAGLEN];
391 #define TAGMOD  10000
392
393 /* list of hosts assembled from run control file and command line */
394 extern struct query cmd_opts, *querylist;
395
396 /* what's returned by envquery */
397 extern void envquery(int, char **);
398
399 /* controls the detail level of status/progress messages written to stderr */
400 extern int outlevel;            /* see the O_.* constants above */
401 extern int yydebug;             /* enable parse debugging */
402
403 /* these get computed */
404 extern int batchcount;          /* count of messages sent in current batch */
405 extern flag peek_capable;       /* can we read msgs without setting seen? */
406
407 /* miscellaneous global controls */
408 extern struct runctl run;       /* global controls for this run */
409 extern flag nodetach;           /* if TRUE, don't detach daemon process */
410 extern flag quitmode;           /* if --quit was set */
411 extern flag check_only;         /* if --check was set */
412 extern char *rcfile;            /* path name of rc file */
413 extern int linelimit;           /* limit # lines retrieved per site */
414 extern flag versioninfo;        /* emit only version info */
415 extern char *user;              /* name of invoking user */
416 extern char *home;              /* home directory of invoking user */
417 extern char *fmhome;            /* fetchmail home directory */
418 extern int pass;                /* number of re-polling pass */
419 extern flag configdump;         /* dump control blocks as Python dictionary */
420 extern char *fetchmailhost;     /* either "localhost" or an FQDN */
421 extern int suppress_tags;       /* suppress tags in tagged protocols? */
422 extern char shroud[PASSWORDLEN*2+3];    /* string to shroud in debug output */
423 #ifdef SDPS_ENABLE
424 extern char *sdps_envfrom;
425 extern char *sdps_envto;
426 #endif /* SDPS_ENABLE */
427
428 extern const char *iana_charset;        /* IANA assigned charset name */
429
430 /* from ucs/norm_charmap.c */
431 const char *norm_charmap(const char *name);
432
433 /* prototypes for globally callable functions */
434
435 /* from /usr/include/sys/cdefs.h */
436 #if !defined __GNUC__ || __GNUC__ < 2
437 # define __attribute__(xyz)    /* Ignore. */
438 #endif
439
440 /* error.c: Error reporting */
441 #if defined(HAVE_STDARG_H)
442 void report_init(int foreground);
443 void report (FILE *fp, const char *format, ...)
444     __attribute__ ((format (printf, 2, 3)))
445     ;
446 void report_build (FILE *fp, const char *format, ...)
447     __attribute__ ((format (printf, 2, 3)))
448     ;
449 void report_complete (FILE *fp, const char *format, ...)
450     __attribute__ ((format (printf, 2, 3)))
451     ;
452 void report_at_line (FILE *fp, int, const char *, unsigned int, const char *, ...)
453     __attribute__ ((format (printf, 5, 6)))
454     ;
455 #else
456 void report ();
457 void report_build ();
458 void report_complete ();
459 void report_at_line ();
460 #endif
461
462 /* driver.c -- main driver loop */
463 void set_timeout(int);
464 int isidletimeout(void);
465 void resetidletimeout(void);
466 int do_protocol(struct query *, const struct method *);
467
468 /* transact.c: transaction support */
469 void init_transact(const struct method *);
470 int readheaders(int sock,
471                        long fetchlen,
472                        long reallen,
473                        struct query *ctl,
474                        int num,
475                        flag *suppress_readbody);
476 int readbody(int sock, struct query *ctl, flag forward, int len);
477 #if defined(HAVE_STDARG_H)
478 void gen_send(int sock, const char *, ... )
479     __attribute__ ((format (printf, 2, 3)))
480     ;
481 int gen_recv(int sock, char *buf, int size);
482 int gen_transact(int sock, const char *, ... )
483     __attribute__ ((format (printf, 2, 3)))
484     ;
485 #else
486 void gen_send();
487 int gen_recv();
488 int gen_transact();
489 #endif
490 extern struct msgblk msgblk;
491
492 /* lock.c: concurrency locking */
493 void lock_setup(void), lock_assert(void);
494 void lock_or_die(void), lock_release(void);
495 int lock_state(void);
496 void lock_dispose(void);
497
498 /* use these to track what was happening when the nonresponse timer fired */
499 #define GENERAL_WAIT    0       /* unknown wait type */
500 #define OPEN_WAIT       1       /* waiting from mailserver open */
501 #define SERVER_WAIT     2       /* waiting for mailserver response */
502 #define LISTENER_WAIT   3       /* waiting for listener initialization */
503 #define FORWARDING_WAIT 4       /* waiting for listener response */
504 extern int phase;
505
506 /* response hooks can use this to identify the query stage */
507 #define STAGE_GETAUTH   0
508 #define STAGE_GETRANGE  1
509 #define STAGE_GETSIZES  2
510 #define STAGE_FETCH     3
511 #define STAGE_IDLE      4
512 #define STAGE_LOGOUT    5
513 extern int stage;
514
515 extern int mytimeout;
516
517 /* mark values for name lists */
518 #define XMIT_ACCEPT     1       /* accepted; matches local domain or name */
519 #define XMIT_REJECT     2       /* rejected; no match */
520 #define XMIT_RCPTBAD    3       /* SMTP listener rejected the name */ 
521
522 /* idle.c */
523 int interruptible_idle(int interval);
524 extern volatile int lastsig;
525
526 /* sink.c: forwarding */
527 void smtp_close(struct query *, int);
528 int smtp_open(struct query *);
529 char *rcpt_address(struct query *, const char *, int);
530 int stuffline(struct query *, char *);
531 int open_sink(struct query*, struct msgblk *, int*, int*);
532 void release_sink(struct query *);
533 int close_sink(struct query *, struct msgblk *, flag);
534 int open_warning_by_mail(struct query *, struct msgblk *);
535 #if defined(HAVE_STDARG_H)
536 void stuff_warning(const char *, struct query *, const char *, ... )
537     __attribute__ ((format (printf, 3, 4)))
538     ;
539 #else
540 void stuff_warning();
541 #endif
542 void close_warning_by_mail(struct query *, struct msgblk *);
543
544 /* rfc822.c: RFC822 header parsing */
545 unsigned char *reply_hack(unsigned char *, const unsigned char *, size_t *);
546 unsigned char *nxtaddr(const unsigned char *);
547
548 /* uid.c: UID support */
549 extern int dofastuidl;
550
551 void initialize_saved_lists(struct query *, const char *);
552 struct idlist *save_str(struct idlist **, const char *, flag);
553 void free_str_list(struct idlist **);
554 struct idlist *copy_str_list(struct idlist *idl);
555 void save_str_pair(struct idlist **, const char *, const char *);
556 void free_str_pair_list(struct idlist **);
557 int delete_str(struct idlist **, long);
558 struct idlist *str_in_list(struct idlist **, const char *, const flag);
559 int str_nr_in_list(struct idlist **, const char *);
560 int str_nr_last_in_list(struct idlist **, const char *);
561 void str_set_mark( struct idlist **, const char *, const flag);
562 int count_list( struct idlist **idl );
563 char *str_from_nr_list( struct idlist **idl, long number );
564 char *str_find(struct idlist **, long);
565 struct idlist *id_find(struct idlist **idl, long);
566 char *idpair_find(struct idlist **, const char *);
567 void append_str_list(struct idlist **, struct idlist **);
568 void expunge_uids(struct query *);
569 void uid_swap_lists(struct query *);
570 void uid_discard_new_list(struct query *ctl);
571 void uid_reset_num(struct query *ctl);
572 void write_saved_lists(struct query *, const char *);
573
574 /* rcfile_y.y */
575 int prc_parse_file(const char *, const flag);
576 int prc_filecheck(const char *, const flag);
577
578 /* base64.c */
579 void to64frombits(unsigned char *, const unsigned char *, int);
580 int from64tobits(char *, const char *, int maxlen);
581
582 /* unmime.c */
583 /* Bit-mask returned by MimeBodyType */
584 #define MSG_IS_7BIT       0x01
585 #define MSG_IS_8BIT       0x02
586 #define MSG_NEEDS_DECODE  0x80
587 extern void UnMimeHeader(unsigned char *buf);
588 extern int  MimeBodyType(unsigned char *hdrs, int WantDecode);
589 extern int  UnMimeBodyline(unsigned char **buf, flag delimited, flag issoftline);
590
591 /* interface.c */
592 void interface_init(void);
593 void interface_parse(char *, struct hostdata *);
594 void interface_note_activity(struct hostdata *);
595 int interface_approve(struct hostdata *, flag domonitor);
596
597 /* xmalloc.c */
598 #if defined(HAVE_VOIDPOINTER)
599 #define XMALLOCTYPE void
600 #else
601 #define XMALLOCTYPE char
602 #endif
603 XMALLOCTYPE *xmalloc(size_t);
604 XMALLOCTYPE *xrealloc(/*@null@*/ XMALLOCTYPE *, size_t);
605 char *xstrdup(const char *);
606 #if defined(HAVE_ALLOCA_H)
607 #include <alloca.h>
608 #else
609 #ifdef _AIX
610 #pragma alloca
611 #endif
612 #endif
613 #define xalloca(ptr, t, n)      if (!(ptr = (t) alloca(n)))\
614        {report(stderr, GT_("alloca failed")); exit(PS_UNDEFINED);}
615 #if 0
616 /*
617  * This is a hack to help xgettext which cannot find strings in
618  * macro definitions like the one for xalloca above.
619  */
620 static char *dummy = gettext_noop("alloca failed");
621 #endif
622
623 /* protocol driver and methods */
624 int doPOP2 (struct query *); 
625 int doPOP3 (struct query *);
626 int doIMAP (struct query *);
627 int doETRN (struct query *);
628 int doODMR (struct query *);
629
630 /* authentication functions */
631 int do_cram_md5(int sock, char *command, struct query *ctl, char *strip);
632 int do_rfc1731(int sock, char *command, char *truename);
633 int do_gssauth(int sock, char *command, char *service, char *hostname, char *username);
634 int do_otp(int sock, char *command, struct query *ctl);
635
636 /* miscellanea */
637
638 /* these should be of size PATH_MAX */
639 extern char currentwd[1024], rcfiledir[1024];
640
641 struct query *hostalloc(struct query *); 
642 int parsecmdline (int, char **, struct runctl *, struct query *);
643 char *prependdir (const char *, const char *);
644 char *MD5Digest (unsigned char *);
645 void hmac_md5 (unsigned char *, size_t, unsigned char *, size_t, unsigned char *, size_t);
646 int POP3_auth_rpa(unsigned char *, unsigned char *, int socket);
647 typedef RETSIGTYPE (*SIGHANDLERTYPE) (int);
648 void deal_with_sigchld(void);
649 RETSIGTYPE null_signal_handler(int sig);
650 SIGHANDLERTYPE set_signal_handler(int sig, SIGHANDLERTYPE handler);
651 int daemonize(const char *, void (*)(int));
652 char *fm_getpassword(char *);
653 void escapes(const char *, char *);
654 char *visbuf(const char *);
655 const char *showproto(int);
656 void dump_config(struct runctl *runp, struct query *querylist);
657 int is_host_alias(const char *, struct query *);
658 char *host_fqdn(void);
659 char *rfc822timestamp(void);
660 flag isafile(int);
661 char *rfc2047e(const char*, const char *);
662
663 void yyerror(const char *);
664 int yylex(void);
665
666 #ifdef __EMX__
667 void itimerthread(void*);
668 /* Have to include these first to avoid errors from redefining getcwd
669    and chdir.  They're re-include protected in EMX, so it's okay, I
670    guess.  */
671 #include <stdlib.h>
672 #include <unistd.h>
673 /* Redefine getcwd and chdir to get drive-letter support so we can
674    find all of our lock files and stuff. */
675 #define getcwd _getcwd2
676 #define chdir _chdir2
677 #endif /* _EMX_ */
678
679 # if HAVE_STRERROR
680 #  ifndef strerror              /* On some systems, strerror is a macro */
681 char *strerror (int);
682 #  endif
683 # endif /* HAVE_STRERROR */
684
685 #define STRING_DISABLED (char *)-1
686 #define STRING_DUMMY    ""
687
688 #ifdef NeXT
689 #ifndef S_IXGRP
690 #define S_IXGRP 0000010
691 #endif
692 #endif
693
694 #ifndef HAVE_STPCPY
695 char *stpcpy(char *, const char*);
696 #endif
697
698 #ifdef FETCHMAIL_DEBUG
699 #define exit(e) do { \
700        FILE *out; \
701        out = fopen("/tmp/fetchmail.log", "a"); \
702        fprintf(out, \
703                "Exiting fetchmail from file %s, line %d with status %d\n", \
704                __FILE__, __LINE__, e); \
705        fclose(out); \
706        _exit(e); \
707        } while(0)
708 #endif /* FETCHMAIL_DEBUG */
709
710 #ifdef __CYGWIN__
711 #define ROOT_UID 18
712 #else /* !__CYGWIN__ */
713 #define ROOT_UID 0
714 #endif /* __CYGWIN__ */
715
716 extern int mailserver_socket_temp;
717 extern char *program_name;
718
719 /* POSIX space characters,
720  * <tab>;<newline>;<vertical-tab>;<form-feed>;<carriage-return>;<space> */
721 #define POSIX_space "\t\n\v\f\r "
722
723 /* strlcpy/strlcat prototypes */
724 #ifndef HAVE_STRLCAT
725 size_t
726 strlcat(chat *dst, const char *src, size_t siz);
727 #endif
728 #ifndef HAVE_STRLCPY
729 size_t
730 strlcpy(char *dst, const char *src, size_t siz);
731 #endif
732
733 /* fetchmail.h ends here */