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