move all the parameter related functions into the lib-mime.
[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 #include <stdio.h>
23
24 #include "mutt.h"
25
26 /*
27  * supported mailbox formats
28  * in mx_init() the registration order must be exactly as given here!!!1!
29  */
30 enum {
31     M_MBOX = 1,
32     M_MMDF,
33     M_MH,
34     M_MAILDIR,
35     M_IMAP,
36     M_POP,
37 #ifdef USE_NNTP
38     M_NNTP,
39 #endif
40     M_COMPRESSED
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   FILE *fp;                     /* pointer to the message data */
67   char *path;                   /* path to temp file */
68   short magic;                  /* type of mailbox this message belongs to */
69   short write;                  /* nonzero if message is open for writing */
70   struct {
71     unsigned read:1;
72     unsigned flagged:1;
73     unsigned replied:1;
74   } flags;
75   time_t received;              /* the time at which this message was received */
76 } MESSAGE;
77
78 typedef struct {
79   /* folder magic */
80   int type;
81   /* may we stat() it? */
82   unsigned int local : 1;
83   /* tests if given path is of its magic */
84   int (*mx_is_magic) (const char*, struct stat*);
85   /* tests if folder is empty */
86   int (*mx_check_empty) (const char*);
87   /* test for access */
88   int (*mx_access) (const char*, int);
89   /* read mailbox into ctx structure */
90   int (*mx_open_mailbox) (CONTEXT*);
91   /* open new message */
92   int (*mx_open_new_message) (MESSAGE*, CONTEXT*, HEADER*);
93   /* check ACL flags; if not implemented, always assume granted
94    * permissions */
95   int (*mx_acl_check) (CONTEXT*, int);
96   /* check for new mail; see mx_check_mailbox() below for return vals */
97   int (*mx_check_mailbox) (CONTEXT*, int*, int);
98   /* fast closing */
99   void (*mx_fastclose_mailbox) (CONTEXT*);
100   /* write out changes */
101   int (*mx_sync_mailbox) (CONTEXT*, int, int*);
102   /* commit a message to a folder */
103   int (*mx_commit_message) (MESSAGE*, CONTEXT*);
104 } mx_t;
105
106 /* called from main: init all folder types */
107 void mx_init (void);
108
109 /* flags for mx_open_mailbox() */
110 #define M_NOSORT        (1<<0)  /* do not sort the mailbox after opening it */
111 #define M_APPEND        (1<<1)  /* open mailbox for appending messages */
112 #define M_READONLY      (1<<2)  /* open in read-only mode */
113 #define M_QUIET         (1<<3)  /* do not print any messages */
114 #define M_NEWFOLDER     (1<<4)  /* create a new folder - same as M_APPEND, but uses
115                                  * safe_fopen() for mbox-style folders. */
116 #define M_COUNT         (1<<5)  /* just do counting? needed to do speed optimizations
117                                    for sidebar */
118
119 /* mx_open_new_message() */
120 #define M_ADD_FROM      1       /* add a From_ line */
121
122 #define MAXLOCKATTEMPT 5
123
124 WHERE short DefaultMagic INITVAL (M_MBOX);
125
126 /*
127  * please use the following _ONLY_ when doing "something"
128  * with folders
129  */
130
131 CONTEXT *mx_open_mailbox (const char *, int, CONTEXT *);
132
133 MESSAGE *mx_open_message (CONTEXT *, int);
134 MESSAGE *mx_open_new_message (CONTEXT *, HEADER *, int);
135
136 void mx_fastclose_mailbox (CONTEXT *);
137
138 int mx_close_mailbox (CONTEXT *, int *);
139 int mx_sync_mailbox (CONTEXT *, int *);
140 int mx_commit_message (MESSAGE *, CONTEXT *);
141 int mx_close_message (MESSAGE **);
142
143 /* determines magic for given folder */
144 int mx_get_magic (const char*);
145 /* sets/parses DefaultMagic */
146 int mx_set_magic (const char *);
147 /* tests whether given folder magic is (valid and) local */
148 int mx_is_local (int);
149
150 /* return values from mx_check_mailbox() */
151 enum {
152   M_NEW_MAIL = 1,               /* new mail received in mailbox */
153   M_LOCKED,                     /* couldn't lock the mailbox */
154   M_REOPENED,                   /* mailbox was reopened */
155   M_FLAGS                       /* nondestructive flags change (IMAP) */
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 int mx_rebuild_cache (void);
172
173 #endif /* !_MX_H */