Statistics
| Revision:

root / src / procmsg.h @ 1

History | View | Annotate | Download (8.08 KB)

1
/*
2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 1999-2004 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 _MsgFileInfo        MsgFileInfo;
36

    
37
#include "folder.h"
38
#include "procmime.h"
39
#include "prefs_filter.h"
40

    
41
typedef enum
42
{
43
        DATA_READ,
44
        DATA_WRITE,
45
        DATA_APPEND
46
} DataOpenMode;
47

    
48
#define MSG_NEW                        (1U << 0)
49
#define MSG_UNREAD                (1U << 1)
50
#define MSG_MARKED                (1U << 2)
51
#define MSG_DELETED                (1U << 3)
52
#define MSG_REPLIED                (1U << 4)
53
#define MSG_FORWARDED                (1U << 5)
54

    
55
#define MSG_CLABEL_SBIT        (7)                /* start bit of color label */
56
#define MAKE_MSG_CLABEL(h, m, l)        (((h) << (MSG_CLABEL_SBIT + 2)) | \
57
                                         ((m) << (MSG_CLABEL_SBIT + 1)) | \
58
                                         ((l) << (MSG_CLABEL_SBIT + 0)))
59

    
60
#define MSG_CLABEL_NONE                MAKE_MSG_CLABEL(0U, 0U, 0U)
61
#define MSG_CLABEL_1                MAKE_MSG_CLABEL(0U, 0U, 1U)
62
#define MSG_CLABEL_2                MAKE_MSG_CLABEL(0U, 1U, 0U)
63
#define MSG_CLABEL_3                MAKE_MSG_CLABEL(0U, 1U, 1U)
64
#define MSG_CLABEL_4                MAKE_MSG_CLABEL(1U, 0U, 0U)
65
#define MSG_CLABEL_5                MAKE_MSG_CLABEL(1U, 0U, 1U)
66
#define MSG_CLABEL_6                MAKE_MSG_CLABEL(1U, 1U, 0U)
67
#define MSG_CLABEL_7                MAKE_MSG_CLABEL(1U, 1U, 1U)
68

    
69
#define MSG_CLABEL_ORANGE        MSG_CLABEL_1
70
#define MSG_CLABEL_RED                MSG_CLABEL_2
71
#define MSG_CLABEL_PINK                MSG_CLABEL_3
72
#define MSG_CLABEL_SKYBLUE        MSG_CLABEL_4
73
#define MSG_CLABEL_BLUE                MSG_CLABEL_5
74
#define MSG_CLABEL_GREEN        MSG_CLABEL_6
75
#define MSG_CLABEL_BROWN        MSG_CLABEL_7
76

    
77
/* RESERVED */
78
#define        MSG_RESERVED                (1U << 31)
79

    
80
#define MSG_CLABEL_FLAG_MASK        (MSG_CLABEL_7)
81

    
82
typedef guint32 MsgPermFlags;
83

    
84
#define MSG_MOVE                (1U << 0)
85
#define MSG_COPY                (1U << 1)
86
#define MSG_QUEUED                (1U << 16)
87
#define MSG_DRAFT                (1U << 17)
88
#define MSG_ENCRYPTED                (1U << 18)
89
#define MSG_IMAP                (1U << 19)
90
#define MSG_NEWS                (1U << 20)
91
#define MSG_SIGNED                (1U << 21)
92
#define MSG_MIME                (1U << 29)
93
#define MSG_INVALID                (1U << 30)
94
#define MSG_RECEIVED                (1U << 31)
95

    
96
#define MSG_CACHED_FLAG_MASK        (MSG_MIME)
97

    
98
typedef guint32 MsgTmpFlags;
99

    
100
#define MSG_SET_FLAGS(msg, flags)        { (msg) |= (flags); }
101
#define MSG_UNSET_FLAGS(msg, flags)        { (msg) &= ~(flags); }
102
#define MSG_SET_PERM_FLAGS(msg, flags) \
103
        MSG_SET_FLAGS((msg).perm_flags, flags)
104
#define MSG_SET_TMP_FLAGS(msg, flags) \
105
        MSG_SET_FLAGS((msg).tmp_flags, flags)
106
#define MSG_UNSET_PERM_FLAGS(msg, flags) \
107
        MSG_UNSET_FLAGS((msg).perm_flags, flags)
