4670ea54162b0c19f073a0121eaf92ffa1c02731
[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 /*
114         maybe enhance with:
115         FOLDER_NEW_FOLDERITEM
116         FOLDER_REMOVE_FOLDERITEM
117 */
118 } FolderUpdateFlags;
119
120 typedef enum
121 {
122         F_ITEM_UPDATE_MSGCNT = 1 << 0,
123         F_ITEM_UPDATE_CONTENT = 1 << 1,
124 } FolderItemUpdateFlags;
125
126 typedef void (*FolderUIFunc)            (Folder         *folder,
127                                          FolderItem     *item,
128                                          gpointer        data);
129 typedef void (*FolderDestroyNotify)     (Folder         *folder,
130                                          FolderItem     *item,
131                                          gpointer        data);
132 typedef void (*FolderItemFunc)          (FolderItem     *item,
133                                          gpointer        data);
134
135 #include "folder_item_prefs.h"
136
137 #include "prefs_account.h"
138 #include "session.h"
139 #include "procmsg.h"
140 #include "msgcache.h"
141
142 struct _Folder
143 {
144         FolderClass *klass;
145
146         gchar *name;
147         PrefsAccount *account;
148
149         FolderItem *inbox;
150         FolderItem *outbox;
151         FolderItem *draft;
152         FolderItem *queue;
153         FolderItem *trash;
154
155         FolderUIFunc ui_func;
156         gpointer     ui_func_data;
157
158         GNode *node;
159
160         gpointer data;
161
162         GHashTable *newsart;
163 };
164
165 struct _FolderClass
166 {
167         FolderType  type;
168         gchar      *idstr;
169         gchar      *uistr;
170
171         /* virtual functions */
172
173         /* Folder funtions */
174         Folder          *(*new_folder)          (const gchar    *name,
175                                                  const gchar    *path);
176         void            (*destroy_folder)       (Folder         *folder);
177         void            (*scan_tree)            (Folder         *folder);
178
179         gint            (*create_tree)          (Folder         *folder);
180
181         /* FolderItem functions */
182         FolderItem      *(*item_new)            (Folder         *folder);
183         void            (*item_destroy)         (Folder         *folder,
184                                                  FolderItem     *item);
185         gchar           *(*item_get_path)       (Folder         *folder,
186                                                  FolderItem     *item);
187         FolderItem      *(*create_folder)       (Folder         *folder,
188                                                  FolderItem     *parent,
189                                                  const gchar    *name);
190         gint            (*rename_folder)        (Folder         *folder,
191                                                  FolderItem     *item,
192                                                  const gchar    *name);
193         gint            (*remove_folder)        (Folder         *folder,
194                                                  FolderItem     *item);
195         gint            (*close)                (Folder         *folder,
196                                                  FolderItem     *item);
197         gint            (*get_num_list)         (Folder         *folder,
198                                                  FolderItem     *item,
199                                                  GSList        **list,
200                                                  gboolean       *old_uids_valid);
201         void            (*update_mark)          (Folder         *folder,
202                                                  FolderItem     *item);
203         void            (*finished_copy)        (Folder         *folder,
204                                                  FolderItem     *item);
205         void            (*finished_remove)      (Folder         *folder,
206                                                  FolderItem     *item);
207         gboolean        (*scan_required)        (Folder         *folder,
208                                                  FolderItem     *item);
209
210         /* Message functions */
211         MsgInfo         *(*get_msginfo)         (Folder         *folder,
212                                                  FolderItem     *item,
213                                                  gint            num);
214         GSList          *(*get_msginfos)        (Folder         *folder,
215                                                  FolderItem     *item,
216                                                  MsgNumberList  *msgnum_list);
217         gchar           *(*fetch_msg)           (Folder         *folder,
218                                                  FolderItem     *item,
219                                                  gint            num);
220         gint            (*add_msg)              (Folder         *folder,
221                                                  FolderItem     *dest,
222                                                  const gchar    *file,
223                                                  MsgFlags       *flags);
224         gint            (*add_msgs)             (Folder         *folder,
225                                                  FolderItem     *dest,
226                                                  GSList         *file_list,
227                                                  GRelation      *relation);
228         gint            (*copy_msg)             (Folder         *folder,
229                                                  FolderItem     *dest,
230                                                  MsgInfo        *msginfo);
231         gint            (*copy_msgs)            (Folder         *folder,
232                                                  FolderItem     *dest,
233                                                  MsgInfoList    *msglist,
234                                                  GRelation      *relation);
235         gint            (*remove_msg)           (Folder         *folder,
236                                                  FolderItem     *item,
237                                                  gint            num);
238         gint            (*remove_all_msg)       (Folder         *folder,
239                                                  FolderItem     *item);
240         gboolean        (*is_msg_changed)       (Folder         *folder,
241                                                  FolderItem     *item,
242                                                  MsgInfo        *msginfo);
243         void            (*change_flags)         (Folder         *folder,
244                                                  FolderItem     *item,
245                                                  MsgInfo        *msginfo,
246                                                  MsgPermFlags    newflags);
247 };
248
249 struct _LocalFolder
250 {
251         Folder folder;
252
253         gchar *rootpath;
254 };
255
256 struct _RemoteFolder
257 {
258         Folder folder;
259
260         Session *session;
261 };
262
263 #if 0
264 struct _MaildirFolder
265 {
266         LocalFolder lfolder;
267 };
268 #endif
269
270 struct _FolderItem
271 {
272         SpecialFolderItemType stype;
273
274         gchar *name;
275         gchar *path;
276
277         time_t mtime;
278
279         gint new_msgs;
280         gint unread_msgs;
281         gint total_msgs;
282         gint unreadmarked_msgs;
283
284         gint last_num;
285
286         MsgCache *cache;
287
288         /* special flags */
289         guint no_sub         : 1; /* no child allowed?    */
290         guint no_select      : 1; /* not selectable?      */
291         guint collapsed      : 1; /* collapsed item       */
292         guint thread_collapsed      : 1; /* collapsed item       */
293         guint threaded       : 1; /* threaded folder view */
294         guint hide_read_msgs : 1; /* hide read messages   */
295         guint ret_rcpt       : 1; /* return receipt       */
296
297         gint op_count;
298         guint opened         : 1; /* opened by summary view */
299         FolderItemUpdateFlags update_flags; /* folderview for this folder should be updated */
300
301         FolderSortKey sort_key;
302         FolderSortType sort_type;
303
304         GNode *node;
305
306         FolderItem *parent;
307
308         Folder *folder;
309
310         PrefsAccount *account;
311
312         gboolean apply_sub;
313         
314         GSList *mark_queue;
315
316         gpointer data;
317
318         FolderItemPrefs * prefs;
319 };
320
321 typedef struct {
322         FolderSortKey   sort_key;
323         FolderSortType  sort_type;
324         guint           collapsed       : 1;
325         guint           thread_collapsed        : 1;
326         guint           threaded        : 1;
327         guint           hide_read_msgs  : 1; /* CLAWS */
328         guint           ret_rcpt        : 1; /* CLAWS */
329 } PersistPrefs;
330
331 struct _FolderUpdateData
332 {
333         Folder                  *folder;
334         FolderUpdateFlags        update_flags;
335 /*
336         FolderItem              *item
337 */
338 };
339
340 struct _FolderItemUpdateData
341 {
342         FolderItem              *item;
343         FolderItemUpdateFlags    update_flags;
344 };
345
346 void        folder_system_init          (void);
347 void        folder_register_class       (FolderClass    *klass);
348 Folder     *folder_new                  (FolderClass    *type,
349                                          const gchar    *name,
350                                          const gchar    *path);
351 void        folder_local_folder_init    (Folder         *folder,
352                                          const gchar    *name,
353                                          const gchar    *path);
354 void        folder_remote_folder_init   (Folder         *folder,
355                                          const gchar    *name,
356                                          const gchar    *path);
357
358 void        folder_destroy              (Folder         *folder);
359 void        folder_local_folder_destroy (LocalFolder    *lfolder);
360 void        folder_remote_folder_destroy(RemoteFolder   *rfolder);
361
362 FolderItem *folder_item_new             (Folder         *folder,
363                                          const gchar    *name,
364                                          const gchar    *path);
365 void        folder_item_append          (FolderItem     *parent,
366                                          FolderItem     *item);
367 void        folder_item_remove          (FolderItem     *item);
368 void        folder_item_remove_children (FolderItem     *item);
369 void        folder_item_destroy         (FolderItem     *item);
370
371 void        folder_set_ui_func  (Folder         *folder,
372                                  FolderUIFunc    func,
373                                  gpointer        data);
374 void        folder_set_name     (Folder         *folder,
375                                  const gchar    *name);
376 void        folder_tree_destroy (Folder         *folder);
377
378 void   folder_add               (Folder         *folder);
379
380 GList *folder_get_list          (void);
381 gint   folder_read_list         (void);
382 void   folder_write_list        (void);
383 void   folder_scan_tree         (Folder *folder);
384 FolderItem *folder_create_folder(FolderItem     *parent, const gchar *name);
385 void   folder_update_op_count           (void);
386 void   folder_func_to_all_folders       (FolderItemFunc function,
387                                          gpointer data);
388 void   folder_count_total_msgs  (guint          *new_msgs,
389                                  guint          *unread_msgs,
390                                  guint          *unreadmarked_msgs,
391                                  guint          *total_msgs);
392 gchar *folder_get_status        (GPtrArray      *folders,
393                                  gboolean        full);
394
395 Folder     *folder_find_from_path               (const gchar    *path);
396 Folder     *folder_find_from_name               (const gchar    *name,
397                                                  FolderClass    *klass);
398 FolderItem *folder_find_item_from_path          (const gchar    *path);
399 FolderClass *folder_get_class_from_string       (const gchar    *str);
400 gchar      *folder_get_identifier               (Folder         *folder);
401 gchar      *folder_item_get_identifier          (FolderItem     *item);
402 FolderItem *folder_find_item_from_identifier    (const gchar    *identifier);
403 gchar      *folder_item_get_name                (FolderItem     *item);
404
405 Folder     *folder_get_default_folder   (void);
406 FolderItem *folder_get_default_inbox    (void);
407 FolderItem *folder_get_default_outbox   (void);
408 FolderItem *folder_get_default_draft    (void);
409 FolderItem *folder_get_default_queue    (void);
410 FolderItem *folder_get_default_trash    (void);
411 FolderItem *folder_get_default_processing (void);
412 void folder_set_missing_folders         (void);
413 void folder_unref_account_all           (PrefsAccount   *account);
414
415 gchar *folder_item_get_path             (FolderItem     *item);
416
417 gint   folder_item_open                 (FolderItem     *item);
418 gint   folder_item_close                (FolderItem     *item);
419 gint   folder_item_scan                 (FolderItem     *item);
420 void   folder_item_scan_foreach         (GHashTable     *table);
421 MsgInfo *folder_item_get_msginfo        (FolderItem     *item,
422                                          gint            num);
423 MsgInfo *folder_item_get_msginfo_by_msgid(FolderItem    *item,
424                                          const gchar    *msgid);
425 GSList *folder_item_get_msg_list        (FolderItem     *item);
426 gchar *folder_item_fetch_msg            (FolderItem     *item,
427                                          gint            num);
428 gint   folder_item_add_msg              (FolderItem     *dest,
429                                          const gchar    *file,
430                                          MsgFlags       *flags,
431                                          gboolean        remove_source);
432 gint   folder_item_add_msgs             (FolderItem     *dest,
433                                          GSList         *file_list,
434                                          gboolean        remove_source);
435 gint   folder_item_move_to              (FolderItem     *src,
436                                          FolderItem     *dest,
437                                          FolderItem    **new_item);
438 gint   folder_item_move_msg             (FolderItem     *dest,
439                                          MsgInfo        *msginfo);
440 gint   folder_item_move_msgs            (FolderItem     *dest,
441                                          GSList         *msglist);
442 gint   folder_item_copy_msg             (FolderItem     *dest,
443                                          MsgInfo        *msginfo);
444 gint   folder_item_copy_msgs            (FolderItem     *dest,
445                                          GSList         *msglist);
446 gint   folder_item_remove_msg           (FolderItem     *item,
447                                          gint            num);
448 gint   folder_item_remove_msgs          (FolderItem     *item,
449                                          GSList         *msglist);
450 gint   folder_item_remove_all_msg       (FolderItem     *item);
451 void    folder_item_change_msg_flags    (FolderItem     *item,
452                                          MsgInfo        *msginfo,
453                                          MsgPermFlags    newflags);
454 gboolean folder_item_is_msg_changed     (FolderItem     *item,
455                                          MsgInfo        *msginfo);
456 gchar *folder_item_get_cache_file       (FolderItem     *item);
457 gchar *folder_item_get_mark_file        (FolderItem     *item);
458 gchar * folder_item_get_identifier      (FolderItem * item);
459
460 GHashTable *folder_persist_prefs_new    (Folder *folder);
461 void folder_persist_prefs_free          (GHashTable *pptable);
462 const PersistPrefs *folder_get_persist_prefs
463                                         (GHashTable *pptable, const char *name);
464
465 void folder_item_restore_persist_prefs  (FolderItem *item, GHashTable *pptable);
466 void folder_clean_cache_memory          (void);
467 void folder_item_write_cache            (FolderItem *item);
468 void folder_item_set_default_flags      (FolderItem *dest, MsgFlags *flags);
469
470 void folder_item_apply_processing       (FolderItem *item);
471
472 void folder_item_update                 (FolderItem *item,
473                                          FolderItemUpdateFlags update_flags);
474 void folder_item_update_recursive       (FolderItem *item,
475                                          FolderItemUpdateFlags update_flags);
476 void folder_item_update_freeze          (void);
477 void folder_item_update_thaw            (void);
478
479 #endif /* __FOLDER_H__ */