0.9.4claws71
[claws.git] / src / folder.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2003 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 _FolderClass             FolderClass;
28 typedef struct _LocalFolder             LocalFolder;
29 typedef struct _RemoteFolder            RemoteFolder;
30 #if 0
31 typedef struct _MaildirFolder           MaildirFolder;
32 #endif
33 typedef struct _FolderItem              FolderItem;
34
35 typedef struct _FolderUpdateData        FolderUpdateData;
36 typedef struct _FolderItemUpdateData    FolderItemUpdateData;
37
38 #define FOLDER(obj)             ((Folder *)obj)
39 #define FOLDER_TYPE(obj)        (FOLDER(obj)->klass->type)
40
41 #define FOLDER_CLASS(obj)       (FOLDER(obj)->klass)
42 #define LOCAL_FOLDER(obj)       ((LocalFolder *)obj)
43 #define REMOTE_FOLDER(obj)      ((RemoteFolder *)obj)
44
45 #define FOLDER_IS_LOCAL(obj)    (FOLDER_TYPE(obj) == F_MH      || \
46                                  FOLDER_TYPE(obj) == F_MBOX    || \
47                                  FOLDER_TYPE(obj) == F_MAILDIR)
48
49 #if 0
50 #define MAILDIR_FOLDER(obj)     ((MaildirFolder *)obj)
51 #endif
52
53 #define FOLDER_ITEM(obj)        ((FolderItem *)obj)
54
55 #define FOLDER_UPDATE_HOOKLIST "folder_update"
56 #define FOLDER_ITEM_UPDATE_HOOKLIST "folder_item_update"
57
58 typedef enum
59 {
60         F_MH,
61         F_MBOX,
62         F_MAILDIR,
63         F_IMAP,
64         F_NEWS,
65         F_UNKNOWN
66 } FolderType;
67
68 typedef enum
69 {
70         F_NORMAL,
71         F_INBOX,
72         F_OUTBOX,
73         F_DRAFT,
74         F_QUEUE,
75         F_TRASH
76 } SpecialFolderItemType;
77
78 typedef enum
79 {
80         SORT_BY_NONE,
81         SORT_BY_NUMBER,
82         SORT_BY_SIZE,
83         SORT_BY_DATE,
84         SORT_BY_FROM,
85         SORT_BY_SUBJECT,
86         SORT_BY_SCORE,
87         SORT_BY_LABEL,
88         SORT_BY_MARK,
89         SORT_BY_STATUS,
90         SORT_BY_MIME,
91         SORT_BY_TO,
92         SORT_BY_LOCKED
93 } FolderSortKey;
94
95 typedef enum
96 {
97         SORT_ASCENDING,
98         SORT_DESCENDING
99 } FolderSortType;
100
101 typedef enum
102 {
103         F_MOVE_OK = 0,
104         F_MOVE_FAILED_DEST_IS_PARENT = -1,
105         F_MOVE_FAILED_DEST_IS_CHILD = -2,
106         F_MOVE_FAILED_DEST_OUTSIDE_MAILBOX = -3,
107         F_MOVE_FAILED = -4,
108 } FolderItemMoveResult;
109
110 typedef enum
111 {
112         FOLDER_TREE_CHANGED = 1 << 0,
113         FOLDER_NEW_FOLDERITEM = 1 << 1,
114         FOLDER_REMOVE_FOLDERITEM = 1 << 2,
115 } FolderUpdateFlags;
116
117 typedef enum
118 {
119         F_ITEM_UPDATE_MSGCNT = 1 << 0,
120         F_ITEM_UPDATE_CONTENT = 1 << 1,
121 } FolderItemUpdateFlags;
122
123 typedef void (*FolderUIFunc)            (Folder         *folder,
124                                          FolderItem     *item,
125                                          gpointer        data);
126 typedef void (*FolderDestroyNotify)     (Folder         *folder,
127                                          FolderItem     *item,
128                                          gpointer        data);
129 typedef void (*FolderItemFunc)          (FolderItem     *item,
130                                          gpointer        data);
131
132 #include "folder_item_prefs.h"
133
134 #include "prefs_account.h"
135 #include "session.h"
136 #include "procmsg.h"
137 #include "msgcache.h"
138
139 struct _Folder
140 {
141         FolderClass *klass;
142
143         gchar *name;
144         PrefsAccount *account;
145
146         FolderItem *inbox;
147         FolderItem *outbox;
148         FolderItem *draft;
149         FolderItem *queue;
150         FolderItem *trash;
151
152         FolderUIFunc ui_func;
153         gpointer     ui_func_data;
154
155         GNode *node;
156
157         gpointer data;
158
159         GHashTable *newsart;
160 };
161
162 struct _FolderClass
163 {
164         FolderType  type;
165         gchar      *idstr;
166         gchar      *uistr;
167
168         /* virtual functions */
169
170         /* Folder funtions */
171         Folder          *(*new_folder)          (const gchar    *name,
172                                                  const gchar    *path);
173         void            (*destroy_folder)       (Folder         *folder);
174         void            (*scan_tree)            (Folder         *folder);
175
176         gint            (*create_tree)          (Folder         *folder);
177
178         /* FolderItem functions */
179         FolderItem      *(*item_new)            (Folder         *folder);
180         void            (*item_destroy)         (Folder         *folder,
181                                                  FolderItem     *item);
182         gchar           *(*item_get_path)       (Folder         *folder,
183                                                  FolderItem     *item);
184         FolderItem      *(*create_folder)       (Folder         *folder,
185                                                  FolderItem     *parent,
186                                                  const gchar    *name);
187         gint            (*rename_folder)        (Folder         *folder,
188                                                  FolderItem     *item,
189                                                  const gchar    *name);
190         gint            (*remove_folder)        (Folder         *folder,
191                                                  FolderItem     *item);
192         gint            (*close)                (Folder         *folder,
193                                                  FolderItem     *item);
194         gint            (*get_num_list)         (Folder         *folder,
195                                                  FolderItem     *item,
196                                                  GSList        **list,
197                                                  gboolean       *old_uids_valid);
198         void            (*update_mark)          (Folder         *folder,
199                                                  FolderItem     *item);
200         void            (*finished_copy)        (Folder         *folder,
201                                                  FolderItem     *item);
202         void            (*finished_remove)      (Folder         *folder,
203                                                  FolderItem     *item);
204         gboolean        (*scan_required)        (Folder         *folder,
205                                                  FolderItem     *item);
206
207         /* Message functions */
208         MsgInfo         *(*get_msginfo)         (Folder         *folder,
209                                                  FolderItem     *item,
210                                                  gint            num);
211         GSList          *(*get_msginfos)        (Folder         *folder,
212                                                  FolderItem     *item,
213                                                  MsgNumberList  *msgnum_list);
214         gchar           *(*fetch_msg)           (Folder         *folder,
215                                                  FolderItem     *item,
216                                                  gint            num);
217         gint            (*add_msg)              (Folder         *folder,
218                                                  FolderItem     *dest,
219                                                  const gchar    *file,
220                                                  MsgFlags       *flags);
221         gint            (*add_msgs)             (Folder         *folder,
222                                                  FolderItem     *dest,
223                                                  GSList         *file_list,
224                                                  GRelation      *relation);
225         gint            (*copy_msg)             (Folder         *folder,
226                                                  FolderItem     *dest,
227                                                  MsgInfo        *msginfo);
228         gint            (*copy_msgs)            (Folder         *folder,
229                                                  FolderItem     *dest,
230                                                  MsgInfoList    *msglist,
231                                                  GRelation      *relation);
232         gint            (*remove_msg)           (Folder         *folder,
233                                                  FolderItem     *item,
234                                                  gint            num);
235         gint            (*remove_all_msg)       (Folder         *folder,
236                                                  FolderItem     *item);
237         gboolean        (*is_msg_changed)       (Folder         *folder,
238                                                  FolderItem     *item,
239                                                  MsgInfo        *msginfo);
240         void            (*change_flags)         (Folder         *folder,
241                                                  FolderItem     *item,
242                                                  MsgInfo        *msginfo,
243                                                  MsgPermFlags    newflags);
244 };
245
246 struct _LocalFolder
247 {
248         Folder folder;
249
250         gchar *rootpath;
251 };
252
253 struct _RemoteFolder
254 {
255         Folder folder;
256
257         Session *session;
258 };
259
260 #if 0
261 struct _MaildirFolder
262 {
263         LocalFolder lfolder;
264 };
265 #endif
266
267 struct _FolderItem
268 {
269         SpecialFolderItemType stype;
270
271         gchar *name;
272         gchar *path;
273
274         time_t mtime;
275
276         gint new_msgs;
277         gint unread_msgs;
278         gint total_msgs;
279         gint unreadmarked_msgs;
280
281         gint last_num;
282
283         MsgCache *cache;
284
285         /* special flags */
286         guint no_sub         : 1; /* no child allowed?    */
287         guint no_select      : 1; /* not selectable?      */
288         guint collapsed      : 1; /* collapsed item       */
289         guint thread_collapsed      : 1; /* collapsed item       */
290         guint threaded       : 1; /* threaded folder view */
291         guint hide_read_msgs : 1; /* hide read messages   */
292         guint ret_rcpt       : 1; /* return receipt       */
293
294         gint op_count;
295         guint opened         : 1; /* opened by summary view */
296         FolderItemUpdateFlags update_flags; /* folderview for this folder should be updated */
297
298         FolderSortKey sort_key;
299         FolderSortType sort_type;
300
301         GNode *node;
302
303         FolderItem *parent;
304
305         Folder *folder;
306
307         PrefsAccount *account;
308
309         gboolean apply_sub;
310         
311         GSList *mark_queue;
312
313         gpointer data;
314
315         FolderItemPrefs * prefs;
316 };
317
318 typedef struct {
319         FolderSortKey   sort_key;
320         FolderSortType  sort_type;
321         guint           collapsed       : 1;
322         guint           thread_collapsed        : 1;
323         guint           threaded        : 1;
324         guint           hide_read_msgs  : 1; /* CLAWS */
325         guint           ret_rcpt        : 1; /* CLAWS */
326 } PersistPrefs;
327
328 struct _FolderUpdateData
329 {
330         Folder                  *folder;
331         FolderUpdateFlags        update_flags;
332         FolderItem              *item;
333 };
334
335 struct _FolderItemUpdateData
336 {
337         FolderItem              *item;
338         FolderItemUpdateFlags    update_flags;
339 };
340
341 void        folder_system_init          (void);
342 void        folder_register_class       (FolderClass    *klass);
343 Folder     *folder_new                  (FolderClass    *type,
344                                          const gchar    *name,
345                                          const gchar    *path);
346 void        folder_local_folder_init    (Folder         *folder,
347                                          const gchar    *name,
348                                          const gchar    *path);
349 void        folder_remote_folder_init   (Folder         *folder,
350                                          const gchar    *name,
351                                          const gchar    *path);
352
353 void        folder_destroy              (Folder         *folder);
354 void        folder_local_folder_destroy (LocalFolder    *lfolder);
355 void        folder_remote_folder_destroy(RemoteFolder   *rfolder);
356
357 FolderItem *folder_item_new             (Folder         *folder,
358                                          const gchar    *name,
359                                          const gchar    *path);
360 void        folder_item_append          (FolderItem     *parent,
361                                          FolderItem     *item);
362 void        folder_item_remove          (FolderItem     *item);
363 void        folder_item_remove_children (FolderItem     *item);
364 void        folder_item_destroy         (FolderItem     *item);
365
366 void        folder_set_ui_func  (Folder         *folder,
367                                  FolderUIFunc    func,
368                                  gpointer        data);
369 void        folder_set_name     (Folder         *folder,
370                                  const gchar    *name);
371 void        folder_tree_destroy (Folder         *folder);
372
373 void   folder_add               (Folder         *folder);
374
375 GList *folder_get_list          (void);
376 gint   folder_read_list         (void);
377 void   folder_write_list        (void);
378 void   folder_scan_tree         (Folder *folder);
379 FolderItem *folder_create_folder(FolderItem     *parent, const gchar *name);
380 void   folder_update_op_count           (void);
381 void   folder_func_to_all_folders       (FolderItemFunc function,
382                                          gpointer data);
383 void   folder_count_total_msgs  (guint          *new_msgs,
384                                  guint          *unread_msgs,
385                                  guint          *unreadmarked_msgs,
386                                  guint          *total_msgs);
387 gchar *folder_get_status        (GPtrArray      *folders,
388                                  gboolean        full);
389
390 Folder     *folder_find_from_path               (const gchar    *path);
391 Folder     *folder_find_from_name               (const gchar    *name,
392                                                  FolderClass    *klass);
393 FolderItem *folder_find_item_from_path          (const gchar    *path);
394 FolderClass *folder_get_class_from_string       (const gchar    *str);
395 gchar      *folder_get_identifier               (Folder         *folder);
396 gchar      *folder_item_get_identifier          (FolderItem     *item);
397 FolderItem *folder_find_item_from_identifier    (const gchar    *identifier);
398 gchar      *folder_item_get_name                (FolderItem     *item);
399
400 Folder     *folder_get_default_folder   (void);
401 FolderItem *folder_get_default_inbox    (void);
402 FolderItem *folder_get_default_outbox   (void);
403 FolderItem *folder_get_default_draft    (void);
404 FolderItem *folder_get_default_queue    (void);
405 FolderItem *folder_get_default_trash    (void);
406 FolderItem *folder_get_default_processing (void);
407 void folder_set_missing_folders         (void);
408 void folder_unref_account_all           (PrefsAccount   *account);
409
410 gchar *folder_item_get_path             (FolderItem     *item);
411
412 gint   folder_item_open                 (FolderItem     *item);
413 gint   folder_item_close                (FolderItem     *item);
414 gint   folder_item_scan                 (FolderItem     *item);
415 void   folder_item_scan_foreach         (GHashTable     *table);
416 MsgInfo *folder_item_get_msginfo        (FolderItem     *item,
417                                          gint            num);
418 MsgInfo *folder_item_get_msginfo_by_msgid(FolderItem    *item,
419                                          const gchar    *msgid);
420 GSList *folder_item_get_msg_list        (FolderItem     *item);
421 gchar *folder_item_fetch_msg            (FolderItem     *item,
422                                          gint            num);
423 gint   folder_item_add_msg              (FolderItem     *dest,
424                                          const gchar    *file,
425                                          MsgFlags       *flags,
426                                          gboolean        remove_source);
427 gint   folder_item_add_msgs             (FolderItem     *dest,
428                                          GSList         *file_list,
429                                          gboolean        remove_source);
430 gint   folder_item_move_to              (FolderItem     *src,
431                                          FolderItem     *dest,
432                                          FolderItem    **new_item);
433 gint   folder_item_move_msg             (FolderItem     *dest,
434                                          MsgInfo        *msginfo);
435 gint   folder_item_move_msgs            (FolderItem     *dest,
436                                          GSList         *msglist);
437 gint   folder_item_copy_msg             (FolderItem     *dest,
438                                          MsgInfo        *msginfo);
439 gint   folder_item_copy_msgs            (FolderItem     *dest,
440                                          GSList         *msglist);
441 gint   folder_item_remove_msg           (FolderItem     *item,
442                                          gint            num);
443 gint   folder_item_remove_msgs          (FolderItem     *item,
444                                          GSList         *msglist);
445 gint   folder_item_remove_all_msg       (FolderItem     *item);
446 void    folder_item_change_msg_flags    (FolderItem     *item,
447                                          MsgInfo        *msginfo,
448                                          MsgPermFlags    newflags);
449 gboolean folder_item_is_msg_changed     (FolderItem     *item,
450                                          MsgInfo        *msginfo);
451 gchar *folder_item_get_cache_file       (FolderItem     *item);
452 gchar *folder_item_get_mark_file        (FolderItem     *item);
453 gchar * folder_item_get_identifier      (FolderItem * item);
454
455 GHashTable *folder_persist_prefs_new    (Folder *folder);
456 void folder_persist_prefs_free          (GHashTable *pptable);
457 const PersistPrefs *folder_get_persist_prefs
458                                         (GHashTable *pptable, const char *name);
459
460 void folder_item_restore_persist_prefs  (FolderItem *item, GHashTable *pptable);
461 void folder_clean_cache_memory          (void);
462 void folder_item_write_cache            (FolderItem *item);
463 void folder_item_set_default_flags      (FolderItem *dest, MsgFlags *flags);
464
465 void folder_item_apply_processing       (FolderItem *item);
466
467 void folder_item_update                 (FolderItem *item,
468                                          FolderItemUpdateFlags update_flags);
469 void folder_item_update_recursive       (FolderItem *item,
470                                          FolderItemUpdateFlags update_flags);
471 void folder_item_update_freeze          (void);
472 void folder_item_update_thaw            (void);
473
474 #endif /* __FOLDER_H__ */