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