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