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 IDLEN 128 /* max length of UID (RFC1939) */
35 /* per RFC1939 this should be 40, but Microsoft Exchange ignores that limit */
36 #define USERNAMELEN 128 /* max POP3 arg length */
38 /* clear a netBSD kernel parameter out of the way */
41 #define MSGBUFSIZE 998 /* RFC822 limit on message line size */
42 #define PASSWORDLEN 64 /* max password length */
43 #define DIGESTLEN 33 /* length of MD5 digest */
45 /* exit code values */
46 #define PS_SUCCESS 0 /* successful receipt of messages */
47 #define PS_NOMAIL 1 /* no mail available */
48 #define PS_SOCKET 2 /* socket I/O woes */
49 #define PS_AUTHFAIL 3 /* user authorization failed */
50 #define PS_PROTOCOL 4 /* protocol violation */
51 #define PS_SYNTAX 5 /* command-line syntax error */
52 #define PS_IOERR 6 /* bad permissions on rc file */
53 #define PS_ERROR 7 /* protocol error */
54 #define PS_EXCLUDE 8 /* client-side exclusion error */
55 #define PS_LOCKBUSY 9 /* server responded lock busy */
56 #define PS_SMTP 10 /* SMTP error */
57 #define PS_DNS 11 /* fatal DNS error */
58 #define PS_UNDEFINED 12 /* something I hadn't thought of */
59 #define PS_TRANSIENT 13 /* transient failure (internal use) */
60 #define PS_REFUSED 14 /* mail refused (internal use) */
61 #define PS_RETAINED 15 /* message retained (internal use) */
62 #define PS_TRUNCATED 16 /* headers incomplete (internal use) */
64 /* output noise level */
65 #define O_SILENT 0 /* mute, max squelch, etc. */
66 #define O_NORMAL 1 /* user-friendly */
67 #define O_VERBOSE 2 /* excessive */
69 #define SIZETICKER 1024 /* print 1 dot per this many bytes */
72 * We #ifdef this and use flag rather than bool
73 * to avoid a type clash with curses.h
81 /* we need to use zero as a flag-uninitialized value */
93 flag mark; /* UID-index information */
94 #define UID_UNSEEN 0 /* hasn't been seen */
95 #define UID_SEEN 1 /* seen, but not deleted */
96 #define UID_DELETED 2 /* this message has been deleted */
97 #define UID_EXPUNGED 3 /* this message has been expunged */
105 struct hostdata /* shared among all user connections to given server */
108 char *pollname; /* poll label of host */
109 char *via; /* "true" server name if non-NULL */
110 struct idlist *akalist; /* server name first, then akas */
111 struct idlist *localdomains; /* list of pass-through domains */
112 int protocol; /* protocol type */
114 char *service; /* IPv6 service name */
115 void *netsec; /* IPv6 security request */
117 int port; /* TCP/IP service port number */
119 int interval; /* # cycles to skip between polls */
120 int preauthenticate; /* preauthentication mode to try */
121 int timeout; /* inactivity timout in seconds */
122 char *envelope; /* envelope address list header */
123 int envskip; /* skip to numbered envelope header */
124 char *qvirtual; /* prefix removed from local user id */
125 flag skip; /* suppress poll in implicit mode? */
126 flag dns; /* do DNS lookup on multidrop? */
127 flag uidl; /* use RFC1725 UIDLs? */
133 struct interface_pair_s *interface_pair;
136 /* computed for internal use */
137 int poll_count; /* count of polls so far */
138 char *queryname; /* name to attempt DNS lookup on */
139 char *truename; /* "true name" of server host */
140 struct hostdata *lead_server; /* ptr to lead query for this server */
146 /* mailserver connection controls */
147 struct hostdata server;
150 struct idlist *localnames; /* including calling user's name */
151 int wildcard; /* should unmatched names be passed through */
152 char *remotename; /* remote login name to use */
153 char *password; /* remote password to use */
154 struct idlist *mailboxes; /* list of mailboxes to check */
155 struct idlist *smtphunt; /* list of SMTP hosts to try forwarding to */
156 char *smtphost; /* actual SMTP host to point to */
157 char *smtpaddress; /* address we want to force in the delivery messages */
158 int antispam; /* listener's antispam response */
159 char *mda; /* local MDA to pass mail to */
160 char *preconnect; /* pre-connection command to execute */
161 char *postconnect; /* post-connection command to execute */
163 /* per-user control flags */
164 flag keep; /* if TRUE, leave messages undeleted */
165 flag fetchall; /* if TRUE, fetch all (not just unseen) */
166 flag flush; /* if TRUE, delete messages already seen */
167 flag rewrite; /* if TRUE, canonicalize recipient addresses */
168 flag stripcr; /* if TRUE, strip CRs in text */
169 flag forcecr; /* if TRUE, force CRs before LFs in text */
170 flag pass8bits; /* if TRUE, ignore Content-Transfer-Encoding */
171 flag dropstatus; /* if TRUE, drop Status lines in mail */
172 flag mimedecode; /* if TRUE, decode MIME-coded headers/coded printable*/
173 int limit; /* limit size of retrieved messages */
174 int fetchlimit; /* max # msgs to get in single poll */
175 int batchlimit; /* max # msgs to pass in single SMTP session */
176 int expunge; /* max # msgs to pass between expunges */
178 struct idlist *oldsaved, *newsaved;
181 flag active; /* should we actually poll this server? */
182 int errcount; /* count transient errors in last pass */
183 int smtp_socket; /* socket descriptor for SMTP connection */
184 unsigned int uid; /* UID of user to deliver to */
185 char digest [DIGESTLEN]; /* md5 digest buffer */
186 struct query *next; /* next query control block in chain */
190 * Numeric option handling. Numeric option value of zero actually means
191 * it's unspecified. Value less than zero is zero.
193 #define NUM_VALUE(n) (((n) == 0) ? -1 : (n))
194 #define NUM_NONZERO(n) ((n) > 0)
195 #define NUM_ZERO(n) ((n) < 0)
196 #define NUM_SPECIFIED(n) ((n) != 0)
198 #define MULTIDROP(ctl) (ctl->wildcard || \
199 ((ctl)->localnames && (ctl)->localnames->next))
203 char *name; /* protocol name */
207 int port; /* service port */
209 flag tagged; /* if true, generate & expect command tags */
210 flag delimited; /* if true, accept "." message delimiter */
211 int (*parse_response)(); /* response_parsing function */
212 int (*password_canonify)(); /* canonicalize password */
213 int (*getauth)(); /* authorization fetcher */
214 int (*getrange)(); /* get message range to fetch */
215 int (*getsizes)(); /* get sizes of messages */
216 int (*is_old)(); /* check for old message */
217 int (*fetch_headers)(); /* fetch FROM headera given message */
218 int (*fetch_body)(); /* fetch a given message */
219 int (*trail)(); /* eat trailer of a message */
220 int (*delete)(); /* delete method */
221 int (*logout_cmd)(); /* logout command */
222 flag retry; /* can getrange poll for new messages? */
226 * Note: tags are generated with an a%04d format from a 1-origin
227 * integer sequence number. Length 4 permits transaction numbers
228 * up to 9999, so we force rollover with % 10000. There's no special
229 * reason for this format other than to look like the exmples in the
232 #define TAGLEN 6 /* 'a' + 4 digits + NUL */
233 extern char tag[TAGLEN];
236 /* list of hosts assembled from run control file and command line */
237 extern struct query cmd_opts, *querylist;
239 /* what's returned by envquery */
240 extern void envquery(int, char **);
242 /* controls the detail level of status/progress messages written to stderr */
243 extern int outlevel; /* see the O_.* constants above */
244 extern int yydebug; /* enable parse debugging */
246 /* daemon mode control */
247 extern int poll_interval; /* poll interval in seconds */
248 extern flag nodetach; /* if TRUE, don't detach daemon process */
249 extern char *logfile; /* log file for daemon mode */
250 extern flag errors_to_syslog; /* if syslog was set */
251 extern flag use_invisible; /* if invisible was set */
252 extern flag quitmode; /* if --quit was set */
253 extern flag check_only; /* if --check was set */
254 extern char *cmd_logfile; /* if --logfile was set */
255 extern int cmd_daemon; /* if --daemon was set */
257 /* these get computed */
258 extern int batchcount; /* count of messages sent in current batch */
259 extern flag peek_capable; /* can we read msgs without setting seen? */
261 /* miscellaneous global controls */
262 extern char *rcfile; /* path name of rc file */
263 extern char *idfile; /* path name of UID file */
264 extern int linelimit; /* limit # lines retrieved per site */
265 extern flag versioninfo; /* emit only version info */
266 extern char *user; /* name of invoking user */
267 extern char *home; /* home directory of invoking user */
268 extern char *fetchmailhost; /* the name of the host running fetchmail */
269 extern int pass; /* number of re-polling pass */
271 /* prototypes for globally callable functions */
273 /* error.c: Error reporting */
274 #if defined(HAVE_STDARG_H)
275 void error_init(int foreground);
276 void error (int status, int errnum, const char *format, ...);
277 void error_build (const char *format, ...);
278 void error_complete (int status, int errnum, const char *format, ...);
279 void error_at_line (int, int, const char *, unsigned int, const char *, ...);
283 void error_complete ();
284 void error_at_line ();
287 /* driver.c: transaction support */
288 #if defined(HAVE_STDARG_H)
289 void gen_send (int sock, const char *, ... );
290 int gen_recv(int sock, char *buf, int size);
291 int gen_transact (int sock, char *, ... );
298 /* rfc822.c: RFC822 header parsing */
299 char *reply_hack(char *, const char *);
300 char *nxtaddr(const char *);
302 /* uid.c: UID support */
303 void initialize_saved_lists(struct query *, const char *);
304 struct idlist *save_str(struct idlist **, const char *, flag);
305 void free_str_list(struct idlist **);
306 void save_str_pair(struct idlist **, const char *, const char *);
307 void free_str_pair_list(struct idlist **);
308 int delete_str(struct idlist **, int);
309 int str_in_list(struct idlist **, const char *, const flag);
310 int str_nr_in_list(struct idlist **, const char *);
311 int str_nr_last_in_list(struct idlist **, const char *);
312 void str_set_mark( struct idlist **, const char *, const flag);
313 int count_list( struct idlist **idl );
314 char *str_from_nr_list( struct idlist **idl, int number );
315 char *str_find(struct idlist **, int);
316 char *idpair_find(struct idlist **, const char *);
317 void append_str_list(struct idlist **, struct idlist **);
318 void expunge_uids(struct query *);
319 void update_str_lists(struct query *);
320 void write_saved_lists(struct query *, const char *);
323 int prc_parse_file(const char *, const flag);
324 int prc_filecheck(const char *);
327 void to64frombits(unsigned char *, const unsigned char *, int);
328 int from64tobits(char *, const char *);
331 /* Bit-mask returned by MimeBodyType */
332 #define MSG_IS_7BIT 0x01
333 #define MSG_IS_8BIT 0x02
334 #define MSG_NEEDS_DECODE 0x80
335 extern void UnMimeHeader(unsigned char *buf);
336 extern int MimeBodyType(unsigned char *hdrs);
337 extern int UnMimeBodyline(unsigned char **buf, int collapsedoubledot);
340 void interface_parse(char *, struct hostdata *);
341 void interface_note_activity(struct hostdata *);
342 int interface_approve(struct hostdata *);
345 #if defined(HAVE_VOIDPOINTER)
346 #define XMALLOCTYPE void
348 #define XMALLOCTYPE char
350 XMALLOCTYPE *xmalloc(int);
351 XMALLOCTYPE *xrealloc(XMALLOCTYPE *, int);
352 char *xstrdup(const char *);
354 /* protocol driver and methods */
355 int do_protocol(struct query *, const struct method *);
356 int doPOP2 (struct query *);
357 int doPOP3 (struct query *);
358 int doIMAP (struct query *);
359 int doETRN (struct query *);
362 struct query *hostalloc(struct query *);
363 int parsecmdline (int, char **, struct query *);
364 void optmerge(struct query *, struct query *);
365 char *MD5Digest (unsigned char *);
366 int POP3_auth_rpa(unsigned char *, unsigned char *, int socket);
367 int daemonize(const char *, void (*)(int));
368 char *getpassword(char *);
369 void escapes(const char *, char *);
370 char *visbuf(const char *);
371 char *showproto(int);
373 void yyerror(const char *);
377 void itimerthread(void*);
378 /* Have to include these first to avoid errors from redefining getcwd
379 and chdir. They're re-include protected in EMX, so it's okay, I
383 /* Redefine getcwd and chdir to get drive-letter support so we can
384 find all of our lock files and stuff. */
385 #define getcwd _getcwd2
386 #define chdir _chdir2
389 #define STRING_DISABLED (char *)-1
391 /* fetchmail.h ends here */