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