2006-05-17 [paul] 2.2.0cvs28
[claws.git] / src / procmsg.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifndef __PROCMSG_H__
21 #define __PROCMSG_H__
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include <glib.h>
28 #include <stdio.h>
29 #include <time.h>
30 #include <sys/types.h>
31 #include <string.h>
32
33 typedef struct _MsgInfo                 MsgInfo;
34 typedef struct _MsgFlags                MsgFlags;
35 typedef struct _MsgFileInfo             MsgFileInfo;
36 typedef struct _MsgInfoUpdate           MsgInfoUpdate;
37 typedef struct _MailFilteringData       MailFilteringData;
38
39 typedef GSList MsgInfoList;
40 typedef GSList MsgNumberList;
41
42 #define MSG_NEW                 (1U << 0)
43 #define MSG_UNREAD              (1U << 1)
44 #define MSG_MARKED              (1U << 2)
45 #define MSG_DELETED             (1U << 3)
46 #define MSG_REPLIED             (1U << 4)
47 #define MSG_FORWARDED           (1U << 5)
48 #define MSG_POSTFILTERED        (1U << 14)
49
50 #define MSG_CLABEL_SBIT (7)             /* start bit of color label */
51 #define MAKE_MSG_CLABEL(h, m, l)        (((h) << (MSG_CLABEL_SBIT + 2)) | \
52                                          ((m) << (MSG_CLABEL_SBIT + 1)) | \
53                                          ((l) << (MSG_CLABEL_SBIT + 0)))
54
55 #define MSG_CLABEL_NONE         MAKE_MSG_CLABEL(0U, 0U, 0U)
56 #define MSG_CLABEL_1            MAKE_MSG_CLABEL(0U, 0U, 1U)
57 #define MSG_CLABEL_2            MAKE_MSG_CLABEL(0U, 1U, 0U)
58 #define MSG_CLABEL_3            MAKE_MSG_CLABEL(0U, 1U, 1U)
59 #define MSG_CLABEL_4            MAKE_MSG_CLABEL(1U, 0U, 0U)
60 #define MSG_CLABEL_5            MAKE_MSG_CLABEL(1U, 0U, 1U)
61 #define MSG_CLABEL_6            MAKE_MSG_CLABEL(1U, 1U, 0U)
62 #define MSG_CLABEL_7            MAKE_MSG_CLABEL(1U, 1U, 1U)
63
64 #define MSG_CLABEL_ORANGE       MSG_CLABEL_1
65 #define MSG_CLABEL_RED          MSG_CLABEL_2
66 #define MSG_CLABEL_PINK         MSG_CLABEL_3
67 #define MSG_CLABEL_SKYBLUE      MSG_CLABEL_4
68 #define MSG_CLABEL_BLUE         MSG_CLABEL_5
69 #define MSG_CLABEL_GREEN        MSG_CLABEL_6
70 #define MSG_CLABEL_BROWN        MSG_CLABEL_7
71
72 #define MSG_IGNORE_THREAD       (1U << 10)   /* ignore threads */
73 #define MSG_LOCKED              (1U << 11)   /* msg is locked  */
74 #define MSG_RETRCPT_SENT        (1U << 12)   /* new one */ 
75 #define MSG_SPAM                (1U << 13)   /* new one */ 
76                                                 
77 /* RESERVED */
78 #define MSG_RESERVED_CLAWS      (1U << 30)   /* for sylpheed-claws */
79 #define MSG_RESERVED            (1U << 31)
80
81 typedef guint32 MsgPermFlags;
82
83 #define MSG_CLABEL_FLAG_MASK    (MSG_CLABEL_7)
84
85 #define MSG_MOVE                (1U << 0)
86 #define MSG_COPY                (1U << 1)
87 #define MSG_QUEUED              (1U << 16)
88 #define MSG_DRAFT               (1U << 17)
89 #define MSG_ENCRYPTED           (1U << 18)
90 #define MSG_IMAP                (1U << 19)
91 #define MSG_NEWS                (1U << 20)
92 #define MSG_SIGNED              (1U << 21)
93 #define MSG_MULTIPART           (1U << 29)
94 #define MSG_HAS_ATTACHMENT      (1U << 30)
95 #define MSG_SCANNED             (1U << 31)
96
97 typedef guint32 MsgTmpFlags;
98
99 #define MSG_CACHED_FLAG_MASK    (MSG_MULTIPART | MSG_ENCRYPTED | MSG_SIGNED | MSG_HAS_ATTACHMENT | MSG_SCANNED)
100
101 #define MSG_SET_FLAGS(msg, flags)       { (msg) |= (flags); }
102 #define MSG_UNSET_FLAGS(msg, flags)     { (msg) &= ~(flags); }
103 #define MSG_SET_PERM_FLAGS(msg, flags) \
104         MSG_SET_FLAGS((msg).perm_flags, flags)
105 #define MSG_SET_TMP_FLAGS(msg, flags) \
106         MSG_SET_FLAGS((msg).tmp_flags, flags)
107 #define MSG_UNSET_PERM_FLAGS(msg, flags) \
108         MSG_UNSET_FLAGS((msg).perm_flags, flags)
109 #define MSG_UNSET_TMP_FLAGS(msg, flags) \
110         MSG_UNSET_FLAGS((msg).tmp_flags, flags)
111
112 #define MSG_IS_NEW(msg)                 (((msg).perm_flags & MSG_NEW) != 0)
113 #define MSG_IS_UNREAD(msg)              (((msg).perm_flags & MSG_UNREAD) != 0)
114 #define MSG_IS_MARKED(msg)              (((msg).perm_flags & MSG_MARKED) != 0)
115 #define MSG_IS_DELETED(msg)             (((msg).perm_flags & MSG_DELETED) != 0)
116 #define MSG_IS_REPLIED(msg)             (((msg).perm_flags & MSG_REPLIED) != 0)
117 #define MSG_IS_LOCKED(msg)              (((msg).perm_flags & MSG_LOCKED) != 0)
118 #define MSG_IS_FORWARDED(msg)           (((msg).perm_flags & MSG_FORWARDED) != 0)
119 #define MSG_IS_POSTFILTERED(msg)        (((msg).perm_flags & MSG_POSTFILTERED) != 0)
120
121 #define MSG_GET_COLORLABEL(msg)         (((msg).perm_flags & MSG_CLABEL_FLAG_MASK))
122 #define MSG_GET_COLORLABEL_VALUE(msg)   (MSG_GET_COLORLABEL(msg) >> MSG_CLABEL_SBIT)
123 #define MSG_SET_COLORLABEL_VALUE(msg, val) \
124         MSG_SET_PERM_FLAGS(msg, ((((guint)(val)) & 7) << MSG_CLABEL_SBIT))
125
126 #define MSG_COLORLABEL_TO_FLAGS(val) ((((guint)(val)) & 7) << MSG_CLABEL_SBIT)
127 #define MSG_COLORLABEL_FROM_FLAGS(val) (val >> MSG_CLABEL_SBIT)
128
129 #define MSG_IS_MOVE(msg)                (((msg).tmp_flags & MSG_MOVE) != 0)
130 #define MSG_IS_COPY(msg)                (((msg).tmp_flags & MSG_COPY) != 0)
131
132 #define MSG_IS_QUEUED(msg)              (((msg).tmp_flags & MSG_QUEUED) != 0)
133 #define MSG_IS_DRAFT(msg)               (((msg).tmp_flags & MSG_DRAFT) != 0)
134 #define MSG_IS_ENCRYPTED(msg)           (((msg).tmp_flags & MSG_ENCRYPTED) != 0)
135 #define MSG_IS_SIGNED(msg)              (((msg).tmp_flags & MSG_SIGNED) != 0)
136 #define MSG_IS_IMAP(msg)                (((msg).tmp_flags & MSG_IMAP) != 0)
137 #define MSG_IS_NEWS(msg)                (((msg).tmp_flags & MSG_NEWS) != 0)
138 #define MSG_IS_MULTIPART(msg)           (((msg).tmp_flags & MSG_MULTIPART) != 0)
139 #define MSG_IS_WITH_ATTACHMENT(msg)     (((msg).tmp_flags & MSG_HAS_ATTACHMENT) != 0)
140 #define MSG_IS_SCANNED(msg)             (((msg).tmp_flags & MSG_SCANNED) != 0)
141
142 /* Claws related flags */
143 #define MSG_IS_REALLY_DELETED(msg)      (((msg).perm_flags & MSG_REALLY_DELETED) != 0)
144 #define MSG_IS_IGNORE_THREAD(msg)       (((msg).perm_flags & MSG_IGNORE_THREAD) != 0)
145 #define MSG_IS_RETRCPT_PENDING(msg)     (((msg).perm_flags & MSG_RETRCPT_PENDING) != 0)
146 #define MSG_IS_RETRCPT_SENT(msg)        (((msg).perm_flags & MSG_RETRCPT_SENT) != 0)
147 #define MSG_IS_SPAM(msg)                (((msg).perm_flags & MSG_SPAM) != 0)
148
149 #define MSGINFO_UPDATE_HOOKLIST "msginfo_update"
150 #define MAIL_FILTERING_HOOKLIST "mail_filtering_hooklist"
151 #define MAIL_POSTFILTERING_HOOKLIST "mail_postfiltering_hooklist"
152
153 typedef enum {
154         MSGINFO_UPDATE_FLAGS = 1 << 0,
155         MSGINFO_UPDATE_DELETED = 1 << 1
156 } MsgInfoUpdateFlags;
157
158 #include "procmime.h"
159 #include "prefs_filtering.h"
160 #include "folder.h"
161
162 struct _MsgFlags
163 {
164         MsgPermFlags perm_flags;
165         MsgTmpFlags  tmp_flags;
166 };
167
168
169 struct _MsgInfo
170 {
171         guint refcnt;
172
173         guint  msgnum;
174         off_t  size;
175         time_t mtime;
176         time_t date_t;
177
178         MsgFlags flags;
179
180         gchar *fromname;
181
182         gchar *date;
183         gchar *from;
184         gchar *to;
185         gchar *cc;
186         gchar *newsgroups;
187         gchar *subject;
188         gchar *msgid;
189         gchar *inreplyto;
190         gchar *xref;
191
192         FolderItem *folder;
193         FolderItem *to_folder;
194
195         FolderItem *to_filter_folder;   
196         gboolean is_move;
197         gboolean is_copy;
198
199         gchar *xface;
200         gchar *face;
201
202         gchar *dispositionnotificationto;
203         gchar *returnreceiptto;
204
205         GSList *references;
206         gchar *fromspace;
207
208         gint score;
209
210         /* used only for encrypted messages */
211         gchar *plaintext_file;
212         
213         gint hidden;
214         
215         /* used only for partially received messages */
216         gchar *partial_recv;
217         gint total_size;
218         gchar *account_server;
219         gchar *account_login;
220         gint planned_download;
221
222         /* Mailing list support */
223         gchar *list_post;
224         gchar *list_subscribe;
225         gchar *list_unsubscribe;
226         gchar *list_help;
227         gchar *list_archive;
228         gchar *list_owner;
229 };
230
231 struct _MsgFileInfo
232 {
233         MsgInfo *msginfo;
234         gchar *file;
235         MsgFlags *flags;
236 };
237
238 struct _MsgInfoUpdate {
239         MsgInfo *msginfo;
240         MsgInfoUpdateFlags flags;
241 };
242
243 struct _MailFilteringData
244 {
245         MsgInfo *msginfo;
246 };
247
248 GHashTable *procmsg_msg_hash_table_create       (GSList         *mlist);
249 void procmsg_msg_hash_table_append              (GHashTable     *msg_table,
250                                                  GSList         *mlist);
251 GHashTable *procmsg_to_folder_hash_table_create (GSList         *mlist);
252
253 GSList *procmsg_read_cache              (FolderItem     *item,
254                                          gboolean        scan_file);
255 gint    procmsg_get_last_num_in_msg_list(GSList         *mlist);
256 void    procmsg_msg_list_free           (GSList         *mlist);
257 void    procmsg_get_mark_sum            (const gchar    *folder,
258                                          gint           *new_msgs,
259                                          gint           *unread_msgs,
260                                          gint           *total_msgs,
261                                          gint           *min,
262                                          gint           *max,
263                                          gint            first);
264
265 GNode  *procmsg_get_thread_tree         (GSList         *mlist);
266
267 gint    procmsg_move_messages           (GSList         *mlist);
268 void    procmsg_copy_messages           (GSList         *mlist);
269
270 /* return path is locale charset */
271 gchar  *procmsg_get_message_file_path   (MsgInfo        *msginfo);
272 gchar  *procmsg_get_message_file        (MsgInfo        *msginfo);
273 gchar  *procmsg_get_message_file_full   (MsgInfo        *msginfo, 
274                                          gboolean        get_headers,
275                                          gboolean        get_body);
276 GSList *procmsg_get_message_file_list   (MsgInfoList    *mlist);
277 void    procmsg_message_file_list_free  (MsgInfoList    *file_list);
278 FILE   *procmsg_open_message            (MsgInfo        *msginfo);
279 gboolean procmsg_msg_exist              (MsgInfo        *msginfo);
280
281 void    procmsg_get_filter_keyword      (MsgInfo          *msginfo,
282                                          gchar           **header,
283                                          gchar           **key,
284                                          PrefsFilterType   type);
285
286 void    procmsg_empty_trash             (FolderItem     *trash);
287 void    procmsg_empty_all_trash         (void);
288
289 gint    procmsg_send_queue              (FolderItem     *queue,
290                                          gboolean        save_msgs);
291 gboolean procmsg_queue_is_empty (FolderItem *queue);
292 gint    procmsg_save_to_outbox          (FolderItem     *outbox,
293                                          const gchar    *file,
294                                          gboolean        is_queued);
295 void    procmsg_print_message           (MsgInfo        *msginfo,
296                                          const gchar    *cmdline);
297
298 MsgInfo *procmsg_msginfo_new            ();
299 MsgInfo *procmsg_msginfo_new_ref        (MsgInfo        *msginfo);
300 MsgInfo *procmsg_msginfo_copy           (MsgInfo        *msginfo);
301 MsgInfo *procmsg_msginfo_get_full_info  (MsgInfo        *msginfo);
302 void     procmsg_msginfo_free           (MsgInfo        *msginfo);
303 guint    procmsg_msginfo_memusage       (MsgInfo        *msginfo);
304
305 gint procmsg_cmp_msgnum_for_sort        (gconstpointer   a,
306                                          gconstpointer   b);
307 gint procmsg_send_message_queue         (const gchar *file);
308
309 void procmsg_msginfo_set_flags          (MsgInfo *msginfo,
310                                          MsgPermFlags perm_flags,
311                                          MsgTmpFlags tmp_flags);
312 void procmsg_msginfo_unset_flags        (MsgInfo *msginfo,
313                                          MsgPermFlags perm_flags,
314                                          MsgTmpFlags tmp_flags);
315 void procmsg_msginfo_change_flags       (MsgInfo *msginfo, 
316                                          MsgPermFlags add_perm_flags, 
317                                          MsgTmpFlags add_tmp_flags,
318                                          MsgPermFlags rem_perm_flags, 
319                                          MsgTmpFlags rem_tmp_flags);
320 gint procmsg_remove_special_headers     (const gchar    *in, 
321                                          const gchar    *out);
322
323 gboolean procmsg_msg_has_flagged_parent (MsgInfo        *info,
324                                          MsgPermFlags    perm_flags);
325 gboolean procmsg_msg_has_marked_parent  (MsgInfo        *info);
326 GSList *procmsg_find_children           (MsgInfo        *info);
327 void procmsg_update_unread_children     (MsgInfo        *info,
328                                          gboolean        newly_marked);
329 void procmsg_msginfo_set_to_folder      (MsgInfo        *msginfo,
330                                          FolderItem     *to_folder);
331 gboolean procmsg_msginfo_filter         (MsgInfo        *msginfo);
332 MsgInfo *procmsg_msginfo_new_from_mimeinfo
333                                         (MsgInfo        *src_msginfo, 
334                                          MimeInfo       *mimeinfo);
335
336 void procmsg_register_spam_learner (int (*learn_func)(MsgInfo *info, GSList *list, gboolean spam));
337 void procmsg_unregister_spam_learner (int (*learn_func)(MsgInfo *info, GSList *list, gboolean spam));
338 gboolean procmsg_spam_can_learn         (void);
339 void procmsg_spam_set_folder            (const char *item_identifier);
340 FolderItem *procmsg_spam_get_folder     (void);
341 int procmsg_spam_learner_learn  (MsgInfo *msginfo, GSList *msglist, gboolean spam);
342
343 #endif /* __PROCMSG_H__ */