2b12de6d6078378957292e69aad017a43b99912b
[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 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 struct _Folder
122 {
123         FolderType type;
124
125         gchar *name;
126         PrefsAccount *account;
127
128         FolderItem *inbox;
129         FolderItem *outbox;
130         FolderItem *draft;
131         FolderItem *queue;
132         FolderItem *trash;
133
134         FolderUIFunc ui_func;
135         gpointer     ui_func_data;
136
137         GNode *node;
138
139         gpointer data;
140
141         GHashTable *newsart;
142
143         /* virtual functions */
144 /*
145         GSList * (*get_msg_list)        (Folder         *folder,
146                                          FolderItem     *item,
147                                          gboolean        use_cache);
148 */
149         FolderItem *(*item_new)         (Folder         *folder);
150         void     (*item_destroy)        (Folder         *folder,
151                                          FolderItem     *item);
152         gchar *  (*fetch_msg)           (Folder         *folder,
153                                          FolderItem     *item,
154                                          gint            num);
155         MsgInfo * (*get_msginfo)        (Folder         *folder,
156                                          FolderItem     *item,
157                                          gint            num);
158         GSList  * (*get_msginfos)       (Folder         *folder,
159                                          FolderItem     *item,
160                                          GSList         *msgnum_list);
161         gint     (*add_msg)             (Folder         *folder,
162                                          FolderItem     *dest,
163                                          const gchar    *file,
164                                          gboolean        remove_source);
165         gint     (*move_msg)            (Folder         *folder,
166                                          FolderItem     *dest,
167                                          MsgInfo        *msginfo);
168         gint     (*move_msgs_with_dest) (Folder         *folder,
169                                          FolderItem     *dest,
170                                          GSList         *msglist);
171         gint     (*copy_msg)            (Folder         *folder,
172                                          FolderItem     *dest,
173                                          MsgInfo        *msginfo);
174         gint     (*copy_msgs_with_dest) (Folder         *folder,
175                                          FolderItem     *dest,
176                                          GSList         *msglist);
177         gint     (*remove_msg)          (Folder         *folder,
178                                          FolderItem     *item,
179                                          gint            num);
180         gint     (*remove_msgs)         (Folder         *folder,
181                                          FolderItem     *item,
182                                          GSList         *msglist);
183         gint     (*remove_all_msg)      (Folder         *folder,
184                                          FolderItem     *item);
185         gboolean (*is_msg_changed)      (Folder         *folder,
186                                          FolderItem     *item,
187                                          MsgInfo        *msginfo);
188         gint     (*scan)                (Folder         *folder);
189         gint     (*get_num_list)        (Folder         *folder,
190                                          FolderItem     *item,
191                                          GSList        **list);
192         void     (*scan_tree)           (Folder         *folder);
193
194         gint     (*create_tree)         (Folder         *folder);
195         FolderItem * (*create_folder)   (Folder         *folder,
196                                          FolderItem     *parent,
197                                          const gchar    *name);
198         gint     (*rename_folder)       (Folder         *folder,
199                                          FolderItem     *item,
200                                          const gchar    *name);
201         gint     (*remove_folder)       (Folder         *folder,
202                                          FolderItem     *item);
203
204         void     (*destroy)             (Folder         *folder);
205         void     (*update_mark)         (Folder         *folder,
206                                          FolderItem     *item);
207         void     (*change_flags)        (Folder         *folder,
208                                          FolderItem     *item,
209                                          MsgInfo        *info);
210         void     (*finished_copy)       (Folder * folder, FolderItem * item);
211         void     (*finished_remove)     (Folder * folder, FolderItem * item);
212         gboolean (*check_msgnum_validity) (Folder * folder, FolderItem * item);
213 };
214
215 struct _LocalFolder
216 {
217         Folder folder;
218
219         gchar *rootpath;
220 };
221
222 struct _RemoteFolder
223 {
224         Folder folder;
225
226         Session *session;
227 };
228
229 #if 0
230 struct _MaildirFolder
231 {
232         LocalFolder lfolder;
233 };
234 #endif
235
236 struct _FolderItem
237 {
238         SpecialFolderItemType stype;
239
240         gchar *name;
241         gchar *path;
242
243         time_t mtime;
244
245         gint new;
246         gint unread;
247         gint total;
248         gint unreadmarked;
249
250         gint last_num;
251
252         MsgCache *cache;
253
254         /* special flags */
255         guint no_sub         : 1; /* no child allowed?    */
256         guint no_select      : 1; /* not selectable?      */
257         guint collapsed      : 1; /* collapsed item       */
258         guint threaded       : 1; /* threaded folder view */
259         guint hide_read_msgs : 1; /* hide read messages   */
260         guint ret_rcpt       : 1; /* return receipt       */
261
262         gint op_count;
263         guint opened    : 1; /* opened by summary view */
264         guint need_update    : 1; /* folderview for this folder should be updated */
265
266         FolderSortKey sort_key;
267         FolderSortType sort_type;
268
269         FolderItem *parent;
270
271         Folder *folder;
272
273         PrefsAccount *account;
274
275         gboolean apply_sub;
276         
277         GSList *mark_queue;
278
279         gpointer data;
280
281         PrefsFolderItem * prefs;
282 };
283
284 typedef struct {
285         FolderSortKey   sort_key;
286         FolderSortType  sort_type;
287         guint           collapsed       : 1;
288         guint           threaded        : 1;
289         guint           hide_read_msgs  : 1; /* CLAWS */
290         guint           ret_rcpt        : 1; /* CLAWS */
291 } PersistPrefs;
292
293 struct _FolderItemUpdateData
294 {
295         FolderItem      *item;
296         gboolean         content_change;
297 };
298
299 Folder     *folder_new                  (FolderType      type,
300                                          const gchar    *name,
301                                          const gchar    *path);
302 void        folder_local_folder_init    (Folder         *folder,
303                                          const gchar    *name,
304                                          const gchar    *path);
305 void        folder_remote_folder_init   (Folder         *folder,
306                                          const gchar    *name,
307                                          const gchar    *path);
308
309 void        folder_destroy              (Folder         *folder);
310 void        folder_local_folder_destroy (LocalFolder    *lfolder);
311 void        folder_remote_folder_destroy(RemoteFolder   *rfolder);
312
313 FolderItem *folder_item_new     (Folder         *folder,
314                                  const gchar    *name,
315                                  const gchar    *path);
316 void        folder_item_append  (FolderItem     *parent,
317                                  FolderItem     *item);
318 void        folder_item_remove  (FolderItem     *item);
319 void        folder_item_destroy (FolderItem     *item);
320
321 void        folder_set_ui_func  (Folder         *folder,
322                                  FolderUIFunc    func,
323                                  gpointer        data);
324 void        folder_set_name     (Folder         *folder,
325                                  const gchar    *name);
326 void        folder_tree_destroy (Folder         *folder);
327
328 void   folder_add               (Folder         *folder);
329
330 GList *folder_get_list          (void);
331 gint   folder_read_list         (void);
332 void   folder_write_list        (void);
333 void   folder_scan_tree         (Folder *folder);
334 FolderItem *folder_create_folder(FolderItem     *parent, const gchar *name);
335 void   folder_update_op_count           (void);
336 void   folder_func_to_all_folders       (FolderItemFunc function,
337                                          gpointer data);
338 void   folder_count_total_msgs  (guint          *new,
339                                  guint          *unread,
340                                  guint          *unreadmarked,
341                                  guint          *total);
342
343 Folder     *folder_find_from_path               (const gchar    *path);
344 Folder     *folder_find_from_name               (const gchar    *name,
345                                                  FolderType      type);
346 FolderItem *folder_find_item_from_path          (const gchar    *path);
347 gchar      *folder_get_identifier               (Folder         *folder);
348 gchar      *folder_item_get_identifier          (FolderItem     *item);
349 FolderItem *folder_find_item_from_identifier    (const gchar    *identifier);
350
351 Folder     *folder_get_default_folder   (void);
352 FolderItem *folder_get_default_inbox    (void);
353 FolderItem *folder_get_default_outbox   (void);
354 FolderItem *folder_get_default_draft    (void);
355 FolderItem *folder_get_default_queue    (void);
356 FolderItem *folder_get_default_trash    (void);
357 FolderItem *folder_get_default_processing (void);
358 void folder_set_missing_folders         (void);
359 void folder_unref_account_all           (PrefsAccount   *account);
360
361 gchar *folder_get_path                  (Folder         *folder);
362 gchar *folder_item_get_path             (FolderItem     *item);
363
364 gint   folder_item_open                 (FolderItem     *item);
365 void   folder_item_close                (FolderItem     *item);
366 gint   folder_item_scan                 (FolderItem     *item);
367 void   folder_item_scan_foreach         (GHashTable     *table);
368 MsgInfo *folder_item_get_msginfo        (FolderItem     *item,
369                                          gint            num);
370 MsgInfo *folder_item_get_msginfo_by_msgid(FolderItem    *item,
371                                          const gchar    *msgid);
372 GSList *folder_item_get_msg_list        (FolderItem     *item);
373 gchar *folder_item_fetch_msg            (FolderItem     *item,
374                                          gint            num);
375 gint   folder_item_add_msg              (FolderItem     *dest,
376                                          const gchar    *file,
377                                          gboolean        remove_source);
378 gint   folder_item_move_to              (FolderItem     *src,
379                                          FolderItem     *dest,
380                                          FolderItem    **new_item);
381 gint   folder_item_move_msg             (FolderItem     *dest,
382                                          MsgInfo        *msginfo);
383 gint   folder_item_move_msgs_with_dest  (FolderItem     *dest,
384                                          GSList         *msglist);
385 gint   folder_item_copy_msg             (FolderItem     *dest,
386                                          MsgInfo        *msginfo);
387 gint   folder_item_copy_msgs_with_dest  (FolderItem     *dest,
388                                          GSList         *msglist);
389 gint   folder_item_remove_msg           (FolderItem     *item,
390                                          gint            num);
391 gint   folder_item_remove_msgs          (FolderItem     *item,
392                                          GSList         *msglist);
393 gint   folder_item_remove_all_msg       (FolderItem     *item);
394 gboolean folder_item_is_msg_changed     (FolderItem     *item,
395                                          MsgInfo        *msginfo);
396 gchar *folder_item_get_cache_file       (FolderItem     *item);
397 gchar *folder_item_get_mark_file        (FolderItem     *item);
398 gchar * folder_item_get_identifier(FolderItem * item);
399
400 GHashTable *folder_persist_prefs_new    (Folder *folder);
401 void folder_persist_prefs_free          (GHashTable *pptable);
402 const PersistPrefs *folder_get_persist_prefs
403                                         (GHashTable *pptable, const char *name);
404
405 void folder_item_restore_persist_prefs  (FolderItem *item, GHashTable *pptable);
406 void folder_clean_cache_memory          ();
407 void folder_item_write_cache            (FolderItem *item);
408 void folder_item_set_default_flags      (FolderItem *dest, MsgFlags *flags);
409
410 void folder_item_apply_processing       (FolderItem *item);
411
412 void folder_update_item                 (FolderItem *item,
413                                          gboolean contentchange);
414 void folder_update_items_when_required  (gboolean contentchange);
415 void folder_update_item_recursive       (FolderItem *item,
416                                          gboolean update_summary);
417
418 #endif /* __FOLDER_H__ */