108
#define MSG_UNSET_TMP_FLAGS(msg, flags) \
109
        MSG_UNSET_FLAGS((msg).tmp_flags, flags)
110

    
111
#define MSG_IS_NEW(msg)                        (((msg).perm_flags & MSG_NEW) != 0)
112
#define MSG_IS_UNREAD(msg)                (((msg).perm_flags & MSG_UNREAD) != 0)
113
#define MSG_IS_MARKED(msg)                (((msg).perm_flags & MSG_MARKED) != 0)
114
#define MSG_IS_DELETED(msg)                (((msg).perm_flags & MSG_DELETED) != 0)
115
#define MSG_IS_REPLIED(msg)                (((msg).perm_flags & MSG_REPLIED) != 0)
116
#define MSG_IS_FORWARDED(msg)                (((msg).perm_flags & MSG_FORWARDED) != 0)
117

    
118
#define MSG_GET_COLORLABEL(msg)                (((msg).perm_flags & MSG_CLABEL_FLAG_MASK))
119
#define MSG_GET_COLORLABEL_VALUE(msg)        (MSG_GET_COLORLABEL(msg) >> MSG_CLABEL_SBIT)
120
#define MSG_SET_COLORLABEL_VALUE(msg, val) \
121
        MSG_SET_PERM_FLAGS(msg, ((((guint)(val)) & 7) << MSG_CLABEL_SBIT))
122

    
123
#define MSG_IS_MOVE(msg)                (((msg).tmp_flags & MSG_MOVE) != 0)
124
#define MSG_IS_COPY(msg)                (((msg).tmp_flags & MSG_COPY) != 0)
125

    
126
#define MSG_IS_QUEUED(msg)                (((msg).tmp_flags & MSG_QUEUED) != 0)
127
#define MSG_IS_DRAFT(msg)                (((msg).tmp_flags & MSG_DRAFT) != 0)
128
#define MSG_IS_ENCRYPTED(msg)                (((msg).tmp_flags & MSG_ENCRYPTED) != 0)
129
#define MSG_IS_IMAP(msg)                (((msg).tmp_flags & MSG_IMAP) != 0)
130
#define MSG_IS_NEWS(msg)                (((msg).tmp_flags & MSG_NEWS) != 0)
131
#define MSG_IS_MIME(msg)                (((msg).tmp_flags & MSG_MIME) != 0)
132
#define MSG_IS_INVALID(msg)                (((msg).tmp_flags & MSG_INVALID) != 0)
133
#define MSG_IS_RECEIVED(msg)                (((msg).tmp_flags & MSG_RECEIVED) != 0)
134

    
135
#define WRITE_CACHE_DATA_INT(n, fp)                \
136
{                                                \
137
        guint32 idata;                                \
138
                                                \
139
        idata = (guint32)n;                        \
140
        fwrite(&idata, sizeof(idata), 1, fp);        \
141
}
142

    
143
#define WRITE_CACHE_DATA(data, fp)                        \
144
{                                                        \
145
        size_t len;                                        \
146
                                                        \
147
        if (data == NULL) {                                \
148
                len = 0;                                \
149
                WRITE_CACHE_DATA_INT(len, fp);                \
150
        } else {                                        \
151
                len = strlen(data);                        \
152
                WRITE_CACHE_DATA_INT(len, fp);                \
153
                if (len > 0)                                \
154
                        fwrite(data, len, 1, fp);        \
155
        }                                                \
156
}
157

    
158
struct _MsgFlags
159
{
160
        MsgPermFlags perm_flags;
161
        MsgTmpFlags  tmp_flags;
162
};
163

    
164
struct _MsgInfo
165
{
166
        guint  msgnum;
167
        off_t  size;
168
        time_t mtime;
169
        time_t date_t;
170

    
171
        MsgFlags flags;
172

    
173
        gchar *fromname;
174

    
175
        gchar *date;
176
        gchar *from;
177
        gchar *to;
178
        gchar *cc;
179
        gchar *newsgroups;
180
        gchar *subject;
181
        gchar *msgid;
182
        gchar *inreplyto;
183

    
184
        FolderItem *folder;
185
        FolderItem *to_folder;
186

    
187
        gchar *xface;
188

    
189
        /* used only for temporary messages */
190
        gchar *file_path;
191

    
192
        /* used only for encrypted messages */
193
        gchar *plaintext_file;
194
        guint decryption_failed : 1;
195
};
196

    
197
struct _MsgFileInfo
198
{
199
        gchar *file;
200
        MsgFlags *flags;
201
};
202

    
203
GHashTable *procmsg_msg_hash_table_create        (GSList                *mlist);
204
void procmsg_msg_hash_table_append                (GHashTable        *msg_table,
205
                                                 GSList                *mlist);
