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