prefs_filtering.c - wrong widget were shown after creation
[claws.git] / src / procmsg.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2003 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 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_REALLY_DELETED      (1U << 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 #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                                                 
76 /* RESERVED */
77 #define MSG_RESERVED_CLAWS      (1U << 30)   /* for sylpheed-claws */
78 #define MSG_RESERVED            (1U << 31)
79
80 typedef guint32 MsgPermFlags;
81
82 #define MSG_CLABEL_FLAG_MASK    (MSG_CLABEL_7)
83
84 #define MSG_MOVE                (1U << 0)
85 #define MSG_COPY                (1U << 1)
86 #define MSG_QUEUED              (1U << 16)
87 #define MSG_DRAFT               (1U << 17)
88 #define MSG_ENCRYPTED           (1U << 18)
89 #define MSG_IMAP                (1U << 19)
90 #define MSG_NEWS                (1U << 20)
91 #define MSG_SIGNED              (1U << 21)
92 #define MSG_MIME                (1U << 29)
93 #define MSG_CACHED              (1U << 31)
94
95 typedef guint32 MsgTmpFlags;
96
97 #define MSG_CACHED_FLAG_MASK    (MSG_MIME | MSG_ENCRYPTED | MSG_SIGNED)
98
99 #define MSG_SET_FLAGS(msg, flags)       { (msg) |= (flags); }
100 #define MSG_UNSET_FLAGS(msg, flags)     { (msg) &= ~(flags); }
101 #define MSG_SET_PERM_FLAGS(msg, flags) \
102         MSG_SET_FLAGS((msg).perm_flags, flags)
103 #define MSG_SET_TMP_FLAGS(msg, flags) \
104         MSG_SET_FLAGS((msg).tmp_flags, flags)
105 #define MSG_UNSET_PERM_FLAGS(msg, flags) \
106         MSG_UNSET_FLAGS((msg).perm_flags, flags)
107 #define MSG_UNSET_TMP_FLAGS(msg, flags) \
108         MSG_UNSET_FLAGS((msg).tmp_flags, flags)
109
110 #define MSG_IS_NEW(msg)                 (((msg).perm_flags & MSG_NEW) != 0)
111 #define MSG_IS_UNREAD(msg)              (((msg).perm_flags & MSG_UNREAD) != 0)
112 #define MSG_IS_MARKED(msg)              (((msg).perm_flags & MSG_MARKED) != 0)
113 #define MSG_IS_DELETED(msg)             (((msg).perm_flags & MSG_DELETED) != 0)
114 #define MSG_IS_REPLIED(msg)             (((msg).perm_flags & MSG_REPLIED) != 0)
115 #define MSG_IS_LOCKED(msg)              (((msg).perm_flags & MSG_LOCKED) != 0)
116 #define MSG_IS_FORWARDED(msg)           (((msg).perm_flags & MSG_FORWARDED) != 0)
117
118 #define MSG_GET_COLORLABEL(msg)         (((msg).perm_flags & MSG_CLABEL_FLAG_MASK))
119 #define MSG_GET_COLORLABEL_VALUE(msg)   (MSG_GET_COLORLABEL(msg) >> MSG_CLABEL_SBIT)
120 #define MSG_SET_COLORLABEL_VALUE(msg, val) \
121         MSG_SET_PERM_FLAGS(msg, ((((guint)(val)) & 7) << MSG_CLABEL_SBIT))
122
123 #define MSG_COLORLABEL_TO_FLAGS(val) ((((guint)(val)) & 7) << MSG_CLABEL_SBIT)
124 #define MSG_COLORLABEL_FROM_FLAGS(val) (val >> MSG_CLABEL_SBIT)
125
126 #define MSG_IS_MOVE(msg)                (((msg).tmp_flags & MSG_MOVE) != 0)
127 #define MSG_IS_COPY(msg)                (((msg).tmp_flags & MSG_COPY) != 0)
128
129 #define MSG_IS_QUEUED(msg)              (((msg).tmp_flags & MSG_QUEUED) != 0)
130 #define MSG_IS_DRAFT(msg)               (((msg).tmp_flags & MSG_DRAFT) != 0)
131 #define MSG_IS_ENCRYPTED(msg)           (((msg).tmp_flags & MSG_ENCRYPTED) != 0)
132 #define MSG_IS_SIGNED(msg)              (((msg).tmp_flags & MSG_SIGNED) != 0)
133 #define MSG_IS_IMAP(msg)                (((msg).tmp_flags & MSG_IMAP) != 0)
134 #define MSG_IS_NEWS(msg)                (((msg).tmp_flags & MSG_NEWS) != 0)
135 #define MSG_IS_MIME(msg)                (((msg).tmp_flags & MSG_MIME) != 0)
136 #define MSG_IS_CACHED(msg)              (((msg).tmp_flags & MSG_CACHED) != 0)
137
138 /* Claws related flags */
139 #define MSG_IS_REALLY_DELETED(msg)      (((msg).perm_flags & MSG_REALLY_DELETED) != 0)
140 #define MSG_IS_IGNORE_THREAD(msg)       (((msg).perm_flags & MSG_IGNORE_THREAD) != 0)
141 #define MSG_IS_RETRCPT_PENDING(msg)     (((msg).perm_flags & MSG_RETRCPT_PENDING) != 0)
142 #define MSG_IS_RETRCPT_SENT(msg)        (((msg).perm_flags & MSG_RETRCPT_SENT) != 0)
143
144 #define MSGINFO_UPDATE_HOOKLIST "msginfo_update"
145 #define MAIL_FILTERING_HOOKLIST "mail_filtering_hooklist"
146
147 #include "folder.h"
148 #include "procmime.h"
149 #include "prefs_filtering.h"
150
151 struct _MsgFlags
152 {
153         MsgPermFlags perm_flags;
154         MsgTmpFlags  tmp_flags;
155 };
156
157
158 struct _MsgInfo
159 {
160         guint refcnt;
161
162         guint  msgnum;
163         off_t  size;
164         time_t mtime;
165         time_t date_t;
166
167         MsgFlags flags;
168
169         gchar *fromname;
170
171         gchar *date;
172         gchar *from;
173         gchar *to;
174         gchar *cc;
175         gchar *newsgroups;
176         gchar *subject;
177         gchar *msgid;
178         gchar *inreplyto;
179         gchar *xref;
180
181         FolderItem *folder;
182         FolderItem *to_folder;
183
184         gchar *xface;
185
186         gchar *dispositionnotificationto;
187         gchar *returnreceiptto;
188
189         gchar *references;
190         gchar *fromspace;
191
192         gint score;
193         gint threadscore;
194
195         /* used only for encrypted messages */
196         gchar *plaintext_file;
197         guint decryption_failed : 1;
198 };
199
200 struct _MsgFileInfo
201 {
202         MsgInfo *msginfo;
203         gchar *file;
204         MsgFlags *flags;
205 };
206
207 struct _MsgInfoUpdate {
208         MsgInfo *msginfo;
209 };
210
211 struct _MailFilteringData
212 {
213         MsgInfo *msginfo;
214 };
215
216 GHashTable *procmsg_msg_hash_table_create       (GSList         *mlist);
217 void procmsg_msg_hash_table_append              (GHashTable     *msg_table,
218                                                  GSList         *mlist);
219 GHashTable *procmsg_to_folder_hash_table_create (GSList         *mlist);
220
221 GSList *procmsg_read_cache              (FolderItem     *item,
222                                          gboolean        scan_file);
223 gint    procmsg_get_last_num_in_msg_list(GSList         *mlist);
224 void    procmsg_msg_list_free           (GSList         *mlist);
225 void    procmsg_get_mark_sum            (const gchar    *folder,
226                                          gint           *new_msgs,
227                                          gint           *unread_msgs,
228                                          gint           *total_msgs,
229                                          gint           *min,
230                                          gint           *max,
231                                          gint            first);
232
233 GNode  *procmsg_get_thread_tree         (GSList         *mlist);
234
235 void    procmsg_move_messages           (GSList         *mlist);
236 void    procmsg_copy_messages           (GSList         *mlist);
237
238 gchar  *procmsg_get_message_file_path   (MsgInfo        *msginfo);
239 gchar  *procmsg_get_message_file        (MsgInfo        *msginfo);
240 GSList *procmsg_get_message_file_list   (MsgInfoList    *mlist);
241 void    procmsg_message_file_list_free  (MsgInfoList    *file_list);
242 FILE   *procmsg_open_message            (MsgInfo        *msginfo);
243 #if USE_GPGME
244 FILE   *procmsg_open_message_decrypted  (MsgInfo        *msginfo,
245                                          MimeInfo      **mimeinfo);
246 #endif
247 gboolean procmsg_msg_exist              (MsgInfo        *msginfo);
248
249 void    procmsg_get_filter_keyword      (MsgInfo          *msginfo,
250                                          gchar           **header,
251                                          gchar           **key,
252                                          PrefsFilterType   type);
253
254 void    procmsg_empty_trash             (void);
255 gint    procmsg_send_queue              (FolderItem     *queue,
256                                          gboolean        save_msgs);
257 gint    procmsg_save_to_outbox          (FolderItem     *outbox,
258                                          const gchar    *file,
259                                          gboolean        is_queued);
260 void    procmsg_print_message           (MsgInfo        *msginfo,
261                                          const gchar    *cmdline);
262
263 MsgInfo *procmsg_msginfo_new            ();
264 MsgInfo *procmsg_msginfo_new_ref        (MsgInfo        *msginfo);
265 MsgInfo *procmsg_msginfo_copy           (MsgInfo        *msginfo);
266 MsgInfo *procmsg_msginfo_get_full_info  (MsgInfo        *msginfo);
267 void     procmsg_msginfo_free           (MsgInfo        *msginfo);
268 guint    procmsg_msginfo_memusage       (MsgInfo        *msginfo);
269
270 gint procmsg_cmp_msgnum_for_sort        (gconstpointer   a,
271                                          gconstpointer   b);
272 gint procmsg_send_message_queue         (const gchar *file);
273
274 void procmsg_msginfo_set_flags          (MsgInfo *msginfo,
275                                          MsgPermFlags perm_flags,
276                                           MsgTmpFlags tmp_flags);
277 void procmsg_msginfo_unset_flags        (MsgInfo *msginfo,
278                                          MsgPermFlags perm_flags,
279                                           MsgTmpFlags tmp_flags);
280 gint procmsg_remove_special_headers     (const gchar    *in, 
281                                          const gchar    *out);
282
283 gboolean procmsg_msg_has_flagged_parent (MsgInfo        *info,
284                                          MsgPermFlags    perm_flags);
285 gboolean procmsg_msg_has_marked_parent  (MsgInfo        *info);
286 GSList *procmsg_find_children           (MsgInfo        *info);
287 void procmsg_update_unread_children     (MsgInfo        *info,
288                                          gboolean        newly_marked);
289 void procmsg_msginfo_set_to_folder      (MsgInfo        *msginfo,
290                                          FolderItem     *to_folder);
291 gboolean procmsg_msginfo_filter         (MsgInfo        *msginfo);
292
293 #endif /* __PROCMSG_H__ */