fix bug 2979, 'claws fails to load (empty) folderlist.xml and shows account wizard'
[claws.git] / src / folder.h
index 72e2a26d0ac323e35ac70c0239281283875b9c7c..44f69bb2c25d30a015a5ff8b676eb86780826179 100644 (file)
@@ -2,7 +2,7 @@
 
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -129,12 +129,12 @@ typedef void (*FolderItemFunc)    (FolderItem     *item,
                                         gpointer        data);
 
 
-#include "folder_item_prefs.h"
-
-#include "procmsg.h"
-#include "msgcache.h"
+#include "proctypes.h"
 #include "xml.h"
 #include "prefs_account.h"
+#include "matchertypes.h"
+
+struct _MsgCache;
 
 struct _Folder
 {
@@ -160,6 +160,23 @@ struct _Folder
        GHashTable *newsart;
 };
 
+/**
+ * Callback used to convey progress information of a specific search.
+ *
+ * \param data User-provided data
+ * \param on_server Whether or not the current progress information originated from the
+ *                  server
+ * \param at Number of the last message processed
+ * \param matched Number of messages with definitive matches found so far
+ * \param total Number of messages to be processed
+ *
+ * \note
+ * Even if the mailserver does not support progress reports, an instance of this type
+ * should be invoked when serverside search starts and ends, with \c at set to \c 0 and
+ * \c total, respectively.
+ */
+typedef gboolean (*SearchProgressNotify)(gpointer data, gboolean on_server, guint at, guint matched, guint total);
+
 struct _FolderClass
 {
        /**
@@ -176,6 +193,13 @@ struct _FolderClass
         * user. Can be upper and lowercase unlike the idstr.
         */
        gchar      *uistr;
+       /**
+       * A boolean to indicate whether or not the FolderClass supports search on the
+       * server. If \c TRUE, setting \c on_server in \c search_msgs offloads search to
+       * the server.
+       */
+       gboolean    supports_server_search;
+
        
        /* virtual functions */
 
@@ -474,7 +498,7 @@ struct _FolderClass
        gint            (*add_msgs)             (Folder         *folder,
                                                 FolderItem     *dest,
                                                 GSList         *file_list,
-                                                GRelation      *relation);
+                                                GHashTable     *relation);
        /**
         * Copy a message to a FolderItem
         *
@@ -505,7 +529,59 @@ struct _FolderClass
        gint            (*copy_msgs)            (Folder         *folder,
                                                 FolderItem     *dest,
                                                 MsgInfoList    *msglist,
-                                                GRelation      *relation);
+                                                GHashTable     *relation);
+
+       /**
+        * Search the given FolderItem for messages matching \c predicate.
+        * The search may be offloaded to the server if the \c folder
+        * supports server side search, as indicated by \c supports_server_search.
+        *
+        * \param folder The \c Folder of the container FolderItem
+        * \param container The \c FolderItem containing the messages to be searched
+        * \param msgs The \c MsgNumberList results will be saved to.
+        *             If <tt>*msgs != NULL</tt>, the search will be restricted to
+        *             messages whose numbers are contained therein.
+        *             If \c on_server is considered \c FALSE, messages are guaranteed to
+        *             be processed in the order they are listed in \c msgs.
+        *             On error, \c msgs will not be changed.
+        * \param on_server Whether or not the search should be offloaded to the server.
+        *                  If \c on_server is not \c NULL and points to a \c TRUE value,
+        *                  search will be done on the server. If \c predicate contains
+        *                  one or more atoms the server does not support, the value
+        *                  pointed to by \c on_server will be set to \c FALSE upon return.
+        *                  In this case, \c msgs must still contain a valid superset of
+        *                  messages actually matched by \c predicate, or this method must
+        *                  return an error.
+        *                  \c on_server may only point to a \c TRUE value if
+        *                  \c supports_server_search is also \c TRUE.
+        *                  \c NULL and pointer to \c FALSE are considered equivalent and
+        *                  will start a client-only search.
+        * \param predicate The \c MatcherList to use in the search
+        * \param progress_cb Called for every message searched.
+        *                    When search is offloaded to the server, this function
+        *                    may or may not be called, depending on the implementation.
+        *                    The second argument of this function will be the number of
+        *                    messages already processed.
+        *                    Return \c FALSE from this function to end the search.
+        *                    May be \c NULL, no calls will be made in this case.
+        * \param progress_data First argument value for \c progress_cb
+        * \return Number of messages that matched \c predicate on success, a negative
+        *         number otherwise.
+        *
+        * \note
+        * When search is stopped by returning \c FALSE from \c progress_cb, \c msgs will
+        * contain all messages found until the point of cancellation. The number of
+        * messages found will be returned as indicated above.
+        */
+       gint            (*search_msgs)          (Folder                 *folder,
+                                                FolderItem             *container,
+                                                MsgNumberList          **msgs,
+                                                gboolean               *on_server,
+                                                MatcherList            *predicate,
+                                                SearchProgressNotify   progress_cb,
+                                                gpointer               progress_data);
+
+
        /**
         * Remove a message from a \c FolderItem.
         *
@@ -520,7 +596,9 @@ struct _FolderClass
        gint            (*remove_msgs)          (Folder         *folder,
                                                 FolderItem     *item,
                                                 MsgInfoList    *msglist,
-                                                GRelation      *relation);
+                                                GHashTable     *relation);
+       gint            (*expunge)              (Folder         *folder,
+                                                FolderItem     *item);
        /**
         * Remove all messages in a \ c FolderItem
         *
@@ -576,7 +654,7 @@ struct _FolderClass
        gint            (*get_flags)            (Folder         *folder,
                                                 FolderItem     *item,
                                                 MsgInfoList    *msglist,
-                                                GRelation      *msgflags);
+                                                GHashTable     *msgflags);
        
        /* Sets batch mode for a FolderItem. It means that numerous flags updates
         * could follow, and the FolderClass implementation can cache them in order
@@ -621,6 +699,8 @@ struct _FolderClass
                                                 MsgInfo        *msginfo,
                                                 GSList         *tags_set,
                                                 GSList         *tags_unset);
+       void            (*item_opened)          (FolderItem     *item);
+       void            (*item_closed)          (FolderItem     *item);
 };
 
 enum {
@@ -629,6 +709,8 @@ enum {
        ITEM_SCANNING
 };
 
+struct _FolderItemPrefs;
+
 struct _FolderItem
 {
        SpecialFolderItemType stype;
@@ -643,12 +725,20 @@ struct _FolderItem
        gint total_msgs;
        gint unreadmarked_msgs;
        gint marked_msgs;
+       gint replied_msgs;
+       gint forwarded_msgs;
+       gint locked_msgs;
+       gint ignored_msgs;
+       gint watched_msgs;
 
        gint order;
 
        gint last_num;
 
-       MsgCache *cache;
+       struct _MsgCache *cache;
+       gboolean cache_dirty;
+       gboolean mark_dirty;
+       gboolean tags_dirty;
 
        /* special flags */
        guint no_sub         : 1; /* no child allowed?    */
