updated pt_BR.po
[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_LABEL_SBIT (7)              /* start bit message label */
46 #define MAKE_MSG_LABEL(h, m, l) (((h) << (MSG_LABEL_SBIT+2)) | \
47                                 ((m) << (MSG_LABEL_SBIT+1)) | \
48                                 ((l) << (MSG_LABEL_SBIT+0)))
49                                 
50         MSG_LABEL       = MAKE_MSG_LABEL(1, 1, 1),
51         MSG_LABEL_NONE  = MAKE_MSG_LABEL(0, 0, 0),
52         MSG_LABEL_1     = MAKE_MSG_LABEL(0, 0, 1),
53         MSG_LABEL_2     = MAKE_MSG_LABEL(0, 1, 0),
54         MSG_LABEL_3     = MAKE_MSG_LABEL(0, 1, 1),
55         MSG_LABEL_4     = MAKE_MSG_LABEL(1, 0, 0),
56         MSG_LABEL_5     = MAKE_MSG_LABEL(1, 0, 1),
57         MSG_LABEL_6     = MAKE_MSG_LABEL(1, 1, 0),
58         MSG_LABEL_7     = MAKE_MSG_LABEL(1, 1, 1),
59
60 #define MSG_LABEL_ORANGE   (MSG_LABEL_1)
61 #define MSG_LABEL_RED      (MSG_LABEL_2)
62 #define MSG_LABEL_PINK     (MSG_LABEL_3)
63 #define MSG_LABEL_SKYBLUE  (MSG_LABEL_4)
64 #define MSG_LABEL_BLUE     (MSG_LABEL_5)
65 #define MSG_LABEL_GREEN    (MSG_LABEL_6)
66 #define MSG_LABEL_BROWN    (MSG_LABEL_7)
67
68         MSG_IGNORE_THREAD   = 1 << 10,   /* ignore threads */
69
70         /* RESERVED */
71         MSG_RESERVED_CLAWS  = 1 << 30,  /* for sylpheed-claws */
72         MSG_RESERVED_MAIN   = 1 << 31   /* for sylpheed-main  */
73 } MsgPermFlags;
74
75 typedef enum
76 {
77         MSG_MOVE        = 1 << 0,
78         MSG_COPY        = 1 << 1,
79         
80         MSG_QUEUED      = 1 << 16,
81         MSG_DRAFT       = 1 << 17,
82         MSG_ENCRYPTED   = 1 << 18,
83         MSG_IMAP        = 1 << 19,
84         MSG_NEWS        = 1 << 20,
85
86         MSG_FILTERING   = 1 << 25,      /* claws: re/set by filtering */
87
88         MSG_MIME        = 1 << 29,
89         MSG_CACHED      = 1 << 31
90 } MsgTmpFlags;
91
92 #define MSG_CACHED_FLAG_MASK            (MSG_MIME)
93
94 #define MSG_SET_FLAGS(msg, flags)       { (msg) |= (flags); }
95 #define MSG_UNSET_FLAGS(msg, flags)     { (msg) &= ~(flags); }
96 #define MSG_SET_PERM_FLAGS(msg, flags) \
97         MSG_SET_FLAGS((msg).perm_flags, flags)
98 #define MSG_SET_TMP_FLAGS(msg, flags) \
99         MSG_SET_FLAGS((msg).tmp_flags, flags)
100 #define MSG_UNSET_PERM_FLAGS(msg, flags) \
101         MSG_UNSET_FLAGS((msg).perm_flags, flags)
102 #define MSG_UNSET_TMP_FLAGS(msg, flags) \
103         MSG_UNSET_FLAGS((msg).tmp_flags, flags)
104
105 #define MSG_IS_NEW(msg)                 (((msg).perm_flags & MSG_NEW) != 0)
106 #define MSG_IS_UNREAD(msg)              (((msg).perm_flags & MSG_UNREAD) != 0)
107 #define MSG_IS_MARKED(msg)              (((msg).perm_flags & MSG_MARKED) != 0)
108 #define MSG_IS_DELETED(msg)             (((msg).perm_flags & MSG_DELETED) != 0)
109 #define MSG_IS_REPLIED(msg)             (((msg).perm_flags & MSG_REPLIED) != 0)
110 #define MSG_IS_FORWARDED(msg)           (((msg).perm_flags & MSG_FORWARDED) != 0)
111
112 #define MSG_IS_MOVE(msg)                (((msg).tmp_flags & MSG_MOVE) != 0)
113 #define MSG_IS_COPY(msg)                (((msg).tmp_flags & MSG_COPY) != 0)
114
115 #define MSG_IS_QUEUED(msg)              (((msg).tmp_flags & MSG_QUEUED) != 0)
116 #define MSG_IS_DRAFT(msg)               (((msg).tmp_flags & MSG_DRAFT) != 0)
117 #define MSG_IS_ENCRYPTED(msg)           (((msg).tmp_flags & MSG_ENCRYPTED) != 0)
118 #define MSG_IS_IMAP(msg)                (((msg).tmp_flags & MSG_IMAP) != 0)
119 #define MSG_IS_NEWS(msg)                (((msg).tmp_flags & MSG_NEWS) != 0)
120 #define MSG_IS_MIME(msg)                (((msg).tmp_flags & MSG_MIME) != 0)
121 #define MSG_IS_CACHED(msg)              (((msg).tmp_flags & MSG_CACHED) != 0)
122
123 /* Claws related flags */
124 #define MSG_IS_REALLY_DELETED(msg)      (((msg).perm_flags & MSG_REALLY_DELETED) != 0)
125 #define MSG_IS_IGNORE_THREAD(msg)       (((msg).perm_flags & MSG_IGNORE_THREAD) != 0)
126 #define MSG_GET_LABEL(msg)              (((msg).perm_flags & MSG_LABEL))
127 #define MSG_GET_LABEL_VALUE(msg)        (MSG_GET_LABEL(msg) >> MSG_LABEL_SBIT)
128 /* 7 == nr. of colors excl. none */
129 #define MSG_SET_LABEL_VALUE(msg, val)   MSG_SET_PERM_FLAGS(msg, ((((unsigned)(val)) & 7) << MSG_LABEL_SBIT))
130 #define MSG_IS_FILTERING(msg)           (((msg).tmp_flags  & MSG_FILTERING) != 0)
131
132
133 #define WRITE_CACHE_DATA_INT(n, fp) \
134         fwrite(&n, sizeof(n), 1, fp)
135
136 #define WRITE_CACHE_DATA(data, fp) \
137 { \
138         gint len; \
139  \
140         if (data == NULL || (len = strlen(data)) == 0) { \
141                 len = 0; \
142                 WRITE_CACHE_DATA_INT(len, fp); \
143         } else { \
144                 len = strlen(data); \
145                 WRITE_CACHE_DATA_INT(len, fp); \
146                 fwrite(data, len, 1, fp); \
147         } \
148 }
149
150 struct _MsgFlags
151 {
152         MsgPermFlags perm_flags;
153         MsgTmpFlags  tmp_flags;
154 };
155
156 struct _MsgInfo
157 {
158         guint  msgnum;
159         off_t  size;
160         time_t mtime;
161         time_t date_t;
162
163         MsgFlags flags;
164
165         gchar *fromname;
166
167         gchar *date;
168         gchar *from;
169         gchar *to;
170         gchar *cc;
171         gchar *newsgroups;
172         gchar *subject;
173         gchar *msgid;
174         gchar *inreplyto;
175
176         FolderItem *folder;
177         FolderItem *to_folder;
178
179         gchar *xface;
180
181         gchar *dispositionnotificationto;
182         gchar *returnreceiptto;
183
184         gchar *references;
185         gchar *fromspace;
186
187         gint score;
188         gint threadscore;
189
190         /* used only for encrypted messages */
191         gchar *plaintext_file;
192         guint decryption_failed : 1;
193 };
194
195 GHashTable *procmsg_msg_hash_table_create       (GSList         *mlist);
196 void procmsg_msg_hash_table_append              (GHashTable     *msg_table,
197                                                  GSList         *mlist);
198 GHashTable *procmsg_to_folder_hash_table_create (GSList         *mlist);
199
200 GSList *procmsg_read_cache              (FolderItem     *item,
201                                          gboolean        scan_file);
202 void    procmsg_set_flags               (GSList         *mlist,
203                                          FolderItem     *item);
204 gint    procmsg_get_last_num_in_cache   (GSList         *mlist);
205 void    procmsg_msg_list_free           (GSList         *mlist);
206 void    procmsg_write_cache             (MsgInfo        *msginfo,
207                                          FILE           *fp);
208 void    procmsg_write_flags             (MsgInfo        *msginfo,
209                                          FILE           *fp);
210 void    procmsg_get_mark_sum            (const gchar    *folder,
211                                          gint           *new,
212                                          gint           *unread,
213                                          gint           *total);
214 FILE   *procmsg_open_mark_file          (const gchar    *folder,
215                                          gboolean        append);
216
217 void    procmsg_move_messages           (GSList         *mlist);
218 void    procmsg_copy_messages           (GSList         *mlist);
219
220 gchar  *procmsg_get_message_file_path   (MsgInfo        *msginfo);
221 gchar  *procmsg_get_message_file        (MsgInfo        *msginfo);
222 FILE   *procmsg_open_message            (MsgInfo        *msginfo);
223 gboolean procmsg_msg_exist              (MsgInfo        *msginfo);
224
225 void    procmsg_empty_trash             (void);
226 gint    procmsg_send_queue              (void);
227 void    procmsg_print_message           (MsgInfo        *msginfo,
228                                          const gchar    *cmdline);
229
230 MsgInfo *procmsg_msginfo_copy           (MsgInfo        *msginfo);
231 void     procmsg_msginfo_free           (MsgInfo        *msginfo);
232
233 gint procmsg_cmp_msgnum_for_sort        (gconstpointer   a,
234                                          gconstpointer   b);
235
236 #endif /* __PROCMSG_H__ */