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