fef815ffd82ef605adcf3add8240a41789bf9297
[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 _MsgInfoUpdate           MsgInfoUpdate;
36 typedef struct _MailFilteringData       MailFilteringData;
37
38 typedef GSList MsgInfoList;
39 typedef GSList MsgNumberList;
40
41 #define MSG_NEW                 (1U << 0)
42 #define MSG_UNREAD              (1U << 1)
43 #define MSG_MARKED              (1U << 2)
44 #define MSG_DELETED             (1U << 3)
45 #define MSG_REPLIED             (1U << 4)
46 #define MSG_FORWARDED           (1U << 5)
47 #define MSG_REALLY_DELETED      (1U << 6)               /* mbox stuff */
48
49 #define MSG_CLABEL_SBIT (7)             /* start bit of color label */
50 #define MAKE_MSG_CLABEL(h, m, l)        (((h) << (MSG_CLABEL_SBIT + 2)) | \
51                                          ((m) << (MSG_CLABEL_SBIT + 1)) | \
52                                          ((l) << (MSG_CLABEL_SBIT + 0)))
53
54 #define MSG_CLABEL_NONE         MAKE_MSG_CLABEL(0U, 0U, 0U)
55 #define MSG_CLABEL_1            MAKE_MSG_CLABEL(0U, 0U, 1U)
56 #define MSG_CLABEL_2            MAKE_MSG_CLABEL(0U, 1U, 0U)
57 #define MSG_CLABEL_3            MAKE_MSG_CLABEL(0U, 1U, 1U)
58 #define MSG_CLABEL_4            MAKE_MSG_CLABEL(1U, 0U, 0U)
59 #define MSG_CLABEL_5            MAKE_MSG_CLABEL(1U, 0U, 1U)
60 #define MSG_CLABEL_6            MAKE_MSG_CLABEL(1U, 1U, 0U)
61 #define MSG_CLABEL_7            MAKE_MSG_CLABEL(1U, 1U, 1U)
62
63 #define MSG_CLABEL_ORANGE       MSG_CLABEL_1
64 #define MSG_CLABEL_RED          MSG_CLABEL_2
65 #define MSG_CLABEL_PINK         MSG_CLABEL_3
66 #define MSG_CLABEL_SKYBLUE      MSG_CLABEL_4
67 #define MSG_CLABEL_BLUE         MSG_CLABEL_5
68 #define MSG_CLABEL_GREEN        MSG_CLABEL_6
69 #define MSG_CLABEL_BROWN        MSG_CLABEL_7
70
71 #define MSG_IGNORE_THREAD       (1U << 10)   /* ignore threads */
72 #define MSG_LOCKED              (1U << 11)   /* msg is locked  */
73 #define MSG_RETRCPT_PENDING     (1U << 12)   /* return receipt pending */
74 /* RESERVED */
75 #define MSG_RESERVED_CLAWS      (1U << 30)   /* for sylpheed-claws */
76 #define MSG_RESERVED            (1U << 31)
77
78 typedef guint32 MsgPermFlags;
79
80 #define MSG_CLABEL_FLAG_MASK    (MSG_CLABEL_7)
81
82 #define MSG_MOVE                (1U << 0)
83 #define MSG_COPY                (1U << 1)
84 #define MSG_QUEUED              (1U << 16)
85 #define MSG_DRAFT               (1U << 17)
86 #define MSG_ENCRYPTED           (1U << 18)
87 #define MSG_IMAP                (1U << 19)
88 #define MSG_NEWS                (1U << 20)
89 #define MSG_SIGNED              (1U << 21)
90 #define MSG_MIME                (1U << 29)
91 #define MSG_CACHED              (1U << 31)
92
93 typedef guint32 MsgTmpFlags;
94
95 #define MSG_CACHED_FLAG_MASK    (MSG_MIME | MSG_ENCRYPTED | MSG_SIGNED)
96
97 #define MSG_SET_FLAGS(msg, flags)       { (msg) |= (flags); }
98 #define MSG_UNSET_FLAGS(msg, flags)     { (msg) &= ~(flags); }
99 #define MSG_SET_PERM_FLAGS(msg, flags) \
100         MSG_SET_FLAGS((msg).perm_flags, flags)
101 #define MSG_SET_TMP_FLAGS(msg, flags) \
102         MSG_SET_FLAGS((msg).tmp_flags, flags)
103 #define MSG_UNSET_PERM_FLAGS(msg, flags) \
104         MSG_UNSET_FLAGS((msg).perm_flags, flags)
105 #define MSG_UNSET_TMP_FLAGS(msg, flags) \
106         MSG_UNSET_FLAGS((msg).tmp_flags, flags)
107
108 #define MSG_IS_NEW(msg)                 (((msg).perm_flags & MSG_NEW) != 0)
109 #define MSG_IS_UNREAD(msg)              (((msg).perm_flags & MSG_UNREAD) != 0)
110 #define MSG_IS_MARKED(msg)              (((msg).perm_flags & MSG_MARKED) != 0)
111 #define MSG_IS_DELETED(msg)             (((msg).perm_flags & MSG_DELETED) != 0)
112 #define MSG_IS_REPLIED(msg)             (((msg).perm_flags & MSG_REPLIED) != 0)
113 #define MSG_IS_LOCKED(msg)              (((msg).perm_flags & MSG_LOCKED) != 0)
114 #define MSG_IS_FORWARDED(msg)           (((msg).perm_flags & MSG_FORWARDED) != 0)
115
116 #define MSG_GET_COLORLABEL(msg)         (((msg).perm_flags & MSG_CLABEL_FLAG_MASK))
117 #define MSG_GET_COLORLABEL_VALUE(msg)   (MSG_GET_COLORLABEL(msg) >> MSG_CLABEL_SBIT)
118 #define MSG_SET_COLORLABEL_VALUE(msg, val) \
119         MSG_SET_PERM_FLAGS(msg, ((((guint)(val)) & 7) << MSG_CLABEL_SBIT))
120
121 #define MSG_COLORLABEL_TO_FLAGS(val) ((((guint)(val)) & 7) << MSG_CLABEL_SBIT)
122 #define MSG_COLORLABEL_FROM_FLAGS(val) (val >> MSG_CLABEL_SBIT)
123
124 #define MSG_IS_MOVE(msg)                (((msg).tmp_flags & MSG_MOVE) != 0)
125 #define MSG_IS_COPY(msg)                (((msg).tmp_flags & MSG_COPY) != 0)
126
127 #define MSG_IS_QUEUED(msg)              (((msg).tmp_flags & MSG_QUEUED) != 0)
128 #define MSG_IS_DRAFT(msg)               (((msg).tmp_flags & MSG_DRAFT) != 0)
129 #define MSG_IS_ENCRYPTED(msg)           (((msg).tmp_flags & MSG_ENCRYPTED) != 0)
130 #define MSG_IS_SIGNED(msg)              (((msg).tmp_flags & MSG_SIGNED) != 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 #define MSGINFO_UPDATE_HOOKLIST "msginfo_update"
142 #define MAIL_FILTERING_HOOKLIST "mail_filtering_hooklist"
143
144 #include "folder.h"
145 #include "procmime.h"
146 #include "prefs_filtering.h"
147
148 struct _MsgFlags
149 {
150         MsgPermFlags perm_flags;
151         MsgTmpFlags  tmp_flags;
152 };
153
154
155 struct _MsgInfo
156 {
157         guint refcnt;
158
159         guint  msgnum;
160         off_t  size;
161         time_t mtime;
162         time_t date_t;
163
164         MsgFlags flags;
165
166         gchar *fromname;
167
168         gchar *date;
169         gchar *from;
170         gchar *to;
171         gchar *cc;
172         gchar *newsgroups;
173         gchar *subject;
174         gchar *msgid;
175         gchar *inreplyto;
176         gchar *xref;
177
178         FolderItem *folder;
179         FolderItem *to_folder;
180
181         gchar *xface;
182
183         gchar *dispositionnotificationto;
184         gchar *returnreceiptto;
185
186         gchar *references;
187         gchar *fromspace;
188
189         gint score;
190         gint threadscore;
191
192         /* used only for encrypted messages */
193         gchar *plaintext_file;
194         guint decryption_failed : 1;
195 };
196
197 struct _MsgInfoUpdate {
198         MsgInfo *msginfo;
199 };
200
201 struct _MailFilteringData
202 {
203         MsgInfo *msginfo;
204 };
205
206 GHashTable *procmsg_msg_hash_table_create       (GSList         *mlist);
207 void procmsg_msg_hash_table_append              (GHashTable     *msg_table,
208                                                  GSList         *mlist);
209 GHashTable *procmsg_to_folder_hash_table_create (GSList         *mlist);
210
211 GSList *procmsg_read_cache              (FolderItem     *item,
212                                          gboolean        scan_file);
213 gint    procmsg_get_last_num_in_msg_list(GSList         *mlist);
214 void    procmsg_msg_list_free           (GSList         *mlist);
215 void    procmsg_get_mark_sum            (const gchar    *folder,
216                                          gint           *new_msgs,
217                                          gint           *unread_msgs,
218                                          gint           *total_msgs,
219                                          gint           *min,
220                                          gint           *max,
221                                          gint            first);
222
223 GNode  *procmsg_get_thread_tree         (GSList         *mlist);
224
225 void    procmsg_move_messages           (GSList         *mlist);
226 void    procmsg_copy_messages           (GSList         *mlist);
227
228 gchar  *procmsg_get_message_file_path   (MsgInfo        *msginfo);
229 gchar  *procmsg_get_message_file        (MsgInfo        *msginfo);
230 FILE   *procmsg_open_message            (MsgInfo        *msginfo);
231 #if USE_GPGME
232 FILE   *procmsg_open_message_decrypted  (MsgInfo        *msginfo,
233                                          MimeInfo      **mimeinfo);
234 #endif
235 gboolean procmsg_msg_exist              (MsgInfo        *msginfo);
236
237 void    procmsg_get_filter_keyword      (MsgInfo          *msginfo,
238                                          gchar           **header,
239                                          gchar           **key,
240                                          PrefsFilterType   type);
241
242 void    procmsg_empty_trash             (void);
243 gint    procmsg_send_queue              (FolderItem     *queue,
244                                          gboolean        save_msgs);
245 gint    procmsg_save_to_outbox          (FolderItem     *outbox,
246                                          const gchar    *file,
247                                          gboolean        is_queued);
248 void    procmsg_print_message           (MsgInfo        *msginfo,
249                                          const gchar    *cmdline);
250
251 MsgInfo *procmsg_msginfo_new            ();
252 MsgInfo *procmsg_msginfo_new_ref        (MsgInfo        *msginfo);
253 MsgInfo *procmsg_msginfo_copy           (MsgInfo        *msginfo);
254 MsgInfo *procmsg_msginfo_get_full_info  (MsgInfo        *msginfo);
255 void     procmsg_msginfo_free           (MsgInfo        *msginfo);
256 guint    procmsg_msginfo_memusage       (MsgInfo        *msginfo);
257
258 gint procmsg_cmp_msgnum_for_sort        (gconstpointer   a,
259                                          gconstpointer   b);
260 gint procmsg_send_message_queue         (const gchar *file);
261
262 void procmsg_msginfo_set_flags          (MsgInfo *msginfo,
263                                          MsgPermFlags perm_flags,
264                                           MsgTmpFlags tmp_flags);
265 void procmsg_msginfo_unset_flags        (MsgInfo *msginfo,
266                                          MsgPermFlags perm_flags,
267                                           MsgTmpFlags tmp_flags);
268 gint procmsg_remove_special_headers     (const gchar    *in, 
269                                          const gchar    *out);
270
271 gboolean procmsg_msg_has_flagged_parent (MsgInfo        *info,
272                                          MsgPermFlags    perm_flags);
273 gboolean procmsg_msg_has_marked_parent  (MsgInfo        *info);
274 GSList *procmsg_find_children           (MsgInfo        *info);
275 void procmsg_update_unread_children     (MsgInfo        *info,
276                                          gboolean        newly_marked);
277 void procmsg_msginfo_set_to_folder      (MsgInfo        *msginfo,
278                                          FolderItem     *to_folder);
279 gboolean procmsg_msginfo_filter         (MsgInfo        *msginfo);
280
281 #endif /* __PROCMSG_H__ */