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