5afe3f623937364ff5a8a6b1a808065228184d9f
[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
31 #include "folder.h"
32
33 typedef enum
34 {
35         /* permanent flags (0x0000ffff) */
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         MSG_REALLY_DELETED = 1 << 6,
43
44         MSG_LABEL         = 1 << 9 | 1 << 8 | 1 << 7,
45         MSG_LABEL_NONE    = 0 << 9 | 0 << 8 | 0 << 7,
46         MSG_LABEL_ORANGE  = 0 << 9 | 0 << 8 | 1 << 7,
47         MSG_LABEL_RED     = 0 << 9 | 1 << 8 | 0 << 7,
48         MSG_LABEL_PINK    = 0 << 9 | 1 << 8 | 1 << 7,
49         MSG_LABEL_SKYBLUE = 1 << 9 | 0 << 8 | 0 << 7,
50         MSG_LABEL_BLUE    = 1 << 9 | 0 << 8 | 1 << 7,
51         MSG_LABEL_GREEN   = 1 << 9 | 1 << 8 | 0 << 7,
52         MSG_LABEL_BROWN   = 1 << 9 | 1 << 8 | 1 << 7,
53
54         /* temporary flags (0xffff0000) */
55         MSG_MOVE        = 1 << 16,
56         MSG_COPY        = 1 << 17,
57
58         MSG_QUEUED      = 1 << 25,
59         MSG_DRAFT       = 1 << 26,
60         MSG_ENCRYPTED   = 1 << 27,
61         MSG_IMAP        = 1 << 28,
62         MSG_MIME        = 1 << 29,
63         MSG_NEWS        = 1 << 30,
64         MSG_CACHED      = 1 << 31
65 } MsgFlags;
66
67 #define MSG_PERMANENT_FLAG_MASK         (MSG_NEW       | \
68                                          MSG_UNREAD    | \
69                                          MSG_MARKED    | \
70                                          MSG_DELETED   | \
71                                          MSG_REPLIED   | \
72                                          MSG_FORWARDED | \
73                                          MSG_LABEL     | \
74                                          MSG_REALLY_DELETED | \
75                                          MSG_IGNORE_THREAD)
76 #define MSG_CACHED_FLAG_MASK            (MSG_MIME)
77
78 #define MSG_SET_FLAGS(msg, flags)       { (msg) |= (flags); }
79 #define MSG_UNSET_FLAGS(msg, flags)     { (msg) &= ~(flags); }
80 #define MSG_IS_NEW(msg)                 ((msg & MSG_NEW) != 0)
81 #define MSG_IS_UNREAD(msg)              ((msg & MSG_UNREAD) != 0)
82 #define MSG_IS_MARKED(msg)              ((msg & MSG_MARKED) != 0)
83 #define MSG_IS_DELETED(msg)             ((msg & MSG_DELETED) != 0)
84 #define MSG_IS_REPLIED(msg)             ((msg & MSG_REPLIED) != 0)
85 #define MSG_IS_FORWARDED(msg)           ((msg & MSG_FORWARDED) != 0)
86
87 #define MSG_IS_MOVE(msg)                ((msg & MSG_MOVE) != 0)
88 #define MSG_IS_COPY(msg)                ((msg & MSG_COPY) != 0)
89 #define MSG_IS_REALLY_DELETED(msg)      ((msg & MSG_REALLY_DELETED) != 0)
90
91 #define MSG_IS_QUEUED(msg)              ((msg & MSG_QUEUED) != 0)
92 #define MSG_IS_DRAFT(msg)               ((msg & MSG_DRAFT) != 0)
93 #define MSG_IS_ENCRYPTED(msg)           ((msg & MSG_ENCRYPTED) != 0)
94 #define MSG_IS_IMAP(msg)                ((msg & MSG_IMAP) != 0)
95 #define MSG_IS_MIME(msg)                ((msg & MSG_MIME) != 0)
96 #define MSG_IS_NEWS(msg)                ((msg & MSG_NEWS) != 0)
97 #define MSG_IS_CACHED(msg)              ((msg & MSG_CACHED) != 0)
98 #define MSG_IS_IGNORE_THREAD(msg)       ((msg & MSG_IGNORE_THREAD) != 0)
99 #define MSG_GET_LABEL(msg)              (msg & MSG_LABEL)
100
101 #define WRITE_CACHE_DATA_INT(n, fp) \
102         fwrite(&n, sizeof(n), 1, fp)
103
104 #define WRITE_CACHE_DATA(data, fp) \
105 { \
106         gint len; \
107  \
108         if (data == NULL || (len = strlen(data)) == 0) { \
109                 len = 0; \
110                 WRITE_CACHE_DATA_INT(len, fp); \
111         } else { \
112                 len = strlen(data); \
113                 WRITE_CACHE_DATA_INT(len, fp); \
114                 fwrite(data, len, 1, fp); \
115         } \
116 }
117
118 struct _MsgInfo
119 {
120         guint  msgnum;
121         off_t  size;
122         time_t mtime;
123         time_t date_t;
124         MsgFlags flags;
125
126         gchar *fromname;
127
128         gchar *date;
129         gchar *from;
130         gchar *to;
131         gchar *cc;
132         gchar *newsgroups;
133         gchar *subject;
134         gchar *msgid;
135         gchar *inreplyto;
136
137         FolderItem *folder;
138         FolderItem *to_folder;
139
140         gchar *xface;
141
142         gchar *dispositionnotificationto;
143         gchar *returnreceiptto;
144
145         gchar *references;
146         gchar *fromspace;
147
148         gint score;
149         gint threadscore;
150
151         /* used only for encrypted messages */
152         gchar *plaintext_file;
153         guint decryption_failed : 1;
154 };
155
156 GHashTable *procmsg_msg_hash_table_create       (GSList         *mlist);
157 void procmsg_msg_hash_table_append              (GHashTable     *msg_table,
158                                                  GSList         *mlist);
159 GHashTable *procmsg_to_folder_hash_table_create (GSList         *mlist);
160
161 GSList *procmsg_read_cache              (FolderItem     *item,
162                                          gboolean        scan_file);
163 void    procmsg_set_flags               (GSList         *mlist,
164                                          FolderItem     *item);
165 gint    procmsg_get_last_num_in_cache   (GSList         *mlist);
166 void    procmsg_msg_list_free           (GSList         *mlist);
167 void    procmsg_write_cache             (MsgInfo        *msginfo,
168                                          FILE           *fp);
169 void    procmsg_write_flags             (MsgInfo        *msginfo,
170                                          FILE           *fp);
171 void    procmsg_get_mark_sum            (const gchar    *folder,
172                                          gint           *new,
173                                          gint           *unread,
174                                          gint           *total);
175 FILE   *procmsg_open_mark_file          (const gchar    *folder,
176                                          gboolean        append);
177
178 void    procmsg_move_messages           (GSList         *mlist);
179 void    procmsg_copy_messages           (GSList         *mlist);
180
181 gchar  *procmsg_get_message_file_path   (MsgInfo        *msginfo);
182 gchar  *procmsg_get_message_file        (MsgInfo        *msginfo);
183 FILE   *procmsg_open_message            (MsgInfo        *msginfo);
184 gboolean procmsg_msg_exist              (MsgInfo        *msginfo);
185
186 void    procmsg_empty_trash             (void);
187 gint    procmsg_send_queue              (void);
188 void    procmsg_print_message           (MsgInfo        *msginfo,
189                                          const gchar    *cmdline);
190
191 MsgInfo *procmsg_msginfo_copy           (MsgInfo        *msginfo);
192 void     procmsg_msginfo_free           (MsgInfo        *msginfo);
193
194 gint procmsg_cmp_msgnum_for_sort        (gconstpointer   a,
195                                          gconstpointer   b);
196
197 #endif /* __PROCMSG_H__ */