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