Fix a bunch of warnings in imap code
[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 <lib-lib/mem.h>
13 #include <lib-lib/file.h>
14 #include <lib-lib/str.h>
15 #include <lib-lib/url.h>
16
17 #include "mutt.h"
18 #include "imap_private.h"
19
20 #include "mx.h"
21 #include "mx_imap.h"
22
23
24
25 int imap_is_magic (const char* path, struct stat* st __attribute__ ((unused))) {
26   url_scheme_t s;
27   if (!path || !*path)
28     return (-1);
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 static int imap_open_new_message (MESSAGE * msg,
39                                   CONTEXT * dest __attribute__ ((unused)),
40                                   HEADER * hdr __attribute__ ((unused)))
41 {
42   char tmp[_POSIX_PATH_MAX];
43
44   mutt_mktemp (tmp);
45   if ((msg->fp = safe_fopen (tmp, "w")) == NULL) {
46     mutt_perror (tmp);
47     return (-1);
48   }
49   msg->path = m_strdup(tmp);
50   return 0;
51 }
52
53 /* this ugly kludge is required since the last int to
54  * imap_check_mailbox() doesn't mean 'lock' but 'force'... */
55 static int _imap_check_mailbox (CONTEXT* ctx,
56                                 int* index_hint,
57                                 int lock __attribute__ ((unused))) {
58   return (imap_check_mailbox (ctx, index_hint, 0));
59 }
60
61 static int imap_commit_message (MESSAGE* msg, CONTEXT* ctx) {
62   int r = 0;
63
64   if ((r = safe_fclose (&msg->fp)) == 0)
65     r = imap_append_message (ctx, msg);
66   return (r);
67 }
68
69 mx_t* imap_reg_mx (void) {
70   mx_t* fmt = p_new(mx_t, 1);
71
72   /* make up mx_t record... */
73   fmt->type = M_IMAP;
74   fmt->mx_is_magic = imap_is_magic;
75   fmt->mx_access = imap_access;
76   fmt->mx_open_mailbox = imap_open_mailbox;
77   fmt->mx_open_new_message = imap_open_new_message;
78   fmt->mx_acl_check = acl_check_imap;
79   fmt->mx_fastclose_mailbox = imap_close_mailbox;
80   fmt->mx_sync_mailbox = imap_sync_mailbox;
81   fmt->mx_check_mailbox = _imap_check_mailbox;
82   fmt->mx_commit_message = imap_commit_message;
83   return (fmt);
84 }