2 * For license terms, see the file COPYING in this directory.
5 /* constants designating the various supported protocols */
14 #define KPOP_PORT 1109
16 /* authentication types */
17 #define A_PASSWORD 0 /* password or inline authentication */
18 #define A_KERBEROS_V4 1 /* preauthenticate w/ Kerberos V4 */
20 /* definitions for buffer sizes -- somewhat arbitrary */
21 #define POPBUFSIZE 512 /* per RFC 937 */
22 #define MSGBUFSIZE 2048 /* size of message read buffer */
23 #define HOSTLEN 128 /* max hostname length */
24 #define USERNAMELEN 32 /* max user-name length */
25 #define PASSWORDLEN 64 /* max password length */
26 #define DIGESTLEN 33 /* length of MD5 digest */
27 #define IDLEN 128 /* length of UIDL message ID */
29 /* exit code values */
30 #define PS_SUCCESS 0 /* successful receipt of messages */
31 #define PS_NOMAIL 1 /* no mail available */
32 #define PS_SOCKET 2 /* socket I/O woes */
33 #define PS_AUTHFAIL 3 /* user authorization failed */
34 #define PS_PROTOCOL 4 /* protocol violation */
35 #define PS_SYNTAX 5 /* command-line syntax error */
36 #define PS_IOERR 6 /* bad permissions on rc file */
37 #define PS_ERROR 7 /* protocol error */
38 #define PS_EXCLUDE 8 /* exclusion error */
39 #define PS_SMTP 9 /* SMTP error */
40 #define PS_UNDEFINED 10 /* something I hadn't thought of */
41 #define PS_TRANSIENT 11 /* transient failure (internal use) */
43 /* output noise level */
44 #define O_SILENT 0 /* mute, max squelch, etc. */
45 #define O_NORMAL 1 /* user-friendly */
46 #define O_VERBOSE 2 /* excessive */
48 #define SIZETICKER 1024 /* print 1 dot per this many bytes */
50 /* we need to use zero as a flag-uninitialized value */
66 struct hostdata /* shared among all user connections to given server */
69 struct idlist *names; /* server name first, then akas */
70 struct idlist *localdomains; /* list of pass-through domains */
84 struct interface_pair_s *interface_pair;
87 /* computed for internal use */
88 #ifdef HAVE_GETHOSTBYNAME
89 char *canonical_name; /* DNS canonical name of server host */
90 #endif /* HAVE_GETHOSTBYNAME */
91 struct hostdata *lead_server; /* ptr to lead query for this server */
97 /* mailserver connection controls */
98 struct hostdata server;
101 struct idlist *localnames; /* including calling user's name */
102 int wildcard; /* should unmatched names be passed through */
106 struct idlist *smtphunt;
111 /* per-user control flags */
122 /* unseen, previous state of mailbox (initially from .fetchids) */
123 struct idlist *oldsaved, *newsaved;
127 int errcount; /* count transient errors in last pass */
128 struct query *next; /* next query control block in chain */
129 int smtp_socket; /* socket descriptor for SMTP connection */
130 unsigned int uid; /* UID of user to deliver to */
131 char digest [DIGESTLEN]; /* md5 digest buffer */
134 #define MULTIDROP(ctl) (ctl->wildcard || \
135 ((ctl)->localnames && (ctl)->localnames->next))
139 char *name; /* protocol name */
140 int port; /* service port */
141 int tagged; /* if true, generate & expect command tags */
142 int delimited; /* if true, accept "." message delimiter */
143 int (*parse_response)(); /* response_parsing function */
144 int (*getauth)(); /* authorization fetcher */
145 int (*getrange)(); /* get message range to fetch */
146 int (*getsizes)(); /* get sizes of messages */
147 int (*is_old)(); /* check for old message */
148 int (*fetch)(); /* fetch a given message */
149 int (*trail)(); /* eat trailer of a message */
150 int (*delete)(); /* delete method */
151 char *exit_cmd; /* exit command */
155 extern char tag[TAGLEN];
157 /* list of hosts assembled from run control file and command line */
158 extern struct query cmd_opts, *querylist;
160 /* controls the detail level of status/progress messages written to stderr */
161 extern int outlevel; /* see the O_.* constants above */
162 extern int yydebug; /* enable parse debugging */
164 /* daemon mode control */
165 extern int poll_interval; /* poll interval in seconds */
166 extern int nodetach; /* if TRUE, don't detach daemon process */
167 extern char *logfile; /* log file for daemon mode */
168 extern int use_syslog; /* if --syslog was set */
169 extern int quitmode; /* if --quit was set */
170 extern int check_only; /* if --check was set */
171 extern char *cmd_logfile; /* if --logfile was set */
172 extern int cmd_daemon; /* if --daemon was set */
174 /* these get computed */
175 extern int batchcount; /* count of messages sent in current batch */
176 extern int peek_capable; /* can we read msgs without setting seen? */
178 /* miscellaneous global controls */
179 extern char *rcfile; /* path name of rc file */
180 extern char *idfile; /* path name of UID file */
181 extern int linelimit; /* limit # lines retrieved per site */
182 extern int versioninfo; /* emit only version info */
183 extern char *user; /* name of invoking user */
184 extern char *fetchmailhost; /* the name of the host running fetchmail */
186 /* prototypes for globally callable functions */
187 #if defined(HAVE_STDARG_H)
188 void error_init(int foreground);
189 void error (int status, int errnum, const char *format, ...);
190 void error_build (const char *format, ...);
191 void error_complete (int status, int errnum, const char *format, ...);
192 void gen_send (int sock, char *, ... );
193 int gen_recv(int sock, char *buf, int size);
194 int gen_transact (int sock, char *, ... );
198 void error_complete ();
203 int do_protocol(struct query *, const struct method *);
204 int doPOP2 (struct query *);
205 int doPOP3 (struct query *);
206 int doIMAP (struct query *);
207 int doETRN (struct query *);
209 void reply_hack(char *, const char *);
210 char *nxtaddr(const char *);
212 void initialize_saved_lists(struct query *, const char *);
213 struct idlist *save_str(struct idlist **, int, const char *);
214 void free_str_list(struct idlist **);
215 void save_str_pair(struct idlist **, const char *, const char *);
216 void free_str_pair_list(struct idlist **);
217 int delete_str(struct idlist **, int);
218 int str_in_list(struct idlist **, const char *);
219 char *str_find(struct idlist **, int);
220 char *idpair_find(struct idlist **, const char *);
221 void append_str_list(struct idlist **, struct idlist **);
222 void update_str_lists(struct query *);
223 void write_saved_lists(struct query *, const char *);
225 struct query *hostalloc(struct query *);
226 int parsecmdline (int, char **, struct query *);
227 void optmerge(struct query *, struct query *);
228 char *MD5Digest (char *);
229 int daemonize(const char *, void (*)(int));
231 int prc_parse_file(const char *);
232 int prc_filecheck(const char *);
234 void interface_parse(char *, struct hostdata *);
235 void interface_note_activity(struct hostdata *);
236 int interface_approve(struct hostdata *);
238 char *getpassword(char *);
240 void escapes(const char *, char *);
242 void yyerror(const char *);
245 #if defined(HAVE_VOIDPOINTER)
246 #define XMALLOCTYPE void
248 #define XMALLOCTYPE char
251 XMALLOCTYPE *xmalloc(int);
252 XMALLOCTYPE *xrealloc(XMALLOCTYPE *, int);
253 char *xstrdup(const char *);
258 #define STRING_DISABLED (char *)-1