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