Fix a bug when changing folder
[apps/madmutt.git] / mx.h
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
4  * Copyright (C) 1999-2002 Thomas Roessler <roessler@does-not-exist.org>
5  *
6  * This file is part of mutt-ng, see http://www.muttng.org/.
7  * It's licensed under the GNU General Public License,
8  * please see the file GPL in the top level source directory.
9  */
10
11 /*
12  * mailbox abstraction
13  * when adding code dealing with folders or whatever,
14  * please use these only
15  */
16
17 #ifndef _MX_H
18 #define _MX_H
19
20 #include <utime.h>
21 #include "mutt.h"
22
23 /*
24  * supported mailbox formats
25  * in mx_init() the registration order must be exactly as given here!!!1!
26  */
27 enum {
28     M_MBOX = 1,
29     M_MMDF,
30     M_MH,
31     M_MAILDIR,
32     M_IMAP,
33     M_POP,
34 #ifdef USE_NNTP
35     M_NNTP,
36 #endif
37     M_COMPRESSED
38 };
39
40 enum {
41   ACL_LOOKUP = 0,
42   ACL_READ,
43   ACL_SEEN,
44   ACL_WRITE,
45   ACL_INSERT,
46   ACL_POST,
47   ACL_CREATE,
48   ACL_DELETE,
49   ACL_ADMIN,
50
51   RIGHTSMAX
52 };
53
54 /* ugly hack to define macro once (for pager+index) */
55 #define CHECK_MX_ACL(c,f,s) if(!mx_acl_check(c,f)) \
56                      {\
57                         mutt_flushinp (); \
58                         mutt_error(_("%s not permitted by ACL."), s); \
59                         break; \
60                      }
61
62 typedef struct {
63   FILE *fp;                     /* pointer to the message data */
64   char *path;                   /* path to temp file */
65   short magic;                  /* type of mailbox this message belongs to */
66   short write;                  /* nonzero if message is open for writing */
67   struct {
68     unsigned read:1;
69     unsigned flagged:1;
70     unsigned replied:1;
71   } flags;
72   time_t received;              /* the time at which this message was received */
73 } MESSAGE;
74
75 typedef struct {
76   /* folder magic */
77   int type;
78   /* may we stat() it? */
79   unsigned int local : 1;
80   /* tests if given path is of its magic */
81   int (*mx_is_magic) (const char*, struct stat*);
82   /* tests if folder is empty */
83   int (*mx_check_empty) (const char*);
84   /* test for access */
85   int (*mx_access) (const char*, int);
86   /* read mailbox into ctx structure */
87   int (*mx_open_mailbox) (CONTEXT*);
88   /* open new message */
89   int (*mx_open_new_message) (MESSAGE*, CONTEXT*, HEADER*);
90   /* check ACL flags; if not implemented, always assume granted
91    * permissions */
92   int (*mx_acl_check) (CONTEXT*, int);
93   /* check for new mail; see mx_check_mailbox() below for return vals */
94   int (*mx_check_mailbox) (CONTEXT*, int*, int);
95   /* fast closing */
96   void (*mx_fastclose_mailbox) (CONTEXT*);
97   /* write out changes */
98   int (*mx_sync_mailbox) (CONTEXT*, int, int*);
99   /* commit a message to a folder */
100   int (*mx_commit_message) (MESSAGE*, CONTEXT*);
101 } mx_t;
102
103 /* called from main: init all folder types */
104 void mx_init (void);
105
106 /* flags for mx_open_mailbox() */
107 #define M_NOSORT        (1<<0)  /* do not sort the mailbox after opening it */
108 #define M_APPEND        (1<<1)  /* open mailbox for appending messages */
109 #define M_READONLY      (1<<2)  /* open in read-only mode */
110 #define M_QUIET         (1<<3)  /* do not print any messages */
111 #define M_NEWFOLDER     (1<<4)  /* create a new folder - same as M_APPEND, but uses
112                                  * safe_fopen() for mbox-style folders. */
113 #define M_COUNT         (1<<5)  /* just do counting? needed to do speed optimizations
114                                    for sidebar */
115
116 /* mx_open_new_message() */
117 #define M_ADD_FROM      1       /* add a From_ line */
118
119 #define MAXLOCKATTEMPT 5
120
121 WHERE short DefaultMagic INITVAL (M_MBOX);
122
123 /*
124  * please use the following _ONLY_ when doing "something"
125  * with folders
126  */
127
128 CONTEXT *mx_open_mailbox (const char *, int, CONTEXT *);
129
130 MESSAGE *mx_open_message (CONTEXT *, int);
131 MESSAGE *mx_open_new_message (CONTEXT *, HEADER *, int);
132
133 void mx_fastclose_mailbox (CONTEXT *);
134
135 int mx_close_mailbox (CONTEXT *, int *);
136 int mx_sync_mailbox (CONTEXT *, int *);
137 int mx_commit_message (MESSAGE *, CONTEXT *);
138 int mx_close_message (MESSAGE **);
139
140 /* determines magic for given folder */
141 int mx_get_magic (const char*);
142 /* sets/parses DefaultMagic */
143 int mx_set_magic (const char *);
144 /* tests whether given folder magic is (valid and) local */
145 int mx_is_local (int);
146
147 /* return values from mx_check_mailbox() */
148 enum {
149   M_NEW_MAIL = 1,               /* new mail received in mailbox */
150   M_LOCKED,                     /* couldn't lock the mailbox */
151   M_REOPENED,                   /* mailbox was reopened */
152   M_FLAGS                       /* nondestructive flags change (IMAP) */
153 };
154 int mx_check_mailbox (CONTEXT *, int *, int);
155
156 int mx_access (const char *, int);
157 int mx_check_empty (const char *);
158
159 int mx_acl_check (CONTEXT*, int);
160
161 void mx_alloc_memory (CONTEXT *);
162 void mx_update_context (CONTEXT *, int);
163 void mx_update_tables (CONTEXT *, int);
164
165 int mx_lock_file (const char *, int, int, int, int);
166 int mx_unlock_file (const char *path, int fd, int dot);
167
168 int mx_rebuild_cache (void);
169 void mutt_parse_mime_message (CONTEXT * ctx, HEADER *);
170
171 #endif /* !_MX_H */