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