]> Pileus Git - ~andy/fetchmail/blob - fetchmail.h
e18a7b5274404bb0b95d4801d144b07eb6280430
[~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_APOP          5
11 #define         P_RPOP          6
12
13 #define         KPOP_PORT       1109
14
15 /* authentication types */
16 #define         A_PASSWORD      0       /* passwords in cleartext */
17 #define         A_KERBEROS      1       /* get Kerberos V4 ticket */
18
19 /* definitions for buffer sizes -- somewhat arbitrary */
20 #define         POPBUFSIZE      512     /* per RFC 937 */
21 #define         MSGBUFSIZE      2048    /* size of message read buffer */
22 #define         HOSTLEN         128     /* max hostname length */
23 #define         USERNAMELEN     32      /* max user-name length */
24 #define         PASSWORDLEN     64      /* max password length */
25 #define         DIGESTLEN       33      /* length of MD5 digest */
26 #define         IDLEN           128     /* length of UIDL message ID */
27
28 /* exit code values */
29 #define         PS_SUCCESS      0       /* successful receipt of messages */
30 #define         PS_NOMAIL       1       /* no mail available */
31 #define         PS_SOCKET       2       /* socket I/O woes */
32 #define         PS_AUTHFAIL     3       /* user authorization failed */
33 #define         PS_PROTOCOL     4       /* protocol violation */
34 #define         PS_SYNTAX       5       /* command-line syntax error */
35 #define         PS_IOERR        6       /* bad permissions on rc file */
36 #define         PS_ERROR        7       /* protocol error */
37 #define         PS_EXCLUDE      8       /* exclusion error */
38 #define         PS_SMTP         9       /* SMTP error */
39 #define         PS_UNDEFINED    10      /* something I hadn't thought of */
40 #define         PS_TRANSIENT    11      /* transient failure (internal use) */
41
42 /* output noise level */
43 #define         O_SILENT        0       /* mute, max squelch, etc. */
44 #define         O_NORMAL        1       /* user-friendly */
45 #define         O_VERBOSE       2       /* excessive */
46
47 #define         SIZETICKER      1024    /* print 1 dot per this many bytes */
48
49 struct idlist
50 {
51     char *id;
52     union
53     {
54         int num;
55         char *id2;
56     } val;
57     struct idlist *next;
58 };
59
60
61 struct hostdata         /* shared among all user connections to given server */
62 {
63     /* rc file data */
64     struct idlist *names;               /* server name first, then akas */
65     struct idlist *localdomains;        /* list of pass-through domains */
66     int protocol;
67     int port;
68     int authenticate;
69     int timeout;
70     char *envelope;
71     int skip;
72     int no_dns;
73
74 #ifdef linux
75     char *interface;
76     char *monitor;
77     int  monitor_io;
78     struct interface_pair_s *interface_pair;
79 #endif /* linux */
80
81     /* computed for internal use */
82 #ifdef HAVE_GETHOSTBYNAME
83     char *canonical_name;               /* DNS canonical name of server host */
84 #endif /* HAVE_GETHOSTBYNAME */
85     struct hostdata *lead_server;       /* ptr to lead query for this server */
86     int esmtp_options;
87 };
88
89 struct query
90 {
91     /* mailserver connection controls */
92     struct hostdata server;
93
94     /* per-user data */
95     struct idlist *localnames;          /* including calling user's name */
96     int wildcard;               /* should unmatched names be passed through */
97     char *remotename;
98     char *password;
99     char *mailbox;
100     char *smtphost;
101     char *mda;
102     char *preconnect;
103
104     /* per-user control flags */
105     int keep;
106     int fetchall;
107     int flush;
108     int no_rewrite;
109     int limit;
110     int fetchlimit;
111     int batchlimit;
112
113     /* unseen, previous state of mailbox (initially from .fetchids) */
114     struct idlist *oldsaved, *newsaved;
115
116     /* internal use */
117     int active;
118     int errcount;               /* count transient errors in last pass */
119     struct query *next;         /* next query control block in chain */
120     struct query *lead_smtp;    /* pointer to this query's SMTP leader */
121     FILE *smtp_sockfp;          /* socket descriptor for SMTP connection */
122     unsigned int uid;           /* UID of user to deliver to */
123     char digest [DIGESTLEN];    /* md5 digest buffer */
124 };
125
126 #define MULTIDROP(ctl)  (ctl->wildcard || \
127                                 ((ctl)->localnames && (ctl)->localnames->next))
128
129 struct method
130 {
131     char *name;                 /* protocol name */
132     int port;                   /* service port */
133     int tagged;                 /* if true, generate & expect command tags */
134     int delimited;              /* if true, accept "." message delimiter */
135     int (*parse_response)();    /* response_parsing function */
136     int (*getauth)();           /* authorization fetcher */
137     int (*getrange)();          /* get message range to fetch */
138     int (*getsizes)();          /* get sizes of messages */
139     int (*is_old)();            /* check for old message */
140     int (*fetch)();             /* fetch a given message */
141     int (*trail)();             /* eat trailer of a message */
142     int (*delete)();            /* delete method */
143     char *exit_cmd;             /* exit command */
144 };
145
146 #define TAGLEN  6
147 extern char tag[TAGLEN];
148
149 /* list of hosts assembled from run control file and command line */
150 extern struct query cmd_opts, *querylist;
151
152 /* controls the detail level of status/progress messages written to stderr */
153 extern int outlevel;            /* see the O_.* constants above */
154 extern int yydebug;             /* enable parse debugging */
155
156 /* daemon mode control */
157 extern int poll_interval;       /* poll interval in seconds */
158 extern int nodetach;            /* if TRUE, don't detach daemon process */
159 extern char *logfile;           /* log file for daemon mode */
160 extern int use_syslog;          /* if --syslog was set */
161 extern int quitmode;            /* if --quit was set */
162 extern int check_only;          /* if --check was set */
163 extern char *cmd_logfile;       /* if --logfile was set */
164
165 /* these get computed */
166 extern int batchcount;          /* count of messages sent in current batch */
167 extern int peek_capable;        /* can we read msgs without setting seen? */
168
169 /* miscellaneous global controls */
170 extern char *rcfile;            /* path name of rc file */
171 extern char *idfile;            /* path name of UID file */
172 extern int linelimit;           /* limit # lines retrieved per site */
173 extern int versioninfo;         /* emit only version info */
174 extern char *user;              /* name of invoking user */
175
176 /* prototypes for globally callable functions */
177 #if defined(HAVE_STDARG_H)
178 void error_init(int foreground);
179 void error (int status, int errnum, const char *format, ...);
180 void error_build (const char *format, ...);
181 void error_complete (int status, int errnum, const char *format, ...);
182 void gen_send (FILE *sockfp, char *, ... );
183 int gen_recv(FILE *sockfp, char *buf, int size);
184 int gen_transact (FILE *sockfp, char *, ... );
185 #else
186 void error ();
187 void error_build ();
188 void error_complete ();
189 void gen_send ();
190 int gen_transact ();
191 #endif
192
193 void *xmalloc(int);
194 void *xrealloc(void *, int);
195 char *xstrdup(const char *);
196
197 int do_protocol(struct query *, const struct method *);
198 int doPOP2 (struct query *); 
199 int doPOP3 (struct query *);
200 int doIMAP (struct query *);
201
202 void reply_hack(char *, const char *);
203 char *nxtaddr(const char *);
204
205 void initialize_saved_lists(struct query *, const char *);
206 struct idlist *save_str(struct idlist **, int, const char *);
207 void free_str_list(struct idlist **);
208 void save_str_pair(struct idlist **, const char *, const char *);
209 void free_str_pair_list(struct idlist **);
210 int delete_str(struct idlist **, int);
211 int str_in_list(struct idlist **, const char *);
212 char *str_find(struct idlist **, int);
213 char *idpair_find(struct idlist **, const char *);
214 void append_str_list(struct idlist **, struct idlist **);
215 void update_str_lists(struct query *);
216 void write_saved_lists(struct query *, const char *);
217
218 struct query *hostalloc(struct query *); 
219 int parsecmdline (int, char **, struct query *);
220 void optmerge(struct query *, struct query *);
221 char *MD5Digest (char *);
222 int daemonize(const char *, void (*)(int));
223
224 int prc_parse_file(const char *);
225 int prc_filecheck(const char *);
226
227 void interface_parse(struct hostdata *);
228 void interface_note_activity(struct hostdata *);
229 int interface_approve(struct hostdata *);
230
231 char *getpassword(char *);
232
233 void escapes(const char *, char *);
234
235 void yyerror(const char *);
236 int yylex(void);
237
238 #define FALSE   0
239 #define TRUE    1