]> Pileus Git - ~andy/fetchmail/blob - fetchmail.h
Configurable antispam response.
[~andy/fetchmail] / fetchmail.h
1 /*
2  * For license terms, see the file COPYING in this directory.
3  */
4
5 /* constants designating the various supported protocols */
6 #define         P_AUTO          0
7 #define         P_POP2          2
8 #define         P_POP3          3
9 #define         P_IMAP          4
10 #define         P_IMAP_K4       5
11 #define         P_IMAP_GSS      6
12 #define         P_APOP          7
13 #define         P_RPOP          8
14 #define         P_ETRN          9
15
16 #if INET6
17 #define         KPOP_PORT       "kpop"
18 #else /* INET6 */
19 #define         KPOP_PORT       1109
20 #endif /* INET6 */
21
22 /* preauthentication types */
23 #define         A_PASSWORD      0       /* password or inline authentication */
24 #define         A_KERBEROS_V4   1       /* preauthenticate w/ Kerberos V4 */
25 #define         A_KERBEROS_V5   2       /* preauthenticate w/ Kerberos V5 */
26
27 /*
28  * Definitions for buffer sizes.  We get little help on setting maxima
29  * from IMAP RFCs up to 2060, so these are mostly from POP3.
30  */
31 #define         HOSTLEN         635     /* max hostname length (RFC1123) */
32 #define         POPBUFSIZE      512     /* max length of response (RFC1939) */
33 #define         USERNAMELEN     40      /* max POP3 arg length (RFC1939) */
34 #define         IDLEN           128     /* max length of UID (RFC1939) */
35
36 /* clear a netBSD kernel parameter out of the way */ 
37 #undef          MSGBUFSIZE
38
39 #define         MSGBUFSIZE      2048    /* size of message read buffer */
40 #define         PASSWORDLEN     64      /* max password length */
41 #define         DIGESTLEN       33      /* length of MD5 digest */
42
43 /* exit code values */
44 #define         PS_SUCCESS      0       /* successful receipt of messages */
45 #define         PS_NOMAIL       1       /* no mail available */
46 #define         PS_SOCKET       2       /* socket I/O woes */
47 #define         PS_AUTHFAIL     3       /* user authorization failed */
48 #define         PS_PROTOCOL     4       /* protocol violation */
49 #define         PS_SYNTAX       5       /* command-line syntax error */
50 #define         PS_IOERR        6       /* bad permissions on rc file */
51 #define         PS_ERROR        7       /* protocol error */
52 #define         PS_EXCLUDE      8       /* client-side exclusion error */
53 #define         PS_LOCKBUSY     9       /* server responded lock busy */
54 #define         PS_SMTP         10      /* SMTP error */
55 #define         PS_DNS          11      /* fatal DNS error */   
56 #define         PS_UNDEFINED    12      /* something I hadn't thought of */
57 #define         PS_TRANSIENT    13      /* transient failure (internal use) */
58 #define         PS_REFUSED      14      /* mail refused (internal use) */
59 #define         PS_RETAINED     15      /* message retained (internal use) */
60 #define         PS_TRUNCATED    16      /* headers incomplete (internal use) */
61
62 /* output noise level */
63 #define         O_SILENT        0       /* mute, max squelch, etc. */
64 #define         O_NORMAL        1       /* user-friendly */
65 #define         O_VERBOSE       2       /* excessive */
66
67 #define         SIZETICKER      1024    /* print 1 dot per this many bytes */
68
69 /* we need to use zero as a flag-uninitialized value */
70 #define FLAG_TRUE       2
71 #define FLAG_FALSE      1
72
73 struct idlist
74 {
75     char *id;
76     union
77     {
78         int num;
79         char *id2;
80     } val;
81     struct idlist *next;
82 };
83
84 /*
85  * We #ifdef this and use flag rather than bool
86  * to avoid a type clash with curses.h
87  */
88 #ifndef TRUE
89 #define FALSE   0
90 #define TRUE    1
91 #endif /* TRUE */
92 typedef char    flag;
93
94 struct hostdata         /* shared among all user connections to given server */
95 {
96     /* rc file data */
97     char *pollname;                     /* poll label of host */
98     char *via;                          /* "true" server name if non-NULL */
99     struct idlist *akalist;             /* server name first, then akas */
100     struct idlist *localdomains;        /* list of pass-through domains */
101     int protocol;                       /* protocol type */
102 #if INET6
103     char *service;                      /* IPv6 service name */
104     void *netsec;                       /* IPv6 security request */
105 #else /* INET6 */
106     int port;                           /* TCP/IP service port number */
107 #endif /* INET6 */
108     int interval;                       /* # cycles to skip between polls */
109     int preauthenticate;                /* preauthentication mode to try */
110     int timeout;                        /* inactivity timout in seconds */
111     char *envelope;                     /* envelope address list header */
112     int envskip;                        /* skip to numbered envelope header */
113     char *qvirtual;                     /* prefix removed from local user id */
114     flag skip;                          /* suppress poll in implicit mode? */
115     flag dns;                           /* do DNS lookup on multidrop? */
116     flag uidl;                          /* use RFC1725 UIDLs? */
117
118 #ifdef linux
119     char *interface;
120     char *monitor;
121     int  monitor_io;
122     struct interface_pair_s *interface_pair;
123 #endif /* linux */
124
125     /* computed for internal use */
126     int poll_count;                     /* count of polls so far */
127     char *queryname;                    /* name to attempt DNS lookup on */
128     char *truename;                     /* "true name" of server host */
129     struct hostdata *lead_server;       /* ptr to lead query for this server */
130     int esmtp_options;
131 };
132
133 struct query
134 {
135     /* mailserver connection controls */
136     struct hostdata server;
137
138     /* per-user data */
139     struct idlist *localnames;  /* including calling user's name */
140     int wildcard;               /* should unmatched names be passed through */
141     char *remotename;           /* remote login name to use */
142     char *password;             /* remote password to use */
143     struct idlist *mailboxes;   /* list of mailboxes to check */
144     struct idlist *smtphunt;    /* list of SMTP hosts to try forwarding to */
145     char *smtphost;             /* actual SMTP host to point to */
146     char *smtpaddress;          /* address we want to force in the delivery messages */ 
147     int antispam;               /* listener's antispam response */
148     char *mda;                  /* local MDA to pass mail to */
149     char *preconnect;           /* pre-connection command to execute */
150     char *postconnect;          /* post-connection command to execute */
151
152     /* per-user control flags */
153     flag keep;                  /* if TRUE, leave messages undeleted */
154     flag fetchall;              /* if TRUE, fetch all (not just unseen) */
155     flag flush;                 /* if TRUE, delete messages already seen */
156     flag rewrite;               /* if TRUE, canonicalize recipient addresses */
157     flag stripcr;               /* if TRUE, strip CRs in text */
158     flag forcecr;               /* if TRUE, force CRs before LFs in text */
159     flag pass8bits;             /* if TRUE, ignore Content-Transfer-Encoding */
160     flag dropstatus;            /* if TRUE, drop Status lines in mail */
161     int limit;                  /* limit size of retrieved messages */
162     int fetchlimit;             /* max # msgs to get in single poll */
163     int batchlimit;             /* max # msgs to pass in single SMTP session */
164     int expunge;                /* max # msgs to pass between expunges */
165
166     struct idlist *oldsaved, *newsaved;
167
168     /* internal use */
169     flag active;                /* should we actually poll this server? */
170     int errcount;               /* count transient errors in last pass */
171     int smtp_socket;            /* socket descriptor for SMTP connection */
172     unsigned int uid;           /* UID of user to deliver to */
173     char digest [DIGESTLEN];    /* md5 digest buffer */
174     struct query *next;         /* next query control block in chain */
175 };
176
177 /*
178  * UID-index information.  If the sign bit is on, this means the 
179  * message UID has been seen or expunged and should be written
180  * out to .fetchids at end of run.
181  */
182 #define UID_KEPT        0               /* remembered from a previous run */
183 #define UID_DELETED     INT_MIN         /* this message has been deleted */
184 #define UID_EXPUNGED    INT_MAX         /* this message has been expunged */ 
185 #define SAVE_UID(n)     ((n) < 0)       /* must this UID be saved? */
186 #define MARK_SEEN(n)    n *= -1         /* mark a UID seen */
187
188 /*
189  * Numeric option handling.  Numeric option value of zero actually means
190  * it's unspecified.  Value less than zero is zero.
191  */
192 #define NUM_VALUE(n)            (((n) == 0) ? -1 : (n))
193 #define NUM_NONZERO(n)          ((n) > 0)
194 #define NUM_ZERO(n)             ((n) < 0)
195 #define NUM_SPECIFIED(n)        ((n) != 0)
196
197 #define MULTIDROP(ctl)  (ctl->wildcard || \
198                                 ((ctl)->localnames && (ctl)->localnames->next))
199
200 struct method
201 {
202     char *name;                 /* protocol name */
203 #if INET6
204     char *service;
205 #else /* INET6 */
206     int port;                   /* service port */
207 #endif /* INET6 */
208     flag tagged;                /* if true, generate & expect command tags */
209     flag delimited;             /* if true, accept "." message delimiter */
210     int (*parse_response)();    /* response_parsing function */
211     int (*getauth)();           /* authorization fetcher */
212     int (*getrange)();          /* get message range to fetch */
213     int (*getsizes)();          /* get sizes of messages */
214     int (*is_old)();            /* check for old message */
215     int (*fetch_headers)();     /* fetch FROM headera given message */
216     int (*fetch_body)();        /* fetch a given message */
217     int (*trail)();             /* eat trailer of a message */
218     int (*delete)();            /* delete method */
219     int (*logout_cmd)();        /* logout command */
220     flag retry;                 /* can getrange poll for new messages? */
221 };
222
223 /*
224  * Note: tags are generated with an a%04d format from a 1-origin
225  * integer sequence number.  Length 4 permits transaction numbers
226  * up to 9999, so we force rollover with % 10000.  There's no special
227  * reason for this format other than to look like the exmples in the
228  * IMAP RFCs.
229  */
230 #define TAGLEN  6               /* 'a' + 4 digits + NUL */
231 extern char tag[TAGLEN];
232 #define TAGMOD  10000
233
234 /* list of hosts assembled from run control file and command line */
235 extern struct query cmd_opts, *querylist;
236
237 /* what's returned by envquery */
238 extern void envquery(int, char **);
239
240 /* controls the detail level of status/progress messages written to stderr */
241 extern int outlevel;            /* see the O_.* constants above */
242 extern int yydebug;             /* enable parse debugging */
243
244 /* daemon mode control */
245 extern int poll_interval;       /* poll interval in seconds */
246 extern flag nodetach;           /* if TRUE, don't detach daemon process */
247 extern char *logfile;           /* log file for daemon mode */
248 extern flag errors_to_syslog;   /* if syslog was set */
249 extern flag use_invisible;      /* if invisible was set */
250 extern flag quitmode;           /* if --quit was set */
251 extern flag check_only;         /* if --check was set */
252 extern char *cmd_logfile;       /* if --logfile was set */
253 extern int cmd_daemon;          /* if --daemon was set */
254
255 /* these get computed */
256 extern int batchcount;          /* count of messages sent in current batch */
257 extern flag peek_capable;       /* can we read msgs without setting seen? */
258
259 /* miscellaneous global controls */
260 extern char *rcfile;            /* path name of rc file */
261 extern char *idfile;            /* path name of UID file */
262 extern int linelimit;           /* limit # lines retrieved per site */
263 extern flag versioninfo;        /* emit only version info */
264 extern char *user;              /* name of invoking user */
265 extern char *home;              /* home directory of invoking user */
266 extern char *fetchmailhost;     /* the name of the host running fetchmail */
267 extern int pass;                /* number of re-polling pass */
268
269 /* prototypes for globally callable functions */
270
271 /* error.c: Error reporting */
272 #if defined(HAVE_STDARG_H)
273 void error_init(int foreground);
274 void error (int status, int errnum, const char *format, ...);
275 void error_build (const char *format, ...);
276 void error_complete (int status, int errnum, const char *format, ...);
277 void error_at_line (int, int, const char *, unsigned int, const char *, ...);
278 #else
279 void error ();
280 void error_build ();
281 void error_complete ();
282 void error_at_line ();
283 #endif
284
285 /* driver.c: transaction support */
286 #if defined(HAVE_STDARG_H)
287 void gen_send (int sock, const char *, ... );
288 int gen_recv(int sock, char *buf, int size);
289 int gen_transact (int sock, char *, ... );
290 #else
291 void gen_send ();
292 int gen_recv();
293 int gen_transact ();
294 #endif
295
296 /* rfc822.c: RFC822 header parsing */
297 char *reply_hack(char *, const char *);
298 char *nxtaddr(const char *);
299
300 /* uid.c: UID support */
301 void initialize_saved_lists(struct query *, const char *);
302 struct idlist *save_str(struct idlist **, int, const char *);
303 void free_str_list(struct idlist **);
304 void save_str_pair(struct idlist **, const char *, const char *);
305 void free_str_pair_list(struct idlist **);
306 int delete_str(struct idlist **, int);
307 int str_in_list(struct idlist **, const char *);
308 int str_nr_in_list(struct idlist **, const char *);
309 int str_nr_last_in_list(struct idlist **, const char *);
310 int count_list( struct idlist **idl );
311 char *str_from_nr_list( struct idlist **idl, int number );
312 char *str_find(struct idlist **, int);
313 char *idpair_find(struct idlist **, const char *);
314 void append_str_list(struct idlist **, struct idlist **);
315 void expunge_uids(struct query *);
316 void update_str_lists(struct query *);
317 void write_saved_lists(struct query *, const char *);
318
319 /* rcfile_y.y */
320 int prc_parse_file(const char *, const flag);
321 int prc_filecheck(const char *);
322
323 /* base64.c */
324 void to64frombits(unsigned char *, const unsigned char *, int);
325 int from64tobits(char *, const char *);
326
327 /* interface.c */
328 void interface_parse(char *, struct hostdata *);
329 void interface_note_activity(struct hostdata *);
330 int interface_approve(struct hostdata *);
331
332 /* xmalloc.c */
333 #if defined(HAVE_VOIDPOINTER)
334 #define XMALLOCTYPE void
335 #else
336 #define XMALLOCTYPE char
337 #endif
338 XMALLOCTYPE *xmalloc(int);
339 XMALLOCTYPE *xrealloc(XMALLOCTYPE *, int);
340 char *xstrdup(const char *);
341
342 /* protocol driver and methods */
343 int do_protocol(struct query *, const struct method *);
344 int doPOP2 (struct query *); 
345 int doPOP3 (struct query *);
346 int doIMAP (struct query *);
347 int doETRN (struct query *);
348
349 /* miscellanea */
350 struct query *hostalloc(struct query *); 
351 int parsecmdline (int, char **, struct query *);
352 void optmerge(struct query *, struct query *);
353 char *MD5Digest (unsigned char *);
354 int POP3_auth_rpa(unsigned char *, unsigned char *, int socket);
355 int daemonize(const char *, void (*)(int));
356 char *getpassword(char *);
357 void escapes(const char *, char *);
358 char *visbuf(const char *);
359 char *showproto(int);
360
361 void yyerror(const char *);
362 int yylex(void);
363
364 #ifdef __EMX__
365 void itimerthread(void*);
366 /* Have to include these first to avoid errors from redefining getcwd
367    and chdir.  They're re-include protected in EMX, so it's okay, I
368    guess.  */
369 #include <stdlib.h>
370 #include <unistd.h>
371 /* Redefine getcwd and chdir to get drive-letter support so we can
372    find all of our lock files and stuff. */
373 #define getcwd _getcwd2
374 #define chdir _chdir2
375 #endif
376
377 #define STRING_DISABLED (char *)-1
378
379 /* fetchmail.h ends here */