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