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