0.8.6claws51
[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 typedef struct _FolderItemUpdateData    FolderItemUpdateData;
34
35 #include "prefs_folder_item.h"
36
37 #include "prefs_account.h"
38 #include "session.h"
39 #include "procmsg.h"
40 #include "msgcache.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 #if 0
53 #define MAILDIR_FOLDER(obj)     ((MaildirFolder *)obj)
54 #endif
55
56 #define FOLDER_ITEM(obj)        ((FolderItem *)obj)
57
58 #define FOLDER_ITEM_UPDATE_HOOKLIST "folder_item_update"
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 enum
81 {
82         SORT_BY_NONE,
83         SORT_BY_NUMBER,
84         SORT_BY_SIZE,
85         SORT_BY_DATE,
86         SORT_BY_FROM,
87         SORT_BY_SUBJECT,
88         SORT_BY_SCORE,
89         SORT_BY_LABEL,
90         SORT_BY_MARK,
91         SORT_BY_UNREAD,
92         SORT_BY_MIME,
93         SORT_BY_LOCKED
94 } FolderSortKey;
95
96 typedef enum
97 {
98         SORT_ASCENDING,
99         SORT_DESCENDING
100 } FolderSortType;
101
102 typedef enum
103 {
104         F_MOVE_OK,
105         F_MOVE_FAILED_DEST_IS_PARENT,
106         F_MOVE_FAILED_DEST_IS_CHILD,
107         F_MOVE_FAILED_DEST_OUTSIDE_MAILBOX,
108         F_MOVE_FAILED
109 } FolderMoveStatus;
110
111 typedef void (*FolderUIFunc)            (Folder         *folder,
112                                          FolderItem     *item,
113                                          gpointer        data);
114 typedef void (*FolderDestroyNotify)     (Folder         *folder,
115                                          FolderItem     *item,
116                                          gpointer        data);
117 typedef void (*FolderItemFunc)          (FolderItem     *item,
118                                          gpointer        data);
119
120 struct _Folder
121 {
122         FolderType type;
123
124         gchar *name;
125         PrefsAccount *account;
126
127         FolderItem *inbox;
128         FolderItem *outbox;
129         FolderItem *draft;
130         FolderItem *queue;
131         FolderItem *trash;
132
133         FolderUIFunc ui_func;
134         gpointer     ui_func_data;
135
136         GNode *node;
137
138         gpointer data;
139
140         GHashTable *newsart;
141
142         /* virtual functions */
143 /*
144         GSList * (*get_msg_list)        (Folder         *folder,
145                                          FolderItem     *item,
146                                          gboolean        use_cache);
147 */
148         FolderItem *(*item_new)         (Folder         *folder);
149         void     (*item_destroy)        (Folder         *folder,
150                                          FolderItem     *item);
151         gchar *  (*fetch_msg)           (Folder         *folder,
152                                          FolderItem     *item,
153                                          gint            num);
154         MsgInfo * (*get_msginfo)        (Folder         *folder,
155                                          FolderItem     *item,
156                                          gint            num);
157         GSList  * (*get_msginfos)       (Folder         *folder,
158                                          FolderItem     *item,
159                                          GSList         *msgnum_list);
160         gint     (*add_msg)             (Folder         *folder,
161                                          FolderItem     *dest,
162                                          const gchar    *file,
163                                          gboolean        remove_source);
164         gint     (*move_msg)            (Folder         *folder,
165                                          FolderItem     *dest,
166                                          MsgInfo        *msginfo);
167         gint     (*move_msgs_with_dest) (Folder         *folder,
168                                          FolderItem     *dest,
169                                          GSList         *msglist);
170         gint     (*copy_msg)            (Folder         *folder,
171                                          FolderItem     *dest,
172                                          MsgInfo        *msginfo);
173         gint     (*copy_msgs_with_dest) (Folder         *folder,
174                                          FolderItem     *dest,
175                                          GSList         *msglist);
176         gint     (*remove_msg)          (Folder         *folder,
177                                          FolderItem     *item,
178                                          gint            num);
179         gint     (*remove_msgs)         (Folder         *folder,
180                                          FolderItem     *item,
181                                          GSList         *msglist);
182         gint     (*remove_all_msg)      (Folder         *folder,
183                                          FolderItem     *item);
184         gboolean (*is_msg_changed)      (Folder         *folder,
185                                          FolderItem     *item,
186                                          MsgInfo        *msginfo);
187         gint     (*scan)                (Folder         *folder);
188         gint     (*get_num_list)        (Folder         *folder,
189                                          FolderItem     *item,
190                                          GSList        **list);
191         void     (*scan_tree)           (Folder         *folder);
192
193         gint     (*create_tree)         (Folder         *folder);
194         FolderItem * (*create_folder)   (Folder         *folder,
195                                          FolderItem     *parent,
196                                          const gchar    *name);
197         gint     (*rename_folder)       (Folder         *folder,
198                                          FolderItem     *item,
199                                          const gchar    *name);
200         gint     (*remove_folder)       (Folder         *folder,
201                                          FolderItem     *item);
202
203         void     (*destroy)             (Folder         *folder);
204         void     (*update_mark)         (Folder         *folder,
205                                          FolderItem     *item);
206         void     (*change_flags)        (Folder         *folder,
207                                          FolderItem     *item,
208                                          MsgInfo        *info);
209         void     (*finished_copy)       (Folder * folder, FolderItem * item);
210         void     (*finished_remove)     (Folder * folder, FolderItem * item);
211         gboolean (*check_msgnum_validity) (Folder * folder, FolderItem * item);
212 };
213
214 struct _LocalFolder
215 {
216         Folder folder;
217
218         gchar *rootpath;
219 };
220
221 struct _RemoteFolder
222 {
223         Folder folder;
224
225         Session *session;
226 };
227
228 #if 0
229 struct _MaildirFolder
230 {
231         LocalFolder lfolder;
232 };
233 #endif
234
235 struct _FolderItem
236 {
237         SpecialFolderItemType stype;
238
239         gchar *name;
240         gchar *path;
241
242         time_t mtime;
243
244         gint new;
245         gint unread;
246         gint total;
247         gint unreadmarked;
248
249         gint last_num;
250
251         MsgCache *cache;
252
253         /* special flags */
254         guint no_sub         : 1; /* no child allowed?    */
255         guint no_select      : 1; /* not selectable?      */
256         guint collapsed      : 1; /* collapsed item       */
257         guint threaded       : 1; /* threaded folder view */
258         guint hide_read_msgs : 1; /* hide read messages   */
259         guint ret_rcpt       : 1; /* return receipt       */
260
261         gint op_count;
262         guint opened    : 1; /* opened by summary view */
263         guint need_update    : 1; /* folderview for this folder should be updated */
264
265         FolderSortKey sort_key;
266         FolderSortType sort_type;
267
268         FolderItem *parent;
269
270         Folder *folder;
271
272         PrefsAccount *account;
273
274         gboolean apply_sub;
275         
276         GSList *mark_queue;
277
278         gpointer data;
279
280         PrefsFolderItem * prefs;
281 };
282
283 typedef struct {
284         FolderSortKey   sort_key;
285         FolderSortType  sort_type;
286         guint           collapsed       : 1;
287         guint           threaded        : 1;
288         guint           hide_read_msgs  : 1; /* CLAWS */
289         guint           ret_rcpt        : 1; /* CLAWS */
290 } PersistPrefs;
291
292 struct _FolderItemUpdateData
293 {
294         FolderItem      *item;
295         gboolean         content_change;
296 };
297
298 Folder     *folder_new                  (FolderType      type,
299                                          const gchar    *name,
300                                          const gchar    *path);
301 void        folder_local_folder_init    (Folder         *folder,
302                                          const gchar    *name,
303                                          const gchar    *path);
304 void        folder_remote_folder_init   (Folder         *folder,
305                                          const gchar    *name,
306                                          const gchar    *path);
307
308 void        folder_destroy              (Folder         *folder);
309 void        folder_local_folder_destroy (LocalFolder    *lfolder);
310 void        folder_remote_folder_destroy(RemoteFolder   *rfolder);
311
312 FolderItem *folder_item_new     (Folder         *folder,
313                                  const gchar    *name,
314                                  const gchar    *path);
315 void        folder_item_append  (FolderItem     *parent,
316                                  FolderItem     *item);
317 void        folder_item_remove  (FolderItem     *item);
318 void        folder_item_destroy (FolderItem     *item);
319
320 void        folder_set_ui_func  (Folder         *folder,
321                                  FolderUIFunc    func,
322                                  gpointer        data);
323 void        folder_set_name     (Folder         *folder,
324                                  const gchar    *name);
325 void        folder_tree_destroy (Folder         *folder);
326
327 void   folder_add               (Folder         *folder);
328
329 GList *folder_get_list          (void);
330 gint   folder_read_list         (void);
331 void   folder_write_list        (void);
332 void   folder_scan_tree         (Folder *folder);
333 FolderItem *folder_create_folder(FolderItem     *parent, const gchar *name);
334 void   folder_update_op_count           (void);
335 void   folder_func_to_all_folders       (FolderItemFunc function,
336                                          gpointer data);
337 void   folder_count_total_msgs  (guint          *new,
338                                  guint          *unread,
339                                  guint          *unreadmarked,
340                                  guint          *total);
341
342 Folder     *folder_find_from_path               (const gchar    *path);
343 Folder     *folder_find_from_name               (const gchar    *name,
344                                                  FolderType      type);
345 FolderItem *folder_find_item_from_path          (const gchar    *path);
346 gchar      *folder_get_identifier               (Folder         *folder);
347 gchar      *folder_item_get_identifier          (FolderItem     *item);
348 FolderItem *folder_find_item_from_identifier    (const gchar    *identifier);
349
350 Folder     *folder_get_default_folder   (void);
351 FolderItem *folder_get_default_inbox    (void);
352 FolderItem *folder_get_default_outbox   (void);
353 FolderItem *folder_get_default_draft    (void);
354 FolderItem *folder_get_default_queue    (void);
355 FolderItem *folder_get_default_trash    (void);
356 FolderItem *folder_get_default_processing (void);
357 void folder_set_missing_folders         (void);
358 void folder_unref_account_all           (PrefsAccount   *account);
359
360 gchar *folder_get_path                  (Folder         *folder);
361 gchar *folder_item_get_path             (FolderItem     *item);
362
363 gint   folder_item_open                 (FolderItem     *item);
364 void   folder_item_close                (FolderItem     *item);
365 gint   folder_item_scan                 (FolderItem     *item);
366 void   folder_item_scan_foreach         (GHashTable     *table);
367 MsgInfo *folder_item_get_msginfo        (FolderItem     *item,
368                                          gint            num);
369 MsgInfo *folder_item_get_msginfo_by_msgid(FolderItem    *item,
370                                          const gchar    *msgid);
371 GSList *folder_item_get_msg_list        (FolderItem     *item);
372 gchar *folder_item_fetch_msg            (FolderItem     *item,
373                                          gint            num);
374 gint   folder_item_add_msg              (FolderItem     *dest,
375                                          const gchar    *file,
376                                          gboolean        remove_source);
377 gint   folder_item_move_to              (FolderItem     *src,
378                                          FolderItem     *dest,
379                                          FolderItem    **new_item);
380 gint   folder_item_move_msg             (FolderItem     *dest,
381                                          MsgInfo        *msginfo);
382 gint   folder_item_move_msgs_with_dest  (FolderItem     *dest,
383                                          GSList         *msglist);
384 gint   folder_item_copy_msg             (FolderItem     *dest,
385                                          MsgInfo        *msginfo);
386 gint   folder_item_copy_msgs_with_dest  (FolderItem     *dest,
387                                          GSList         *msglist);
388 gint   folder_item_remove_msg           (FolderItem     *item,
389                                          gint            num);
390 gint   folder_item_remove_msgs          (FolderItem     *item,
391                                          GSList         *msglist);
392 gint   folder_item_remove_all_msg       (FolderItem     *item);
393 gboolean folder_item_is_msg_changed     (FolderItem     *item,
394                                          MsgInfo        *msginfo);
395 gchar *folder_item_get_cache_file       (FolderItem     *item);
396 gchar *folder_item_get_mark_file        (FolderItem     *item);
397 gchar * folder_item_get_identifier(FolderItem * item);
398
399 GHashTable *folder_persist_prefs_new    (Folder *folder);
400 void folder_persist_prefs_free          (GHashTable *pptable);
401 const PersistPrefs *folder_get_persist_prefs
402                                         (GHashTable *pptable, const char *name);
403
404 void folder_item_restore_persist_prefs  (FolderItem *item, GHashTable *pptable);
405 void folder_clean_cache_memory          ();
406 void folder_item_write_cache            (FolderItem *item);
407 void folder_item_set_default_flags      (FolderItem *dest, MsgFlags *flags);
408
409 void folder_item_apply_processing       (FolderItem *item);
410
411 void folder_update_item                 (FolderItem *item,
412                                          gboolean contentchange);
413 void folder_update_items_when_required  (gboolean contentchange);
414 void folder_update_item_recursive       (FolderItem *item,
415                                          gboolean update_summary);
416
417 #endif /* __FOLDER_H__ */