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