Rocco Rutte
[apps/madmutt.git] / imap / mx_imap.c
1 /*
2  * This file is part of mutt-ng, see http://www.muttng.org/.
3  * It's licensed under the GNU General Public License,
4  * please see the file GPL in the top level source directory.
5  */
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 #include <sys/stat.h>
11
12 #include "mutt.h"
13 #include "imap_private.h"
14
15 #include "mx.h"
16 #include "mx_imap.h"
17
18 #include "lib/mem.h"
19 #include "lib/str.h"
20
21 #include "url.h"
22
23 int imap_is_magic (const char* path, struct stat* st) {
24   url_scheme_t s;
25   if (!path || !*path)
26     return (-1);
27   if (*path == '{')     /* pain\17pine compatibility */
28     return (M_IMAP);
29   s = url_check_scheme (NONULL (path));
30   return ((s == U_IMAP || s == U_IMAPS) ? M_IMAP : -1);
31 }
32
33 static int acl_check_imap (CONTEXT* ctx, int bit) {
34   return (!mutt_bit_isset (((IMAP_DATA*) ctx->data)->capabilities, ACL) ||
35           mutt_bit_isset (((IMAP_DATA*) ctx->data)->rights, bit));
36 }
37
38 mx_t* imap_reg_mx (void) {
39   mx_t* fmt = safe_calloc (1, sizeof (mx_t));
40
41   /* make up mx_t record... */
42   fmt->type = M_IMAP;
43   fmt->mx_is_magic = imap_is_magic;
44   fmt->mx_access = imap_access;
45   fmt->mx_open_mailbox = imap_open_mailbox;
46   fmt->mx_acl_check = acl_check_imap;
47   fmt->mx_fastclose_mailbox = imap_close_mailbox;
48   fmt->mx_sync_mailbox = imap_sync_mailbox;
49   return (fmt);
50 }