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