17147e5f54867b792c1d2a89b538c50be615aabd
[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
7 #include <lib-lib/lib-lib.h>
8
9 #include "mutt.h"
10 #include "imap_private.h"
11
12 #include "mx.h"
13 #include "mx_imap.h"
14
15 int imap_is_magic (const char* path, struct stat* st __attribute__ ((unused))) {
16   url_scheme_t s;
17   if (!path || !*path)
18     return (-1);
19   s = url_check_scheme (NONULL (path));
20   return ((s == U_IMAP || s == U_IMAPS) ? M_IMAP : -1);
21 }
22
23 static int acl_check_imap (CONTEXT* ctx, int bit) {
24   return (!mutt_bit_isset (((IMAP_DATA*) ctx->data)->capabilities, ACL) ||
25           mutt_bit_isset (((IMAP_DATA*) ctx->data)->rights, bit));
26 }
27
28 static int imap_open_new_message (MESSAGE * msg,
29                                   CONTEXT * dest __attribute__ ((unused)),
30                                   HEADER * hdr __attribute__ ((unused)))
31 {
32   char tmp[_POSIX_PATH_MAX];
33
34   mutt_mktemp (tmp);
35   if ((msg->fp = safe_fopen (tmp, "w")) == NULL) {
36     mutt_perror (tmp);
37     return (-1);
38   }
39   msg->path = m_strdup(tmp);
40   return 0;
41 }
42
43 /* this ugly kludge is required since the last int to
44  * imap_check_mailbox() doesn't mean 'lock' but 'force'... */
45 static int _imap_check_mailbox (CONTEXT* ctx,
46                                 int* index_hint,
47                                 int lock __attribute__ ((unused))) {
48   return (imap_check_mailbox (ctx, index_hint, 0));
49 }
50
51 static int imap_commit_message (MESSAGE* msg, CONTEXT* ctx) {
52   int r = 0;
53
54   if ((r = safe_fclose (&msg->fp)) == 0)
55     r = imap_append_message (ctx, msg);
56   return (r);
57 }
58
59 mx_t const imap_mx = {
60     M_IMAP,
61     0,
62     imap_is_magic,
63     NULL,
64     imap_access,
65     imap_open_mailbox,
66     imap_open_new_message,
67     acl_check_imap,
68     _imap_check_mailbox,
69     imap_close_mailbox,
70     imap_sync_mailbox,
71     imap_commit_message,
72 };