fd611ce616c7b78c3a6fc910ac18abf65346e1ac
[claws.git] / src / folder.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __FOLDER_H__
21 #define __FOLDER_H__
22
23 #include <glib.h>
24 #include <time.h>
25
26 typedef struct _Folder          Folder;
27 typedef struct _LocalFolder     LocalFolder;
28 typedef struct _RemoteFolder    RemoteFolder;
29 typedef struct _MHFolder        MHFolder;
30 typedef struct _MboxFolder      MboxFolder;
31 typedef struct _MaildirFolder   MaildirFolder;
32 typedef struct _IMAPFolder      IMAPFolder;
33 typedef struct _NewsFolder      NewsFolder;
34 typedef struct _FolderItem      FolderItem;
35
36 #include "prefs_folder_item.h"
37
38 #include "prefs_account.h"
39 #include "session.h"
40 #include "procmsg.h"
41
42 #define FOLDER(obj)             ((Folder *)obj)
43 #define FOLDER_TYPE(obj)        (FOLDER(obj)->type)
44
45 #define LOCAL_FOLDER(obj)       ((LocalFolder *)obj)
46 #define REMOTE_FOLDER(obj)      ((RemoteFolder *)obj)
47
48 #define FOLDER_IS_LOCAL(obj)    (FOLDER_TYPE(obj) == F_MH      || \
49                                  FOLDER_TYPE(obj) == F_MBOX    || \
50                                  FOLDER_TYPE(obj) == F_MAILDIR)
51
52 #define MH_FOLDER(obj)          ((MHFolder *)obj)
53 #define MBOX_FOLDER(obj)        ((MboxFolder *)obj)
54 #define MAILDIR_FOLDER(obj)     ((MaildirFolder *)obj)
55 #define IMAP_FOLDER(obj)        ((IMAPFolder *)obj)
56 #define NEWS_FOLDER(obj)        ((NewsFolder *)obj)
57
58 #define FOLDER_ITEM(obj)        ((FolderItem *)obj)
59
60 typedef enum
61 {
62         F_MH,
63         F_MBOX,
64         F_MAILDIR,
65         F_IMAP,
66         F_NEWS,
67         F_UNKNOWN
68 } FolderType;
69
70 typedef enum
71 {
72         F_NORMAL,
73         F_INBOX,
74         F_OUTBOX,
75         F_DRAFT,
76         F_QUEUE,
77         F_TRASH
78 } SpecialFolderItemType;
79
80 typedef void (*FolderUIFunc)            (Folder         *folder,
81                                          FolderItem     *item,
82                                          gpointer        data);
83 typedef void (*FolderDestroyNotify)     (Folder         *folder,
84                                          FolderItem     *item,
85                                          gpointer        data);
86
87 struct _Folder
88 {
89         FolderType type;
90
91         gchar *name;
92         PrefsAccount *account;
93
94         FolderItem *inbox;
95         FolderItem *outbox;
96         FolderItem *draft;
97         FolderItem *queue;
98         FolderItem *trash;
99
100         FolderUIFunc ui_func;
101         gpointer     ui_func_data;
102
103         GNode *node;
104
105         gpointer data;
106
107         /* virtual functions */
108         GSList * (*get_msg_list)        (Folder         *folder,
109                                          FolderItem     *item,
110                                          gboolean        use_cache);
111         gchar *  (*fetch_msg)           (Folder         *folder,
112                                          FolderItem     *item,
113                                          gint            num);
114         gint     (*add_msg)             (Folder         *folder,
115                                          FolderItem     *dest,
116                                          const gchar    *file,
117                                          gboolean        remove_source);
118         gint     (*move_msg)            (Folder         *folder,
119                                          FolderItem     *dest,
120                                          MsgInfo        *msginfo);
121         gint     (*move_msgs_with_dest) (Folder         *folder,
122                                          FolderItem     *dest,
123                                          GSList         *msglist);
124         gint     (*copy_msg)            (Folder         *folder,
125                                          FolderItem     *dest,
126                                          MsgInfo        *msginfo);
127         gint     (*copy_msgs_with_dest) (Folder         *folder,
128                                          FolderItem     *dest,
129                                          GSList         *msglist);
130         gint     (*remove_msg)          (Folder         *folder,
131                                          FolderItem     *item,
132                                          gint            num);
133         gint     (*remove_all_msg)      (Folder         *folder,
134                                          FolderItem     *item);
135         gboolean (*is_msg_changed)      (Folder         *folder,
136                                          FolderItem     *item,
137                                          MsgInfo        *msginfo);
138         void     (*scan)                (Folder         *folder,
139                                          FolderItem     *item);
140         void     (*scan_tree)           (Folder         *folder);
141
142         gint     (*create_tree)         (Folder         *folder);
143         FolderItem * (*create_folder)   (Folder         *folder,
144                                          FolderItem     *parent,
145                                          const gchar    *name);
146         gint     (*rename_folder)       (Folder         *folder,
147                                          FolderItem     *item,
148                                          const gchar    *name);
149         gint     (*remove_folder)       (Folder         *folder,
150                                          FolderItem     *item);
151         void     (*update_mark)         (Folder         *folder,
152                                          FolderItem     *item);
153         void     (*change_flags)        (Folder         *folder,
154                                          FolderItem     *item,
155                                          MsgInfo        *info);
156         void     (*finished_copy)       (Folder * folder, FolderItem * item);
157         void     (*finished_remove)       (Folder * folder, FolderItem * item);
158 };
159
160 struct _LocalFolder
161 {
162         Folder folder;
163
164         gchar *rootpath;
165 };
166
167 struct _RemoteFolder
168 {
169         Folder folder;
170
171         Session *session;
172 };
173
174 struct _MHFolder
175 {
176         LocalFolder lfolder;
177 };
178
179 struct _MboxFolder
180 {
181         LocalFolder lfolder;
182 };
183
184 struct _MaildirFolder
185 {
186         LocalFolder lfolder;
187 };
188
189 struct _IMAPFolder
190 {
191         RemoteFolder rfolder;
192
193         GList *namespace;       /* list of IMAPNameSpace */
194 };
195
196 struct _NewsFolder
197 {
198         RemoteFolder rfolder;
199
200         gboolean use_auth;
201 };
202
203 struct _FolderItem
204 {
205         SpecialFolderItemType stype;
206
207         gchar *name;
208         gchar *path;
209         PrefsAccount *account;
210
211         time_t mtime;
212
213         gint new;
214         gint unread;
215         gint total;
216
217         gint last_num;
218
219         /* special flags */
220         guint no_sub         : 1; /* no child allowed?    */
221         guint no_select      : 1; /* not selectable?      */
222         guint collapsed      : 1; /* collapsed item       */
223         guint threaded       : 1; /* threaded folder view */
224         guint hide_read_msgs : 1; /* hide read messages   */
225         guint ret_rcpt       : 1; /* return receipt       */
226
227         gint op_count;
228
229         FolderItem *parent;
230
231         Folder *folder;
232
233         gpointer data;
234
235         PrefsFolderItem * prefs;
236 };
237
238 Folder     *folder_new          (FolderType      type,
239                                  const gchar    *name,
240                                  const gchar    *path);
241 Folder     *mh_folder_new       (const gchar    *name,
242                                  const gchar    *path);
243 Folder     *mbox_folder_new     (const gchar    *name,
244                                  const gchar    *path);
245 Folder     *maildir_folder_new  (const gchar    *name,
246                                  const gchar    *path);
247 Folder     *imap_folder_new     (const gchar    *name,
248                                  const gchar    *path);
249 Folder     *news_folder_new     (const gchar    *name,
250                                  const gchar    *path);
251 FolderItem *folder_item_new     (const gchar    *name,
252                                  const gchar    *path);
253 void        folder_item_append  (FolderItem     *parent,
254                                  FolderItem     *item);
255 void        folder_item_remove  (FolderItem     *item);
256 void        folder_item_destroy (FolderItem     *item);
257 void        folder_set_ui_func  (Folder         *folder,
258                                  FolderUIFunc    func,
259                                  gpointer        data);
260 void        folder_set_name     (Folder         *folder,
261                                  const gchar    *name);
262 void        folder_destroy      (Folder         *folder);
263 void        folder_tree_destroy (Folder         *folder);
264
265 void   folder_add               (Folder         *folder);
266
267 GList *folder_get_list          (void);
268 gint   folder_read_list         (void);
269 void   folder_write_list        (void);
270 void   folder_update_op_count           (void);
271 void   folder_count_total_msgs  (guint          *new,
272                                  guint          *unread,
273                                  guint          *total);
274
275 Folder     *folder_find_from_path       (const gchar    *path);
276 FolderItem *folder_find_item_from_path  (const gchar    *path);
277 Folder     *folder_get_default_folder   (void);
278 FolderItem *folder_get_default_inbox    (void);
279 FolderItem *folder_get_default_outbox   (void);
280 FolderItem *folder_get_default_draft    (void);
281 FolderItem *folder_get_default_queue    (void);
282 FolderItem *folder_get_default_trash    (void);
283 FolderItem *folder_get_default_processing (void);
284
285 gchar *folder_item_get_path             (FolderItem     *item);
286 void   folder_item_scan                 (FolderItem     *item);
287 void   folder_item_scan_foreach         (GHashTable     *table);
288 gchar *folder_item_fetch_msg            (FolderItem     *item,
289                                          gint            num);
290 gint   folder_item_add_msg              (FolderItem     *dest,
291                                          const gchar    *file,
292                                          gboolean        remove_source);
293 gint   folder_item_move_msg             (FolderItem     *dest,
294                                          MsgInfo        *msginfo);
295 gint   folder_item_move_msgs_with_dest  (FolderItem     *dest,
296                                          GSList         *msglist);
297 gint   folder_item_copy_msg             (FolderItem     *dest,
298                                          MsgInfo        *msginfo);
299 gint   folder_item_copy_msgs_with_dest  (FolderItem     *dest,
300                                          GSList         *msglist);
301 gint   folder_item_remove_msg           (FolderItem     *item,
302                                          gint            num);
303 gint   folder_item_remove_msgs          (FolderItem     *item,
304                                          GSList         *msglist);
305 gint   folder_item_remove_all_msg       (FolderItem     *item);
306 gboolean folder_item_is_msg_changed     (FolderItem     *item,
307                                          MsgInfo        *msginfo);
308 gchar *folder_item_get_cache_file       (FolderItem     *item);
309 gchar *folder_item_get_mark_file        (FolderItem     *item);
310 gchar * folder_item_get_identifier(FolderItem * item);
311 FolderItem * folder_find_item_from_identifier(const gchar *identifier);
312
313 #endif /* __FOLDER_H__ */