Fix bug #3574: Template addressing
[claws.git] / src / procmsg.h
blob9b143f1bfe687d28ebd081ef95022ff92ca52ddb
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
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 3 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef __PROCMSG_H__
21 #define __PROCMSG_H__
23 #ifdef HAVE_CONFIG_H
24 #include "claws-features.h"
25 #endif
27 #include <glib.h>
28 #include <stdio.h>
29 #include <time.h>
30 #include <sys/types.h>
31 #include <string.h>
32 #include "utils.h"
33 #include "proctypes.h"
35 #define MSG_NEW (1U << 0)
36 #define MSG_UNREAD (1U << 1)
37 #define MSG_MARKED (1U << 2)
38 #define MSG_DELETED (1U << 3)
39 #define MSG_REPLIED (1U << 4)
40 #define MSG_FORWARDED (1U << 5)
42 #define MSG_CLABEL_SBIT (6) /* start bit of color label */
43 /* color labels use 4 bits: 6, 7, 8, 9; bit weight is 7<8<9<6,
44 IOW the color label value itself must be computed from MsgPermFlags
45 bits like this:
46 value = bit-7-value*2^0
47 + bit-8-value*2^1
48 + bit-9-value*2^2
49 + bit-6-value*2^3 */
51 /* color label permflags masks */
52 #define MAKE_MSG_CLABEL(x, h, m, l) (\
53 ((x) << (MSG_CLABEL_SBIT + 0)) | \
54 ((h) << (MSG_CLABEL_SBIT + 3)) | \
55 ((m) << (MSG_CLABEL_SBIT + 2)) | \
56 ((l) << (MSG_CLABEL_SBIT + 1)))
57 #define MSG_CLABEL_NONE MAKE_MSG_CLABEL(0U, 0U, 0U, 0U)
58 #define MSG_CLABEL_1 MAKE_MSG_CLABEL(0U, 0U, 0U, 1U)
59 #define MSG_CLABEL_2 MAKE_MSG_CLABEL(0U, 0U, 1U, 0U)
60 #define MSG_CLABEL_3 MAKE_MSG_CLABEL(0U, 0U, 1U, 1U)
61 #define MSG_CLABEL_4 MAKE_MSG_CLABEL(0U, 1U, 0U, 0U)
62 #define MSG_CLABEL_5 MAKE_MSG_CLABEL(0U, 1U, 0U, 1U)
63 #define MSG_CLABEL_6 MAKE_MSG_CLABEL(0U, 1U, 1U, 0U)
64 #define MSG_CLABEL_7 MAKE_MSG_CLABEL(0U, 1U, 1U, 1U)
65 #define MSG_CLABEL_8 MAKE_MSG_CLABEL(1U, 0U, 0U, 0U)
66 #define MSG_CLABEL_9 MAKE_MSG_CLABEL(1U, 0U, 0U, 1U)
67 #define MSG_CLABEL_10 MAKE_MSG_CLABEL(1U, 0U, 1U, 0U)
68 #define MSG_CLABEL_11 MAKE_MSG_CLABEL(1U, 0U, 1U, 1U)
69 #define MSG_CLABEL_12 MAKE_MSG_CLABEL(1U, 1U, 0U, 0U)
70 #define MSG_CLABEL_13 MAKE_MSG_CLABEL(1U, 1U, 0U, 1U)
71 #define MSG_CLABEL_14 MAKE_MSG_CLABEL(1U, 1U, 1U, 0U)
72 #define MSG_CLABEL_15 MAKE_MSG_CLABEL(1U, 1U, 1U, 1U)
73 #define MSG_CLABEL_FLAG_MASK (MSG_CLABEL_15)
75 #define MSG_IGNORE_THREAD (1U << 10) /* ignore threads */
76 #define MSG_LOCKED (1U << 11) /* msg is locked */
77 #define MSG_RETRCPT_SENT (1U << 12) /* new one */
78 #define MSG_SPAM (1U << 13) /* new one */
79 #define MSG_POSTFILTERED (1U << 14)
80 #define MSG_WATCH_THREAD (1U << 15) /* watch threads */
81 #define MSG_FULLY_CACHED (1U << 16) /* IMAP: fully cached */
82 #define MSG_RETRCPT_GOT (1U << 17) /* got return receipt */
84 /* RESERVED */
85 #define MSG_RESERVED_CLAWS (1U << 30) /* for claws-mail */
86 #define MSG_RESERVED (1U << 31)
88 #define MSG_MOVE (1U << 0)
89 #define MSG_COPY (1U << 1)
90 #define MSG_MOVE_DONE (1U << 15)
91 #define MSG_QUEUED (1U << 16)
92 #define MSG_DRAFT (1U << 17)
93 #define MSG_ENCRYPTED (1U << 18)
94 #define MSG_IMAP (1U << 19)
95 #define MSG_NEWS (1U << 20)
96 #define MSG_SIGNED (1U << 21)
97 #define MSG_MULTIPART (1U << 29)
98 #define MSG_HAS_ATTACHMENT (1U << 30)
99 #define MSG_SCANNED (1U << 31)
101 #define MSG_CACHED_FLAG_MASK (MSG_MULTIPART | MSG_ENCRYPTED | MSG_SIGNED | MSG_HAS_ATTACHMENT | MSG_SCANNED)
103 #define MSG_SET_FLAGS(msg, flags) { (msg) |= (flags); }
104 #define MSG_UNSET_FLAGS(msg, flags) { (msg) &= ~(flags); }
105 #define MSG_SET_PERM_FLAGS(msg, flags) \
106 MSG_SET_FLAGS((msg).perm_flags, flags)
107 #define MSG_SET_TMP_FLAGS(msg, flags) \
108 MSG_SET_FLAGS((msg).tmp_flags, flags)
109 #define MSG_UNSET_PERM_FLAGS(msg, flags) \
110 MSG_UNSET_FLAGS((msg).perm_flags, flags)
111 #define MSG_UNSET_TMP_FLAGS(msg, flags) \
112 MSG_UNSET_FLAGS((msg).tmp_flags, flags)
114 #define MSG_IS_NEW(msg) (((msg).perm_flags & MSG_NEW) != 0)
115 #define MSG_IS_UNREAD(msg) (((msg).perm_flags & MSG_UNREAD) != 0)
116 #define MSG_IS_MARKED(msg) (((msg).perm_flags & MSG_MARKED) != 0)
117 #define MSG_IS_DELETED(msg) (((msg).perm_flags & MSG_DELETED) != 0)
118 #define MSG_IS_REPLIED(msg) (((msg).perm_flags & MSG_REPLIED) != 0)
119 #define MSG_IS_LOCKED(msg) (((msg).perm_flags & MSG_LOCKED) != 0)
120 #define MSG_IS_FORWARDED(msg) (((msg).perm_flags & MSG_FORWARDED) != 0)
121 #define MSG_IS_POSTFILTERED(msg) (((msg).perm_flags & MSG_POSTFILTERED) != 0)
123 /* color label decoding/encoding (permflag storage bits <-> color list index value)*/
124 #define MSG_COLORLABEL_TO_FLAGS(val) (((((guint)(val)) & 7) << (MSG_CLABEL_SBIT+1)) \
125 | (((guint)(val) & 8) << (MSG_CLABEL_SBIT-3)))
126 #define MSG_COLORLABEL_FROM_FLAGS(val) ((((guint)(val) >> (MSG_CLABEL_SBIT+1)) & 7 ) \
127 | (((guint)(val) >> (MSG_CLABEL_SBIT-3)) & 8))
128 #define MSG_GET_COLORLABEL(msg) (((msg).perm_flags & MSG_CLABEL_FLAG_MASK))
129 #define MSG_GET_COLORLABEL_VALUE(msg) (MSG_COLORLABEL_FROM_FLAGS(MSG_GET_COLORLABEL(msg)))
130 #define MSG_SET_COLORLABEL_VALUE(msg, val) MSG_SET_PERM_FLAGS(msg, MSG_COLORLABEL_TO_FLAGS(val))
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)
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)
146 /* Claws related flags */
147 #define MSG_IS_IGNORE_THREAD(msg) (((msg).perm_flags & MSG_IGNORE_THREAD) != 0)
148 #define MSG_IS_RETRCPT_PENDING(msg) (((msg).perm_flags & MSG_RETRCPT_PENDING) != 0)
149 #define MSG_IS_RETRCPT_SENT(msg) (((msg).perm_flags & MSG_RETRCPT_SENT) != 0)
150 #define MSG_IS_RETRCPT_GOT(msg) (((msg).perm_flags & MSG_RETRCPT_GOT) != 0)
151 #define MSG_IS_SPAM(msg) (((msg).perm_flags & MSG_SPAM) != 0)
152 #define MSG_IS_WATCH_THREAD(msg) (((msg).perm_flags & MSG_WATCH_THREAD) != 0)
153 #define MSG_IS_FULLY_CACHED(msg) (((msg).perm_flags & MSG_FULLY_CACHED) != 0)
155 #define MSGINFO_UPDATE_HOOKLIST "msginfo_update"
156 #define MAIL_FILTERING_HOOKLIST "mail_filtering_hooklist"
157 #define MAIL_LISTFILTERING_HOOKLIST "mail_listfiltering_hooklist"
158 #define MAIL_POSTFILTERING_HOOKLIST "mail_postfiltering_hooklist"
160 typedef enum {
161 MSGINFO_UPDATE_FLAGS = 1 << 0,
162 MSGINFO_UPDATE_DELETED = 1 << 1
163 } MsgInfoUpdateFlags;
165 #include "prefs_account.h"
166 #include "prefs_filtering.h"
167 #include "folder.h"
169 struct _MsgFlags
171 MsgPermFlags perm_flags;
172 MsgTmpFlags tmp_flags;
175 typedef enum {
176 IS_NOTHING = 0,
177 IS_MOVE,
178 IS_COPY,
179 IS_DELE
180 } FiltOp;
182 /* *********************************************************** *
183 * WARNING: When adding or removing members to this structure, *
184 * be sure to update procmsg.c::procmsg_msginfo_memusage() to *
185 * avoid underestimating cache memory usage - especially since *
186 * this would cause an overflow and metadata loss when writing *
187 * the cache to disk. *
188 * *********************************************************** */
189 struct _MsgInfo
191 guint refcnt;
193 guint msgnum;
194 goffset size;
195 time_t mtime;
196 time_t date_t;
197 time_t thread_date;
199 MsgFlags flags;
201 gchar *fromname;
203 gchar *date;
204 gchar *from;
205 gchar *to;
206 gchar *cc;
207 gchar *newsgroups;
208 gchar *subject;
209 gchar *msgid;
210 gchar *inreplyto;
211 gchar *xref;
213 FolderItem *folder;
214 FolderItem *to_folder;
216 FolderItem *to_filter_folder;
217 FiltOp filter_op;
219 GSList *references;
220 gchar *fromspace;
222 gint score;
224 /* used only for encrypted messages */
225 gchar *plaintext_file;
227 gint hidden;
229 /* used only for partially received messages */
230 gint total_size;
231 gint planned_download;
233 /* list of tags ids */
234 GSList *tags;
236 MsgInfoExtraData *extradata;
239 struct _MsgInfoExtraData
241 GSList *avatars;
243 gchar *dispositionnotificationto;
244 gchar *returnreceiptto;
246 gchar *resent_from;
248 /* used only for partially received messages */
249 gchar *partial_recv;
250 gchar *account_server;
251 gchar *account_login;
253 /* Mailing list support */
254 gchar *list_post;
255 gchar *list_subscribe;
256 gchar *list_unsubscribe;
257 gchar *list_help;
258 gchar *list_archive;
259 gchar *list_owner;
262 struct _MsgInfoAvatar
264 gint avatar_id;
265 gchar *avatar_src;
268 struct _MsgFileInfo
270 MsgInfo *msginfo;
271 gchar *file;
272 MsgFlags *flags;
275 struct _MsgInfoUpdate {
276 MsgInfo *msginfo;
277 MsgInfoUpdateFlags flags;
280 struct _MailFilteringData
282 MsgInfo *msginfo;
283 GSList *msglist;
284 GSList *filtered;
285 GSList *unfiltered;
286 PrefsAccount *account;
289 struct _AvatarCaptureData
291 MsgInfo *msginfo;
292 const gchar *header;
293 const gchar *content;
296 GSList *procmsg_read_cache (FolderItem *item,
297 gboolean scan_file);
298 void procmsg_msg_list_free (MsgInfoList *mlist);
299 MsgNumberList *procmsg_get_number_list_for_msgs(MsgInfoList *msglist);
300 void procmsg_get_mark_sum (const gchar *folder,
301 gint *new_msgs,
302 gint *unread_msgs,
303 gint *total_msgs,
304 gint *min,
305 gint *max,
306 gint first);
308 GNode *procmsg_get_thread_tree (GSList *mlist);
310 gint procmsg_move_messages (GSList *mlist);
311 void procmsg_copy_messages (GSList *mlist);
313 /* return path is locale charset */
314 gchar *procmsg_get_message_file_path (MsgInfo *msginfo);
315 gchar *procmsg_get_message_file (MsgInfo *msginfo);
316 gchar *procmsg_get_message_file_full (MsgInfo *msginfo,
317 gboolean get_headers,
318 gboolean get_body);
319 GSList *procmsg_get_message_file_list (MsgInfoList *mlist);
320 void procmsg_message_file_list_free (MsgInfoList *file_list);
321 FILE *procmsg_open_message (MsgInfo *msginfo);
322 gboolean procmsg_msg_exist (MsgInfo *msginfo);
324 void procmsg_get_filter_keyword (MsgInfo *msginfo,
325 gchar **header,
326 gchar **key,
327 PrefsFilterType type);
329 void procmsg_empty_all_trash (void);
331 gint procmsg_send_queue (FolderItem *queue,
332 gboolean save_msgs,
333 gchar **errstr);
334 gboolean procmsg_queue_lock (gchar **errstr);
335 void procmsg_queue_unlock (void);
336 gboolean procmsg_queue_is_empty (FolderItem *queue);
338 MsgInfo *procmsg_msginfo_new ();
339 MsgInfo *procmsg_msginfo_new_ref (MsgInfo *msginfo);
340 MsgInfo *procmsg_msginfo_copy (MsgInfo *msginfo);
341 MsgInfo *procmsg_msginfo_get_full_info (MsgInfo *msginfo);
342 MsgInfo *procmsg_msginfo_get_full_info_from_file
343 (MsgInfo *msginfo,
344 const gchar *file);
345 void procmsg_msginfo_free (MsgInfo **msginfo);
346 guint procmsg_msginfo_memusage (MsgInfo *msginfo);
348 gint procmsg_send_message_queue_with_lock(const gchar *file,
349 gchar **errstr,
350 FolderItem *queue,
351 gint msgnum,
352 gboolean *queued_removed);
354 gint procmsg_send_message_queue (const gchar *file,
355 gchar **errstr,
356 FolderItem *queue,
357 gint msgnum,
358 gboolean *queued_removed);
360 void procmsg_msginfo_set_flags (MsgInfo *msginfo,
361 MsgPermFlags perm_flags,
362 MsgTmpFlags tmp_flags);
363 void procmsg_msginfo_unset_flags (MsgInfo *msginfo,
364 MsgPermFlags perm_flags,
365 MsgTmpFlags tmp_flags);
366 void procmsg_msginfo_change_flags (MsgInfo *msginfo,
367 MsgPermFlags add_perm_flags,
368 MsgTmpFlags add_tmp_flags,
369 MsgPermFlags rem_perm_flags,
370 MsgTmpFlags rem_tmp_flags);
371 gint procmsg_remove_special_headers (const gchar *in,
372 const gchar *out);
374 gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
375 gboolean is_queued);
376 gboolean procmsg_msg_has_flagged_parent (MsgInfo *info,
377 MsgPermFlags perm_flags);
378 gboolean procmsg_msg_has_marked_parent (MsgInfo *info);
379 void procmsg_msginfo_set_to_folder (MsgInfo *msginfo,
380 FolderItem *to_folder);
381 void procmsg_msglist_filter (GSList *list,
382 PrefsAccount *ac,
383 GSList **filtered,
384 GSList **unfiltered,
385 gboolean do_filter);
387 MsgInfo *procmsg_msginfo_new_from_mimeinfo
388 (MsgInfo *src_msginfo,
389 MimeInfo *mimeinfo);
391 void procmsg_register_spam_learner (int (*learn_func)(MsgInfo *info, GSList *list, gboolean spam));
392 void procmsg_unregister_spam_learner (int (*learn_func)(MsgInfo *info, GSList *list, gboolean spam));
393 gboolean procmsg_spam_can_learn (void);
394 void procmsg_spam_set_folder (const char *item_identifier, FolderItem *(*spam_get_folder_func)(MsgInfo *info));
395 FolderItem *procmsg_spam_get_folder (MsgInfo *msginfo);
396 int procmsg_spam_learner_learn (MsgInfo *msginfo, GSList *msglist, gboolean spam);
397 gboolean procmsg_have_queued_mails_fast (void);
398 gboolean procmsg_have_trashed_mails_fast (void);
399 gboolean procmsg_is_sending(void);
400 gchar *procmsg_msginfo_get_tags_str(MsgInfo *msginfo);
401 void procmsg_msginfo_update_tags(MsgInfo *msginfo, gboolean set, gint id);
402 void procmsg_msginfo_clear_tags(MsgInfo *msginfo);
403 void procmsg_msginfo_commit_tags(GSList *msglist);
404 MsgInfo *procmsg_get_msginfo_from_identifier(const gchar *id);
405 gchar *procmsg_msginfo_get_identifier(MsgInfo *msginfo);
407 gchar *procmsg_msginfo_get_avatar(MsgInfo *msginfo, gint type);
408 void procmsg_msginfo_add_avatar(MsgInfo *msginfo, gint type, const gchar *data);
409 #endif /* __PROCMSG_H__ */