2 * Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
3 * Copyright (C) 1999-2008 Brendan Cully <brendan@kublai.com>
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #ifndef _IMAP_PRIVATE_H
21 #define _IMAP_PRIVATE_H 1
24 #include "mutt_curses.h"
25 #include "mutt_socket.h"
33 #define IMAP_SSL_PORT 993
36 #define IMAP_LOG_CMD 2
37 #define IMAP_LOG_LTRL 4
38 #define IMAP_LOG_PASS 5
40 /* IMAP command responses. Used in IMAP_COMMAND.state too */
42 #define IMAP_CMD_OK (0)
44 #define IMAP_CMD_BAD (-1)
46 #define IMAP_CMD_NO (-2)
48 #define IMAP_CMD_CONTINUE (1)
50 #define IMAP_CMD_RESPOND (2)
51 /* IMAP_COMMAND.state additions */
52 #define IMAP_CMD_NEW (3)
54 /* number of entries in the hash table */
55 #define IMAP_CACHE_LEN 10
58 /* maximum length of command lines before they must be split (for
60 #define IMAP_MAX_CMDLEN 1024
62 #define IMAP_REOPEN_ALLOW (1<<0)
63 #define IMAP_EXPUNGE_EXPECTED (1<<1)
64 #define IMAP_EXPUNGE_PENDING (1<<2)
65 #define IMAP_NEWMAIL_PENDING (1<<3)
66 #define IMAP_FLAGS_PENDING (1<<4)
68 /* imap_exec flags (see imap_exec) */
69 #define IMAP_CMD_FAIL_OK (1<<0)
70 #define IMAP_CMD_PASS (1<<1)
71 #define IMAP_CMD_QUEUE (1<<2)
73 /* length of "DD-MMM-YYYY HH:MM:SS +ZZzz" (null-terminated) */
74 #define IMAP_DATELEN 27
85 IMAP_DISCONNECTED = 0,
90 /* and pseudo-states */
102 /* Capabilities we are interested in */
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 IDLE, /* RFC 2177: IDLE */
116 SASL_IR, /* SASL initial response draft */
121 /* imap_conn_find flags */
122 #define M_IMAP_CONN_NONEW (1<<0)
123 #define M_IMAP_CONN_NOSELECT (1<<1)
125 /* -- data structures -- */
136 unsigned int messages;
138 unsigned int uidnext;
139 unsigned int uidvalidity;
148 /* if we end up storing a lot of these we could turn this into a bitfield */
149 unsigned char noselect;
150 unsigned char noinferiors;
153 /* IMAP command structure */
169 /* This data is specific to a CONNECTION to an IMAP server */
172 unsigned char status;
173 /* let me explain capstr: SASL needs the capability string (not bits).
175 * 1. rerun CAPABILITY inside SASL function.
176 * 2. build appropriate CAPABILITY string by reverse-engineering from bits.
177 * 3. keep a copy until after authentication.
178 * I've chosen (3) for now. (2) might not be too bad, but it involves
179 * tracking all possible capabilities. bah. (1) I don't like because
180 * it's just no fun to get the same information twice */
182 unsigned char capabilities[(CAPMAX + 7)/8];
184 time_t lastread; /* last time we read a command for the server */
188 /* if set, the response parser will store results for complicated commands
190 IMAP_COMMAND_TYPE cmdtype;
200 /* cache IMAP_STATUS of visited mailboxes */
203 /* The following data is all specific to the currently SELECTED mbox */
207 unsigned short check_status;
208 unsigned char reopen;
209 unsigned int newMailCount;
210 IMAP_CACHE cache[IMAP_CACHE_LEN];
211 unsigned int uid_validity;
212 unsigned int uidnext;
213 body_cache_t *bcache;
215 /* all folder flags - system flags AND keywords */
218 header_cache_t *hcache;
221 /* I wish that were called IMAP_CONTEXT :( */
224 #define CTX_DATA ((IMAP_DATA *) ctx->data)
226 /* -- private IMAP functions -- */
228 int imap_create_mailbox (IMAP_DATA* idata, char* mailbox);
229 int imap_rename_mailbox (IMAP_DATA* idata, IMAP_MBOX* mx, const char* newname);
230 IMAP_STATUS* imap_mboxcache_get (IMAP_DATA* idata, const char* mbox,
232 void imap_mboxcache_free (IMAP_DATA* idata);
233 int imap_exec_msgset (IMAP_DATA* idata, const char* pre, const char* post,
234 int flag, int changed, int invert);
235 int imap_open_connection (IMAP_DATA* idata);
236 void imap_close_connection (IMAP_DATA* idata);
237 IMAP_DATA* imap_conn_find (const ACCOUNT* account, int flags);
238 int imap_read_literal (FILE* fp, IMAP_DATA* idata, long bytes, progress_t*);
239 void imap_expunge_mailbox (IMAP_DATA* idata);
240 void imap_logout (IMAP_DATA** idata);
241 int imap_sync_message (IMAP_DATA *idata, HEADER *hdr, BUFFER *cmd,
243 int imap_has_flag (LIST* flag_list, const char* flag);
246 int imap_authenticate (IMAP_DATA* idata);
249 int imap_cmd_start (IMAP_DATA* idata, const char* cmd);
250 int imap_cmd_step (IMAP_DATA* idata);
251 void imap_cmd_finish (IMAP_DATA* idata);
252 int imap_code (const char* s);
253 const char* imap_cmd_trailer (IMAP_DATA* idata);
254 int imap_exec (IMAP_DATA* idata, const char* cmd, int flags);
255 int imap_cmd_idle (IMAP_DATA* idata);
258 void imap_add_keywords (char* s, HEADER* keywords, LIST* mailbox_flags, size_t slen);
259 void imap_free_header_data (void** data);
260 int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend);
261 char* imap_set_flags (IMAP_DATA* idata, HEADER* h, char* s);
262 int imap_cache_del (IMAP_DATA* idata, HEADER* h);
263 int imap_cache_clean (IMAP_DATA* idata);
267 header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path);
268 void imap_hcache_close (IMAP_DATA* idata);
269 HEADER* imap_hcache_get (IMAP_DATA* idata, unsigned int uid);
270 int imap_hcache_put (IMAP_DATA* idata, HEADER* h);
271 int imap_hcache_del (IMAP_DATA* idata, unsigned int uid);
274 int imap_continue (const char* msg, const char* resp);
275 void imap_error (const char* where, const char* msg);
276 IMAP_DATA* imap_new_idata (void);
277 void imap_free_idata (IMAP_DATA** idata);
278 char* imap_fix_path (IMAP_DATA* idata, const char* mailbox, char* path,
280 void imap_cachepath(IMAP_DATA* idata, const char* mailbox, char* dest,
282 int imap_get_literal_count (const char* buf, long* bytes);
283 char* imap_get_qualifier (char* buf);
284 int imap_mxcmp (const char* mx1, const char* mx2);
285 char* imap_next_word (char* s);
286 time_t imap_parse_date (char* s);
287 void imap_make_date (char* buf, time_t timestamp);
288 void imap_qualify_path (char *dest, size_t len, IMAP_MBOX *mx, char* path);
289 void imap_quote_string (char* dest, size_t slen, const char* src);
290 void imap_unquote_string (char* s);
291 void imap_munge_mbox_name (char *dest, size_t dlen, const char *src);
292 void imap_unmunge_mbox_name (char *s);
293 int imap_wordcasecmp(const char *a, const char *b);
296 void imap_utf7_encode (char **s);
297 void imap_utf7_decode (char **s);
300 /* typedef size_t (*hcache_keylen_t)(const char* fn); */
301 #define imap_hcache_keylen mutt_strlen
302 #endif /* USE_HCACHE */