Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / camel-store.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camel-store.h : Abstract class for an email store */
3
4 /* 
5  *
6  * Authors: Bertrand Guiheneuf <bertrand@helixcode.com>
7  *          Michael Zucchi <NotZed@ximian.com>
8  *          Jeffrey Stedfast <fejj@ximian.com>
9  *
10  * Copyright 1999, 2003 Ximian, Inc. (www.ximian.com)
11  *
12  * This program is free software; you can redistribute it and/or 
13  * modify it under the terms of version 2 of the GNU Lesser General Public 
14  * License as published by the Free Software Foundation.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
24  * USA
25  */
26
27 #ifndef CAMEL_STORE_H
28 #define CAMEL_STORE_H 1
29
30 /* for mode_t */
31 #include <sys/types.h>
32
33 #include <camel/camel-object.h>
34 #include <camel/camel-service.h>
35
36 G_BEGIN_DECLS
37
38 enum {
39         CAMEL_STORE_ARG_FIRST  = CAMEL_SERVICE_ARG_FIRST + 100,
40 };
41
42 typedef struct _CamelFolderInfo {
43         struct _CamelFolderInfo *next;
44         struct _CamelFolderInfo *parent;
45         struct _CamelFolderInfo *child;
46
47         char *uri;
48         char *name;
49         char *full_name;
50
51         guint32 flags;
52         gint32 unread;
53         gint32 total;
54 } CamelFolderInfo;
55
56 /* Note: these are abstractions (duh), its upto the provider to make them make sense */
57
58 /* a folder which can't contain messages */
59 #define CAMEL_FOLDER_NOSELECT (1<<0)
60 /* a folder which cannot have children */
61 #define CAMEL_FOLDER_NOINFERIORS (1<<1)
62 /* a folder which has children (not yet fully implemented) */
63 #define CAMEL_FOLDER_CHILDREN (1<<2)
64 /* a folder which does not have any children (not yet fully implemented) */
65 #define CAMEL_FOLDER_NOCHILDREN (1<<3)
66 /* a folder which is subscribed */
67 #define CAMEL_FOLDER_SUBSCRIBED (1<<4)
68 /* a virtual folder, cannot copy/move messages here */
69 #define CAMEL_FOLDER_VIRTUAL (1<<5)
70 /* a system folder, cannot be renamed/deleted */
71 #define CAMEL_FOLDER_SYSTEM (1<<6)
72 /* a virtual folder that can't be copied to, and can only be moved to if in an existing folder */
73 #define CAMEL_FOLDER_VTRASH (1<<7)
74 /* a shared folder i'm accessing */
75 #define CAMEL_FOLDER_SHARED_TO_ME (1<<8)
76 /* a folder that i'm sharing */
77 #define CAMEL_FOLDER_SHARED_BY_ME (1<<9)
78
79 /* use 3 bits as a hint for a folder type */
80 #define CAMEL_FOLDER_TYPE_MASK (7 << 10)
81 #define CAMEL_FOLDER_TYPE_BIT (10)
82 /* a normal folder */
83 #define CAMEL_FOLDER_TYPE_NORMAL (0 << 10)
84 /* an inbox folder */
85 #define CAMEL_FOLDER_TYPE_INBOX (1 << 10)
86 /* an outbox folder */
87 #define CAMEL_FOLDER_TYPE_OUTBOX (2 << 10)
88 /* a rubbish folder */
89 #define CAMEL_FOLDER_TYPE_TRASH (3 << 10)
90 /* a spam folder */
91 #define CAMEL_FOLDER_TYPE_JUNK (4 << 10)
92 /* a sent-items folder */
93 #define CAMEL_FOLDER_TYPE_SENT (5 << 10)
94
95 /* next bit is 1<<13 */
96
97 /* store premissions */
98 #define CAMEL_STORE_READ  (1 << 0)
99 #define CAMEL_STORE_WRITE (1 << 1)
100
101 /* Structure of rename event's event_data */
102 typedef struct _CamelRenameInfo {
103         char *old_base;
104         struct _CamelFolderInfo *new;
105 } CamelRenameInfo;
106
107 #define CAMEL_STORE_TYPE     (camel_store_get_type ())
108 #define CAMEL_STORE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_STORE_TYPE, CamelStore))
109 #define CAMEL_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_STORE_TYPE, CamelStoreClass))
110 #define CAMEL_IS_STORE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_STORE_TYPE))
111
112 /* Flags for store flags */
113 #define CAMEL_STORE_SUBSCRIPTIONS       (1 << 0)
114 #define CAMEL_STORE_VTRASH              (1 << 1)
115 #define CAMEL_STORE_FILTER_INBOX        (1 << 2)
116 #define CAMEL_STORE_VJUNK               (1 << 3)
117 #define CAMEL_STORE_PROXY               (1 << 4)
118
119 struct _CamelStore {
120         CamelService parent_object;
121         struct _CamelStorePrivate *priv;
122         
123         CamelObjectBag *folders;
124
125         guint32 flags;
126         guint32 mode;
127 };
128
129 /* open mode for folder */
130 #define CAMEL_STORE_FOLDER_CREATE (1<<0)
131 #define CAMEL_STORE_FOLDER_EXCL (1<<1)
132 #define CAMEL_STORE_FOLDER_BODY_INDEX (1<<2)
133 #define CAMEL_STORE_FOLDER_PRIVATE (1<<3) /* a private folder, that shouldn't show up in unmatched/folder info's, etc */
134
135 #define CAMEL_STORE_FOLDER_CREATE_EXCL (CAMEL_STORE_FOLDER_CREATE | CAMEL_STORE_FOLDER_EXCL)
136
137 #define CAMEL_STORE_FOLDER_INFO_FAST       (1 << 0)
138 #define CAMEL_STORE_FOLDER_INFO_RECURSIVE  (1 << 1)
139 #define CAMEL_STORE_FOLDER_INFO_SUBSCRIBED (1 << 2)
140 #define CAMEL_STORE_FOLDER_INFO_NO_VIRTUAL (1 << 3)  /* don't include vTrash/vJunk folders */
141
142 typedef struct {
143         CamelServiceClass parent_class;
144
145         GHashFunc       hash_folder_name;
146         GCompareFunc    compare_folder_name;
147
148         CamelFolder *   (*get_folder)               (CamelStore *store,
149                                                      const char *folder_name,
150                                                      guint32 flags,
151                                                      CamelException *ex);
152
153         CamelFolder *   (*get_inbox)                (CamelStore *store, CamelException *ex);    
154         CamelFolder *   (*get_trash)                (CamelStore *store, CamelException *ex);
155         CamelFolder *   (*get_junk)                 (CamelStore *store, CamelException *ex);
156         
157         CamelFolderInfo *(*create_folder)           (CamelStore *store,
158                                                      const char *parent_name,
159                                                      const char *folder_name,
160                                                      CamelException *ex);
161         void            (*delete_folder)            (CamelStore *store,
162                                                      const char *folder_name,
163                                                      CamelException *ex);
164         void            (*rename_folder)            (CamelStore *store,
165                                                      const char *old_name,
166                                                      const char *new_name,
167                                                      CamelException *ex);
168         
169         void            (*sync)                     (CamelStore *store, int expunge, CamelException *ex);
170         
171         CamelFolderInfo *(*get_folder_info)         (CamelStore *store,
172                                                      const char *top,
173                                                      guint32 flags,
174                                                      CamelException *ex);
175         void            (*free_folder_info)         (CamelStore *store,
176                                                      CamelFolderInfo *fi);
177         
178         gboolean        (*folder_subscribed)        (CamelStore *store,
179                                                      const char *folder_name);
180         void            (*subscribe_folder)         (CamelStore *store,
181                                                      const char *folder_name,
182                                                      CamelException *ex);
183         void            (*unsubscribe_folder)       (CamelStore *store,
184                                                      const char *folder_name,
185                                                      CamelException *ex);
186         void            (*noop)                     (CamelStore *store,
187                                                      CamelException *ex);
188 } CamelStoreClass;
189
190 /* Standard Camel function */
191 CamelType camel_store_get_type (void);
192
193 /* public methods */
194 CamelFolder *    camel_store_get_folder         (CamelStore *store,
195                                                  const char *folder_name,
196                                                  guint32 flags,
197                                                  CamelException *ex);
198 CamelFolder *    camel_store_get_inbox          (CamelStore *store,
199                                                  CamelException *ex);
200 CamelFolder *    camel_store_get_trash          (CamelStore *store,
201                                                  CamelException *ex);
202 CamelFolder *    camel_store_get_junk           (CamelStore *store,
203                                                  CamelException *ex);
204
205 CamelFolderInfo *camel_store_create_folder      (CamelStore *store,
206                                                  const char *parent_name,
207                                                  const char *folder_name,
208                                                  CamelException *ex);
209 void             camel_store_delete_folder      (CamelStore *store,
210                                                  const char *folder_name,
211                                                  CamelException *ex);
212 void             camel_store_rename_folder      (CamelStore *store,
213                                                  const char *old_name,
214                                                  const char *new_name,
215                                                  CamelException *ex);
216
217 void             camel_store_sync               (CamelStore *store, int expunge, CamelException *ex);
218
219 CamelFolderInfo *camel_store_get_folder_info    (CamelStore *store,
220                                                  const char *top,
221                                                  guint32 flags,
222                                                  CamelException *ex);
223 void             camel_store_free_folder_info   (CamelStore *store,
224                                                  CamelFolderInfo *fi);
225
226 void             camel_store_free_folder_info_full (CamelStore *store,
227                                                     CamelFolderInfo *fi);
228 void             camel_store_free_folder_info_nop  (CamelStore *store,
229                                                     CamelFolderInfo *fi);
230
231 void             camel_folder_info_free            (CamelFolderInfo *fi);
232 CamelFolderInfo *camel_folder_info_build           (GPtrArray *folders,
233                                                     const char *namespace,
234                                                     char separator,
235                                                     gboolean short_names);
236 CamelFolderInfo *camel_folder_info_clone           (CamelFolderInfo *fi);
237
238 gboolean         camel_store_supports_subscriptions   (CamelStore *store);
239
240 gboolean         camel_store_folder_subscribed        (CamelStore *store,
241                                                        const char *folder_name);
242 void             camel_store_subscribe_folder         (CamelStore *store,
243                                                        const char *folder_name,
244                                                        CamelException *ex);
245 void             camel_store_unsubscribe_folder       (CamelStore *store,
246                                                        const char *folder_name,
247                                                        CamelException *ex);
248
249 void             camel_store_noop                     (CamelStore *store,
250                                                        CamelException *ex);
251
252 int              camel_store_folder_uri_equal         (CamelStore *store,
253                                                        const char *uri0,
254                                                        const char *uri1);
255
256 typedef struct _CamelISubscribe CamelISubscribe;
257 struct _CamelISubscribe {
258         CamelInterface iface;
259
260         gboolean (*subscribed)(CamelStore *store, const char *folder_name);
261         void (*subscribe)(CamelStore *store, const char *folder_name, CamelException *ex);
262         void (*unsubscribe)(CamelStore *store, const char *folder_name, CamelException *ex);
263 };
264
265 CamelType camel_isubscribe_get_type (void);
266 gboolean camel_isubscribe_subscribed(CamelStore *store, const char *name);
267 void camel_isubscribe_subscribe(CamelStore *store, const char *folder_name, CamelException *ex);
268 void camel_isubscribe_unsubscribe(CamelStore *store, const char *folder_name, CamelException *ex);
269
270 G_END_DECLS
271
272 #endif /* CAMEL_STORE_H */