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