7a75f683fc3764a3b2e0bec29db2177f716c2d4c
[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         /* return value is locale charset */
215         gchar           *(*fetch_msg)           (Folder         *folder,
216                                                  FolderItem     *item,
217                                                  gint            num);
218         gint            (*add_msg)              (Folder         *folder,
219                                                  FolderItem     *dest,
220                                                  const gchar    *file,
221                                                  MsgFlags       *flags);
222         gint            (*add_msgs)             (Folder         *folder,
223                                                  FolderItem     *dest,
224                                                  GSList         *file_list,
225                                                  GRelation      *relation);
226         gint            (*copy_msg)             (Folder         *folder,
227                                                  FolderItem     *dest,
228                                                  MsgInfo        *msginfo);
229         gint            (*copy_msgs)            (Folder         *folder,
230                                                  FolderItem     *dest,
231                                                  MsgInfoList    *msglist,
232                                                  GRelation      *relation);
233         gint            (*remove_msg)           (Folder         *folder,
234                                                  FolderItem     *item,
235                                                  gint            num);
236         gint            (*remove_all_msg)       (Folder         *folder,
237                                                  FolderItem     *item);
238         gboolean        (*is_msg_changed)       (Folder         *folder,
239                                                  FolderItem     *item,
240                                                  MsgInfo        *msginfo);
241         void            (*change_flags)         (Folder         *folder,
242                                                  FolderItem     *item,
243                                                  MsgInfo        *msginfo,
244                                                  MsgPermFlags    newflags);
245 };
246
247 struct _LocalFolder
248 {
249         Folder folder;
250
251         gchar *rootpath;
252 };
253
254 struct _RemoteFolder
255 {
256         Folder folder;
257
258         Session *session;
259 };
260
261 #if 0
262 struct _MaildirFolder
263 {
264         LocalFolder lfolder;
265 };
266 #endif
267
268 struct _FolderItem
269 {
270         SpecialFolderItemType stype;
271
272         gchar *name; /* UTF-8 */
273         gchar *path; /* UTF-8 */
274
275         time_t mtime;
276
277         gint new_msgs;
278         gint unread_msgs;
279         gint total_msgs;
280         gint unreadmarked_msgs;
281
282         gint last_num;
283
284         MsgCache *cache;
285
286         /* special flags */
287         guint no_sub         : 1; /* no child allowed?    */
288         guint no_select      : 1; /* not selectable?      */
289         guint collapsed      : 1; /* collapsed item       */
290         guint thread_collapsed      : 1; /* collapsed item       */
291         guint threaded       : 1; /* threaded folder view */
292         guint hide_read_msgs : 1; /* hide read messages   */
293         guint ret_rcpt       : 1; /* return receipt       */
294
295         gint op_count;
296         guint opened         : 1; /* opened by summary view */
297         FolderItemUpdateFlags update_flags; /* folderview for this folder should be updated */
298
299         FolderSortKey sort_key;
300         FolderSortType sort_type;
301
302         GNode *node;
303
304         FolderItem *parent;
305
306         Folder *folder;
307
308         PrefsAccount *account;
309
310         gboolean apply_sub;
311         
312         GSList *mark_queue;
313
314         gpointer data;
315
316         FolderItemPrefs * prefs;
317 };
318
319 typedef struct {
320         FolderSortKey   sort_key;
321         FolderSortType  sort_type;
322         guint           collapsed       : 1;
323         guint           thread_collapsed        : 1;
324         guint           threaded        : 1;
325         guint           hide_read_msgs  : 1; /* CLAWS */
326         guint           ret_rcpt        : 1; /* CLAWS */
327 } PersistPrefs;
328
329 struct _FolderUpdateData
330 {
331         Folder                  *folder;
332         FolderUpdateFlags        update_flags;
333         FolderItem              *item;
334 };
335
336 struct _FolderItemUpdateData
337 {
338         FolderItem              *item;
339         FolderItemUpdateFlags    update_flags;
340 };
341
342 void        folder_system_init          (void);
343 void        folder_register_class       (FolderClass    *klass);
344 Folder     *folder_new                  (FolderClass    *type,
345                                          const gchar    *name,
346                                          const gchar    *path);
347 void        folder_local_folder_init    (Folder         *folder,
348                                          const gchar    *name,
349                                          const gchar    *path);
350 void        folder_remote_folder_init   (Folder         *folder,
351                                          const gchar    *name,
352                                          const gchar    *path);
353
354 void        folder_destroy              (Folder         *folder);
355 void        folder_local_folder_destroy (LocalFolder    *lfolder);
356 void        folder_remote_folder_destroy(RemoteFolder   *rfolder);
357
358 FolderItem *folder_item_new             (Folder         *folder,
359                                          const gchar    *name,
360                                          const gchar    *path);
361 void        folder_item_append          (FolderItem     *parent,
362                                          FolderItem     *item);
363 void        folder_item_remove          (FolderItem     *item);
364 void        folder_item_remove_children (FolderItem     *item);
365 void        folder_item_destroy         (FolderItem     *item);
366
367 void        folder_set_ui_func  (Folder         *folder,
368                                  FolderUIFunc    func,
369                                  gpointer        data);
370 void        folder_set_name     (Folder         *folder,
371                                  const gchar    *name);
372 void        folder_tree_destroy (Folder         *folder);
373
374 void   folder_add               (Folder         *folder);
375
376 GList *folder_get_list          (void);
377 gint   folder_read_list         (void);
378 void   folder_write_list        (void);
379 void   folder_scan_tree         (Folder *folder);
380 FolderItem *folder_create_folder(FolderItem     *parent, const gchar *name);
381 void   folder_update_op_count           (void);
382 void   folder_func_to_all_folders       (FolderItemFunc function,
383                                          gpointer data);
384 void   folder_count_total_msgs  (guint          *new_msgs,
385                                  guint          *unread_msgs,
386                                  guint          *unreadmarked_msgs,
387                                  guint          *total_msgs);
388 gchar *folder_get_status        (GPtrArray      *folders,
389                                  gboolean        full);
390
391 Folder     *folder_find_from_path               (const gchar    *path);
392 Folder     *folder_find_from_name               (const gchar    *name,
393                                                  FolderClass    *klass);
394 FolderItem *folder_find_item_from_path          (const gchar    *path);
395 FolderClass *folder_get_class_from_string       (const gchar    *str);
396 gchar      *folder_get_identifier               (Folder         *folder);
397 gchar      *folder_item_get_identifier          (FolderItem     *item);
398 FolderItem *folder_find_item_from_identifier    (const gchar    *identifier);
399 gchar      *folder_item_get_name                (FolderItem     *item);
400
401 Folder     *folder_get_default_folder   (void);
402 FolderItem *folder_get_default_inbox    (void);
403 FolderItem *folder_get_default_outbox   (void);
404 FolderItem *folder_get_default_draft    (void);
405 FolderItem *folder_get_default_queue    (void);
406 FolderItem *folder_get_default_trash    (void);
407 FolderItem *folder_get_default_processing (void);
408 void folder_set_missing_folders         (void);
409 void folder_unref_account_all           (PrefsAccount   *account);
410
411 /* return value is locale encoded file name */
412 gchar *folder_item_get_path             (FolderItem     *item);
413
414 gint   folder_item_open                 (FolderItem     *item);
415 gint   folder_item_close                (FolderItem     *item);
416 gint   folder_item_scan                 (FolderItem     *item);
417 void   folder_item_scan_foreach         (GHashTable     *table);
418 MsgInfo *folder_item_get_msginfo        (FolderItem     *item,
419                                          gint            num);
420 MsgInfo *folder_item_get_msginfo_by_msgid(FolderItem    *item,
421                                          const gchar    *msgid);
422 GSList *folder_item_get_msg_list        (FolderItem     *item);
423 /* return value is locale charset */
424 gchar *folder_item_fetch_msg            (FolderItem     *item,
425                                          gint            num);
426 gint   folder_item_add_msg              (FolderItem     *dest,
427                                          const gchar    *file,
428                                          MsgFlags       *flags,
429                                          gboolean        remove_source);
430 gint   folder_item_add_msgs             (FolderItem     *dest,
431                                          GSList         *file_list,
432                                          gboolean        remove_source);
433 gint   folder_item_move_to              (FolderItem     *src,
434                                          FolderItem     *dest,
435                                          FolderItem    **new_item);
436 gint   folder_item_move_msg             (FolderItem     *dest,
437                                          MsgInfo        *msginfo);
438 gint   folder_item_move_msgs            (FolderItem     *dest,
439                                          GSList         *msglist);
440 gint   folder_item_copy_msg             (FolderItem     *dest,
441                                          MsgInfo        *msginfo);
442 gint   folder_item_copy_msgs            (FolderItem     *dest,
443                                          GSList         *msglist);
444 gint   folder_item_remove_msg           (FolderItem     *item,
445                                          gint            num);
446 gint   folder_item_remove_msgs          (FolderItem     *item,
447                                          GSList         *msglist);
448 gint   folder_item_remove_all_msg       (FolderItem     *item);
449 void    folder_item_change_msg_flags    (FolderItem     *item,
450                                          MsgInfo        *msginfo,
451                                          MsgPermFlags    newflags);
452 gboolean folder_item_is_msg_changed     (FolderItem     *item,
453                                          MsgInfo        *msginfo);
454 /* return value is locale chaset */
455 gchar *folder_item_get_cache_file       (FolderItem     *item);
456 gchar *folder_item_get_mark_file        (FolderItem     *item);
457 gchar * folder_item_get_identifier      (FolderItem * item);
458
459 GHashTable *folder_persist_prefs_new    (Folder *folder);
460 void folder_persist_prefs_free          (GHashTable *pptable);
461 const PersistPrefs *folder_get_persist_prefs
462                                         (GHashTable *pptable, const char *name);
463
464 void folder_item_restore_persist_prefs  (FolderItem *item, GHashTable *pptable);
465 void folder_clean_cache_memory          (void);
466 void folder_item_write_cache            (FolderItem *item);
467 void folder_item_set_default_flags      (FolderItem *dest, MsgFlags *flags);
468
469 void folder_item_apply_processing       (FolderItem *item);
470
471 void folder_item_update                 (FolderItem *item,
472                                          FolderItemUpdateFlags update_flags);
473 void folder_item_update_recursive       (FolderItem *item,
474                                          FolderItemUpdateFlags update_flags);
475 void folder_item_update_freeze          (void);
476 void folder_item_update_thaw            (void);
477
478 #endif /* __FOLDER_H__ */