2 * For license terms, see the file COPYING in this directory.
5 /* constants designating the various supported protocols */
17 #define KPOP_PORT "kpop"
19 #define KPOP_PORT 1109
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 */
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.
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) */
36 /* clear a netBSD kernel parameter out of the way */
39 #define MSGBUFSIZE 2048 /* size of message read buffer */
40 #define PASSWORDLEN 64 /* max password length */
41 #define DIGESTLEN 33 /* length of MD5 digest */
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) */
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 */
67 #define SIZETICKER 1024 /* print 1 dot per this many bytes */
69 /* we need to use zero as a flag-uninitialized value */
85 * We #ifdef this and use flag rather than bool
86 * to avoid a type clash with curses.h
94 struct hostdata /* shared among all user connections to given server */
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 */
103 char *service; /* IPv6 service name */
104 void *netsec; /* IPv6 security request */
106 int port; /* TCP/IP service port number */
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? */
122 struct interface_pair_s *interface_pair;
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 */
135 /* mailserver connection controls */
136 struct hostdata server;
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 */
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 */
166 struct idlist *oldsaved, *newsaved;
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 */
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.
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 */
189 * Numeric option handling. Numeric option value of zero actually means
190 * it's unspecified. Value less than zero is zero.
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)
197 #define MULTIDROP(ctl) (ctl->wildcard || \
198 ((ctl)->localnames && (ctl)->localnames->next))
202 char *name; /* protocol name */
206 int port; /* service port */
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? */
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
230 #define TAGLEN 6 /* 'a' + 4 digits + NUL */
231 extern char tag[TAGLEN];
234 /* list of hosts assembled from run control file and command line */
235 extern struct query cmd_opts, *querylist;
237 /* what's returned by envquery */
238 extern void envquery(int, char **);
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 */
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 */
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? */
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 */
269 /* prototypes for globally callable functions */
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 *, ...);
281 void error_complete ();
282 void error_at_line ();
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 *, ... );
296 /* rfc822.c: RFC822 header parsing */
297 char *reply_hack(char *, const char *);
298 char *nxtaddr(const char *);
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 *);
320 int prc_parse_file(const char *, const flag);
321 int prc_filecheck(const char *);
324 void to64frombits(unsigned char *, const unsigned char *, int);
325 int from64tobits(char *, const char *);
328 void interface_parse(char *, struct hostdata *);
329 void interface_note_activity(struct hostdata *);
330 int interface_approve(struct hostdata *);
333 #if defined(HAVE_VOIDPOINTER)
334 #define XMALLOCTYPE void
336 #define XMALLOCTYPE char
338 XMALLOCTYPE *xmalloc(int);
339 XMALLOCTYPE *xrealloc(XMALLOCTYPE *, int);
340 char *xstrdup(const char *);
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 *);
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);
361 void yyerror(const char *);
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
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
377 #define STRING_DISABLED (char *)-1
379 /* fetchmail.h ends here */