ba70b7d5db6c1f81b06177a06304b21b15c13214
[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         MSG_SIGNED      = 1 << 21,
94
95         MSG_MIME        = 1 << 29,
96
97         MSG_CACHED      = 1 << 31
98 } MsgTmpFlags;
99
100 #define MSG_CACHED_FLAG_MASK    (MSG_MIME | MSG_ENCRYPTED | MSG_SIGNED)
101
102 #define MSG_SET_FLAGS(msg, flags)       { (msg) |= (flags); }
103 #define MSG_UNSET_FLAGS(msg, flags)     { (msg) &= ~(flags); }
104 #define MSG_SET_PERM_FLAGS(msg, flags) \
105         MSG_SET_FLAGS((msg).perm_flags, flags)
106 #define MSG_SET_TMP_FLAGS(msg, flags) \
107         MSG_SET_FLAGS((msg).tmp_flags, flags)
108 #define MSG_UNSET_PERM_FLAGS(msg, flags) \
109         MSG_UNSET_FLAGS((msg).perm_flags, flags)
110 #define MSG_UNSET_TMP_FLAGS(msg, flags) \
111         MSG_UNSET_FLAGS((msg).tmp_flags, flags)
112
113 #define MSG_IS_NEW(msg)                 (((msg).perm_flags & MSG_NEW) != 0)
114 #define MSG_IS_UNREAD(msg)              (((msg).perm_flags & MSG_UNREAD) != 0)
115 #define MSG_IS_MARKED(msg)              (((msg).perm_flags & MSG_MARKED) != 0)
116 #define MSG_IS_DELETED(msg)             (((msg).perm_flags & MSG_DELETED) != 0)
117 #define MSG_IS_REPLIED(msg)             (((msg).perm_flags & MSG_REPLIED) != 0)
118 #define MSG_IS_LOCKED(msg)              (((msg).perm_flags & MSG_LOCKED) != 0)
119 #define MSG_IS_FORWARDED(msg)           (((msg).perm_flags & MSG_FORWARDED) != 0)
120
121 #define MSG_GET_COLORLABEL(msg)         (((msg).perm_flags & MSG_CLABEL_FLAG_MASK))
122 #define MSG_GET_COLORLABEL_VALUE(msg)   (MSG_GET_COLORLABEL(msg) >> MSG_CLABEL_SBIT)
123 #define MSG_SET_COLORLABEL_VALUE(msg, val) \
124         MSG_SET_PERM_FLAGS(msg, ((((guint)(val)) & 7) << MSG_CLABEL_SBIT))
125
126 #define MSG_COLORLABEL_TO_FLAGS(val) ((((guint)(val)) & 7) << MSG_CLABEL_SBIT)
127 #define MSG_COLORLABEL_FROM_FLAGS(val) (val >> MSG_CLABEL_SBIT)
128
129 #define MSG_IS_MOVE(msg)                (((msg).tmp_flags & MSG_MOVE) != 0)
130 #define MSG_IS_COPY(msg)                (((msg).tmp_flags & MSG_COPY) != 0)
131
132 #define MSG_IS_QUEUED(msg)              (((msg).tmp_flags & MSG_QUEUED) != 0)
133 #define MSG_IS_DRAFT(msg)               (((msg).tmp_flags & MSG_DRAFT) != 0)
134 #define MSG_IS_ENCRYPTED(msg)           (((msg).tmp_flags & MSG_ENCRYPTED) != 0)
135 #define MSG_IS_SIGNED(msg)              (((msg).tmp_flags & MSG_SIGNED) != 0)
136 #define MSG_IS_IMAP(msg)                (((msg).tmp_flags & MSG_IMAP) != 0)
137 #define MSG_IS_NEWS(msg)                (((msg).tmp_flags & MSG_NEWS) != 0)
138 #define MSG_IS_MIME(msg)                (((msg).tmp_flags & MSG_MIME) != 0)
139 #define MSG_IS_CACHED(msg)              (((msg).tmp_flags & MSG_CACHED) != 0)
140
141 /* Claws related flags */
142 #define MSG_IS_REALLY_DELETED(msg)      (((msg).perm_flags & MSG_REALLY_DELETED) != 0)
143 #define MSG_IS_IGNORE_THREAD(msg)       (((msg).perm_flags & MSG_IGNORE_THREAD) != 0)
144 #define MSG_IS_RETRCPT_PENDING(msg)     (((msg).perm_flags & MSG_RETRCPT_PENDING) != 0)
145
146 struct _MsgFlags
147 {
148         MsgPermFlags perm_flags;
149         MsgTmpFlags  tmp_flags;
150 };
151
152 struct _MsgInfo
153 {
154         guint refcnt;
155
156         guint  msgnum;
157         off_t  size;
158         time_t mtime;
159         time_t date_t;
160
161         MsgFlags flags;
162
163         gchar *fromname;
164
165         gchar *date;
166         gchar *from;
167         gchar *to;
168         gchar *cc;
169         gchar *newsgroups;
170         gchar *subject;
171         gchar *msgid;
172         gchar *inreplyto;
173         gchar *xref;
174
175         FolderItem *folder;
176         FolderItem *to_folder;
177
178         gchar *xface;
179
180         gchar *dispositionnotificationto;
181         gchar *returnreceiptto;
182
183         gchar *references;
184         gchar *fromspace;
185
186         gint score;
187         gint threadscore;
188
189         /* used only for encrypted messages */
190         gchar *plaintext_file;
191         guint decryption_failed : 1;
192 };
193
194 #define MSGINFO_UPDATE_HOOKLIST "msginfo_update"
195
196 typedef struct _MsgInfoUpdate MsgInfoUpdate;
197
198 struct _MsgInfoUpdate {
199         MsgInfo *msginfo;
200 };
201
202 GHashTable *procmsg_msg_hash_table_create       (GSList         *mlist);
203 void procmsg_msg_hash_table_append              (GHashTable     *msg_table,
204                                                  GSList         *mlist);
205 GHashTable *procmsg_to_folder_hash_table_create (GSList         *mlist);
206
207 GSList *procmsg_read_cache              (FolderItem     *item,
208                                          gboolean        scan_file);
209 gint    procmsg_get_last_num_in_msg_list(GSList         *mlist);
210 void    procmsg_msg_list_free           (GSList         *mlist);
211 void    procmsg_get_mark_sum            (const gchar    *folder,
212                                          gint           *new,
213                                          gint           *unread,
214                                          gint           *total,
215                                          gint           *min,
216                                          gint           *max,
217                                          gint            first);
218
219 GNode  *procmsg_get_thread_tree         (GSList         *mlist);
220
221 void    procmsg_move_messages           (GSList         *mlist);
222 void    procmsg_copy_messages           (GSList         *mlist);
223
224 gchar  *procmsg_get_message_file_path   (MsgInfo        *msginfo);
225 gchar  *procmsg_get_message_file        (MsgInfo        *msginfo);
226 FILE   *procmsg_open_message            (MsgInfo        *msginfo);
227 #if USE_GPGME
228 FILE   *procmsg_open_message_decrypted  (MsgInfo        *msginfo,
229                                          MimeInfo      **mimeinfo);
230 #endif
231 gboolean procmsg_msg_exist              (MsgInfo        *msginfo);
232
233 void    procmsg_empty_trash             (void);
234 gint    procmsg_send_queue              (FolderItem     *queue,
235                                          gboolean        save_msgs);
236 gint    procmsg_save_to_outbox          (FolderItem     *outbox,
237                                          const gchar    *file,
238                                          gboolean        is_queued);
239 void    procmsg_print_message           (MsgInfo        *msginfo,
240                                          const gchar    *cmdline);
241
242 MsgInfo *procmsg_msginfo_new            ();
243 MsgInfo *procmsg_msginfo_new_ref        (MsgInfo        *msginfo);
244 MsgInfo *procmsg_msginfo_copy           (MsgInfo        *msginfo);
245 MsgInfo *procmsg_msginfo_get_full_info  (MsgInfo        *msginfo);
246 void     procmsg_msginfo_free           (MsgInfo        *msginfo);
247 guint    procmsg_msginfo_memusage       (MsgInfo        *msginfo);
248
249 gint procmsg_cmp_msgnum_for_sort        (gconstpointer   a,
250                                          gconstpointer   b);
251 gint procmsg_send_message_queue         (const gchar *file);
252
253 void procmsg_msginfo_set_flags          (MsgInfo *msginfo,
254                                          MsgPermFlags perm_flags,
255                                           MsgTmpFlags tmp_flags);
256 void procmsg_msginfo_unset_flags        (MsgInfo *msginfo,
257                                          MsgPermFlags perm_flags,
258                                           MsgTmpFlags tmp_flags);
259 gint procmsg_remove_special_headers     (const gchar    *in, 
260                                          const gchar    *out);
261
262 gboolean procmsg_msg_has_flagged_parent (MsgInfo        *info,
263                                          MsgPermFlags    perm_flags);
264 gboolean procmsg_msg_has_marked_parent  (MsgInfo        *info);
265 GSList *procmsg_find_children           (MsgInfo        *info);
266 void procmsg_update_unread_children     (MsgInfo        *info,
267                                          gboolean        newly_marked);
268 void procmsg_msginfo_set_to_folder      (MsgInfo        *msginfo,
269                                          FolderItem     *to_folder);
270 #endif /* __PROCMSG_H__ */