1a0cf8036364bd8a09ebb19cdb08137a6ccaab5f
[claws.git] / src / folder.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999,2000 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 MH_FOLDER(obj)          ((MHFolder *)obj)
48 #define MBOX_FOLDER(obj)        ((MboxFolder *)obj)
49 #define MAILDIR_FOLDER(obj)     ((MaildirFolder *)obj)
50 #define IMAP_FOLDER(obj)        ((IMAPFolder *)obj)
51 #define NEWS_FOLDER(obj)        ((NewsFolder *)obj)
52
53 #define FOLDER_ITEM(obj)        ((FolderItem *)obj)
54
55 typedef enum
56 {
57         F_MH,
58         F_MBOX,
59         F_MAILDIR,
60         F_IMAP,
61         F_NEWS,
62         F_UNKNOWN
63 } FolderType;
64
65 typedef enum
66 {
67         F_NORMAL,
68         F_INBOX,
69         F_OUTBOX,
70         F_DRAFT,
71         F_QUEUE,
72         F_TRASH
73 } SpecialFolderItemType;
74
75 typedef void (*FolderUIFunc)            (Folder         *folder,
76                                          FolderItem     *item,
77                                          gpointer        data);
78 typedef void (*FolderDestroyNotify)     (Folder         *folder,
79                                          FolderItem     *item,
80                                          gpointer        data);
81
82 struct _Folder
83 {
84         FolderType type;
85
86         gchar *name;
87         PrefsAccount *account;
88
89         FolderItem *inbox;
90         FolderItem *outbox;
91         FolderItem *draft;
92         FolderItem *queue;
93         FolderItem *trash;
94
95         FolderUIFunc ui_func;
96         gpointer     ui_func_data;
97
98         GNode *node;
99
100         gpointer data;
101
102         /* virtual functions */
103         GSList * (*get_msg_list)        (Folder         *folder,
104                                          FolderItem     *item,
105                                          gboolean        use_cache);
106         gchar *  (*fetch_msg)           (Folder         *folder,
107                                          FolderItem     *item,
108                                          gint            num);
109         gint     (*add_msg)             (Folder         *folder,
110                                          FolderItem     *dest,
111                                          const gchar    *file,
112                                          gboolean        remove_source);
113         gint     (*move_msg)            (Folder         *folder,
114                                          FolderItem     *dest,
115                                          MsgInfo        *msginfo);
116         gint     (*move_msgs_with_dest) (Folder         *folder,
117                                          FolderItem     *dest,
118                                          GSList         *msglist);
119         gint     (*copy_msg)            (Folder         *folder,
120                                          FolderItem     *dest,
121                                          MsgInfo        *msginfo);
122         gint     (*copy_msgs_with_dest) (Folder         *folder,
123                                          FolderItem     *dest,
124                                          GSList         *msglist);
125         gint     (*remove_msg)          (Folder         *folder,
126                                          FolderItem     *item,
127                                          gint            num);
128         gint     (*remove_all_msg)      (Folder         *folder,
129                                          FolderItem     *item);
130         gboolean (*is_msg_changed)      (Folder         *folder,
131                                          FolderItem     *item,
132                                          MsgInfo        *msginfo);
133         void     (*scan)                (Folder         *folder,
134                                          FolderItem     *item);
135         void     (*scan_tree)           (Folder         *folder);
136
137         gint     (*create_tree)         (Folder         *folder);
138         FolderItem * (*create_folder)   (Folder         *folder,
139                                          FolderItem     *parent,
140                                          const gchar    *name);
141         gint     (*rename_folder)       (Folder         *folder,
142                                          FolderItem     *item,
143                                          const gchar    *name);
144         gint     (*remove_folder)       (Folder         *folder,
145                                          FolderItem     *item);
146 };
147
148 struct _LocalFolder
149 {
150         Folder folder;
151
152         gchar *rootpath;
153 };
154
155 struct _RemoteFolder
156 {
157         Folder folder;
158
159         Session *session;
160 };
161
162 struct _MHFolder
163 {
164         LocalFolder lfolder;
165 };
166
167 struct _MboxFolder
168 {
169         LocalFolder lfolder;
170 };
171
172 struct _MaildirFolder
173 {
174         LocalFolder lfolder;
175 };
176
177 struct _IMAPFolder
178 {
179         RemoteFolder rfolder;
180 };
181
182 struct _NewsFolder
183 {
184         RemoteFolder rfolder;
185
186         gboolean use_auth;
187 };
188
189 struct _FolderItem
190 {
191         SpecialFolderItemType stype;
192
193         gchar *name;
194         gchar *path;
195         PrefsAccount *account;
196
197         time_t mtime;
198
199         gint new;
200         gint unread;
201         gint total;
202
203         gint last_num;
204
205         FolderItem *parent;
206
207         Folder *folder;
208
209         gpointer data;
210
211         PrefsFolderItem * prefs;
212 };
213
214 Folder     *folder_new          (FolderType      type,
215                                  const gchar    *name,
216                                  const gchar    *path);
217 Folder     *mh_folder_new       (const gchar    *name,
218                                  const gchar    *path);
219 Folder     *mbox_folder_new     (const gchar    *name,
220                                  const gchar    *path);
221 Folder     *maildir_folder_new  (const gchar    *name,
222                                  const gchar    *path);
223 Folder     *imap_folder_new     (const gchar    *name,
224                                  const gchar    *path);
225 Folder     *news_folder_new     (const gchar    *name,
226                                  const gchar    *path);
227 FolderItem *folder_item_new     (const gchar    *name,
228                                  const gchar    *path);
229 void        folder_item_append  (FolderItem     *parent,
230                                  FolderItem     *item);
231 void        folder_item_remove  (FolderItem     *item);
232 void        folder_set_ui_func  (Folder         *folder,
233                                  FolderUIFunc    func,
234                                  gpointer        data);
235 void        folder_set_name     (Folder         *folder,
236                                  const gchar    *name);
237 void        folder_destroy      (Folder         *folder);
238 void        folder_tree_destroy (Folder         *folder);
239
240 void   folder_add               (Folder         *folder);
241
242 GList *folder_get_list          (void);
243 gint   folder_read_list         (void);
244 void   folder_write_list        (void);
245
246 Folder     *folder_find_from_path       (const gchar    *path);
247 FolderItem *folder_find_item_from_path  (const gchar    *path);
248 Folder     *folder_get_default_folder   (void);
249 FolderItem *folder_get_default_inbox    (void);
250 FolderItem *folder_get_default_outbox   (void);
251 FolderItem *folder_get_default_draft    (void);
252 FolderItem *folder_get_default_queue    (void);
253 FolderItem *folder_get_default_trash    (void);
254
255 gchar *folder_item_get_path             (FolderItem     *item);
256 void   folder_item_scan                 (FolderItem     *item);
257 void   folder_item_scan_foreach         (GHashTable     *table);
258 gchar *folder_item_fetch_msg            (FolderItem     *item,
259                                          gint            num);
260 gint   folder_item_add_msg              (FolderItem     *dest,
261                                          const gchar    *file,
262                                          gboolean        remove_source);
263 gint   folder_item_move_msg             (FolderItem     *dest,
264                                          MsgInfo        *msginfo);
265 gint   folder_item_move_msgs_with_dest  (FolderItem     *dest,
266                                          GSList         *msglist);
267 gint   folder_item_copy_msg             (FolderItem     *dest,
268                                          MsgInfo        *msginfo);
269 gint   folder_item_copy_msgs_with_dest  (FolderItem     *dest,
270                                          GSList         *msglist);
271 gint   folder_item_remove_msg           (FolderItem     *item,
272                                          gint            num);
273 gint   folder_item_remove_all_msg       (FolderItem     *item);
274 gboolean folder_item_is_msg_changed     (FolderItem     *item,
275                                          MsgInfo        *msginfo);
276 gchar *folder_item_get_cache_file       (FolderItem     *item);
277 gchar *folder_item_get_mark_file        (FolderItem     *item);
278
279 #endif /* __FOLDER_H__ */