@@ -659,6 +749,8 @@ struct _FolderItem
        guint hide_read_msgs : 1; /* hide read messages   */
        guint ret_rcpt       : 1; /* return receipt       */
        guint search_match   : 1;
+       guint hide_del_msgs : 1; /* hide deleted messages   */
+       guint hide_read_threads : 1; /* hide threads with only read messages   */
 
        gint op_count;
        guint opened         : 1; /* opened by summary view */
@@ -679,7 +771,7 @@ struct _FolderItem
 
        gpointer data;
 
-       FolderItemPrefs * prefs;
+       struct _FolderItemPrefs * prefs;
        
        /* for faster search of special parents */
        SpecialFolderItemType parent_stype;
@@ -697,6 +789,8 @@ struct _PersistPrefs
        guint           threaded        : 1;
        guint           hide_read_msgs  : 1; /* CLAWS */
        guint           ret_rcpt        : 1; /* CLAWS */
+       guint           hide_del_msgs   : 1; /* CLAWS */
+       guint           hide_read_threads       : 1;
 };
 
 struct _FolderUpdateData
@@ -768,19 +862,27 @@ void   folder_func_to_all_folders (FolderItemFunc function,
                                         gpointer data);
 void folder_count_total_msgs(guint *new_msgs, guint *unread_msgs, 
                             guint *unreadmarked_msgs, guint *marked_msgs,
-                            guint *total_msgs);
+                            guint *total_msgs, guint *replied_msgs,
+                            guint *forwarded_msgs, guint *locked_msgs,
+                            guint *ignored_msgs, guint *watched_msgs);
 gchar *folder_get_status       (GPtrArray      *folders,
                                 gboolean        full);
 
