2 * For license terms, see the file COPYING in this directory.
5 /* constants designating the various supported protocols */
15 #define KPOP_PORT 1109
17 /* preauthentication types */
18 #define A_PASSWORD 0 /* password or inline authentication */
19 #define A_KERBEROS_V4 1 /* preauthenticate w/ Kerberos V4 */
21 /* definitions for buffer sizes -- somewhat arbitrary */
22 #define POPBUFSIZE 512 /* per RFC 937 */
23 #define MSGBUFSIZE 2048 /* size of message read buffer */
24 #define HOSTLEN 128 /* max hostname length */
25 #define USERNAMELEN 32 /* max user-name length */
26 #define PASSWORDLEN 64 /* max password length */
27 #define DIGESTLEN 33 /* length of MD5 digest */
28 #define IDLEN 128 /* length of UIDL message ID */
30 /* exit code values */
31 #define PS_SUCCESS 0 /* successful receipt of messages */
32 #define PS_NOMAIL 1 /* no mail available */
33 #define PS_SOCKET 2 /* socket I/O woes */
34 #define PS_AUTHFAIL 3 /* user authorization failed */
35 #define PS_PROTOCOL 4 /* protocol violation */
36 #define PS_SYNTAX 5 /* command-line syntax error */
37 #define PS_IOERR 6 /* bad permissions on rc file */
38 #define PS_ERROR 7 /* protocol error */
39 #define PS_EXCLUDE 8 /* client-side exclusion error */
40 #define PS_LOCKBUSY 9 /* server responded lock busy */
41 #define PS_SMTP 10 /* SMTP error */
42 #define PS_UNDEFINED 11 /* something I hadn't thought of */
43 #define PS_TRANSIENT 12 /* transient failure (internal use) */
44 #define PS_REFUSED 13 /* mail refused (internal use) */
46 /* output noise level */
47 #define O_SILENT 0 /* mute, max squelch, etc. */
48 #define O_NORMAL 1 /* user-friendly */
49 #define O_VERBOSE 2 /* excessive */
51 #define SIZETICKER 1024 /* print 1 dot per this many bytes */
53 /* we need to use zero as a flag-uninitialized value */
69 * We #ifdef this and use flag rather than bool
70 * to avoid a type clash with curses.h
78 struct hostdata /* shared among all user connections to given server */
81 char *via; /* "true" server name if non-NULL */
82 struct idlist *names; /* server name first, then akas */
83 struct idlist *localdomains; /* list of pass-through domains */
84 int protocol; /* protocol type */
85 int port; /* TCP/IP service port number */
86 int interval; /* # cycles to skip between polls */
87 int preauthenticate; /* preauthentication mode to try */
88 int timeout; /* inactivity timout in seconds */
89 char *envelope; /* envelope address list header */
90 flag skip; /* suppress poll in implicit mode? */
91 flag dns; /* do DNS lookup on multidrop? */
92 flag uidl; /* use RFC1725 UIDLs? */
98 struct interface_pair_s *interface_pair;
101 /* computed for internal use */
102 int poll_count; /* count of polls so far */
103 #ifdef HAVE_GETHOSTBYNAME
104 char *canonical_name; /* DNS canonical name of server host */
105 #endif /* HAVE_GETHOSTBYNAME */
106 struct hostdata *lead_server; /* ptr to lead query for this server */
112 /* mailserver connection controls */
113 struct hostdata server;
116 struct idlist *localnames; /* including calling user's name */
117 int wildcard; /* should unmatched names be passed through */
118 char *remotename; /* remote login name to use */
119 char *password; /* remote password to use */
120 struct idlist *mailboxes; /* list of mailboxes to check */
121 struct idlist *smtphunt; /* list of SMTP hosts to try forwarding to */
122 char *smtphost; /* actual SMTP host to point to */
123 char *mda; /* local MDA to pass mail to */
124 char *preconnect; /* pre-connection command to execute */
126 /* per-user control flags */
127 flag keep; /* if TRUE, leave messages undeleted */
128 flag fetchall; /* if TRUE, fetch all (not just unseen) */
129 flag flush; /* if TRUE, delete messages already seen */
130 flag rewrite; /* if TRUE, canonicalize recipient addresses */
131 flag stripcr; /* if TRUE, strip CRs in text */
132 flag forcecr; /* if TRUE, force CRs before LFs in text */
133 flag pass8bits; /* if TRUE, ignore Content-Transfer-Encoding */
134 flag dropstatus; /* if TRUE, drop Status lines in mail */
135 int limit; /* limit size of retrieved messages */
136 int fetchlimit; /* max # msgs to get in single poll */
137 int batchlimit; /* max # msgs to pass in single SMTP session */
139 /* unseen, previous state of mailbox (initially from .fetchids) */
140 struct idlist *oldsaved, *newsaved;
143 flag active; /* should we actually poll this server? */
144 int errcount; /* count transient errors in last pass */
145 int smtp_socket; /* socket descriptor for SMTP connection */
146 unsigned int uid; /* UID of user to deliver to */
147 char digest [DIGESTLEN]; /* md5 digest buffer */
148 struct query *next; /* next query control block in chain */
151 #define MULTIDROP(ctl) (ctl->wildcard || \
152 ((ctl)->localnames && (ctl)->localnames->next))
156 char *name; /* protocol name */
157 int port; /* service port */
158 flag tagged; /* if true, generate & expect command tags */
159 flag delimited; /* if true, accept "." message delimiter */
160 flag force_getsizes; /* if true, fetch's size return unreliable */
161 int (*parse_response)(); /* response_parsing function */
162 int (*getauth)(); /* authorization fetcher */
163 int (*getrange)(); /* get message range to fetch */
164 int (*getsizes)(); /* get sizes of messages */
165 int (*is_old)(); /* check for old message */
166 int (*fetch_headers)(); /* fetch FROM headera given message */
167 int (*fetch_body)(); /* fetch a given message */
168 int (*trail)(); /* eat trailer of a message */
169 int (*delete)(); /* delete method */
170 char *exit_cmd; /* exit command */
174 extern char tag[TAGLEN];
176 /* list of hosts assembled from run control file and command line */
177 extern struct query cmd_opts, *querylist;
179 /* what's returned by envquery */
180 extern void envquery(int, char **);
181 char *user, *home, *fetchmailhost;
183 /* controls the detail level of status/progress messages written to stderr */
184 extern int outlevel; /* see the O_.* constants above */
185 extern int yydebug; /* enable parse debugging */
187 /* daemon mode control */
188 extern int poll_interval; /* poll interval in seconds */
189 extern flag nodetach; /* if TRUE, don't detach daemon process */
190 extern char *logfile; /* log file for daemon mode */
191 extern flag use_syslog; /* if --syslog was set */
192 extern flag quitmode; /* if --quit was set */
193 extern flag check_only; /* if --check was set */
194 extern char *cmd_logfile; /* if --logfile was set */
195 extern int cmd_daemon; /* if --daemon was set */
197 /* these get computed */
198 extern int batchcount; /* count of messages sent in current batch */
199 extern flag peek_capable; /* can we read msgs without setting seen? */
201 /* miscellaneous global controls */
202 extern char *rcfile; /* path name of rc file */
203 extern char *idfile; /* path name of UID file */
204 extern int linelimit; /* limit # lines retrieved per site */
205 extern flag versioninfo; /* emit only version info */
206 extern char *user; /* name of invoking user */
207 extern char *fetchmailhost; /* the name of the host running fetchmail */
209 /* prototypes for globally callable functions */
210 #if defined(HAVE_STDARG_H)
211 void error_init(int foreground);
212 void error (int status, int errnum, const char *format, ...);
213 void error_build (const char *format, ...);
214 void error_complete (int status, int errnum, const char *format, ...);
215 void error_at_line (int, int, const char *, unsigned int, const char *, ...);
216 void gen_send (int sock, char *, ... );
217 int gen_recv(int sock, char *buf, int size);
218 int gen_transact (int sock, char *, ... );
222 void error_complete ();
223 void error_at_line ();
228 int do_protocol(struct query *, const struct method *);
229 int doPOP2 (struct query *);
230 int doPOP3 (struct query *);
231 int doIMAP (struct query *);
232 int doETRN (struct query *);
234 void reply_hack(char *, const char *);
235 char *nxtaddr(const char *);
238 void initialize_saved_lists(struct query *, const char *);
239 struct idlist *save_str(struct idlist **, int, const char *);
240 void free_str_list(struct idlist **);
241 void save_str_pair(struct idlist **, const char *, const char *);
242 void free_str_pair_list(struct idlist **);
243 int delete_str(struct idlist **, int);
244 int str_in_list(struct idlist **, const char *);
245 char *str_find(struct idlist **, int);
246 char *idpair_find(struct idlist **, const char *);
247 void append_str_list(struct idlist **, struct idlist **);
248 void update_str_lists(struct query *);
249 void write_saved_lists(struct query *, const char *);
251 struct query *hostalloc(struct query *);
252 int parsecmdline (int, char **, struct query *);
253 void optmerge(struct query *, struct query *);
254 char *MD5Digest (char *);
255 int daemonize(const char *, void (*)(int));
257 int prc_parse_file(const char *, flag);
258 int prc_filecheck(const char *);
260 void interface_parse(char *, struct hostdata *);
261 void interface_note_activity(struct hostdata *);
262 int interface_approve(struct hostdata *);
264 char *getpassword(char *);
266 void escapes(const char *, char *);
267 char *visbuf(const char *);
268 char *showproto(int);
270 void yyerror(const char *);
273 void to64frombits(unsigned char *, const unsigned char *, int);
274 int from64tobits(char *, const char *);
276 #if defined(HAVE_VOIDPOINTER)
277 #define XMALLOCTYPE void
279 #define XMALLOCTYPE char
282 XMALLOCTYPE *xmalloc(int);
283 XMALLOCTYPE *xrealloc(XMALLOCTYPE *, int);
284 char *xstrdup(const char *);
286 #define STRING_DISABLED (char *)-1
288 /* fetchmail.h ends here */