2006-01-15 [colin] 1.9.100cvs153
[claws.git] / src / folder.h
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
3 /*
4  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
5  * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21
22 #ifndef __FOLDER_H__
23 #define __FOLDER_H__
24
25 #include <glib.h>
26 #include <time.h>
27
28 typedef struct _Folder          Folder;
29 typedef struct _FolderClass     FolderClass;
30
31 typedef struct _FolderItem      FolderItem;
32 typedef struct _FolderUpdateData        FolderUpdateData;
33 typedef struct _FolderItemUpdateData    FolderItemUpdateData;
34 typedef struct _PersistPrefs            PersistPrefs;
35
36 #define FOLDER(obj)             ((Folder *)obj)
37 #define FOLDER_CLASS(obj)       (FOLDER(obj)->klass)
38 #define FOLDER_TYPE(obj)        (FOLDER(obj)->klass->type)
39
40 #define FOLDER_IS_LOCAL(obj)    (FOLDER_TYPE(obj) == F_MH      || \
41                                  FOLDER_TYPE(obj) == F_MBOX    || \
42                                  FOLDER_TYPE(obj) == F_MAILDIR)
43
44 #define FOLDER_ITEM(obj)        ((FolderItem *)obj)
45
46 #define FOLDER_UPDATE_HOOKLIST "folder_update"
47 #define FOLDER_ITEM_UPDATE_HOOKLIST "folder_item_update"
48
49 typedef enum
50 {
51         F_MH,
52         F_MBOX,
53         F_MAILDIR,
54         F_IMAP,
55         F_NEWS,
56         F_UNKNOWN
57 } FolderType;
58
59 typedef enum
60 {
61         F_NORMAL,
62         F_INBOX,
63         F_OUTBOX,
64         F_DRAFT,
65         F_QUEUE,
66         F_TRASH
67 } SpecialFolderItemType;
68
69 typedef enum
70 {
71         SORT_BY_NONE,
72         SORT_BY_NUMBER,
73         SORT_BY_SIZE,
74         SORT_BY_DATE,
75         SORT_BY_FROM,
76         SORT_BY_SUBJECT,
77         SORT_BY_SCORE,
78         SORT_BY_LABEL,
79         SORT_BY_MARK,
80         SORT_BY_STATUS,
81         SORT_BY_MIME,
82         SORT_BY_TO,
83         SORT_BY_LOCKED
84 } FolderSortKey;
85
86 typedef enum
87 {
88         SORT_ASCENDING,
89         SORT_DESCENDING
90 } FolderSortType;
91
92 typedef enum
93 {
94         F_MOVE_OK = 0,
95         F_MOVE_FAILED_DEST_IS_PARENT = -1,
96         F_MOVE_FAILED_DEST_IS_CHILD = -2,
97         F_MOVE_FAILED_DEST_OUTSIDE_MAILBOX = -3,
98         F_MOVE_FAILED = -4
99 } FolderItemMoveResult;
100
101 typedef enum
102 {
103         FOLDER_ADD_FOLDER               = 1 << 0,
104         FOLDER_REMOVE_FOLDER            = 1 << 1,
105         FOLDER_TREE_CHANGED             = 1 << 2,
106         FOLDER_ADD_FOLDERITEM           = 1 << 3,
107         FOLDER_REMOVE_FOLDERITEM        = 1 << 4
108 } FolderUpdateFlags;
109
110 typedef enum
111 {
112         F_ITEM_UPDATE_MSGCNT = 1 << 0,
113         F_ITEM_UPDATE_CONTENT = 1 << 1,
114         F_ITEM_UPDATE_ADDMSG = 1 << 2,
115         F_ITEM_UPDATE_REMOVEMSG = 1 << 3,
116         F_ITEM_UPDATE_NAME = 1 << 4
117 } FolderItemUpdateFlags;
118
119 typedef void (*FolderUIFunc)            (Folder         *folder,
120                                          FolderItem     *item,
121                                          gpointer        data);
122 typedef void (*FolderDestroyNotify)     (Folder         *folder,
123                                          FolderItem     *item,
124                                          gpointer        data);
125 typedef void (*FolderItemFunc)  (FolderItem     *item,
126                                          gpointer        data);
127
128
129 #include "folder_item_prefs.h"
130
131 #include "procmsg.h"
132 #include "msgcache.h"
133 #include "xml.h"
134 #include "prefs_account.h"
135
136 struct _Folder
137 {
138         FolderClass *klass;
139
140         gchar *name;
141         PrefsAccount *account;
142         guint sort;
143
144         FolderItem *inbox;
145         FolderItem *outbox;
146         FolderItem *draft;
147         FolderItem *queue;
148         FolderItem *trash;
149
150         FolderUIFunc ui_func;
151         gpointer     ui_func_data;
152
153         GNode *node;
154
155         gpointer data;
156
157         GHashTable *newsart;
158 };
159
160 struct _FolderClass
161 {
162         /**
163          * A numeric identifier for the FolderClass. Will be removed in the future
164          */
165         FolderType  type;
166         /**
167          * A string identifier for the FolderClass. Currently used in folderlist.xml.
168          * Should be lowercase.
169          */
170         gchar      *idstr;
171         /**
172          * A string for the User Interface that identifies the FolderClass to the
173          * user. Can be upper and lowercase unlike the idstr.
174          */
175         gchar      *uistr;
176         
177         /* virtual functions */
178
179         /* Folder funtions */
180         /**
181          * Create a new \c Folder of this \c FolderClass.
182          *
183          * \param name The name of the new Folder
184          * \param path The path of the new Folder
185          * \return The new \c Folder, or \c NULL when creating the \c Folder 
186          *         failed
187          */
188         Folder          *(*new_folder)          (const gchar    *name,
189                                                  const gchar    *path);
190         /**
191          * Destroy a \c Folder of this \c FolderClass, frees all resources
192          * allocated by the Folder
193          *
194          * \param folder The \c Folder that should be destroyed.
195          */
196         void            (*destroy_folder)       (Folder         *folder);
197         /**
198          * Set the Folder's internal attributes from an \c XMLTag. Also sets the
199          * parameters of the root-FolderItem of the \c Folder. If \c NULL
200          * the default function of the basic \ยข FolderClass is used, so it
201          * must not be \c NULL if one of the parent \c FolderClasses has a \c set_xml
202          * function. In that case the parent \c FolderClass' \c set_xml function
203          * can be used or it has to be called with the \c folder and \c tag by
204          * the implementation.
205          *
206          * \param folder The \c Folder which's attributes should be updated
207          * \param tag The \c XMLTag containing the \c XMLAttrs for the attributes
208          */
209         void             (*set_xml)             (Folder         *folder,
210                                                  XMLTag         *tag);
211         /**
212          * Get an \c XMLTag for the attributes of the \c Folder and the root-FolderItem
213          * of the \c Folder. If \c NULL the default implementation for the basic
214          * FolderClass will be used, so it must not be \c NULL if one of the
215          * parent \c FolderClasses has it's own implementation for \c get_xml.
216          * In that case the parent FolderClass' \c get_xml function can be
217          * used or the \c XMLTag has to be fetched from the parent's \c get_xml
218          * function and then the \c FolderClass specific attributes can be
219          * added to it.
220          *
221          * \param Folder The \c Folder which's attributes should be set in the
222          *               \c XMLTag's \c XMLAttrs
223          * \return XMLTag An \c XMLTag with \c XMLAttrs containing the \c Folder's
224          *                attributes.
225          */
226         XMLTag          *(*get_xml)             (Folder         *folder);
227         /**
228          * Rebuild the folder tree from the folder's data
229          * \todo New implementations of MH and IMAP are actually syncronizing
230          *       the tree with the folder by reusing the old \c FolderItems.
231          *       Claws still destroys the old tree before calling this function.
232          *
233          * \param folder The folder which's tree should be rebuild
234          * \return 0 on success, a negative number otherwise
235          */
236         gint            (*scan_tree)            (Folder         *folder);
237
238         gint            (*create_tree)          (Folder         *folder);
239
240         /* FolderItem functions */
241         /**
242          * Create a new \c FolderItem structure for the \c FolderClass.
243          * \c FolderClasses can have their own \c FolderItem structure with
244          * extra attributes.
245          *
246          * \param folder The \c Folder for that a \c FolderItem should be
247          *               created
248          * \return The new \c FolderItem or NULL in case of an error
249          */
250         FolderItem      *(*item_new)            (Folder         *folder);
251         /**
252          * Destroy a \c FolderItem from this \c FolderClass. The \c FolderClass
253          * has to free all private resources used by the \c FolderItem.
254          *
255          * \param folder The \c Folder of the \c FolderItem
256          * \param item The \c FolderItem that should be destroyed
257          */
258         void             (*item_destroy)        (Folder         *folder,
259                                                  FolderItem     *item);
260         /**
261          * Set the \c FolderItem's internal attributes from an \c XMLTag. If
262          * \c NULL the default function of the basic \c FolderClass is used, so it
263          * must not be \c NULL if one of the parent \c FolderClasses has a \c item_set_xml
264          * function. In that case the parent \c FolderClass' \c item_set_xml function
265          * can be used or it has to be called with the \c folder, \c item and \c tag by
266          * the implementation.
267          *
268          * \param folder The \c Folder of the \c FolderItem
269          * \param item The \c FolderItems which's attributes should be set
270          * \param tag The \c XMLTag with \c XMLAttrs for the \c FolderItem's
271          *            attributes
272          */
273         void             (*item_set_xml)        (Folder         *folder,
274                                                  FolderItem     *item,
275                                                  XMLTag         *tag);
276         /**
277          * Get an \c XMLTag for the attributes of the \c FolderItem If \c NULL
278          * the default implementation for the basic \c FolderClass will be used,
279          * so it must not be \c NULL if one of the parent \c FolderClasses has
280          * it's own implementation for \c item_get_xml. In that case the parent 
281          * FolderClass' \c item_get_xml function can be used or the \c XMLTag
282          * has to be fetched from the parent's \c item_get_xml function and 
283          * then the \c FolderClass specific attributes can be added to it.
284          *
285          * \param folder The \c Folder of the \c FolderItem
286          * \parem item The \c FolderItem which's attributes should be set in
287          *             the \c XMLTag's \c XMLAttrs
288          * \return An \c XMLTag with \c XMLAttrs containing the \c FolderItem's
289          *         attributes.
290          */
291         XMLTag          *(*item_get_xml)        (Folder         *folder,
292                                                  FolderItem     *item);
293         /**
294          * Get a local path for the \c FolderItem where Sylpheed can save
295          * it's cache data. For local directory based folders this can be the
296          * real path. For other folders it can be the local cache directory.
297          *
298          * \param folder The \c Folder of the \c FolderItem
299          * \param item The \c FolderItem for that a path should be returned
300          * \return A path for the \c FolderItem
301          */
302         gchar           *(*item_get_path)       (Folder         *folder,
303                                                  FolderItem     *item);
304         /**
305          * Create a new \c FolderItem. The function must use folder_item_append
306          * to add the new \c FolderItem to the folder tree
307          *
308          * \param folder The \c Folder in which a new \c FolderItem should be
309          *               created
310          * \param parent \c The parent \c FolderItem for the new \c FolderItem
311          * \parem name The name for the new \c FolderItem
312          * \return The new \c FolderItem
313          */
314         FolderItem      *(*create_folder)       (Folder         *folder,
315                                                  FolderItem     *parent,
316                                                  const gchar    *name);
317         /**
318          * Rename a \c FolderItem
319          *
320          * \param folder The \c Folder of the \c FolderItem that should be
321          *               renamed
322          * \param item The \c FolderItem that should be renamed
323          * \param name The new name of the \c FolderItem
324          * \return 0 on success, a negative number otherwise
325          */
326         gint             (*rename_folder)       (Folder         *folder,
327                                                  FolderItem     *item,
328                                                  const gchar    *name);
329         /**
330          * Remove a \c FolderItem from the \c Folder
331          *
332          * \param folder The \c Folder that contains the \c FolderItem
333          * \param item The \c FolderItem that should be removed
334          * \return 0 on sucess, a negative number otherwise
335          */
336         gint             (*remove_folder)       (Folder         *folder,
337                                                  FolderItem     *item);
338         /**
339          * Close a \c FolderItem. Called when the user deselects a
340          * \c FolderItem.
341          * 
342          * \attention In Sylpheed-Main operations can only be done on the
343          *            \c FolderItem that is opened in the SummaryView. This
344          *            \c FolderItem will be closed when you select a new
345          *            \c FolderItem in the FolderView. In Claws operations can
346          *            be done any time on any folder and you should not expect
347          *            that all \c FolderItems get closed after operations
348          *
349          * \param folder The \c Folder that contains the \c FolderItem
350          * \param item The \c FolderItem that should be closed
351          * \return 0 on success, a negative number otherwise
352          */
353         gint             (*close)               (Folder         *folder,
354                                                  FolderItem     *item);
355         /**
356          * Get the list of message numbers for the messages in the \c FolderItem
357          *
358          * \param folder The \c Folder that contains the \c FolderItem
359          * \param item The \c FolderItem for which the message numbers should
360          *             be fetched
361          * \param list Pointer to a GSList where message numbers have to be
362          *             added. Because of the implementation of the GSList that
363          *             changes the pointer of the GSList itself when the first
364          *             item is added this is a pointer to a pointer to a
365          *             GSList structure. Use *item = g_slist_...(*item, ...)
366          *             operations to modify the list.
367          * \param old_uids_valid In some \c Folders the old UIDs can be invalid.
368          *                       Set this pointer to a gboolean to TRUE if the
369          *                       old UIDs are still valid, otherwise set it to
370          *                       FALSE and the folder system will discard it's
371          *                       cache data of the previously know UIDs
372          * \return The number of message numbers add to the list on success,
373          *         a negative number otherwise.
374          */
375         gint             (*get_num_list)        (Folder         *folder,
376                                                  FolderItem     *item,
377                                                  GSList        **list,
378                                                  gboolean       *old_uids_valid);
379         /**
380          * Tell the folder system if a \c FolderItem should be scanned
381          * (cache data syncronized with the folder content) when it is required
382          * because the \c FolderItem's content changed. If NULL the folder
383          * system will not do automatic scanning of \c FolderItems
384          *
385          * \param folder The \c Folder that contains the \c FolderItem
386          * \param item The \c FolderItem which's content should be checked
387          * \return TRUE if the \c FolderItem should be scanned, FALSE otherwise
388          */
389         gboolean        (*scan_required)        (Folder         *folder,
390                                                  FolderItem     *item);
391
392         /* Message functions */
393         /**
394          * Get a MsgInfo for a message in a \c FolderItem
395          *
396          * \param folder The \c Folder containing the message
397          * \param item The \c FolderItem containing the message
398          * \param num The message number of the message
399          * \return A pointer to a \c MsgInfo decribing the message or \c 
400          *         NULL in case of an error
401          */
402         MsgInfo         *(*get_msginfo)         (Folder         *folder,
403                                                  FolderItem     *item,
404                                                  gint            num);
405         /**
406          * Get \c MsgInfos for a list of message numbers
407          *
408          * \param folder The \c Folder containing the message
409          * \param item The \c FolderItem containing the message
410          * \param msgnum_list A list of message numbers for which the
411          *                    \c MsgInfos should be fetched
412          * \return A list of \c MsgInfos for the messages in the \c msgnum_list
413          *         that really exist. Messages that are not found can simply
414          *         be left out.
415          */
416         MsgInfoList     *(*get_msginfos)        (Folder         *folder,
417                                                  FolderItem     *item,
418                                                  MsgNumberList  *msgnum_list);
419         /**
420          * Get the filename for a message. This can either be the real message
421          * file for local folders or a temporary file for remote folders.
422          *
423          * \param folder The \c Folder containing the message
424          * \param item The \c FolderItem containing the message
425          * \param num The message number of the message
426          * \return A string with the filename of the message file. The returned
427          *         string has to be freed with \c g_free(). If message is not
428          *         available return NULL.
429          */
430         gchar           *(*fetch_msg)           (Folder         *folder,
431                                                  FolderItem     *item,
432                                                  gint            num);
433         gchar           *(*fetch_msg_full)      (Folder         *folder,
434                                                  FolderItem     *item,
435                                                  gint            num,
436                                                  gboolean        headers,
437                                                  gboolean        body);
438         /**
439          * Add a single message file to a folder with the given flags (if
440          * flag handling is supported by the folder)
441          *
442          * \param folder The target \c Folder for the message
443          * \param dest the target \c FolderItem for the message
444          * \param file The file that contains the message
445          * \param flags The flags the new message should have in the folder
446          * \return 0 on success, a negative number otherwise
447          */
448         gint            (*add_msg)              (Folder         *folder,
449                                                  FolderItem     *dest,
450                                                  const gchar    *file,
451                                                  MsgFlags       *flags);
452         /**
453          * Add multiple messages to a \c FolderItem. If NULL the folder
454          * system will add messages with \c add_msg one by one
455          *
456          * \param folder The target \c Folder for the messages
457          * \param dest the target \c FolderItem for the messages
458          * \param file_list A list of \c MsgFileInfos which contain the
459          *                  filenames and flags for the new messages
460          * \param relation Insert tuples of (MsgFileInfo, new message number) to
461          *                 provide feedback for the folder system which new
462          *                 message number a \c MsgFileInfo got in dest. Insert
463          *                 0 if the new message number is unknown.
464          */
465         gint            (*add_msgs)             (Folder         *folder,
466                                                  FolderItem     *dest,
467                                                  GSList         *file_list,
468                                                  GRelation      *relation);
469         /**
470          * Copy a message to a FolderItem
471          *
472          * \param folder The \c Folder of the destination FolderItem
473          * \param dest The destination \c FolderItem for the message
474          * \param msginfo The message that should be copied
475          * \return The message number the copied message got, 0 if it is
476          *         unknown because message numbers are assigned by an external
477          *         system and not available after copying or a negative number
478          *         if an error occuried
479          */
480         gint            (*copy_msg)             (Folder         *folder,
481                                                  FolderItem     *dest,
482                                                  MsgInfo        *msginfo);
483         /**
484          * Copy multiple messages to a \c FolderItem. If \c NULL the folder
485          * system will use \c copy_msg to copy messages one by one.
486          *
487          * \param folder The \c Folder of the destination FolderItem
488          * \param dest The destination \c FolderItem for the message
489          * \param msglist A list of \c MsgInfos which should be copied to dest
490          * \param relation Insert tuples of (MsgInfo, new message number) to
491          *                 provide feedback for the folder system which new
492          *                 message number a \c MsgInfo got in dest. Insert
493          *                 0 if the new message number is unknown.
494          * \return 0 on success, a negative number otherwise
495          */
496         gint            (*copy_msgs)            (Folder         *folder,
497                                                  FolderItem     *dest,
498                                                  MsgInfoList    *msglist,
499                                                  GRelation      *relation);
500         /**
501          * Remove a message from a \c FolderItem.
502          *
503          * \param folder The \c Folder of the message
504          * \param item The \c FolderItem containing the message
505          * \param num The message number of the message
506          * \return 0 on success, a negative number otherwise
507          */
508         gint            (*remove_msg)           (Folder         *folder,
509                                                  FolderItem     *item,
510                                                  gint            num);
511         gint            (*remove_msgs)          (Folder         *folder,
512                                                  FolderItem     *item,
513                                                  MsgInfoList    *msglist,
514                                                  GRelation      *relation);
515         /**
516          * Remove all messages in a \ c FolderItem
517          *
518          * \param folder The \c Folder of the \c FolderItem
519          * \param item The \FolderItem which's messages should be deleted
520          * \return 0 on succes, a negative number otherwise
521          */
522         gint            (*remove_all_msg)       (Folder         *folder,
523                                                  FolderItem     *item);
524         /**
525          * Check if a message has been modified by someone else
526          *
527          * \param folder The \c Folder of the message
528          * \param item The \c FolderItem containing the message
529          * \param msginfo The \c MsgInfo for the message that should be checked
530          * \return \c TRUE if the message was modified, \c FALSE otherwise
531          */
532         gboolean        (*is_msg_changed)       (Folder         *folder,
533                                                  FolderItem     *item,
534                                                  MsgInfo        *msginfo);
535         /**
536          * Update a message's flags in the folder data. If NULL only the
537          * internal flag management will be used. The function has to set
538          * \c msginfo->flags.perm_flags. It does not have to set the flags
539          * that it got as \c newflags. If a flag can not be set in this
540          * \c FolderClass the function can refuse to set it. Flags that are not
541          * supported by the \c FolderClass should not be refused. They will be
542          * managed by the internal cache in this case.
543          *
544          * \param folder The \c Folder of the message
545          * \param item The \c FolderItem of the message
546          * \param msginfo The \c MsgInfo for the message which's flags should be
547          *                updated
548          * \param newflags The flags the message should get
549          */
550         void            (*change_flags)         (Folder         *folder,
551                                                  FolderItem     *item,
552                                                  MsgInfo        *msginfo,
553                                                  MsgPermFlags    newflags);
554         /**
555          * Get the flags for a list of messages. Flags that are not supported
556          * by the folder should be preserved. They can be copied from
557          * \c msginfo->flags.perm_flags
558          *
559          * \param folder The \c Folder of the messages
560          * \param item The \c FolderItem of the messages
561          * \param msglist The list of \c MsgInfos for which the flags should
562          *                   be returned
563          * \param msgflags A \c GRelation for tuples of (MsgInfo, new permanent
564          *        flags for MsgInfo). Add tuples for the messages in msglist
565          * \return 0 on success, a negative number otherwise
566          */
567         gint            (*get_flags)            (Folder         *folder,
568                                                  FolderItem     *item,
569                                                  MsgInfoList    *msglist,
570                                                  GRelation      *msgflags);
571         
572         void            (*set_batch)            (Folder         *folder,
573                                                  FolderItem     *item,
574                                                  gboolean        batch);
575         void            (*synchronise)          (FolderItem     *item);
576         gboolean        (*subscribe)            (Folder         *folder,
577                                                  const gchar    *uri);
578 };
579
580 struct _FolderItem
581 {
582         SpecialFolderItemType stype;
583
584         gchar *name; /* UTF-8 */
585         gchar *path; /* UTF-8 */
586
587         time_t mtime;
588
589         gint new_msgs;
590         gint unread_msgs;
591         gint total_msgs;
592         gint unreadmarked_msgs;
593         gint marked_msgs;
594
595         gint last_num;
596
597         MsgCache *cache;
598
599         /* special flags */
600         guint no_sub         : 1; /* no child allowed?    */
601         guint no_select      : 1; /* not selectable?      */
602         guint collapsed      : 1; /* collapsed item       */
603         guint thread_collapsed      : 1; /* collapsed item       */
604         guint threaded       : 1; /* threaded folder view */
605         guint hide_read_msgs : 1; /* hide read messages   */
606         guint ret_rcpt       : 1; /* return receipt       */
607         guint search_match   : 1;
608
609         gint op_count;
610         guint opened         : 1; /* opened by summary view */
611         FolderItemUpdateFlags update_flags; /* folderview for this folder should be updated */
612
613         FolderSortKey sort_key;
614         FolderSortType sort_type;
615
616         GNode *node;
617
618         Folder *folder;
619
620         PrefsAccount *account;
621
622         gboolean apply_sub;
623         
624         GSList *mark_queue;
625
626         gpointer data;
627
628         FolderItemPrefs * prefs;
629         
630         /* for faster search of special parents */
631         SpecialFolderItemType parent_stype;
632         gboolean processing_pending;
633 };
634
635 struct _PersistPrefs
636 {
637         FolderSortKey   sort_key;
638         FolderSortType  sort_type;
639         guint           collapsed       : 1;
640         guint           thread_collapsed        : 1;
641         guint           threaded        : 1;
642         guint           hide_read_msgs  : 1; /* CLAWS */
643         guint           ret_rcpt        : 1; /* CLAWS */
644 };
645
646 struct _FolderUpdateData
647 {
648         Folder                  *folder;
649         FolderUpdateFlags        update_flags;
650         FolderItem              *item;
651 };
652
653 struct _FolderItemUpdateData
654 {
655         FolderItem              *item;
656         FolderItemUpdateFlags    update_flags;
657         MsgInfo                 *msg;
658 };
659
660 void        folder_system_init          (void);
661 void        folder_register_class       (FolderClass    *klass);
662 void        folder_unregister_class     (FolderClass    *klass);
663 Folder     *folder_new                  (FolderClass    *type,
664                                          const gchar    *name,
665                                          const gchar    *path);
666 void        folder_init                 (Folder         *folder,
667                                          const gchar    *name);
668
669 void        folder_destroy              (Folder         *folder);
670
671 void        folder_set_xml              (Folder          *folder,
672                                          XMLTag          *tag);
673 XMLTag     *folder_get_xml              (Folder          *folder);
674
675 FolderItem *folder_item_new             (Folder         *folder,
676                                          const gchar    *name,
677                                          const gchar    *path);
678 void        folder_item_append          (FolderItem     *parent,
679                                          FolderItem     *item);
680 void        folder_item_remove          (FolderItem     *item);
681 void        folder_item_remove_children (FolderItem     *item);
682 void        folder_item_destroy         (FolderItem     *item);
683 FolderItem *folder_item_parent          (FolderItem     *item);
684
685 void        folder_item_set_xml         (Folder          *folder,
686                                          FolderItem      *item,
687                                          XMLTag          *tag);
688 XMLTag     *folder_item_get_xml         (Folder          *folder,
689                                          FolderItem      *item);
690
691 void        folder_set_ui_func  (Folder         *folder,
692                                  FolderUIFunc    func,
693                                  gpointer        data);
694 void        folder_set_name     (Folder         *folder,
695                                  const gchar    *name);
696 void        folder_set_sort     (Folder         *folder,
697                                  guint           sort);
698 void        folder_tree_destroy (Folder         *folder);
699
700 void   folder_add               (Folder         *folder);
701 void   folder_remove            (Folder         *folder);
702
703 GList *folder_get_list          (void);
704 gint   folder_read_list         (void);
705 void   folder_write_list        (void);
706 void   folder_scan_tree         (Folder *folder, gboolean rebuild);
707 FolderItem *folder_create_folder(FolderItem     *parent, const gchar *name);
708 gint   folder_item_rename       (FolderItem *item, gchar *newname);
709 void   folder_update_op_count           (void);
710 void   folder_func_to_all_folders       (FolderItemFunc function,
711                                          gpointer data);
712 void folder_count_total_msgs(guint *new_msgs, guint *unread_msgs, 
713                              guint *unreadmarked_msgs, guint *marked_msgs,
714                              guint *total_msgs);
715 gchar *folder_get_status        (GPtrArray      *folders,
716                                  gboolean        full);
717
718 Folder     *folder_find_from_path               (const gchar    *path);
719 Folder     *folder_find_from_name               (const gchar    *name,
720                                                  FolderClass    *klass);
721 FolderItem *folder_find_item_from_path          (const gchar    *path);
722 FolderClass *folder_get_class_from_string       (const gchar    *str);
723 FolderItem *folder_find_child_item_by_name      (FolderItem     *item,
724                                                  const gchar    *name);
725 gchar      *folder_get_identifier               (Folder         *folder);
726 gchar      *folder_item_get_identifier          (FolderItem     *item);
727 FolderItem *folder_find_item_from_identifier    (const gchar    *identifier);
728 gchar      *folder_item_get_name                (FolderItem     *item);
729
730 Folder     *folder_get_default_folder   (void);
731 FolderItem *folder_get_default_inbox    (void);
732 FolderItem *folder_get_default_outbox   (void);
733 FolderItem *folder_get_default_draft    (void);
734 FolderItem *folder_get_default_queue    (void);
735 FolderItem *folder_get_default_trash    (void);
736 FolderItem *folder_get_default_processing (void);
737 void folder_set_missing_folders         (void);
738 void folder_unref_account_all           (PrefsAccount   *account);
739
740 /* return value is locale encoded file name */
741 gchar *folder_item_get_path             (FolderItem     *item);
742
743 gint   folder_item_open                 (FolderItem     *item);
744 gint   folder_item_close                (FolderItem     *item);
745 gint   folder_item_scan                 (FolderItem     *item);
746 gint   folder_item_syncronize_flags     (FolderItem     *item);
747 void   folder_item_scan_foreach         (GHashTable     *table);
748 MsgInfo *folder_item_get_msginfo        (FolderItem     *item,
749                                          gint            num);
750 MsgInfo *folder_item_get_msginfo_by_msgid(FolderItem    *item,
751                                          const gchar    *msgid);
752 GSList *folder_item_get_msg_list        (FolderItem     *item);
753 /* return value is locale charset */
754 gchar *folder_item_fetch_msg            (FolderItem     *item,
755                                          gint            num);
756 gchar *folder_item_fetch_msg_full       (FolderItem     *item,
757                                          gint            num, 
758                                          gboolean        get_headers,
759                                          gboolean        get_body);
760 gint   folder_item_fetch_all_msg        (FolderItem     *item);
761 gint   folder_item_add_msg              (FolderItem     *dest,
762                                          const gchar    *file,
763                                          MsgFlags       *flags,
764                                          gboolean        remove_source);
765 gint   folder_item_add_msgs             (FolderItem     *dest,
766                                          GSList         *file_list,
767                                          gboolean        remove_source);
768 gint   folder_item_move_to              (FolderItem     *src,
769                                          FolderItem     *dest,
770                                          FolderItem    **new_item);
771 gint   folder_item_move_msg             (FolderItem     *dest,
772                                          MsgInfo        *msginfo);
773 gint   folder_item_move_msgs            (FolderItem     *dest,
774                                          GSList         *msglist);
775 gint   folder_item_copy_msg             (FolderItem     *dest,
776                                          MsgInfo        *msginfo);
777 gint   folder_item_copy_msgs            (FolderItem     *dest,
778                                          GSList         *msglist);
779 gint   folder_item_remove_msg           (FolderItem     *item,
780                                          gint            num);
781 gint   folder_item_remove_msgs          (FolderItem     *item,
782                                          GSList         *msglist);
783 gint   folder_item_remove_all_msg       (FolderItem     *item);
784 void    folder_item_change_msg_flags    (FolderItem     *item,
785                                          MsgInfo        *msginfo,
786                                          MsgPermFlags    newflags);
787 gboolean folder_item_is_msg_changed     (FolderItem     *item,
788                                          MsgInfo        *msginfo);
789 /* return value is locale chaset */
790 gchar *folder_item_get_cache_file       (FolderItem     *item);
791 gchar *folder_item_get_mark_file        (FolderItem     *item);
792 gchar * folder_item_get_identifier      (FolderItem * item);
793
794 GHashTable *folder_persist_prefs_new    (Folder *folder);
795 void folder_persist_prefs_free          (GHashTable *pptable);
796 const PersistPrefs *folder_get_persist_prefs
797                                         (GHashTable *pptable, const char *name);
798
799 void folder_item_restore_persist_prefs  (FolderItem *item, GHashTable *pptable);
800 void folder_clean_cache_memory          (void);
801 void folder_clean_cache_memory_force    (void);
802 void folder_item_write_cache            (FolderItem *item);
803 void folder_item_set_default_flags      (FolderItem *dest, MsgFlags *flags);
804
805 void folder_item_apply_processing       (FolderItem *item);
806
807 void folder_item_update                 (FolderItem *item,
808                                          FolderItemUpdateFlags update_flags);
809 void folder_item_update_recursive       (FolderItem *item,
810                                          FolderItemUpdateFlags update_flags);
811 void folder_item_update_freeze          (void);
812 void folder_item_update_thaw            (void);
813 void folder_item_set_batch              (FolderItem *item, gboolean batch);
814 gboolean folder_has_parent_of_type      (FolderItem *item, SpecialFolderItemType type);
815 void folder_synchronise                 (Folder *folder);
816 gboolean folder_want_synchronise        (Folder *folder);
817 void folder_item_process_open           (FolderItem *item,
818                                          void (*before_proc_func)(gpointer data),
819                                          void (*after_proc_func)(gpointer data),
820                                          gpointer data);
821 gboolean folder_subscribe               (const gchar *uri);
822 gboolean folder_have_mailbox            (void);
823
824 #endif /* __FOLDER_H__ */