+Folder            *folder_find_from_identifier         (const gchar *identifier);
 Folder     *folder_find_from_path              (const gchar    *path);
 Folder     *folder_find_from_name              (const gchar    *name,
                                                 FolderClass    *klass);
 FolderItem *folder_find_item_from_path         (const gchar    *path);
+FolderItem *folder_find_item_from_real_path    (const gchar    *path);
 FolderClass *folder_get_class_from_string      (const gchar    *str);
 FolderItem *folder_find_child_item_by_name     (FolderItem     *item,
                                                 const gchar    *name);
+/* return value is locale charset */
+gchar     *folder_get_identifier               (Folder *folder);
+/* return value is locale charset */
 gchar      *folder_item_get_identifier         (FolderItem     *item);
 FolderItem *folder_find_item_from_identifier   (const gchar    *identifier);
+FolderItem *folder_get_item_from_identifier    (const gchar    *identifier);
 gchar     *folder_item_get_name                (FolderItem     *item);
 
 FolderItem *folder_get_default_inbox   (void);
@@ -810,6 +912,8 @@ MsgInfo *folder_item_get_msginfo    (FolderItem     *item,
 MsgInfo *folder_item_get_msginfo_by_msgid(FolderItem   *item,
                                         const gchar    *msgid);
 GSList *folder_item_get_msg_list       (FolderItem     *item);
+MsgNumberList *folder_item_get_number_list(FolderItem *item);
+
 /* return value is locale charset */
 gchar *folder_item_fetch_msg           (FolderItem     *item,
                                         gint            num);
@@ -836,18 +940,24 @@ gint   folder_item_copy_msg               (FolderItem     *dest,
                                         MsgInfo        *msginfo);
 gint   folder_item_copy_msgs           (FolderItem     *dest,
                                         GSList         *msglist);
+gint   folder_item_search_msgs         (Folder                 *folder,
+                                        FolderItem             *container,
+                                        MsgNumberList          **msgs,
+                                        gboolean               *on_server,
+                                        MatcherList            *predicate,
+                                        SearchProgressNotify   progress_cb,
+                                        gpointer               progress_data);
 gint   folder_item_remove_msg          (FolderItem     *item,
                                         gint            num);
 gint   folder_item_remove_msgs         (FolderItem     *item,
                                         GSList         *msglist);
+gint   folder_item_expunge             (FolderItem     *item);
 gint   folder_item_remove_all_msg      (FolderItem     *item);
 void   folder_item_change_msg_flags    (FolderItem     *item,
                                         MsgInfo        *msginfo,
                                         MsgPermFlags    newflags);
 gboolean folder_item_is_msg_changed    (FolderItem     *item,
                                         MsgInfo        *msginfo);
-/* return value is locale chaset */
-gchar * folder_item_get_identifier     (FolderItem * item);
 
 void folder_clean_cache_memory         (FolderItem *protected_item);
 void folder_clean_cache_memory_force   (void);
@@ -863,6 +973,7 @@ void folder_item_update_freeze              (void);
 void folder_item_update_thaw           (void);
 void folder_item_set_batch             (FolderItem *item, gboolean batch);
 gboolean folder_has_parent_of_type     (FolderItem *item, SpecialFolderItemType type);
+gboolean folder_is_child_of            (FolderItem *item, FolderItem *possibleChild);
 void folder_synchronise                        (Folder *folder);
 gboolean folder_want_synchronise       (Folder *folder);
 gboolean folder_subscribe              (const gchar *uri);
@@ -877,4 +988,15 @@ void folder_item_synchronise               (FolderItem *item);
 void folder_item_discard_cache         (FolderItem *item);
 void folder_item_commit_tags(FolderItem *item, MsgInfo *msginfo, GSList *tags_set, GSList *tags_unset);
 
+
+
+gint folder_item_search_msgs_local     (Folder                 *folder,
+                                        FolderItem             *container,
+                                        MsgNumberList          **msgs,
+                                        gboolean               *on_server,
+                                        MatcherList            *predicate,
+                                        SearchProgressNotify   progress_cb,
+                                        gpointer               progress_data);
+
+gchar *folder_get_list_path    (void);
 #endif /* __FOLDER_H__ */