8333140403a84d2382e009b399ac7e684018f627
[claws.git] / src / folder.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __FOLDER_H__
21 #define __FOLDER_H__
22
23 #include <glib.h>
24 #include <time.h>
25
26 typedef struct _Folder          Folder;
27 typedef struct _LocalFolder     LocalFolder;
28 typedef struct _RemoteFolder    RemoteFolder;
29 typedef struct _MHFolder        MHFolder;
30 typedef struct _MboxFolder      MboxFolder;
31 typedef struct _MaildirFolder   MaildirFolder;
32 typedef struct _IMAPFolder      IMAPFolder;
33 typedef struct _NewsFolder      NewsFolder;
34 typedef struct _FolderItem      FolderItem;
35
36 #include "prefs_account.h"
37 #include "session.h"
38 #include "procmsg.h"
39 #include "prefs_folder_item.h"
40
41 #define FOLDER(obj)             ((Folder *)obj)
42 #define FOLDER_TYPE(obj)        (FOLDER(obj)->type)
43
44 #define LOCAL_FOLDER(obj)       ((LocalFolder *)obj)
45 #define REMOTE_FOLDER(obj)      ((RemoteFolder *)obj)
46
47 #define FOLDER_IS_LOCAL(obj)    (FOLDER_TYPE(obj) == F_MH      || \
48                                  FOLDER_TYPE(obj) == F_MBOX    || \
49                                  FOLDER_TYPE(obj) == F_MAILDIR)
50
51 #define MH_FOLDER(obj)          ((MHFolder *)obj)
52 #define MBOX_FOLDER(obj)        ((MboxFolder *)obj)
53 #define MAILDIR_FOLDER(obj)     ((MaildirFolder *)obj)
54 #define IMAP_FOLDER(obj)        ((IMAPFolder *)obj)
55 #define NEWS_FOLDER(obj)        ((NewsFolder *)obj)
56
57 #define FOLDER_ITEM(obj)        ((FolderItem *)obj)
58
59 typedef enum
60 {
61         F_MH,
62         F_MBOX,
63         F_MAILDIR,
64         F_IMAP,
65         F_NEWS,
66         F_UNKNOWN
67 } FolderType;
68
69 typedef enum
70 {
71         F_NORMAL,
72         F_INBOX,
73         F_OUTBOX,
74         F_DRAFT,
75         F_QUEUE,
76         F_TRASH
77 } SpecialFolderItemType;
78
79 typedef void (*FolderUIFunc)            (Folder         *folder,
80                                          FolderItem     *item,
81                                          gpointer        data);
82 typedef void (*FolderDestroyNotify)     (Folder         *folder,
83                                          FolderItem     *item,
84                                          gpointer        data);
85
86 struct _Folder
87 {
88         FolderType type;
89
90         gchar *name;
91         PrefsAccount *account;
92
93         FolderItem *inbox;
94         FolderItem *outbox;
95         FolderItem *draft;
96         FolderItem *queue;
97         FolderItem *trash;
98
99         FolderUIFunc ui_func;
100         gpointer     ui_func_data;
101
102         GNode *node;
103
104         gpointer data;
105
106         /* virtual functions */
107         GSList * (*get_msg_list)        (Folder         *folder,
108                                          FolderItem     *item,
109                                          gboolean        use_cache);
110         gchar *  (*fetch_msg)           (Folder         *folder,
111                                          FolderItem     *item,
112                                          gint            num);
113         gint     (*add_msg)             (Folder         *folder,
114                                          FolderItem     *dest,
115                                          const gchar    *file,
116                                          gboolean        remove_source);
117         gint     (*move_msg)            (Folder         *folder,
118                                          FolderItem     *dest,
119                                          MsgInfo        *msginfo);
120         gint     (*move_msgs_with_dest) (Folder         *folder,
121                                          FolderItem     *dest,
122                                          GSList         *msglist);
123         gint     (*copy_msg)            (Folder         *folder,
124                                          FolderItem     *dest,
125                                          MsgInfo        *msginfo);
126         gint     (*copy_msgs_with_dest) (Folder         *folder,
127                                          FolderItem     *dest,
128                                          GSList         *msglist);
129         gint     (*remove_msg)          (Folder         *folder,
130                                          FolderItem     *item,
131                                          gint            num);
132         gint     (*remove_all_msg)      (Folder         *folder,
133                                          FolderItem     *item);
134         gboolean (*is_msg_changed)      (Folder         *folder,
135                                          FolderItem     *item,
136                                          MsgInfo        *msginfo);
137         void     (*scan)                (Folder         *folder,
138                                          FolderItem     *item);
139         void     (*scan_tree)           (Folder         *folder);
140
141         gint     (*create_tree)         (Folder         *folder);
142         FolderItem * (*create_folder)   (Folder         *folder,
143                                          FolderItem     *parent,
144                                          const gchar    *name);
145         gint     (*rename_folder)       (Folder         *folder,
146                                          FolderItem     *item,
147                                          const gchar    *name);
148         gint     (*remove_folder)       (Folder         *folder,
149                                          FolderItem     *item);
150         void     (*update_mark)         (Folder         *folder,
151                                          FolderItem     *item);
152         void     (*change_flags)        (Folder         *folder,
153                                          FolderItem     *item,
154                                          MsgInfo        *info);
155         void     (*finished_copy)       (Folder * folder, FolderItem * item);
156         void     (*finished_remove)       (Folder * folder, FolderItem * item);
157 };
158
159 struct _LocalFolder
160 {
161         Folder folder;
162
163         gchar *rootpath;
164 };
165
166 struct _RemoteFolder
167 {
168         Folder folder;
169
170         Session *session;
171 };
172
173 struct _MHFolder
174 {
175         LocalFolder lfolder;
176 };
177
178 struct _MboxFolder
179 {
180         LocalFolder lfolder;
181 };
182
183 struct _MaildirFolder
184 {
185         LocalFolder lfolder;
186 };
187
188 struct _IMAPFolder
189 {
190         RemoteFolder rfolder;
191
192         GList *namespace;       /* list of IMAPNameSpace */
193 };
194
195 struct _NewsFolder
196 {
197         RemoteFolder rfolder;
198
199         gboolean use_auth;
200 };
201
202 struct _FolderItem
203 {
204         SpecialFolderItemType stype;
205
206         gchar *name;
207         gchar *path;
208         PrefsAccount *account;
209
210         time_t mtime;
211
212         gint new;
213         gint unread;
214         gint total;
215
216         gint last_num;
217
218         /* special flags */
219         guint no_sub    : 1; /* no child allowed?    */
220         guint no_select : 1; /* not selectable?      */
221         guint collapsed : 1; /* collapsed item       */
222         guint threaded  : 1; /* threaded folder view */
223         guint ret_rcpt  : 1; /* return receipt       */
224
225         gint op_count;
226
227         FolderItem *parent;
228
229         Folder *folder;
230
231         gpointer data;
232
233         PrefsFolderItem * prefs;
234 };
235
236 Folder     *folder_new          (FolderType      type,
237                                  const gchar    *name,
238                                  const gchar    *path);
239 Folder     *mh_folder_new       (const gchar    *name,
240                                  const gchar    *path);
241 Folder     *mbox_folder_new     (const gchar    *name,
242                                  const gchar    *path);
243 Folder     *maildir_folder_new  (const gchar    *name,
244                                  const gchar    *path);
245 Folder     *imap_folder_new     (const gchar    *name,
246                                  const gchar    *path);
247 Folder     *news_folder_new     (const gchar    *name,
248                                  const gchar    *path);
249 FolderItem *folder_item_new     (const gchar    *name,
250                                  const gchar    *path);
251 void        folder_item_append  (FolderItem     *parent,
252                                  FolderItem     *item);
253 void        folder_item_remove  (FolderItem     *item);
254 void        folder_item_destroy (FolderItem     *item);
255 void        folder_set_ui_func  (Folder         *folder,
256                                  FolderUIFunc    func,
257                                  gpointer        data);
258 void        folder_set_name     (Folder         *folder,
259                                  const gchar    *name);
260 void        folder_destroy      (Folder         *folder);
261 void        folder_tree_destroy (Folder         *folder);
262
263 void   folder_add               (Folder         *folder);
264
265 GList *folder_get_list          (void);
266 gint   folder_read_list         (void);
267 void   folder_write_list        (void);
268 void   folder_update_op_count           (void);
269 void   folder_count_total_msgs  (guint          *new,
270                                  guint          *unread,
271                                  guint          *total);
272
273 Folder     *folder_find_from_path       (const gchar    *path);
274 FolderItem *folder_find_item_from_path  (const gchar    *path);
275 Folder     *folder_get_default_folder   (void);
276 FolderItem *folder_get_default_inbox    (void);
277 FolderItem *folder_get_default_outbox   (void);
278 FolderItem *folder_get_default_draft    (void);
279 FolderItem *folder_get_default_queue    (void);
280 FolderItem *folder_get_default_trash    (void);
281
282 gchar *folder_item_get_path             (FolderItem     *item);
283 void   folder_item_scan                 (FolderItem     *item);
284 void   folder_item_scan_foreach         (GHashTable     *table);
285 gchar *folder_item_fetch_msg            (FolderItem     *item,
286                                          gint            num);
287 gint   folder_item_add_msg              (FolderItem     *dest,
288                                          const gchar    *file,
289                                          gboolean        remove_source);
290 gint   folder_item_move_msg             (FolderItem     *dest,
291                                          MsgInfo        *msginfo);
292 gint   folder_item_move_msgs_with_dest  (FolderItem     *dest,
293                                          GSList         *msglist);
294 gint   folder_item_copy_msg             (FolderItem     *dest,
295                                          MsgInfo        *msginfo);
296 gint   folder_item_copy_msgs_with_dest  (FolderItem     *dest,
297                                          GSList         *msglist);
298 gint   folder_item_remove_msg           (FolderItem     *item,
299                                          gint            num);
300 gint   folder_item_remove_msgs          (FolderItem     *item,
301                                          GSList         *msglist);
302 gint   folder_item_remove_all_msg       (FolderItem     *item);
303 gboolean folder_item_is_msg_changed     (FolderItem     *item,
304                                          MsgInfo        *msginfo);
305 gchar *folder_item_get_cache_file       (FolderItem     *item);
306 gchar *folder_item_get_mark_file        (FolderItem     *item);
307 gchar * folder_item_get_identifier(FolderItem * item);
308 FolderItem * folder_find_item_from_identifier(const gchar *identifier);
309
310 #endif /* __FOLDER_H__ */