eb402db269b87dbdacbb6ded6ffe4d068e64128b
[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 "mutt.h"
11 #include "imap_private.h"
12
13 #include "mx.h"
14 #include "mx_imap.h"
15
16 #include "lib/mem.h"
17 #include "lib/str.h"
18
19 #include "url.h"
20
21 static int imap_is_magic (const char* path) {
22   url_scheme_t s;
23   if (!path || !*path)
24     return (-1);
25   if (*path == '{')     /* pain\17pine compatibility */
26     return (M_IMAP);
27   s = url_check_scheme (NONULL (path));
28   return ((s == U_IMAP || s == U_IMAPS) ? M_IMAP : -1);
29 }
30
31 static int acl_check_imap (CONTEXT* ctx, int bit) {
32   return (!mutt_bit_isset (((IMAP_DATA*) ctx->data)->capabilities, ACL) ||
33           mutt_bit_isset (((IMAP_DATA*) ctx->data)->rights, bit));
34 }
35
36 mx_t* imap_reg_mx (void) {
37   mx_t* fmt = safe_calloc (1, sizeof (mx_t));
38
39   /* make up mx_t record... */
40   fmt->type = M_IMAP;
41   fmt->mx_is_magic = imap_is_magic;
42   fmt->mx_access = imap_access;
43   fmt->mx_open_mailbox = imap_open_mailbox;
44   fmt->mx_acl_check = acl_check_imap;
45   return (fmt);
46 }