2010-11-25 [paul] 3.7.7cvs6
[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-2009 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         /**
396          * Updates the known mtime of a folder
397          */
398         void            (*set_mtime)            (Folder         *folder,
399                                                  FolderItem     *item);
400
401         /* Message functions */
402         /**
403          * Get a MsgInfo for a message in a \c FolderItem
404          *
405          * \param folder The \c Folder containing the message
406          * \param item The \c FolderItem containing the message
407          * \param num The message number of the message
408          * \return A pointer to a \c MsgInfo decribing the message or \c 
409          *         NULL in case of an error
410          */
411         MsgInfo         *(*get_msginfo)         (Folder         *folder,
412                                                  FolderItem     *item,
413                                                  gint            num);
414         /**
415          * Get \c MsgInfos for a list of message numbers
416          *
417          * \param folder The \c Folder containing the message
418          * \param item The \c FolderItem containing the message
419          * \param msgnum_list A list of message numbers for which the
420          *                    \c MsgInfos should be fetched
421          * \return A list of \c MsgInfos for the messages in the \c msgnum_list
422          *         that really exist. Messages that are not found can simply
423          *         be left out.
424          */
425         MsgInfoList     *(*get_msginfos)        (Folder         *folder,
426                                                  FolderItem     *item,
427                                                  MsgNumberList  *msgnum_list);
428         /**
429          * Get the filename for a message. This can either be the real message
430          * file for local folders or a temporary file for remote folders.
431          *
432          * \param folder The \c Folder containing the message
433          * \param item The \c FolderItem containing the message
434          * \param num The message number of the message
435          * \return A string with the filename of the message file. The returned
436          *         string has to be freed with \c g_free(). If message is not
437          *         available return NULL.
438          */
439         gchar           *(*fetch_msg)           (Folder         *folder,
440                                                  FolderItem     *item,
441                                                  gint            num);
442         gchar           *(*fetch_msg_full)      (Folder         *folder,
443                                                  FolderItem     *item,
444                                                  gint            num,
445                                                  gboolean        headers,
446                                                  gboolean        body);
447         /**
448          * Add a single message file to a folder with the given flags (if
449          * flag handling is supported by the folder)
450          *
451          * \param folder The target \c Folder for the message
452          * \param dest the target \c FolderItem for the message
453          * \param file The file that contains the message
454          * \param flags The flags the new message should have in the folder
455          * \return 0 on success, a negative number otherwise
456          */
457         gint            (*add_msg)              (Folder         *folder,
458                                                  FolderItem     *dest,
459                                                  const gchar    *file,
460                                                  MsgFlags       *flags);
461         /**
462          * Add multiple messages to a \c FolderItem. If NULL the folder
463          * system will add messages with \c add_msg one by one
464          *
465          * \param folder The target \c Folder for the messages
466          * \param dest the target \c FolderItem for the messages
467          * \param file_list A list of \c MsgFileInfos which contain the
468          *                  filenames and flags for the new messages
469          * \param relation Insert tuples of (MsgFileInfo, new message number) to
470          *                 provide feedback for the folder system which new
471          *                 message number a \c MsgFileInfo got in dest. Insert
472          *                 0 if the new message number is unknown.
473          */
474         gint            (*add_msgs)             (Folder         *folder,
475                                                  FolderItem     *dest,
476                                                  GSList         *file_list,
477                                                  GHashTable     *relation);
478         /**
479          * Copy a message to a FolderItem
480          *
481          * \param folder The \c Folder of the destination FolderItem
482          * \param dest The destination \c FolderItem for the message
483          * \param msginfo The message that should be copied
484          * \return The message number the copied message got, 0 if it is
485          *         unknown because message numbers are assigned by an external
486          *         system and not available after copying or a negative number
487          *         if an error occuried
488          */
489         gint            (*copy_msg)             (Folder         *folder,
490                                                  FolderItem     *dest,
491                                                  MsgInfo        *msginfo);
492         /**
493          * Copy multiple messages to a \c FolderItem. If \c NULL the folder
494          * system will use \c copy_msg to copy messages one by one.
495          *
496          * \param folder The \c Folder of the destination FolderItem
497          * \param dest The destination \c FolderItem for the message
498          * \param msglist A list of \c MsgInfos which should be copied to dest
499          * \param relation Insert tuples of (MsgInfo, new message number) to
500          *                 provide feedback for the folder system which new
501          *                 message number a \c MsgInfo got in dest. Insert
502          *                 0 if the new message number is unknown.
503          * \return 0 on success, a negative number otherwise
504          */
505         gint            (*copy_msgs)            (Folder         *folder,
506                                                  FolderItem     *dest,
507                                                  MsgInfoList    *msglist,
508                                                  GHashTable     *relation);
509         /**
510          * Remove a message from a \c FolderItem.
511          *
512          * \param folder The \c Folder of the message
513          * \param item The \c FolderItem containing the message
514          * \param num The message number of the message
515          * \return 0 on success, a negative number otherwise
516          */
517         gint            (*remove_msg)           (Folder         *folder,
518                                                  FolderItem     *item,
519                                                  gint            num);
520         gint            (*remove_msgs)          (Folder         *folder,
521                                                  FolderItem     *item,
522                                                  MsgInfoList    *msglist,
523                                                  GHashTable     *relation);
524         gint            (*expunge)              (Folder         *folder,
525                                                  FolderItem     *item);
526         /**
527          * Remove all messages in a \ c FolderItem
528          *
529          * \param folder The \c Folder of the \c FolderItem
530          * \param item The \FolderItem which's messages should be deleted
531          * \return 0 on succes, a negative number otherwise
532          */
533         gint            (*remove_all_msg)       (Folder         *folder,
534                                                  FolderItem     *item);
535         /**
536          * Check if a message has been modified by someone else
537          *
538          * \param folder The \c Folder of the message
539          * \param item The \c FolderItem containing the message
540          * \param msginfo The \c MsgInfo for the message that should be checked
541          * \return \c TRUE if the message was modified, \c FALSE otherwise
542          */
543         gboolean        (*is_msg_changed)       (Folder         *folder,
544                                                  FolderItem     *item,
545                                                  MsgInfo        *msginfo);
546         /**
547          * Update a message's flags in the folder data. If NULL only the
548          * internal flag management will be used. The function has to set
549          * \c msginfo->flags.perm_flags. It does not have to set the flags
550          * that it got as \c newflags. If a flag can not be set in this
551          * \c FolderClass the function can refuse to set it. Flags that are not
552          * supported by the \c FolderClass should not be refused. They will be
553          * managed by the internal cache in this case.
554          *
555          * \param folder The \c Folder of the message
556          * \param item The \c FolderItem of the message
557          * \param msginfo The \c MsgInfo for the message which's flags should be
558          *                updated
559          * \param newflags The flags the message should get
560          */
561         void            (*change_flags)         (Folder         *folder,
562                                                  FolderItem     *item,
563                                                  MsgInfo        *msginfo,
564                                                  MsgPermFlags    newflags);
565         /**
566          * Get the flags for a list of messages. Flags that are not supported
567          * by the folder should be preserved. They can be copied from
568          * \c msginfo->flags.perm_flags
569          *
570          * \param folder The \c Folder of the messages
571          * \param item The \c FolderItem of the messages
572          * \param msglist The list of \c MsgInfos for which the flags should
573          *                   be returned
574          * \param msgflags A \c GRelation for tuples of (MsgInfo, new permanent
575          *        flags for MsgInfo). Add tuples for the messages in msglist
576          * \return 0 on success, a negative number otherwise
577          */
578         gint            (*get_flags)            (Folder         *folder,
579                                                  FolderItem     *item,
580                                                  MsgInfoList    *msglist,
581                                                  GHashTable     *msgflags);
582         
583         /* Sets batch mode for a FolderItem. It means that numerous flags updates
584          * could follow, and the FolderClass implementation can cache them in order
585          * to process them later when set_false will be called again with the
586          * batch parameter set to FALSE. 
587          */
588         void            (*set_batch)            (Folder         *folder,
589                                                  FolderItem     *item,
590                                                  gboolean        batch);
591         /* Called when switching offline or asking for synchronisation. the imple
592          * mentation should do what's necessary to be able to read mails present
593          * in the FolderItem at this time with no network connectivity. 
594          * Days: max number of days of mail to fetch.
595          */
596         void            (*synchronise)          (FolderItem     *item,
597                                                  gint            days);
598         
599         /* Passed from claws-mail --subscribe scheme://uri. Implementations
600          * should check if they handle this type of URI, and return TRUE in this
601          * case after having subscribed it.
602          */
603         gboolean        (*subscribe)            (Folder         *folder,
604                                                  const gchar    *uri);
605         
606         /* Gets the preferred sort key and type for a folderclass. */
607         void            (*get_sort_type)        (Folder         *folder,
608                                                  FolderSortKey  *sort_key,
609                                                  FolderSortType *sort_type);
610         
611         /* Copies internal FolderItem data from one folderItem to another. Used
612          * when moving folders (this move is in reality a folder creation, content
613          * move, folder delettion).
614          */
615         void            (*copy_private_data)    (Folder         *folder,
616                                                  FolderItem     *src,
617                                                  FolderItem     *dest);
618
619         void            (*remove_cached_msg)    (Folder         *folder,
620                                                  FolderItem     *item,
621                                                  MsgInfo        *msginfo);
622         void            (*commit_tags)          (FolderItem     *item,
623                                                  MsgInfo        *msginfo,
624                                                  GSList         *tags_set,
625                                                  GSList         *tags_unset);
626         void            (*item_opened)          (FolderItem     *item);
627         void            (*item_closed)          (FolderItem     *item);
628 };
629
630 enum {
631         ITEM_NOT_SCANNING,
632         ITEM_SCANNING_WITH_FLAGS,
633         ITEM_SCANNING
634 };
635
636 struct _FolderItem
637 {
638         SpecialFolderItemType stype;
639
640         gchar *name; /* UTF-8 */
641         gchar *path; /* UTF-8 */
642
643         time_t mtime;
644
645         gint new_msgs;
646         gint unread_msgs;
647         gint total_msgs;
648         gint unreadmarked_msgs;
649         gint marked_msgs;
650         gint replied_msgs;
651         gint forwarded_msgs;
652         gint locked_msgs;
653         gint ignored_msgs;
654         gint watched_msgs;
655
656         gint order;
657
658         gint last_num;
659
660         MsgCache *cache;
661         gboolean cache_dirty;
662         gboolean mark_dirty;
663         gboolean tags_dirty;
664
665         /* special flags */
666         guint no_sub         : 1; /* no child allowed?    */
667         guint no_select      : 1; /* not selectable?      */
668         guint collapsed      : 1; /* collapsed item       */
669         guint thread_collapsed      : 1; /* collapsed item       */
670         guint threaded       : 1; /* threaded folder view */
671         guint hide_read_msgs : 1; /* hide read messages   */
672         guint ret_rcpt       : 1; /* return receipt       */
673         guint search_match   : 1;
674         guint hide_del_msgs : 1; /* hide deleted messages   */
675
676         gint op_count;
677         guint opened         : 1; /* opened by summary view */
678         FolderItemUpdateFlags update_flags; /* folderview for this folder should be updated */
679
680         FolderSortKey sort_key;
681         FolderSortType sort_type;
682
683         GNode *node;
684
685         Folder *folder;
686
687         PrefsAccount *account;
688
689         gboolean apply_sub;
690         
691         GSList *mark_queue;
692
693         gpointer data;
694
695         FolderItemPrefs * prefs;
696         
697         /* for faster search of special parents */
698         SpecialFolderItemType parent_stype;
699         gboolean processing_pending;
700         gint scanning;
701         guint last_seen;
702 };
703
704 struct _PersistPrefs
705 {
706         FolderSortKey   sort_key;
707         FolderSortType  sort_type;
708         guint           collapsed       : 1;
709         guint           thread_collapsed        : 1;
710         guint           threaded        : 1;
711         guint           hide_read_msgs  : 1; /* CLAWS */
712         guint           ret_rcpt        : 1; /* CLAWS */
713         guint           hide_del_msgs   : 1; /* CLAWS */
714 };
715
716 struct _FolderUpdateData
717 {
718         Folder                  *folder;
719         FolderUpdateFlags        update_flags;
720         FolderItem              *item;
721 };
722
723 struct _FolderItemUpdateData
724 {
725         FolderItem              *item;
726         FolderItemUpdateFlags    update_flags;
727         MsgInfo                 *msg;
728 };
729
730 void        folder_system_init          (void);
731 void        folder_register_class       (FolderClass    *klass);
732 void        folder_unregister_class     (FolderClass    *klass);
733 Folder     *folder_new                  (FolderClass    *type,
734                                          const gchar    *name,
735                                          const gchar    *path);
736 void        folder_init                 (Folder         *folder,
737                                          const gchar    *name);
738
739 void        folder_destroy              (Folder         *folder);
740
741 void        folder_set_xml              (Folder          *folder,
742                                          XMLTag          *tag);
743 XMLTag     *folder_get_xml              (Folder          *folder);
744
745 FolderItem *folder_item_new             (Folder         *folder,
746                                          const gchar    *name,
747                                          const gchar    *path);
748 void        folder_item_append          (FolderItem     *parent,
749                                          FolderItem     *item);
750 void        folder_item_remove          (FolderItem     *item);
751 void        folder_item_remove_children (FolderItem     *item);
752 void        folder_item_destroy         (FolderItem     *item);
753 FolderItem *folder_item_parent          (FolderItem     *item);
754
755 void        folder_item_set_xml         (Folder          *folder,
756                                          FolderItem      *item,
757                                          XMLTag          *tag);
758 XMLTag     *folder_item_get_xml         (Folder          *folder,
759                                          FolderItem      *item);
760
761 void        folder_set_ui_func  (Folder         *folder,
762                                  FolderUIFunc    func,
763                                  gpointer        data);
764 void        folder_set_name     (Folder         *folder,
765                                  const gchar    *name);
766 void        folder_set_sort     (Folder         *folder,
767                                  guint           sort);
768 void        folder_tree_destroy (Folder         *folder);
769
770 void   folder_add               (Folder         *folder);
771 void   folder_remove            (Folder         *folder);
772
773 GList *folder_get_list          (void);
774 gint   folder_read_list         (void);
775 void   folder_write_list        (void);
776 void   folder_scan_tree         (Folder *folder, gboolean rebuild);
777 void   folder_fast_scan_tree    (Folder *folder);
778 FolderItem *folder_create_folder(FolderItem     *parent, const gchar *name);
779 gint   folder_item_rename       (FolderItem *item, gchar *newname);
780 void   folder_update_op_count           (void);
781 void   folder_func_to_all_folders       (FolderItemFunc function,
782                                          gpointer data);
783 void folder_count_total_msgs(guint *new_msgs, guint *unread_msgs, 
784                              guint *unreadmarked_msgs, guint *marked_msgs,
785                              guint *total_msgs, guint *replied_msgs,
786                              guint *forwarded_msgs, guint *locked_msgs,
787                              guint *ignored_msgs, guint *watched_msgs);
788 gchar *folder_get_status        (GPtrArray      *folders,
789                                  gboolean        full);
790
791 Folder     *folder_find_from_path               (const gchar    *path);
792 Folder     *folder_find_from_name               (const gchar    *name,
793                                                  FolderClass    *klass);
794 FolderItem *folder_find_item_from_path          (const gchar    *path);
795 FolderItem *folder_find_item_from_real_path     (const gchar    *path);
796 FolderClass *folder_get_class_from_string       (const gchar    *str);
797 FolderItem *folder_find_child_item_by_name      (FolderItem     *item,
798                                                  const gchar    *name);
799 /* return value is locale charset */
800 gchar      *folder_get_identifier               (Folder *folder);
801 /* return value is locale charset */
802 gchar      *folder_item_get_identifier          (FolderItem     *item);
803 FolderItem *folder_find_item_from_identifier    (const gchar    *identifier);
804 FolderItem *folder_get_item_from_identifier     (const gchar    *identifier);
805 gchar      *folder_item_get_name                (FolderItem     *item);
806
807 FolderItem *folder_get_default_inbox    (void);
808 FolderItem *folder_get_default_inbox_for_class(FolderType type);
809 FolderItem *folder_get_default_outbox   (void);
810 FolderItem *folder_get_default_outbox_for_class(FolderType type);
811 FolderItem *folder_get_default_draft    (void);
812 FolderItem *folder_get_default_draft_for_class(FolderType type);
813 FolderItem *folder_get_default_queue    (void);
814 FolderItem *folder_get_default_queue_for_class(FolderType type);
815 FolderItem *folder_get_default_trash    (void);
816 FolderItem *folder_get_default_trash_for_class(FolderType type);
817 FolderItem *folder_get_default_processing (void);
818 void folder_set_missing_folders         (void);
819 void folder_unref_account_all           (PrefsAccount   *account);
820
821 /* return value is locale encoded file name */
822 gchar *folder_item_get_path             (FolderItem     *item);
823
824 gint   folder_item_open                 (FolderItem     *item);
825 gint   folder_item_close                (FolderItem     *item);
826 gint   folder_item_scan                 (FolderItem     *item);
827 gint   folder_item_scan_full            (FolderItem     *item, 
828                                          gboolean        filtering);
829 MsgInfo *folder_item_get_msginfo        (FolderItem     *item,
830                                          gint            num);
831 MsgInfo *folder_item_get_msginfo_by_msgid(FolderItem    *item,
832                                          const gchar    *msgid);
833 GSList *folder_item_get_msg_list        (FolderItem     *item);
834 /* return value is locale charset */
835 gchar *folder_item_fetch_msg            (FolderItem     *item,
836                                          gint            num);
837 gchar *folder_item_fetch_msg_full       (FolderItem     *item,
838                                          gint            num, 
839                                          gboolean        get_headers,
840                                          gboolean        get_body);
841 gint   folder_item_add_msg              (FolderItem     *dest,
842                                          const gchar    *file,
843                                          MsgFlags       *flags,
844                                          gboolean        remove_source);
845 gint   folder_item_add_msgs             (FolderItem     *dest,
846                                          GSList         *file_list,
847                                          gboolean        remove_source);
848 gint   folder_item_move_to              (FolderItem     *src,
849                                          FolderItem     *dest,
850                                          FolderItem    **new_item,
851                                          gboolean        copy);
852 gint   folder_item_move_msg             (FolderItem     *dest,
853                                          MsgInfo        *msginfo);
854 gint   folder_item_move_msgs            (FolderItem     *dest,
855                                          GSList         *msglist);
856 gint   folder_item_copy_msg             (FolderItem     *dest,
857                                          MsgInfo        *msginfo);
858 gint   folder_item_copy_msgs            (FolderItem     *dest,
859                                          GSList         *msglist);
860 gint   folder_item_remove_msg           (FolderItem     *item,
861                                          gint            num);
862 gint   folder_item_remove_msgs          (FolderItem     *item,
863                                          GSList         *msglist);
864 gint   folder_item_expunge              (FolderItem     *item);
865 gint   folder_item_remove_all_msg       (FolderItem     *item);
866 void    folder_item_change_msg_flags    (FolderItem     *item,
867                                          MsgInfo        *msginfo,
868                                          MsgPermFlags    newflags);
869 gboolean folder_item_is_msg_changed     (FolderItem     *item,
870                                          MsgInfo        *msginfo);
871
872 void folder_clean_cache_memory          (FolderItem *protected_item);
873 void folder_clean_cache_memory_force    (void);
874 void folder_item_write_cache            (FolderItem *item);
875
876 void folder_item_apply_processing       (FolderItem *item);
877
878 void folder_item_update                 (FolderItem *item,
879                                          FolderItemUpdateFlags update_flags);
880 void folder_item_update_recursive       (FolderItem *item,
881                                          FolderItemUpdateFlags update_flags);
882 void folder_item_update_freeze          (void);
883 void folder_item_update_thaw            (void);
884 void folder_item_set_batch              (FolderItem *item, gboolean batch);
885 gboolean folder_has_parent_of_type      (FolderItem *item, SpecialFolderItemType type);
886 void folder_synchronise                 (Folder *folder);
887 gboolean folder_want_synchronise        (Folder *folder);
888 gboolean folder_subscribe               (const gchar *uri);
889 gboolean folder_have_mailbox            (void);
890 gboolean folder_item_free_cache         (FolderItem *item, gboolean force);
891 void folder_item_change_type            (FolderItem *item,
892                                          SpecialFolderItemType newtype);
893 gboolean folder_get_sort_type           (Folder         *folder,
894                                          FolderSortKey  *sort_key,
895                                          FolderSortType *sort_type);
896 void folder_item_synchronise            (FolderItem *item);
897 void folder_item_discard_cache          (FolderItem *item);
898 void folder_item_commit_tags(FolderItem *item, MsgInfo *msginfo, GSList *tags_set, GSList *tags_unset);
899
900 #endif /* __FOLDER_H__ */