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