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