5f8f62c2828e08d425a66f65e019ab7d4a485eea
[claws.git] / src / folder.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2002 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 #if 0
30 typedef struct _MaildirFolder   MaildirFolder;
31 #endif
32 typedef struct _FolderItem      FolderItem;
33
34 #include "prefs_folder_item.h"
35
36 #include "prefs_account.h"
37 #include "session.h"
38 #include "procmsg.h"
39
40 #define FOLDER(obj)             ((Folder *)obj)
41 #define FOLDER_TYPE(obj)        (FOLDER(obj)->type)
42
43 #define LOCAL_FOLDER(obj)       ((LocalFolder *)obj)
44 #define REMOTE_FOLDER(obj)      ((RemoteFolder *)obj)
45
46 #define FOLDER_IS_LOCAL(obj)    (FOLDER_TYPE(obj) == F_MH      || \
47                                  FOLDER_TYPE(obj) == F_MBOX    || \
48                                  FOLDER_TYPE(obj) == F_MAILDIR)
49
50 #if 0
51 #define MAILDIR_FOLDER(obj)     ((MaildirFolder *)obj)
52 #endif
53
54 #define FOLDER_ITEM(obj)        ((FolderItem *)obj)
55
56 typedef enum
57 {
58         F_MH,
59         F_MBOX,
60         F_MAILDIR,
61         F_IMAP,
62         F_NEWS,
63         F_UNKNOWN
64 } FolderType;
65
66 typedef enum
67 {
68         F_NORMAL,
69         F_INBOX,
70         F_OUTBOX,
71         F_DRAFT,
72         F_QUEUE,
73         F_TRASH
74 } SpecialFolderItemType;
75
76 typedef void (*FolderUIFunc)            (Folder         *folder,
77                                          FolderItem     *item,
78                                          gpointer        data);
79 typedef void (*FolderDestroyNotify)     (Folder         *folder,
80                                          FolderItem     *item,
81                                          gpointer        data);
82
83 struct _Folder
84 {
85         FolderType type;
86
87         gchar *name;
88         PrefsAccount *account;
89
90         FolderItem *inbox;
91         FolderItem *outbox;
92         FolderItem *draft;
93         FolderItem *queue;
94         FolderItem *trash;
95
96         FolderUIFunc ui_func;
97         gpointer     ui_func_data;
98
99         GNode *node;
100
101         gpointer data;
102
103         GHashTable *newsart;
104
105         /* virtual functions */
106         GSList * (*get_msg_list)        (Folder         *folder,
107                                          FolderItem     *item,
108                                          gboolean        use_cache);
109         gchar *  (*fetch_msg)           (Folder         *folder,
110                                          FolderItem     *item,
111                                          gint            num);
112         gint     (*add_msg)             (Folder         *folder,
113                                          FolderItem     *dest,
114                                          const gchar    *file,
115                                          gboolean        remove_source);
116         gint     (*move_msg)            (Folder         *folder,
117                                          FolderItem     *dest,
118                                          MsgInfo        *msginfo);
119         gint     (*move_msgs_with_dest) (Folder         *folder,
120                                          FolderItem     *dest,
121                                          GSList         *msglist);
122         gint     (*copy_msg)            (Folder         *folder,
123                                          FolderItem     *dest,
124                                          MsgInfo        *msginfo);
125         gint     (*copy_msgs_with_dest) (Folder         *folder,
126                                          FolderItem     *dest,
127                                          GSList         *msglist);
128         gint     (*remove_msg)          (Folder         *folder,
129                                          FolderItem     *item,
130                                          gint            num);
131         gint     (*remove_all_msg)      (Folder         *folder,
132                                          FolderItem     *item);
133         gboolean (*is_msg_changed)      (Folder         *folder,
134                                          FolderItem     *item,
135                                          MsgInfo        *msginfo);
136         gint     (*scan)                (Folder         *folder,
137                                          FolderItem     *item);
138         void     (*scan_tree)           (Folder         *folder);
139
140         gint     (*create_tree)         (Folder         *folder);
141         FolderItem * (*create_folder)   (Folder         *folder,
142                                          FolderItem     *parent,
143                                          const gchar    *name);
144         gint     (*rename_folder)       (Folder         *folder,
145                                          FolderItem     *item,
146                                          const gchar    *name);
147         gint     (*remove_folder)       (Folder         *folder,
148                                          FolderItem     *item);
149         void     (*update_mark)         (Folder         *folder,
150                                          FolderItem     *item);
151         void     (*change_flags)        (Folder         *folder,
152                                          FolderItem     *item,
153                                          MsgInfo        *info);
154         void     (*finished_copy)       (Folder * folder, FolderItem * item);
155         void     (*finished_remove)       (Folder * folder, FolderItem * item);
156 };
157
158 struct _LocalFolder
159 {
160         Folder folder;
161
162         gchar *rootpath;
163 };
164
165 struct _RemoteFolder
166 {
167         Folder folder;
168
169         Session *session;
170 };
171
172 #if 0
173 struct _MaildirFolder
174 {
175         LocalFolder lfolder;
176 };
177 #endif
178
179 struct _FolderItem
180 {
181         SpecialFolderItemType stype;
182
183         gchar *name;
184         gchar *path;
185         PrefsAccount *account;
186
187         time_t mtime;
188
189         gint new;
190         gint unread;
191         gint total;
192
193         gint last_num;
194
195         /* special flags */
196         guint no_sub         : 1; /* no child allowed?    */
197         guint no_select      : 1; /* not selectable?      */
198         guint collapsed      : 1; /* collapsed item       */
199         guint threaded       : 1; /* threaded folder view */
200         guint hide_read_msgs : 1; /* hide read messages   */
201         guint ret_rcpt       : 1; /* return receipt       */
202
203         gint op_count;
204         guint opened    : 1; /* opened by summary view */
205
206         FolderItem *parent;
207
208         Folder *folder;
209
210         GSList *mark_queue;
211
212         gpointer data;
213
214         PrefsFolderItem * prefs;
215 };
216
217 typedef struct {
218         guint   collapsed       : 1;
219         guint   threaded        : 1;
220         guint   hide_read_msgs  : 1; /* CLAWS */
221         guint   ret_rcpt        : 1; /* CLAWS */
222 } PersistPrefs;
223
224 Folder     *folder_new                  (FolderType      type,
225                                          const gchar    *name,
226                                          const gchar    *path);
227 void        folder_local_folder_init    (Folder         *folder,
228                                          const gchar    *name,
229                                          const gchar    *path);
230 void        folder_remote_folder_init   (Folder         *folder,
231                                          const gchar    *name,
232                                          const gchar    *path);
233
234 void        folder_destroy              (Folder         *folder);
235 void        folder_local_folder_destroy (LocalFolder    *lfolder);
236 void        folder_remote_folder_destroy(RemoteFolder   *rfolder);
237
238 FolderItem *folder_item_new     (const gchar    *name,
239                                  const gchar    *path);
240 void        folder_item_append  (FolderItem     *parent,
241                                  FolderItem     *item);
242 void        folder_item_remove  (FolderItem     *item);
243 void        folder_item_destroy (FolderItem     *item);
244
245 void        folder_set_ui_func  (Folder         *folder,
246                                  FolderUIFunc    func,
247                                  gpointer        data);
248 void        folder_set_name     (Folder         *folder,
249                                  const gchar    *name);
250 void        folder_tree_destroy (Folder         *folder);
251
252 void   folder_add               (Folder         *folder);
253
254 GList *folder_get_list          (void);
255 gint   folder_read_list         (void);
256 void   folder_write_list        (void);
257 void   folder_update_op_count           (void);
258 void   folder_count_total_msgs  (guint          *new,
259                                  guint          *unread,
260                                  guint          *total);
261
262 Folder     *folder_find_from_path               (const gchar    *path);
263 Folder     *folder_find_from_name               (const gchar    *name,
264                                                  FolderType      type);
265 FolderItem *folder_find_item_from_path          (const gchar    *path);
266 gchar      *folder_get_identifier               (Folder         *folder);
267 gchar      *folder_item_get_identifier          (FolderItem     *item);
268 FolderItem *folder_find_item_from_identifier    (const gchar    *identifier);
269
270 Folder     *folder_get_default_folder   (void);
271 FolderItem *folder_get_default_inbox    (void);
272 FolderItem *folder_get_default_outbox   (void);
273 FolderItem *folder_get_default_draft    (void);
274 FolderItem *folder_get_default_queue    (void);
275 FolderItem *folder_get_default_trash    (void);
276 FolderItem *folder_get_default_processing (void);
277 void folder_set_missing_folders         (void);
278
279 gchar *folder_item_get_path             (FolderItem     *item);
280 gint   folder_item_scan                 (FolderItem     *item);
281 void   folder_item_scan_foreach         (GHashTable     *table);
282 gchar *folder_item_fetch_msg            (FolderItem     *item,
283                                          gint            num);
284 gint   folder_item_add_msg              (FolderItem     *dest,
285                                          const gchar    *file,
286                                          gboolean        remove_source);
287 gint   folder_item_move_msg             (FolderItem     *dest,
288                                          MsgInfo        *msginfo);
289 gint   folder_item_move_msgs_with_dest  (FolderItem     *dest,
290                                          GSList         *msglist);
291 gint   folder_item_copy_msg             (FolderItem     *dest,
292                                          MsgInfo        *msginfo);
293 gint   folder_item_copy_msgs_with_dest  (FolderItem     *dest,
294                                          GSList         *msglist);
295 gint   folder_item_remove_msg           (FolderItem     *item,
296                                          gint            num);
297 gint   folder_item_remove_msgs          (FolderItem     *item,
298                                          GSList         *msglist);
299 gint   folder_item_remove_all_msg       (FolderItem     *item);
300 gboolean folder_item_is_msg_changed     (FolderItem     *item,
301                                          MsgInfo        *msginfo);
302 gchar *folder_item_get_cache_file       (FolderItem     *item);
303 gchar *folder_item_get_mark_file        (FolderItem     *item);
304 gchar * folder_item_get_identifier(FolderItem * item);
305 FolderItem * folder_find_item_from_identifier(const gchar *identifier);
306
307 GHashTable *folder_persist_prefs_new    (Folder *folder);
308 void folder_persist_prefs_free          (GHashTable *pptable);
309 const PersistPrefs *folder_get_persist_prefs
310                                         (GHashTable *pptable, const char *name);
311
312 void folder_item_restore_persist_prefs  (FolderItem *item, GHashTable *pptable);
313
314 #endif /* __FOLDER_H__ */