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 */
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.
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) */
35 /* clear a netBSD kernel parameter out of the way */
38 #define MSGBUFSIZE 2048 /* size of message read buffer */
39 #define PASSWORDLEN 64 /* max password length */
40 #define DIGESTLEN 33 /* length of MD5 digest */
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) */
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 */
65 #define SIZETICKER 1024 /* print 1 dot per this many bytes */
67 /* we need to use zero as a flag-uninitialized value */
83 * We #ifdef this and use flag rather than bool
84 * to avoid a type clash with curses.h
92 struct hostdata /* shared among all user connections to given server */
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 */
101 char *service; /* IPv6 service name */
102 void *netsec; /* IPv6 security request */
104 int port; /* TCP/IP service port number */
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? */
120 struct interface_pair_s *interface_pair;
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 */
133 /* mailserver connection controls */
134 struct hostdata server;
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 */
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 */
163 struct idlist *oldsaved, *newsaved;
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 */
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.
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 */
186 * Numeric option handling. Numeric option value of zero actually means
187 * it's unspecified. Value less than zero is zero.
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)
194 #define MULTIDROP(ctl) (ctl->wildcard || \
195 ((ctl)->localnames && (ctl)->localnames->next))
199 char *name; /* protocol name */
203 int port; /* service port */
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? */
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
227 #define TAGLEN 6 /* 'a' + 4 digits + NUL */
228 extern char tag[TAGLEN];
231 /* list of hosts assembled from run control file and command line */
232 extern struct query cmd_opts, *querylist;
234 /* what's returned by envquery */
235 extern void envquery(int, char **);
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 */
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 */
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? */
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 */
266 /* prototypes for globally callable functions */
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 *, ...);
278 void error_complete ();
279 void error_at_line ();
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 *, ... );
293 /* rfc822.c: RFC822 header parsing */
294 char *reply_hack(char *, const char *);
295 char *nxtaddr(const char *);
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 *);
317 int prc_parse_file(const char *, const flag);
318 int prc_filecheck(const char *);
321 void to64frombits(unsigned char *, const unsigned char *, int);
322 int from64tobits(char *, const char *);
325 void interface_parse(char *, struct hostdata *);
326 void interface_note_activity(struct hostdata *);
327 int interface_approve(struct hostdata *);
330 #if defined(HAVE_VOIDPOINTER)
331 #define XMALLOCTYPE void
333 #define XMALLOCTYPE char
335 XMALLOCTYPE *xmalloc(int);
336 XMALLOCTYPE *xrealloc(XMALLOCTYPE *, int);
337 char *xstrdup(const char *);
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 *);
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);
358 void yyerror(const char *);
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
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
374 #define STRING_DISABLED (char *)-1
376 /* fetchmail.h ends here */