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