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