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