]> Pileus Git - ~andy/fetchmail/blob - fetchmail.h
STEP 9: Eliminate the static buffer in the socket library.
[~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
12 #define         KPOP_PORT       1109
13
14 /* authentication types */
15 #define         A_PASSWORD      0       /* passwords in cleartext */
16 #define         A_KERBEROS      1       /* get Kerberos V4 ticket */
17
18 /* definitions for buffer sizes -- somewhat arbitrary */
19 #define         POPBUFSIZE      512     /* per RFC 937 */
20 #define         MSGBUFSIZE      2048    /* size of message read buffer */
21 #define         HOSTLEN         128     /* max hostname length */
22 #define         USERNAMELEN     32      /* max user-length */
23 #define         PASSWORDLEN     MAX_PASSWORD_LENGTH
24 #define         FOLDERLEN       256     /* max folder name length */
25 #define         DIGESTLEN       33      /* length of MD5 digest */
26 #define         MDALEN          256     /* length of delivery agent command */
27 #define         IDLEN           128     /* length of UIDL message ID */
28
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
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 #define         MDA_MAXARGS     32      /* max arguments per MDA call */
49
50 struct idlist
51 {
52     char *id;
53     union
54     {
55         int num;
56         char *id2;
57     } val;
58     struct idlist *next;
59 };
60
61 struct query
62 {
63     /* per-host data */
64     char servername [HOSTLEN+1];
65     struct idlist *localnames;
66     int protocol;
67     int port;
68     int authenticate;
69     int timeout;
70     int skip;
71
72     /* per-user data */
73     char remotename [USERNAMELEN+1];
74     char password [PASSWORDLEN+1];
75     char mailbox [FOLDERLEN];
76     char smtphost[HOSTLEN+1];
77     char mda [MDALEN+1];
78
79     /* per-user MDA arguments */
80     int mda_argcount;
81     char *mda_argv[MDA_MAXARGS];
82
83     /* per-user control flags */
84     int keep;
85     int fetchall;
86     int flush;
87     int norewrite;
88     int limit;
89
90     /* unseen, previous state of mailbox (initially from .fetchids) */
91     struct idlist *oldsaved, *newsaved;
92
93     /* internal use */
94     int active;
95     struct query *next;         /* next query control block in chain */
96     struct query *leader;       /* pointer to this query's SMTP leader */
97     FILE *smtp_sockfp;          /* socket descriptor for SMTP connection */
98     unsigned int uid;           /* UID of user to deliver to */
99     char digest [DIGESTLEN];    /* md5 digest buffer */
100 #ifdef HAVE_GETHOSTBYNAME
101     char *canonical_name;       /* DNS canonical name of server host */
102 #endif /* HAVE_GETHOSTBYNAME */
103 };
104
105 #define MULTIDROP(ctl)  ((ctl)->localnames && (ctl)->localnames->next)
106
107 struct method
108 {
109     char *name;                 /* protocol name */
110     int port;                   /* service port */
111     int tagged;                 /* if true, generate & expect command tags */
112     int delimited;              /* if true, accept "." message delimiter */
113     int (*parse_response)();    /* response_parsing function */
114     int (*getauth)();           /* authorization fetcher */
115     int (*getrange)();          /* get message range to fetch */
116     int (*getsizes)();          /* get sizes of messages */
117     int (*is_old)();            /* check for old message */
118     int (*fetch)();             /* fetch a given message */
119     int (*trail)();             /* eat trailer of a message */
120     int (*delete)();            /* delete method */
121     char *expunge_cmd;          /* expunge command */
122     char *exit_cmd;             /* exit command */
123 };
124
125 #define TAGLEN  6
126 extern char tag[TAGLEN];
127
128 /* list of hosts assembled from run control file and command line */
129 extern struct query cmd_opts, *querylist;
130
131 /* controls the detail level of status/progress messages written to stderr */
132 extern int outlevel;            /* see the O_.* constants above */
133 extern int yydebug;             /* enable parse debugging */
134
135 /* daemon mode control */
136 extern int poll_interval;       /* poll interval in seconds */
137 extern int nodetach;            /* if TRUE, don't detach daemon process */
138 extern char *logfile;           /* log file for daemon mode */
139 extern int quitmode;            /* if --quit was set */
140 extern int check_only;          /* if --check was set */
141
142 /* miscellaneous global controls */
143 extern char *rcfile;            /* path name of rc file */
144 extern char *idfile;            /* path name of UID file */
145 extern int linelimit;           /* limit # lines retrieved per site */
146 extern int versioninfo;         /* emit only version info */
147 extern char *user;              /* name of invoking user */
148
149 #ifdef HAVE_PROTOTYPES
150
151 /* prototypes for globally callable functions */
152 #if defined(HAVE_STDARG_H)
153 void gen_send (FILE *sockfp, char *, ... );
154 int gen_transact (FILE *sockfp, char *, ... );
155 #else
156 void gen_send ();
157 int gen_transact ();
158 #endif
159
160 void *xmalloc(int);
161 char *xstrdup(char *);
162
163 int do_protocol(struct query *, const struct method *);
164 int doPOP2 (struct query *); 
165 int doPOP3 (struct query *);
166 int doIMAP (struct query *);
167
168 void initialize_saved_lists(struct query *, char *);
169 void save_uid(struct idlist **, int, char *);
170 void free_uid_list(struct idlist **);
171 void save_id_pair(struct idlist **, char *, char *);
172 void free_idpair_list(struct idlist **);
173 int delete_uid(struct idlist **, int);
174 int uid_in_list(struct idlist **, char *);
175 char *uid_find(struct idlist **, int);
176 char *idpair_find(struct idlist **, char *);
177 void append_uid_list(struct idlist **, struct idlist **);
178 void update_uid_lists(struct query *);
179 void write_saved_lists(struct query *, char *);
180
181 struct query *hostalloc(struct query *); 
182 int parsecmdline (int, char **, struct query *);
183 void optmerge(struct query *, struct query *);
184 char *MD5Digest (char *);
185 int openmailpipe (char **);
186 int closemailpipe(int);
187 int daemonize(const char *, void (*)(int));
188
189 int prc_parse_file(const char *);
190 int prc_filecheck(const char *);
191
192 char *getpassword(char *);
193
194 void escapes(const char *, char *);
195
196 void yyerror(const char *);
197 int yylex();
198
199 #else
200
201 struct query *hostinit(); 
202 char *MD5Digest ();
203 void optmerge();
204
205 #endif
206
207 #define FALSE   0
208 #define TRUE    1