add 'fast filter' for claws' filtering
[claws.git] / src / procmsg.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2002 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 __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
36 #include "folder.h"
37 #include "procmime.h"
38
39 typedef enum
40 {
41         MSG_NEW         = 1 << 0,
42         MSG_UNREAD      = 1 << 1,
43         MSG_MARKED      = 1 << 2,
44         MSG_DELETED     = 1 << 3,
45         MSG_REPLIED     = 1 << 4,
46         MSG_FORWARDED   = 1 << 5,
47         
48         MSG_REALLY_DELETED = 1 << 6,            /* mbox stuff */
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         MSG_CLABEL_NONE = MAKE_MSG_CLABEL(0, 0, 0),
56         MSG_CLABEL_1    = MAKE_MSG_CLABEL(0, 0, 1),
57         MSG_CLABEL_2    = MAKE_MSG_CLABEL(0, 1, 0),
58         MSG_CLABEL_3    = MAKE_MSG_CLABEL(0, 1, 1),
59         MSG_CLABEL_4    = MAKE_MSG_CLABEL(1, 0, 0),
60         MSG_CLABEL_5    = MAKE_MSG_CLABEL(1, 0, 1),
61         MSG_CLABEL_6    = MAKE_MSG_CLABEL(1, 1, 0),
62         MSG_CLABEL_7    = MAKE_MSG_CLABEL(1, 1, 1),
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         MSG_IGNORE_THREAD   = 1 << 10,   /* ignore threads */
73         MSG_LOCKED          = 1 << 11,   /* msg is locked  */
74         MSG_RETRCPT_PENDING = 1 << 12,   /* return receipt pending */
75
76         /* RESERVED */
77         MSG_RESERVED_CLAWS  = 1 << 30,  /* for sylpheed-claws */
78         MSG_RESERVED_MAIN   = 1 << 31   /* for sylpheed-main  */
79 } MsgPermFlags;
80
81 #define MSG_CLABEL_FLAG_MASK    (MSG_CLABEL_7)
82
83 typedef enum
84 {
85         MSG_MOVE        = 1 << 0,
86         MSG_COPY        = 1 << 1,
87
88         MSG_QUEUED      = 1 << 16,
89         MSG_DRAFT       = 1 << 17,
90         MSG_ENCRYPTED   = 1 << 18,
91         MSG_IMAP        = 1 << 19,
92         MSG_NEWS        = 1 << 20,
93
94         MSG_MIME        = 1 << 29,
95
96         MSG_CACHED      = 1 << 31
97 } MsgTmpFlags;
98
99 #define MSG_CACHED_FLAG_MASK    (MSG_MIME | MSG_ENCRYPTED)
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
120 #define MSG_GET_COLORLABEL(msg)         (((msg).perm_flags & MSG_CLABEL_FLAG_MASK))
121 #define MSG_GET_COLORLABEL_VALUE(msg)   (MSG_GET_COLORLABEL(msg) >> MSG_CLABEL_SBIT)
122 #define MSG_SET_COLORLABEL_VALUE(msg, val) \
123         MSG_SET_PERM_FLAGS(msg, ((((guint)(val)) & 7) << MSG_CLABEL_SBIT))
124
125 #define MSG_IS_MOVE(msg)                (((msg).tmp_flags & MSG_MOVE) != 0)
126 #define MSG_IS_COPY(msg)                (((msg).tmp_flags & MSG_COPY) != 0)
127
128 #define MSG_IS_QUEUED(msg)              (((msg).tmp_flags & MSG_QUEUED) != 0)
129 #define MSG_IS_DRAFT(msg)               (((msg).tmp_flags & MSG_DRAFT) != 0)
130 #define MSG_IS_ENCRYPTED(msg)           (((msg).tmp_flags & MSG_ENCRYPTED) != 0)
131 #define MSG_IS_IMAP(msg)                (((msg).tmp_flags & MSG_IMAP) != 0)
132 #define MSG_IS_NEWS(msg)                (((msg).tmp_flags & MSG_NEWS) != 0)
133 #define MSG_IS_MIME(msg)                (((msg).tmp_flags & MSG_MIME) != 0)
134 #define MSG_IS_CACHED(msg)              (((msg).tmp_flags & MSG_CACHED) != 0)
135
136 /* Claws related flags */
137 #define MSG_IS_REALLY_DELETED(msg)      (((msg).perm_flags & MSG_REALLY_DELETED) != 0)
138 #define MSG_IS_IGNORE_THREAD(msg)       (((msg).perm_flags & MSG_IGNORE_THREAD) != 0)
139 #define MSG_IS_RETRCPT_PENDING(msg)     (((msg).perm_flags & MSG_RETRCPT_PENDING) != 0)
140
141
142 #define WRITE_CACHE_DATA_INT(n, fp) \
143         fwrite(&n, sizeof(n), 1, fp)
144
145 #define WRITE_CACHE_DATA(data, fp) \
146 { \
147         gint len; \
148  \
149         if (data == NULL || (len = strlen(data)) == 0) { \
150                 len = 0; \
151                 WRITE_CACHE_DATA_INT(len, fp); \
152         } else { \
153                 len = strlen(data); \
154                 WRITE_CACHE_DATA_INT(len, fp); \
155                 fwrite(data, len, 1, fp); \
156         } \
157 }
158
159 struct _MsgFlags
160 {
161         MsgPermFlags perm_flags;
162         MsgTmpFlags  tmp_flags;
163 };
164
165 struct _MsgInfo
166 {
167         guint  msgnum;
168         off_t  size;
169         time_t mtime;
170         time_t date_t;
171
172         MsgFlags flags;
173
174         gchar *fromname;
175
176         gchar *date;
177         gchar *from;
178         gchar *to;
179         gchar *cc;
180         gchar *newsgroups;
181         gchar *subject;
182         gchar *msgid;
183         gchar *inreplyto;
184         gchar *xref;
185
186         FolderItem *folder;
187         FolderItem *to_folder;
188
189         gchar *xface;
190
191         gchar *dispositionnotificationto;
192         gchar *returnreceiptto;
193
194         gchar *references;
195         gchar *fromspace;
196
197         gint score;
198         gint threadscore;
199
200         /* used only for encrypted messages */
201         gchar *plaintext_file;
202         guint decryption_failed : 1;
203 };
204
205 GHashTable *procmsg_msg_hash_table_create       (GSList         *mlist);
206 void procmsg_msg_hash_table_append              (GHashTable     *msg_table,
207                                                  GSList         *mlist);
208 GHashTable *procmsg_to_folder_hash_table_create (GSList         *mlist);
209
210 GSList *procmsg_read_cache              (FolderItem     *item,
211                                          gboolean        scan_file);
212 void    procmsg_set_flags               (GSList         *mlist,
213                                          FolderItem     *item);
214 gint    procmsg_get_last_num_in_cache   (GSList         *mlist);
215 void    procmsg_msg_list_free           (GSList         *mlist);
216 void    procmsg_write_cache             (MsgInfo        *msginfo,
217                                          FILE           *fp);
218 void    procmsg_write_flags             (MsgInfo        *msginfo,
219                                          FILE           *fp);
220 void    procmsg_get_mark_sum            (const gchar    *folder,
221                                          gint           *new,
222                                          gint           *unread,
223                                          gint           *total,
224                                          gint           *min,
225                                          gint           *max,
226                                          gint            first);
227 FILE   *procmsg_open_mark_file          (const gchar    *folder,
228                                          gboolean        append);
229
230 GNode  *procmsg_get_thread_tree         (GSList         *mlist);
231
232 void    procmsg_move_messages           (GSList         *mlist);
233 void    procmsg_copy_messages           (GSList         *mlist);
234
235 gchar  *procmsg_get_message_file_path   (MsgInfo        *msginfo);
236 gchar  *procmsg_get_message_file        (MsgInfo        *msginfo);
237 FILE   *procmsg_open_message            (MsgInfo        *msginfo);
238 #if USE_GPGME
239 FILE   *procmsg_open_message_decrypted  (MsgInfo        *msginfo,
240                                          MimeInfo      **mimeinfo);
241 #endif
242 gboolean procmsg_msg_exist              (MsgInfo        *msginfo);
243
244 void    procmsg_empty_trash             (void);
245 gint    procmsg_send_queue              (gboolean        save_msgs);
246 gint    procmsg_save_to_outbox          (FolderItem     *outbox,
247                                          const gchar    *file,
248                                          gboolean        is_queued);
249 void    procmsg_print_message           (MsgInfo        *msginfo,
250                                          const gchar    *cmdline);
251
252 MsgInfo *procmsg_msginfo_copy           (MsgInfo        *msginfo);
253 void     procmsg_msginfo_free           (MsgInfo        *msginfo);
254
255 gint procmsg_cmp_msgnum_for_sort        (gconstpointer   a,
256                                          gconstpointer   b);
257 gint procmsg_send_message_queue         (const gchar *file);
258
259 #endif /* __PROCMSG_H__ */