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