2 * For license terms, see the file COPYING in this directory.
5 /* We need this for HAVE_STDARG_H, etc */
8 /* constants designating the various supported protocols */
20 #define KPOP_PORT "kpop"
22 #define KPOP_PORT 1109
25 /* preauthentication types */
26 #define A_PASSWORD 0 /* password or inline authentication */
27 #define A_KERBEROS_V4 1 /* preauthenticate w/ Kerberos V4 */
28 #define A_KERBEROS_V5 2 /* preauthenticate w/ Kerberos V5 */
31 * Definitions for buffer sizes. We get little help on setting maxima
32 * from IMAP RFCs up to 2060, so these are mostly from POP3.
34 #define HOSTLEN 635 /* max hostname length (RFC1123) */
35 #define POPBUFSIZE 512 /* max length of response (RFC1939) */
36 #define IDLEN 128 /* max length of UID (RFC1939) */
38 /* per RFC1939 this should be 40, but Microsoft Exchange ignores that limit */
39 #define USERNAMELEN 128 /* max POP3 arg length */
41 /* clear a netBSD kernel parameter out of the way */
45 * The RFC822 limit on message line size is just 998. But
46 * make this *way* oversized; idiot DOS-world mailers that
47 * don't line-wrap properly often ship entire paragraphs as
50 #define MSGBUFSIZE 8192
52 #define PASSWORDLEN 64 /* max password length */
53 #define DIGESTLEN 33 /* length of MD5 digest */
55 /* exit code values */
56 #define PS_SUCCESS 0 /* successful receipt of messages */
57 #define PS_NOMAIL 1 /* no mail available */
58 #define PS_SOCKET 2 /* socket I/O woes */
59 #define PS_AUTHFAIL 3 /* user authorization failed */
60 #define PS_PROTOCOL 4 /* protocol violation */
61 #define PS_SYNTAX 5 /* command-line syntax error */
62 #define PS_IOERR 6 /* bad permissions on rc file */
63 #define PS_ERROR 7 /* protocol error */
64 #define PS_EXCLUDE 8 /* client-side exclusion error */
65 #define PS_LOCKBUSY 9 /* server responded lock busy */
66 #define PS_SMTP 10 /* SMTP error */
67 #define PS_DNS 11 /* fatal DNS error */
68 #define PS_UNDEFINED 12 /* something I hadn't thought of */
69 #define PS_TRANSIENT 13 /* transient failure (internal use) */
70 #define PS_REFUSED 14 /* mail refused (internal use) */
71 #define PS_RETAINED 15 /* message retained (internal use) */
72 #define PS_TRUNCATED 16 /* headers incomplete (internal use) */
74 /* output noise level */
75 #define O_SILENT 0 /* mute, max squelch, etc. */
76 #define O_NORMAL 1 /* user-friendly */
77 #define O_VERBOSE 2 /* chatty */
78 #define O_DEBUG 3 /* prolix */
79 #define O_MONITOR O_VERBOSE
81 #define SIZETICKER 1024 /* print 1 dot per this many bytes */
84 * We #ifdef this and use flag rather than bool
85 * to avoid a type clash with curses.h
93 /* we need to use zero as a flag-uninitialized value */
104 const char *postmaster;
115 flag mark; /* UID-index information */
116 #define UID_UNSEEN 0 /* hasn't been seen */
117 #define UID_SEEN 1 /* seen, but not deleted */
118 #define UID_DELETED 2 /* this message has been deleted */
119 #define UID_EXPUNGED 3 /* this message has been expunged */
129 struct method /* describe methods for protocol state machine */
131 const char *name; /* protocol name */
135 int port; /* service port */
137 flag tagged; /* if true, generate & expect command tags */
138 flag delimited; /* if true, accept "." message delimiter */
139 int (*parse_response)(int, char *);
140 /* response_parsing function */
141 int (*password_canonify)(char *, char *);
142 /* canonicalize password */
143 int (*getauth)(int, struct query *, char *);
144 /* authorization fetcher */
145 int (*getrange)(int, struct query *, const char *, int *, int *, int *);
146 /* get message range to fetch */
147 int (*getsizes)(int, int, int *);
148 /* get sizes of messages */
149 int (*is_old)(int, struct query *, int);
150 /* check for old message */
151 int (*fetch_headers)(int, struct query *, int, int *);
152 /* fetch FROM headera given message */
153 int (*fetch_body)(int, struct query *, int, int *);
154 /* fetch a given message */
155 int (*trail)(int, struct query *, int);
156 /* eat trailer of a message */
157 int (*delete)(int, struct query *, int);
159 int (*logout_cmd)(int, struct query *);
161 flag retry; /* can getrange poll for new messages? */
164 struct hostdata /* shared among all user connections to given server */
167 char *pollname; /* poll label of host */
168 char *via; /* "true" server name if non-NULL */
169 struct idlist *akalist; /* server name first, then akas */
170 struct idlist *localdomains; /* list of pass-through domains */
171 int protocol; /* protocol type */
173 char *service; /* IPv6 service name */
174 void *netsec; /* IPv6 security request */
176 int port; /* TCP/IP service port number */
178 int interval; /* # cycles to skip between polls */
179 int preauthenticate; /* preauthentication mode to try */
180 int timeout; /* inactivity timout in seconds */
181 char *envelope; /* envelope address list header */
182 int envskip; /* skip to numbered envelope header */
183 char *qvirtual; /* prefix removed from local user id */
184 flag skip; /* suppress poll in implicit mode? */
185 flag dns; /* do DNS lookup on multidrop? */
186 flag uidl; /* use RFC1725 UIDLs? */
188 flag sdps; /* use Demon Internet SDPS *ENV */
189 #endif /* SDPS_ENABLE */
190 flag checkalias; /* resolve aliases by comparing IPs? */
197 struct interface_pair_s *interface_pair;
200 /* computed for internal use */
201 const struct method *base_protocol; /* relevant protocol method table */
202 int poll_count; /* count of polls so far */
203 char *queryname; /* name to attempt DNS lookup on */
204 char *truename; /* "true name" of server host */
205 struct hostdata *lead_server; /* ptr to lead query for this server */
211 /* mailserver connection controls */
212 struct hostdata server;
215 struct idlist *localnames; /* including calling user's name */
216 int wildcard; /* should unmatched names be passed through */
217 char *remotename; /* remote login name to use */
218 char *password; /* remote password to use */
219 struct idlist *mailboxes; /* list of mailboxes to check */
220 struct idlist *smtphunt; /* list of SMTP hosts to try forwarding to */
221 char *smtphost; /* actual SMTP host to point to */
222 char *smtpaddress; /* address we want to force in the delivery messages */
223 struct idlist *antispam; /* list of listener's antispam response */
224 char *mda; /* local MDA to pass mail to */
225 char *preconnect; /* pre-connection command to execute */
226 char *postconnect; /* post-connection command to execute */
228 /* per-user control flags */
229 flag keep; /* if TRUE, leave messages undeleted */
230 flag fetchall; /* if TRUE, fetch all (not just unseen) */
231 flag flush; /* if TRUE, delete messages already seen */
232 flag rewrite; /* if TRUE, canonicalize recipient addresses */
233 flag stripcr; /* if TRUE, strip CRs in text */
234 flag forcecr; /* if TRUE, force CRs before LFs in text */
235 flag pass8bits; /* if TRUE, ignore Content-Transfer-Encoding */
236 flag dropstatus; /* if TRUE, drop Status lines in mail */
237 flag mimedecode; /* if TRUE, decode MIME-coded headers/coded printable*/
238 int limit; /* limit size of retrieved messages */
239 int warnings; /* size warning interval */
240 int fetchlimit; /* max # msgs to get in single poll */
241 int batchlimit; /* max # msgs to pass in single SMTP session */
242 int expunge; /* max # msgs to pass between expunges */
243 char *properties; /* passthrough properties for extensions */
245 struct idlist *oldsaved, *newsaved;
247 /* internal use -- per-poll state */
248 flag active; /* should we actually poll this server? */
249 const char *destaddr; /* destination host for this query */
250 int errcount; /* count transient errors in last pass */
251 int smtp_socket; /* socket descriptor for SMTP connection */
252 unsigned int uid; /* UID of user to deliver to */
253 struct idlist *skipped; /* messages skipped on the mail server */
255 /* internal use -- per-message state */
256 int mimemsg; /* bitmask indicating MIME body-type */
257 char digest [DIGESTLEN]; /* md5 digest buffer */
259 /* internal use -- housekeeping */
260 struct query *next; /* next query control block in chain */
264 * Numeric option handling. Numeric option value of zero actually means
265 * it's unspecified. Value less than zero is zero.
267 #define NUM_VALUE(n) (((n) == 0) ? -1 : (n))
268 #define NUM_NONZERO(n) ((n) > 0)
269 #define NUM_ZERO(n) ((n) < 0)
270 #define NUM_SPECIFIED(n) ((n) != 0)
272 #define MULTIDROP(ctl) (ctl->wildcard || \
273 ((ctl)->localnames && (ctl)->localnames->next))
276 * Note: tags are generated with an a%04d format from a 1-origin
277 * integer sequence number. Length 4 permits transaction numbers
278 * up to 9999, so we force rollover with % 10000. There's no special
279 * reason for this format other than to look like the exmples in the
282 #define TAGLEN 6 /* 'a' + 4 digits + NUL */
283 extern char tag[TAGLEN];
286 /* list of hosts assembled from run control file and command line */
287 extern struct query cmd_opts, *querylist;
289 /* what's returned by envquery */
290 extern void envquery(int, char **);
292 /* controls the detail level of status/progress messages written to stderr */
293 extern int outlevel; /* see the O_.* constants above */
294 extern int yydebug; /* enable parse debugging */
296 /* these get computed */
297 extern int batchcount; /* count of messages sent in current batch */
298 extern flag peek_capable; /* can we read msgs without setting seen? */
300 /* miscellaneous global controls */
301 extern struct runctl run; /* global controls for this run */
302 extern flag nodetach; /* if TRUE, don't detach daemon process */
303 extern flag quitmode; /* if --quit was set */
304 extern flag check_only; /* if --check was set */
305 extern char *rcfile; /* path name of rc file */
306 extern int linelimit; /* limit # lines retrieved per site */
307 extern flag versioninfo; /* emit only version info */
308 extern char *user; /* name of invoking user */
309 extern char *home; /* home directory of invoking user */
310 extern int pass; /* number of re-polling pass */
311 extern flag configdump; /* dump control blocks as Python dictionary */
312 extern const char *fetchmailhost;
313 /* either "localhost" or an FQDN */
315 /* prototypes for globally callable functions */
317 /* error.c: Error reporting */
318 #if defined(HAVE_STDARG_H)
319 void error_init(int foreground);
320 void error (int status, int errnum, const char *format, ...);
321 void error_build (const char *format, ...);
322 void error_complete (int status, int errnum, const char *format, ...);
323 void error_at_line (int, int, const char *, unsigned int, const char *, ...);
327 void error_complete ();
328 void error_at_line ();
331 /* driver.c: transaction support */
332 void set_timeout(int);
333 #if defined(HAVE_STDARG_H)
334 void gen_send (int sock, const char *, ... );
335 int gen_recv(int sock, char *buf, int size);
336 int gen_transact (int sock, const char *, ... );
343 /* use these to track what was happening when the nonresponse timer fired */
344 #define GENERAL_WAIT 0 /* unknown wait type */
345 #define OPEN_WAIT 1 /* waiting from mailserver open */
346 #define SERVER_WAIT 2 /* waiting for mailserver response */
347 #define LISTENER_WAIT 3 /* waiting for listener initialization */
348 #define FORWARDING_WAIT 4 /* waiting for listener response */
351 /* mark values for name lists */
352 #define XMIT_ACCEPT 1
353 #define XMIT_REJECT 2
354 #define XMIT_ANTISPAM 3
356 /* sink.c: forwarding */
357 int stuffline(struct query *, char *);
358 int open_sink(struct query*, const char*, struct idlist*, long reallen, int*, int*);
359 void release_sink(struct query *);
360 int close_sink(struct query *, flag);
362 /* rfc822.c: RFC822 header parsing */
363 char *reply_hack(char *, const char *);
364 char *nxtaddr(const char *);
366 /* uid.c: UID support */
367 void initialize_saved_lists(struct query *, const char *);
368 struct idlist *save_str(struct idlist **, const char *, flag);
369 void free_str_list(struct idlist **);
370 void save_str_pair(struct idlist **, const char *, const char *);
371 void free_str_pair_list(struct idlist **);
372 int delete_str(struct idlist **, int);
373 int str_in_list(struct idlist **, const char *, const flag);
374 int str_nr_in_list(struct idlist **, const char *);
375 int str_nr_last_in_list(struct idlist **, const char *);
376 void str_set_mark( struct idlist **, const char *, const flag);
377 int count_list( struct idlist **idl );
378 char *str_from_nr_list( struct idlist **idl, int number );
379 char *str_find(struct idlist **, int);
380 char *idpair_find(struct idlist **, const char *);
381 void append_str_list(struct idlist **, struct idlist **);
382 void expunge_uids(struct query *);
383 void update_str_lists(struct query *);
384 void write_saved_lists(struct query *, const char *);
387 int prc_parse_file(const char *, const flag);
388 int prc_filecheck(const char *, const flag);
391 void to64frombits(unsigned char *, const unsigned char *, int);
392 int from64tobits(char *, const char *);
395 /* Bit-mask returned by MimeBodyType */
396 #define MSG_IS_7BIT 0x01
397 #define MSG_IS_8BIT 0x02
398 #define MSG_NEEDS_DECODE 0x80
399 extern void UnMimeHeader(unsigned char *buf);
400 extern int MimeBodyType(unsigned char *hdrs, int WantDecode);
401 extern int UnMimeBodyline(unsigned char **buf, int collapsedoubledot);
404 void interface_parse(char *, struct hostdata *);
405 void interface_note_activity(struct hostdata *);
406 int interface_approve(struct hostdata *);
409 #if defined(HAVE_VOIDPOINTER)
410 #define XMALLOCTYPE void
412 #define XMALLOCTYPE char
414 XMALLOCTYPE *xmalloc(int);
415 XMALLOCTYPE *xrealloc(XMALLOCTYPE *, int);
416 char *xstrdup(const char *);
417 #if defined(HAVE_ALLOCA_H)
424 #define xalloca(ptr, t, n) if (!(ptr = (t) alloca(n))) error(PS_UNDEFINED, 0, "alloca failed")
426 /* protocol driver and methods */
427 int do_protocol(struct query *, const struct method *);
428 int doPOP2 (struct query *);
429 int doPOP3 (struct query *);
430 int doIMAP (struct query *);
431 int doETRN (struct query *);
434 struct query *hostalloc(struct query *);
435 int parsecmdline (int, char **, struct runctl *, struct query *);
436 char *MD5Digest (unsigned char *);
437 int POP3_auth_rpa(unsigned char *, unsigned char *, int socket);
438 int daemonize(const char *, void (*)(int));
439 char *getpassword(char *);
440 void escapes(const char *, char *);
441 char *visbuf(const char *);
442 const char *showproto(int);
443 void dump_config(struct runctl *runp, struct query *querylist);
444 int is_host_alias(const char *, struct query *);
445 char *host_fqdn(void);
448 #endif /* SDPS_ENABLE */
450 void yyerror(const char *);
454 void itimerthread(void*);
455 /* Have to include these first to avoid errors from redefining getcwd
456 and chdir. They're re-include protected in EMX, so it's okay, I
460 /* Redefine getcwd and chdir to get drive-letter support so we can
461 find all of our lock files and stuff. */
462 #define getcwd _getcwd2
463 #define chdir _chdir2
466 #define STRING_DISABLED (char *)-1
467 #define STRING_DUMMY ""
469 /* fetchmail.h ends here */