sync with 0.7.6cvs21
[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 enum
77 {
78         SORT_BY_NONE,
79         SORT_BY_NUMBER,
80         SORT_BY_SIZE,
81         SORT_BY_DATE,
82         SORT_BY_FROM,
83         SORT_BY_SUBJECT,
84         SORT_BY_SCORE,
85         SORT_BY_LABEL,
86         SORT_BY_MARK,
87         SORT_BY_UNREAD,
88         SORT_BY_MIME,
89         SORT_BY_LOCKED
90 } FolderSortKey;
91
92 typedef enum
93 {
94         SORT_ASCENDING,
95         SORT_DESCENDING
96 } FolderSortType;
97
98 typedef void (*FolderUIFunc)            (Folder         *folder,
99                                          FolderItem     *item,
100                                          gpointer        data);
101 typedef void (*FolderDestroyNotify)     (Folder         *folder,
102                                          FolderItem     *item,
103                                          gpointer        data);
104
105 struct _Folder
106 {
107         FolderType type;
108
109         gchar *name;
110         PrefsAccount *account;
111
112         FolderItem *inbox;
113         FolderItem *outbox;
114         FolderItem *draft;
115         FolderItem *queue;
116         FolderItem *trash;
117
118         FolderUIFunc ui_func;
119         gpointer     ui_func_data;
120
121         GNode *node;
122
123         gpointer data;
124
125         GHashTable *newsart;
126
127         /* virtual functions */
128         GSList * (*get_msg_list)        (Folder         *folder,
129                                          FolderItem     *item,
130                                          gboolean        use_cache);
131         gchar *  (*fetch_msg)           (Folder         *folder,
132                                          FolderItem     *item,
133                                          gint            num);
134         gint     (*add_msg)             (Folder         *folder,
135                                          FolderItem     *dest,
136                                          const gchar    *file,
137                                          gboolean        remove_source);
138         gint     (*move_msg)            (Folder         *folder,
139                                          FolderItem     *dest,
140                                          MsgInfo        *msginfo);
141         gint     (*move_msgs_with_dest) (Folder         *folder,
142                                          FolderItem     *dest,
143                                          GSList         *msglist);
144         gint     (*copy_msg)            (Folder         *folder,
145                                          FolderItem     *dest,
146                                          MsgInfo        *msginfo);
147         gint     (*copy_msgs_with_dest) (Folder         *folder,
148                                          FolderItem     *dest,
149                                          GSList         *msglist);
150         gint     (*remove_msg)          (Folder         *folder,
151                                          FolderItem     *item,
152                                          gint            num);
153         gint     (*remove_all_msg)      (Folder         *folder,
154                                          FolderItem     *item);
155         gboolean (*is_msg_changed)      (Folder         *folder,
156                                          FolderItem     *item,
157                                          MsgInfo        *msginfo);
158         gint     (*scan)                (Folder         *folder,
159                                          FolderItem     *item);
160         void     (*scan_tree)           (Folder         *folder);
161
162         gint     (*create_tree)         (Folder         *folder);
163         FolderItem * (*create_folder)   (Folder         *folder,
164                                          FolderItem     *parent,
165                                          const gchar    *name);
166         gint     (*rename_folder)       (Folder         *folder,
167                                          FolderItem     *item,
168                                          const gchar    *name);
169         gint     (*remove_folder)       (Folder         *folder,
170                                          FolderItem     *item);
171         void     (*update_mark)         (Folder         *folder,
172                                          FolderItem     *item);
173         void     (*change_flags)        (Folder         *folder,
174                                          FolderItem     *item,
175                                          MsgInfo        *info);
176         void     (*finished_copy)       (Folder * folder, FolderItem * item);
177         void     (*finished_remove)       (Folder * folder, FolderItem * item);
178 };
179
180 struct _LocalFolder
181 {
182         Folder folder;
183
184         gchar *rootpath;
185 };
186
187 struct _RemoteFolder
188 {
189         Folder folder;
190
191         Session *session;
192 };
193
194 #if 0
195 struct _MaildirFolder
196 {
197         LocalFolder lfolder;
198 };
199 #endif
200
201 struct _FolderItem
202 {
203         SpecialFolderItemType stype;
204
205         gchar *name;
206         gchar *path;
207         PrefsAccount *account;
208
209         time_t mtime;
210
211         gint new;
212         gint unread;
213         gint total;
214
215         gint last_num;
216
217         /* special flags */
218         guint no_sub         : 1; /* no child allowed?    */
219         guint no_select      : 1; /* not selectable?      */
220         guint collapsed      : 1; /* collapsed item       */
221         guint threaded       : 1; /* threaded folder view */
222         guint hide_read_msgs : 1; /* hide read messages   */
223         guint ret_rcpt       : 1; /* return receipt       */
224
225         gint op_count;
226         guint opened    : 1; /* opened by summary view */
227
228         FolderSortKey sort_key;
229         FolderSortType sort_type;
230
231         FolderItem *parent;
232
233         Folder *folder;
234
235         GSList *mark_queue;
236
237         gpointer data;
238
239         PrefsFolderItem * prefs;
240 };
241
242 typedef struct {
243         guint   collapsed       : 1;
244         guint   threaded        : 1;
245         guint   hide_read_msgs  : 1; /* CLAWS */
246         guint   ret_rcpt        : 1; /* CLAWS */
247 } PersistPrefs;
248
249 Folder     *folder_new                  (FolderType      type,
250                                          const gchar    *name,
251                                          const gchar    *path);
252 void        folder_local_folder_init    (Folder         *folder,
253                                          const gchar    *name,
254                                          const gchar    *path);
255 void        folder_remote_folder_init   (Folder         *folder,
256                                          const gchar    *name,
257                                          const gchar    *path);
258
259 void        folder_destroy              (Folder         *folder);
260 void        folder_local_folder_destroy (LocalFolder    *lfolder);
261 void        folder_remote_folder_destroy(RemoteFolder   *rfolder);
262
263 FolderItem *folder_item_new     (const gchar    *name,
264                                  const gchar    *path);
265 void        folder_item_append  (FolderItem     *parent,
266                                  FolderItem     *item);
267 void        folder_item_remove  (FolderItem     *item);
268 void        folder_item_destroy (FolderItem     *item);
269
270 void        folder_set_ui_func  (Folder         *folder,
271                                  FolderUIFunc    func,
272                                  gpointer        data);
273 void        folder_set_name     (Folder         *folder,
274                                  const gchar    *name);
275 void        folder_tree_destroy (Folder         *folder);
276
277 void   folder_add               (Folder         *folder);
278
279 GList *folder_get_list          (void);
280 gint   folder_read_list         (void);
281 void   folder_write_list        (void);
282 void   folder_update_op_count           (void);
283 void   folder_count_total_msgs  (guint          *new,
284                                  guint          *unread,
285                                  guint          *total);
286
287 Folder     *folder_find_from_path               (const gchar    *path);
288 Folder     *folder_find_from_name               (const gchar    *name,
289                                                  FolderType      type);
290 FolderItem *folder_find_item_from_path          (const gchar    *path);
291 gchar      *folder_get_identifier               (Folder         *folder);
292 gchar      *folder_item_get_identifier          (FolderItem     *item);
293 FolderItem *folder_find_item_from_identifier    (const gchar    *identifier);
294
295 Folder     *folder_get_default_folder   (void);
296 FolderItem *folder_get_default_inbox    (void);
297 FolderItem *folder_get_default_outbox   (void);
298 FolderItem *folder_get_default_draft    (void);
299 FolderItem *folder_get_default_queue    (void);
300 FolderItem *folder_get_default_trash    (void);
301 FolderItem *folder_get_default_processing (void);
302 void folder_set_missing_folders         (void);
303
304 gchar *folder_item_get_path             (FolderItem     *item);
305 gint   folder_item_scan                 (FolderItem     *item);
306 void   folder_item_scan_foreach         (GHashTable     *table);
307 gchar *folder_item_fetch_msg            (FolderItem     *item,
308                                          gint            num);
309 gint   folder_item_add_msg              (FolderItem     *dest,
310                                          const gchar    *file,
311                                          gboolean        remove_source);
312 gint   folder_item_move_msg             (FolderItem     *dest,
313                                          MsgInfo        *msginfo);
314 gint   folder_item_move_msgs_with_dest  (FolderItem     *dest,
315                                          GSList         *msglist);
316 gint   folder_item_copy_msg             (FolderItem     *dest,
317                                          MsgInfo        *msginfo);
318 gint   folder_item_copy_msgs_with_dest  (FolderItem     *dest,
319                                          GSList         *msglist);
320 gint   folder_item_remove_msg           (FolderItem     *item,
321                                          gint            num);
322 gint   folder_item_remove_msgs          (FolderItem     *item,
323                                          GSList         *msglist);
324 gint   folder_item_remove_all_msg       (FolderItem     *item);
325 gboolean folder_item_is_msg_changed     (FolderItem     *item,
326                                          MsgInfo        *msginfo);
327 gchar *folder_item_get_cache_file       (FolderItem     *item);
328 gchar *folder_item_get_mark_file        (FolderItem     *item);
329 gchar * folder_item_get_identifier(FolderItem * item);
330 FolderItem * folder_find_item_from_identifier(const gchar *identifier);
331
332 GHashTable *folder_persist_prefs_new    (Folder *folder);
333 void folder_persist_prefs_free          (GHashTable *pptable);
334 const PersistPrefs *folder_get_persist_prefs
335                                         (GHashTable *pptable, const char *name);
336
337 void folder_item_restore_persist_prefs  (FolderItem *item, GHashTable *pptable);
338
339 #endif /* __FOLDER_H__ */