Nico Golde:
[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 <sys/stat.h>
21
22 /*
23  * supported mailbox formats
24  * in mx_init() the registration order must be exactly as given here!!!1!
25  */
26 enum {
27   M_MBOX = 1,
28   M_MMDF,
29   M_MH,
30   M_MAILDIR
31 #ifdef USE_IMAP
32     , M_IMAP
33 #endif
34 #ifdef USE_POP
35     , M_POP
36 #endif
37 #ifdef USE_NNTP
38     , M_NNTP
39 #endif
40 #ifdef USE_COMPRESSED
41     , M_COMPRESSED
42 #endif
43 };
44
45 enum {
46   ACL_LOOKUP = 0,
47   ACL_READ,
48   ACL_SEEN,
49   ACL_WRITE,
50   ACL_INSERT,
51   ACL_POST,
52   ACL_CREATE,
53   ACL_DELETE,
54   ACL_ADMIN,
55
56   RIGHTSMAX
57 };
58
59 /* ugly hack to define macro once (for pager+index) */
60 #define CHECK_MX_ACL(c,f,s) if(!mx_acl_check(c,f)) \
61                      {\
62                         mutt_flushinp (); \
63                         mutt_error(_("%s not permitted by ACL."), s); \
64                         break; \
65                      }
66
67 typedef struct {
68   /* folder magic */
69   int type;
70   /* may we stat() it? */
71   unsigned int local : 1;
72   /* tests if given path is of its magic */
73   int (*mx_is_magic) (const char*, struct stat*);
74   /* tests if folder is empty */
75   int (*mx_check_empty) (const char*);
76   /* test for access */
77   int (*mx_access) (const char*, int);
78   /* read mailbox into ctx structure */
79   int (*mx_open_mailbox) (CONTEXT*);
80   /* check ACL flags; if not implemented, always assume granted
81    * permissions */
82   int (*mx_acl_check) (CONTEXT*, int);
83 } mx_t;
84
85 /* called from main: init all folder types */
86 void mx_init (void);
87
88 /* flags for mx_open_mailbox() */
89 #define M_NOSORT        (1<<0)  /* do not sort the mailbox after opening it */
90 #define M_APPEND        (1<<1)  /* open mailbox for appending messages */
91 #define M_READONLY      (1<<2)  /* open in read-only mode */
92 #define M_QUIET         (1<<3)  /* do not print any messages */
93 #define M_NEWFOLDER     (1<<4)  /* create a new folder - same as M_APPEND, but uses
94                                  * safe_fopen() for mbox-style folders.
95                                  */
96
97 /* mx_open_new_message() */
98 #define M_ADD_FROM      1       /* add a From_ line */
99
100 #define MAXLOCKATTEMPT 5
101
102 /* return values from mx_check_mailbox() */
103 enum {
104   M_NEW_MAIL = 1,               /* new mail received in mailbox */
105   M_LOCKED,                     /* couldn't lock the mailbox */
106   M_REOPENED,                   /* mailbox was reopened */
107   M_FLAGS                       /* nondestructive flags change (IMAP) */
108 };
109
110 typedef struct {
111   FILE *fp;                     /* pointer to the message data */
112   char *path;                   /* path to temp file */
113   short magic;                  /* type of mailbox this message belongs to */
114   short write;                  /* nonzero if message is open for writing */
115   struct {
116     unsigned read:1;
117     unsigned flagged:1;
118     unsigned replied:1;
119   } flags;
120   time_t received;              /* the time at which this message was received */
121 } MESSAGE;
122
123 WHERE short DefaultMagic INITVAL (M_MBOX);
124
125 /*
126  * please use the following _ONLY_ when doing "something"
127  * with folders
128  */
129
130 CONTEXT *mx_open_mailbox (const char *, int, CONTEXT *);
131
132 MESSAGE *mx_open_message (CONTEXT *, int);
133 MESSAGE *mx_open_new_message (CONTEXT *, HEADER *, int);
134
135 void mx_fastclose_mailbox (CONTEXT *);
136
137 int mx_close_mailbox (CONTEXT *, int *);
138 int mx_sync_mailbox (CONTEXT *, int *);
139 int mx_commit_message (MESSAGE *, CONTEXT *);
140 int mx_close_message (MESSAGE **);
141
142 /* determines magic for given folder */
143 int mx_get_magic (const char*);
144 /* sets/parses DefaultMagic */
145 int mx_set_magic (const char *);
146 /* tests whether given folder magic is (valid and) local */
147 int mx_is_local (int);
148
149 int mx_check_mailbox (CONTEXT *, int *, int);
150
151 int mx_access (const char *, int);
152 int mx_check_empty (const char *);
153
154 int mx_acl_check (CONTEXT*, int);
155
156 void mx_alloc_memory (CONTEXT *);
157 void mx_update_context (CONTEXT *, int);
158 void mx_update_tables (CONTEXT *, int);
159
160 int mx_lock_file (const char *, int, int, int, int);
161 int mx_unlock_file (const char *path, int fd, int dot);
162
163 #endif /* !_MX_H */