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