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