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