760d6bc1e5cb8851768e4e5335c3443f4224f7db
[claws.git] / src / procmsg.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 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 #include <glib.h>
24 #include <stdio.h>
25 #include <time.h>
26 #include <sys/types.h>
27 #include <string.h>
28
29 typedef struct _MsgInfo         MsgInfo;
30 typedef struct _MsgFlags        MsgFlags;
31
32 #include "folder.h"
33
34 typedef enum
35 {
36         MSG_NEW         = 1 << 0,
37         MSG_UNREAD      = 1 << 1,
38         MSG_MARKED      = 1 << 2,
39         MSG_DELETED     = 1 << 3,
40         MSG_REPLIED     = 1 << 4,
41         MSG_FORWARDED   = 1 << 5,
42         
43         MSG_REALLY_DELETED = 1 << 6,            /* mbox stuff */
44
45 #define MSG_CLABEL_SBIT (7)             /* start bit of color label */
46 #define MAKE_MSG_CLABEL(h, m, l)        (((h) << (MSG_CLABEL_SBIT + 2)) | \
47                                          ((m) << (MSG_CLABEL_SBIT + 1)) | \
48                                          ((l) << (MSG_CLABEL_SBIT + 0)))
49
50         MSG_CLABEL_NONE = MAKE_MSG_CLABEL(0, 0, 0),
51         MSG_CLABEL_1    = MAKE_MSG_CLABEL(0, 0, 1),
52         MSG_CLABEL_2    = MAKE_MSG_CLABEL(0, 1, 0),
53         MSG_CLABEL_3    = MAKE_MSG_CLABEL(0, 1, 1),
54         MSG_CLABEL_4    = MAKE_MSG_CLABEL(1, 0, 0),
55         MSG_CLABEL_5    = MAKE_MSG_CLABEL(1, 0, 1),
56         MSG_CLABEL_6    = MAKE_MSG_CLABEL(1, 1, 0),
57         MSG_CLABEL_7    = MAKE_MSG_CLABEL(1, 1, 1),
58
59 #define MSG_CLABEL_ORANGE       MSG_CLABEL_1
60 #define MSG_CLABEL_RED          MSG_CLABEL_2
61 #define MSG_CLABEL_PINK         MSG_CLABEL_3
62 #define MSG_CLABEL_SKYBLUE      MSG_CLABEL_4
63 #define MSG_CLABEL_BLUE         MSG_CLABEL_5
64 #define MSG_CLABEL_GREEN        MSG_CLABEL_6
65 #define MSG_CLABEL_BROWN        MSG_CLABEL_7
66
67         MSG_IGNORE_THREAD   = 1 << 10,   /* ignore threads */
68         MSG_LOCKED          = 1 << 11,   /* msg is locked  */
69         MSG_RETRCPT_PENDING = 1 << 12,   /* return receipt pending */
70
71         /* RESERVED */
72         MSG_RESERVED_CLAWS  = 1 << 30,  /* for sylpheed-claws */
73         MSG_RESERVED_MAIN   = 1 << 31   /* for sylpheed-main  */
74 } MsgPermFlags;
75
76 #define MSG_CLABEL_FLAG_MASK    (MSG_CLABEL_7)
77
78 typedef enum
79 {
80         MSG_MOVE        = 1 << 0,
81         MSG_COPY        = 1 << 1,
82
83         MSG_QUEUED      = 1 << 16,
84         MSG_DRAFT       = 1 << 17,
85         MSG_ENCRYPTED   = 1 << 18,
86         MSG_IMAP        = 1 << 19,
87         MSG_NEWS        = 1 << 20,
88
89         MSG_MIME        = 1 << 29,
90
91         MSG_CACHED      = 1 << 31
92 } MsgTmpFlags;
93
94 #define MSG_CACHED_FLAG_MASK    (MSG_MIME | MSG_ENCRYPTED)
95
96 #define MSG_SET_FLAGS(msg, flags)       { (msg) |= (flags); }
97 #define MSG_UNSET_FLAGS(msg, flags)     { (msg) &= ~(flags); }
98 #define MSG_SET_PERM_FLAGS(msg, flags) \
99         MSG_SET_FLAGS((msg).perm_flags, flags)
100 #define MSG_SET_TMP_FLAGS(msg, flags) \
101         MSG_SET_FLAGS((msg).tmp_flags, flags)
102 #define MSG_UNSET_PERM_FLAGS(msg, flags) \
103         MSG_UNSET_FLAGS((msg).perm_flags, flags)
104 #define MSG_UNSET_TMP_FLAGS(msg, flags) \
105         MSG_UNSET_FLAGS((msg).tmp_flags, flags)
106
107 #define MSG_IS_NEW(msg)                 (((msg).perm_flags & MSG_NEW) != 0)
108 #define MSG_IS_UNREAD(msg)              (((msg).perm_flags & MSG_UNREAD) != 0)
109 #define MSG_IS_MARKED(msg)              (((msg).perm_flags & MSG_MARKED) != 0)
110 #define MSG_IS_DELETED(msg)             (((msg).perm_flags & MSG_DELETED) != 0)
111 #define MSG_IS_REPLIED(msg)             (((msg).perm_flags & MSG_REPLIED) != 0)
112 #define MSG_IS_LOCKED(msg)              (((msg).perm_flags & MSG_LOCKED) != 0)
113 #define MSG_IS_FORWARDED(msg)           (((msg).perm_flags & MSG_FORWARDED) != 0)
114
115 #define MSG_GET_COLORLABEL(msg)         (((msg).perm_flags & MSG_CLABEL_FLAG_MASK))
116 #define MSG_GET_COLORLABEL_VALUE(msg)   (MSG_GET_COLORLABEL(msg) >> MSG_CLABEL_SBIT)
117 #define MSG_SET_COLORLABEL_VALUE(msg, val) \
118         MSG_SET_PERM_FLAGS(msg, ((((guint)(val)) & 7) << MSG_CLABEL_SBIT))
119
120 #define MSG_IS_MOVE(msg)                (((msg).tmp_flags & MSG_MOVE) != 0)
121 #define MSG_IS_COPY(msg)                (((msg).tmp_flags & MSG_COPY) != 0)
122
123 #define MSG_IS_QUEUED(msg)              (((msg).tmp_flags & MSG_QUEUED) != 0)
124 #define MSG_IS_DRAFT(msg)               (((msg).tmp_flags & MSG_DRAFT) != 0)
125 #define MSG_IS_ENCRYPTED(msg)           (((msg).tmp_flags & MSG_ENCRYPTED) != 0)
126 #define MSG_IS_IMAP(msg)                (((msg).tmp_flags & MSG_IMAP) != 0)
127 #define MSG_IS_NEWS(msg)                (((msg).tmp_flags & MSG_NEWS) != 0)
128 #define MSG_IS_MIME(msg)                (((msg).tmp_flags & MSG_MIME) != 0)
129 #define MSG_IS_CACHED(msg)              (((msg).tmp_flags & MSG_CACHED) != 0)
130
131 /* Claws related flags */
132 #define MSG_IS_REALLY_DELETED(msg)      (((msg).perm_flags & MSG_REALLY_DELETED) != 0)
133 #define MSG_IS_IGNORE_THREAD(msg)       (((msg).perm_flags & MSG_IGNORE_THREAD) != 0)
134 #define MSG_IS_RETRCPT_PENDING(msg)     (((msg).perm_flags & MSG_RETRCPT_PENDING) != 0)
135
136
137 #define WRITE_CACHE_DATA_INT(n, fp) \
138         fwrite(&n, sizeof(n), 1, fp)
139
140 #define WRITE_CACHE_DATA(data, fp) \
141 { \
142         gint len; \
143  \
144         if (data == NULL || (len = strlen(data)) == 0) { \
145                 len = 0; \
146                 WRITE_CACHE_DATA_INT(len, fp); \
147         } else { \
148                 len = strlen(data); \
149                 WRITE_CACHE_DATA_INT(len, fp); \
150                 fwrite(data, len, 1, fp); \
151         } \
152 }
153
154 struct _MsgFlags
155 {
156         MsgPermFlags perm_flags;
157         MsgTmpFlags  tmp_flags;
158 };
159
160 struct _MsgInfo
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
180         FolderItem *folder;
181         FolderItem *to_folder;
182
183         gchar *xface;
184
185         gchar *dispositionnotificationto;
186         gchar *returnreceiptto;
187
188         gchar *references;
189         gchar *fromspace;
190
191         gint score;
192         gint threadscore;
193
194         /* used only for encrypted messages */
195         gchar *plaintext_file;
196         guint decryption_failed : 1;
197 };
198
199 GHashTable *procmsg_msg_hash_table_create       (GSList         *mlist);
200 void procmsg_msg_hash_table_append              (GHashTable     *msg_table,
201                                                  GSList         *mlist);
202 GHashTable *procmsg_to_folder_hash_table_create (GSList         *mlist);
203
204 GSList *procmsg_read_cache              (FolderItem     *item,
205                                          gboolean        scan_file);
206 void    procmsg_set_flags               (GSList         *mlist,
207                                          FolderItem     *item);
208 gint    procmsg_get_last_num_in_cache   (GSList         *mlist);
209 void    procmsg_msg_list_free           (GSList         *mlist);
210 void    procmsg_write_cache             (MsgInfo        *msginfo,
211                                          FILE           *fp);
212 void    procmsg_write_flags             (MsgInfo        *msginfo,
213                                          FILE           *fp);
214 void    procmsg_get_mark_sum            (const gchar    *folder,
215                                          gint           *new,
216                                          gint           *unread,
217                                          gint           *total);
218 FILE   *procmsg_open_mark_file          (const gchar    *folder,
219                                          gboolean        append);
220
221 GNode  *procmsg_get_thread_tree         (GSList         *mlist);
222
223 void    procmsg_move_messages           (GSList         *mlist);
224 void    procmsg_copy_messages           (GSList         *mlist);
225
226 gchar  *procmsg_get_message_file_path   (MsgInfo        *msginfo);
227 gchar  *procmsg_get_message_file        (MsgInfo        *msginfo);
228 FILE   *procmsg_open_message            (MsgInfo        *msginfo);
229 gboolean procmsg_msg_exist              (MsgInfo        *msginfo);
230
231 void    procmsg_empty_trash             (void);
232 gint    procmsg_send_queue              (void);
233 void    procmsg_print_message           (MsgInfo        *msginfo,
234                                          const gchar    *cmdline);
235
236 MsgInfo *procmsg_msginfo_copy           (MsgInfo        *msginfo);
237 void     procmsg_msginfo_free           (MsgInfo        *msginfo);
238
239 gint procmsg_cmp_msgnum_for_sort        (gconstpointer   a,
240                                          gconstpointer   b);
241 gint procmsg_send_message_queue         (const gchar *file);
242
243 #endif /* __PROCMSG_H__ */