]> Pileus Git - ~andy/fetchmail/blob - fetchmail.h
Try to fix the build code.
[~andy/fetchmail] / fetchmail.h
1 /*
2  * For license terms, see the file COPYING in this directory.
3  */
4
5 /* constants designating the various supported protocols */
6 #define         P_AUTO          0
7 #define         P_POP2          2
8 #define         P_POP3          3
9 #define         P_IMAP          4
10 #define         P_IMAP_K4       5
11 #define         P_APOP          6
12 #define         P_RPOP          7
13 #define         P_ETRN          8
14
15 #define         KPOP_PORT       1109
16
17 /* preauthentication types */
18 #define         A_PASSWORD      0       /* password or inline authentication */
19 #define         A_KERBEROS_V4   1       /* preauthenticate w/ Kerberos V4 */
20
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 */
29
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) */
45
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 */
50
51 #define         SIZETICKER      1024    /* print 1 dot per this many bytes */
52
53 /* we need to use zero as a flag-uninitialized value */
54 #define FLAG_TRUE       2
55 #define FLAG_FALSE      1
56
57 struct idlist
58 {
59     char *id;
60     union
61     {
62         int num;
63         char *id2;
64     } val;
65     struct idlist *next;
66 };
67
68 /*
69  * We #ifdef this and use flag rather than bool
70  * to avoid a type clash with curses.h
71  */
72 #ifndef TRUE
73 #define FALSE   0
74 #define TRUE    1
75 #endif /* TRUE */
76 typedef char    flag;
77
78 struct hostdata         /* shared among all user connections to given server */
79 {
80     /* rc file data */
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? */
93
94 #ifdef linux
95     char *interface;
96     char *monitor;
97     int  monitor_io;
98     struct interface_pair_s *interface_pair;
99 #endif /* linux */
100
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 */
107     int esmtp_options;
108 };
109
110 struct query
111 {
112     /* mailserver connection controls */
113     struct hostdata server;
114
115     /* per-user data */
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 */
125
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 */
138
139     /* unseen, previous state of mailbox (initially from .fetchids) */
140     struct idlist *oldsaved, *newsaved;
141
142     /* internal use */
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 */
149 };
150
151 #define MULTIDROP(ctl)  (ctl->wildcard || \
152                                 ((ctl)->localnames && (ctl)->localnames->next))
153
154 struct method
155 {
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 */
171 };
172
173 #define TAGLEN  6
174 extern char tag[TAGLEN];
175
176 /* list of hosts assembled from run control file and command line */
177 extern struct query cmd_opts, *querylist;
178
179 /* what's returned by envquery */
180 extern void envquery(int, char **);
181 char *user, *home, *fetchmailhost;
182
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 */
186
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 */
196
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? */
200
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 */
208
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 *, ... );
219 #else
220 void error ();
221 void error_build ();
222 void error_complete ();
223 void error_at_line ();
224 void gen_send ();
225 int gen_transact ();
226 #endif
227
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 *);
233
234 void reply_hack(char *, const char *);
235 char *nxtaddr(const char *);
236
237 /* UID support */
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 *);
250
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));
256
257 int prc_parse_file(const char *, flag);
258 int prc_filecheck(const char *);
259
260 void interface_parse(char *, struct hostdata *);
261 void interface_note_activity(struct hostdata *);
262 int interface_approve(struct hostdata *);
263
264 char *getpassword(char *);
265
266 void escapes(const char *, char *);
267 char *visbuf(const char *);
268 char *showproto(int);
269
270 void yyerror(const char *);
271 int yylex(void);
272
273 void to64frombits(unsigned char *, const unsigned char *, int);
274 int from64tobits(char *, const char *);
275
276 #if defined(HAVE_VOIDPOINTER)
277 #define XMALLOCTYPE void
278 #else
279 #define XMALLOCTYPE char
280 #endif
281
282 XMALLOCTYPE *xmalloc(int);
283 XMALLOCTYPE *xrealloc(XMALLOCTYPE *, int);
284 char *xstrdup(const char *);
285
286 #define STRING_DISABLED (char *)-1
287
288 /* fetchmail.h ends here */