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