206
GHashTable *procmsg_to_folder_hash_table_create        (GSList                *mlist);
207

    
208
GSList *procmsg_read_cache                (FolderItem        *item,
209
                                         gboolean         scan_file);
210
void        procmsg_set_flags                (GSList                *mlist,
211
                                         FolderItem        *item);
212
GSList *procmsg_sort_msg_list                (GSList                *mlist,
213
                                         FolderSortKey         sort_key,
214
                                         FolderSortType         sort_type);
215
gint        procmsg_get_last_num_in_msg_list(GSList                *mlist);
216
void        procmsg_msg_list_free                (GSList                *mlist);
217
void        procmsg_write_cache                (MsgInfo        *msginfo,
218
                                         FILE                *fp);
219
void        procmsg_write_flags                (MsgInfo        *msginfo,
220
                                         FILE                *fp);
221
void        procmsg_flush_mark_queue        (FolderItem        *item,
222
                                         FILE                *fp);
223
void        procmsg_add_mark_queue                (FolderItem        *item,
224
                                         gint                 num,
225
                                         MsgFlags         flags);
226
void        procmsg_add_flags                (FolderItem        *item,
227
                                         gint                 num,
228
                                         MsgFlags         flags);
229
void        procmsg_get_mark_sum                (FolderItem        *item,
230
                                         gint                *new,
231
                                         gint                *unread,
232
                                         gint                *total,
233
                                         gint                *min,
234
                                         gint                *max,
235
                                         gint                 first);
236
FILE   *procmsg_open_cache_file                (FolderItem        *item,
237
                                         DataOpenMode         mode);
238
FILE   *procmsg_open_mark_file                (FolderItem        *item,
239
                                         DataOpenMode         mode);
240

    
241
GNode  *procmsg_get_thread_tree                (GSList                *mlist);
242

    
243
gint        procmsg_move_messages                (GSList                *mlist);
244
gint        procmsg_copy_messages                (GSList                *mlist);
245

    
246
gchar  *procmsg_get_message_file_path        (MsgInfo        *msginfo);
247
gchar  *procmsg_get_message_file        (MsgInfo        *msginfo);
248
GSList *procmsg_get_message_file_list        (GSList                *mlist);
249
void        procmsg_message_file_list_free        (GSList                *file_list);
250
FILE   *procmsg_open_message                (MsgInfo        *msginfo);
251
#if USE_GPGME
252
FILE   *procmsg_open_message_decrypted        (MsgInfo        *msginfo,
253
                                         MimeInfo      **mimeinfo);
254
#endif
255
gboolean procmsg_msg_exist                (MsgInfo        *msginfo);
256

    
257
void        procmsg_get_filter_keyword        (MsgInfo          *msginfo,
258
                                         gchar                 **header,
259
                                         gchar                 **key,
260
                                         PrefsFilterType   type);
261

    
262
void        procmsg_empty_trash                (FolderItem        *trash);
263
void        procmsg_empty_all_trash                (void);
264

    
265
gint        procmsg_send_queue                (FolderItem        *queue,
266
                                         gboolean         save_msgs);
267
gint        procmsg_save_to_outbox                (FolderItem        *outbox,
268
                                         const gchar        *file,
269
                                         gboolean         is_queued);
270
void        procmsg_print_message                (MsgInfo        *msginfo,
271
                                         const gchar        *cmdline);
272

    
273
MsgInfo *procmsg_msginfo_copy                (MsgInfo        *msginfo);
274
MsgInfo *procmsg_msginfo_get_full_info        (MsgInfo        *msginfo);
275
void         procmsg_msginfo_free                (MsgInfo        *msginfo);
276

    
277
gint procmsg_cmp_msgnum_for_sort        (gconstpointer         a,
278
                                         gconstpointer         b);
279

    
280
#endif /* __PROCMSG_H__ */