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