Andreas Krennmair:
[apps/madmutt.git] / imap / imap_private.h
1 /*
2  * Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
3  * Copyright (C) 1999-2001 Brendan Cully <brendan@kublai.com>
4  * 
5  *     This program is free software; you can redistribute it and/or modify
6  *     it under the terms of the GNU General Public License as published by
7  *     the Free Software Foundation; either version 2 of the License, or
8  *     (at your option) any later version.
9  * 
10  *     This program is distributed in the hope that it will be useful,
11  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *     GNU General Public License for more details.
14  * 
15  *     You should have received a copy of the GNU General Public License
16  *     along with this program; if not, write to the Free Software
17  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
18  */ 
19
20 #ifndef _IMAP_PRIVATE_H
21 #define _IMAP_PRIVATE_H 1
22
23 #include "imap.h"
24 #include "mutt_socket.h"
25
26 /* -- symbols -- */
27 #define IMAP_PORT 143
28 #define IMAP_SSL_PORT 993
29
30 /* logging levels */
31 #define IMAP_LOG_CMD  2
32 #define IMAP_LOG_LTRL 4
33 #define IMAP_LOG_PASS 5
34
35 /* IMAP command responses. Used in IMAP_COMMAND.state too */
36 /* <tag> OK ... */
37 #define IMAP_CMD_OK       (0)
38 /* <tag> BAD ... */
39 #define IMAP_CMD_BAD      (-1)
40 /* <tag> NO ... */
41 #define IMAP_CMD_NO       (-2)
42 /* * ... */
43 #define IMAP_CMD_CONTINUE (1)
44 /* + */
45 #define IMAP_CMD_RESPOND  (2)
46
47 /* number of entries in the hash table */
48 #define IMAP_CACHE_LEN 10
49
50 #define SEQLEN 5
51
52 #define IMAP_REOPEN_ALLOW     (1<<0)
53 #define IMAP_EXPUNGE_EXPECTED (1<<1)
54 #define IMAP_EXPUNGE_PENDING  (1<<2)
55 #define IMAP_NEWMAIL_PENDING  (1<<3)
56 #define IMAP_FLAGS_PENDING    (1<<4)
57
58 /* imap_exec flags (see imap_exec) */
59 #define IMAP_CMD_FAIL_OK (1<<0)
60 #define IMAP_CMD_PASS    (1<<1)
61
62 enum
63 {
64   IMAP_FATAL = 1,
65   IMAP_BYE,
66   IMAP_REOPENED
67 };
68
69 enum
70 {
71   /* States */
72   IMAP_DISCONNECTED = 0,
73   IMAP_CONNECTED,
74   IMAP_AUTHENTICATED,
75   IMAP_SELECTED
76 };
77
78 enum
79 {
80   /* Namespace types */
81   IMAP_NS_PERSONAL = 0,
82   IMAP_NS_OTHER,
83   IMAP_NS_SHARED
84 };
85
86 /* ACL Rights */
87 enum
88 {
89   IMAP_ACL_LOOKUP = 0,
90   IMAP_ACL_READ,
91   IMAP_ACL_SEEN,
92   IMAP_ACL_WRITE,
93   IMAP_ACL_INSERT,
94   IMAP_ACL_POST,
95   IMAP_ACL_CREATE,
96   IMAP_ACL_DELETE,
97   IMAP_ACL_ADMIN,
98
99   RIGHTSMAX
100 };
101
102 /* Capabilities we are interested in */
103 enum
104 {
105   IMAP4 = 0,
106   IMAP4REV1,
107   STATUS,
108   ACL,                          /* RFC 2086: IMAP4 ACL extension */
109   NAMESPACE,                    /* RFC 2342: IMAP4 Namespace */
110   ACRAM_MD5,                    /* RFC 2195: CRAM-MD5 authentication */
111   AGSSAPI,                      /* RFC 1731: GSSAPI authentication */
112   AUTH_ANON,                    /* AUTH=ANONYMOUS */
113   STARTTLS,                     /* RFC 2595: STARTTLS */
114   LOGINDISABLED,                /*           LOGINDISABLED */
115
116   CAPMAX
117 };
118
119 /* imap_conn_find flags */
120 #define M_IMAP_CONN_NONEW    (1<<0)
121 #define M_IMAP_CONN_NOSELECT (1<<1)
122
123 /* -- data structures -- */
124 typedef struct
125 {
126   unsigned int uid;
127   char* path;
128 } IMAP_CACHE;
129
130 typedef struct 
131 {
132   int type;
133   int listable;
134   char *prefix;
135   char delim;
136   int home_namespace;
137   /* We get these when we check if namespace exists - cache them */
138   int noselect;                 
139   int noinferiors;
140 } IMAP_NAMESPACE_INFO;
141
142 /* IMAP command structure */
143 typedef struct
144 {
145   char seq[SEQLEN+1];
146   char* buf;
147   unsigned int blen;
148   int state;
149 } IMAP_COMMAND;
150
151 typedef struct
152 {
153   /* This data is specific to a CONNECTION to an IMAP server */
154   CONNECTION *conn;
155   unsigned char state;
156   unsigned char status;
157   /* let me explain capstr: SASL needs the capability string (not bits).
158    * we have 3 options:
159    *   1. rerun CAPABILITY inside SASL function.
160    *   2. build appropriate CAPABILITY string by reverse-engineering from bits.
161    *   3. keep a copy until after authentication.
162    * I've chosen (3) for now. (2) might not be too bad, but it involves
163    * tracking all possible capabilities. bah. (1) I don't like because
164    * it's just no fun to get the same information twice */
165   char* capstr;
166   unsigned char capabilities[(CAPMAX + 7)/8];
167   unsigned int seqno;
168   time_t lastread; /* last time we read a command for the server */
169   /* who knows, one day we may run multiple commands in parallel */
170   IMAP_COMMAND cmd;
171
172   /* The following data is all specific to the currently SELECTED mbox */
173   char delim;
174   CONTEXT *ctx;
175   char *mailbox;
176   unsigned short check_status;
177   unsigned char reopen;
178   unsigned char rights[(RIGHTSMAX + 7)/8];
179   unsigned int newMailCount;
180   IMAP_CACHE cache[IMAP_CACHE_LEN];
181   int noclose : 1;
182 #ifdef USE_HCACHE
183   unsigned long long uid_validity;
184 #endif
185   
186   /* all folder flags - system flags AND keywords */
187   LIST *flags;
188 } IMAP_DATA;
189 /* I wish that were called IMAP_CONTEXT :( */
190
191 /* -- macros -- */
192 #define CTX_DATA ((IMAP_DATA *) ctx->data)
193
194 /* -- private IMAP functions -- */
195 /* imap.c */
196 int imap_create_mailbox (IMAP_DATA* idata, char* mailbox);
197 int imap_make_msg_set (IMAP_DATA* idata, BUFFER* buf, int flag, int changed);
198 int imap_open_connection (IMAP_DATA* idata);
199 IMAP_DATA* imap_conn_find (const ACCOUNT* account, int flags);
200 int imap_parse_list_response(IMAP_DATA* idata, char** name, int* noselect,
201   int* noinferiors, char* delim);
202 int imap_read_literal (FILE* fp, IMAP_DATA* idata, long bytes);
203 void imap_expunge_mailbox (IMAP_DATA* idata);
204 void imap_logout (IMAP_DATA* idata);
205
206 /* auth.c */
207 int imap_authenticate (IMAP_DATA* idata);
208
209 /* command.c */
210 int imap_cmd_start (IMAP_DATA* idata, const char* cmd);
211 int imap_cmd_step (IMAP_DATA* idata);
212 void imap_cmd_finish (IMAP_DATA* idata);
213 int imap_code (const char* s);
214 int imap_exec (IMAP_DATA* idata, const char* cmd, int flags);
215
216 /* message.c */
217 void imap_add_keywords (char* s, HEADER* keywords, LIST* mailbox_flags, size_t slen);
218 void imap_free_header_data (void** data);
219 int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend);
220 char* imap_set_flags (IMAP_DATA* idata, HEADER* h, char* s);
221
222 /* util.c */
223 int imap_continue (const char* msg, const char* resp);
224 void imap_error (const char* where, const char* msg);
225 IMAP_DATA* imap_new_idata (void);
226 void imap_free_idata (IMAP_DATA** idata);
227 char* imap_fix_path (IMAP_DATA* idata, char* mailbox, char* path, 
228   size_t plen);
229 int imap_get_literal_count (const char* buf, long* bytes);
230 char* imap_get_qualifier (char* buf);
231 char* imap_next_word (char* s);
232 time_t imap_parse_date (char* s);
233 void imap_qualify_path (char *dest, size_t len, IMAP_MBOX *mx, char* path);
234 void imap_quote_string (char* dest, size_t slen, const char* src);
235 void imap_unquote_string (char* s);
236 void imap_munge_mbox_name (char *dest, size_t dlen, const char *src);
237 void imap_unmunge_mbox_name (char *s);
238 int imap_wordcasecmp(const char *a, const char *b);
239
240 /* utf7.c */
241 void imap_utf7_encode (char **s);
242 void imap_utf7_decode (char **s);
243
244 #endif