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