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