Statistics
| Revision:

root / libsylph / procmsg.h @ 3281

History | View | Annotate | Download (10.2 KB)

1
/*
2
 * LibSylph -- E-Mail client library
3
 * Copyright (C) 1999-2013 Hiroyuki Yamamoto
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9
 *
10
 * This library 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 GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  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
typedef struct _MsgEncryptInfo        MsgEncryptInfo;
37

    
38
#include "folder.h"
39
#include "procmime.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_HTML                (1U << 26)
93
#define MSG_FLAG_CHANGED        (1U << 27)
94
#define MSG_CACHED                (1U << 28)
95
#define MSG_MIME                (1U << 29)
96
#define MSG_INVALID                (1U << 30)
97
#define MSG_RECEIVED                (1U << 31)
98

    
99
#define MSG_CACHED_FLAG_MASK        (MSG_MIME|MSG_MIME_HTML)
100

    
101
typedef guint32 MsgTmpFlags;
102

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

    
114
#define MSG_IS_NEW(msg)                        (((msg).perm_flags & MSG_NEW) != 0)
115
#define MSG_IS_UNREAD(msg)                (((msg).perm_flags & MSG_UNREAD) != 0)
116
#define MSG_IS_MARKED(msg)                (((msg).perm_flags & MSG_MARKED) != 0)
117
#define MSG_IS_DELETED(msg)                (((msg).perm_flags & MSG_DELETED) != 0)
118
#define MSG_IS_REPLIED(msg)                (((msg).perm_flags & MSG_REPLIED) != 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_IS_MOVE(msg)                (((msg).tmp_flags & MSG_MOVE) != 0)
127
#define MSG_IS_COPY(msg)                (((msg).tmp_flags & MSG_COPY) != 0)
128

    
129
#define MSG_IS_QUEUED(msg)                (((msg).tmp_flags & MSG_QUEUED) != 0)
130
#define MSG_IS_DRAFT(msg)                (((msg).tmp_flags & MSG_DRAFT) != 0)
131
#define MSG_IS_ENCRYPTED(msg)                (((msg).tmp_flags & MSG_ENCRYPTED) != 0)
132
#define MSG_IS_IMAP(msg)                (((msg).tmp_flags & MSG_IMAP) != 0)
133
#define MSG_IS_NEWS(msg)                (((msg).tmp_flags & MSG_NEWS) != 0)
134
#define MSG_IS_SIGNED(msg)                (((msg).tmp_flags & MSG_SIGNED) != 0)
135
#define MSG_IS_MIME_HTML(msg)                (((msg).tmp_flags & MSG_MIME_HTML) != 0)
136
#define MSG_IS_FLAG_CHANGED(msg)        (((msg).tmp_flags & MSG_FLAG_CHANGED) != 0)
137
#define MSG_IS_CACHED(msg)                (((msg).tmp_flags & MSG_CACHED) != 0)
138
#define MSG_IS_MIME(msg)                (((msg).tmp_flags & MSG_MIME) != 0)
139
#define MSG_IS_INVALID(msg)                (((msg).tmp_flags & MSG_INVALID) != 0)
140
#define MSG_IS_RECEIVED(msg)                (((msg).tmp_flags & MSG_RECEIVED) != 0)
141

    
142
#define WRITE_CACHE_DATA_INT(n, fp)                \
143
{                                                \
144
        guint32 idata;                                \
145
                                                \
146
        idata = (guint32)n;                        \
147
        fwrite(&idata, sizeof(idata), 1, fp);        \
148
}
149

    
150
#define WRITE_CACHE_DATA(data, fp)                        \
151
{                                                        \
152
        size_t len;                                        \
153
                                                        \
154
        if (data == NULL) {                                \
155
                len = 0;                                \
156
                WRITE_CACHE_DATA_INT(len, fp);                \
157
        } else {                                        \
158
                len = strlen(data);                        \
159
                WRITE_CACHE_DATA_INT(len, fp);                \
160
                if (len > 0)                                \
161
                        fwrite(data, len, 1, fp);        \
162
        }                                                \
163
}
164

    
165
struct _MsgFlags
166
{
167
        MsgPermFlags perm_flags;
168
        MsgTmpFlags  tmp_flags;
169
};
170

    
171
struct _MsgInfo
172
{
173
        guint  msgnum;
174
        gsize  size;
175
        time_t mtime;
176
        time_t date_t;
177

    
178
        MsgFlags flags;
179

    
180
        gchar *fromname;
181

    
182
        gchar *date;
183
        gchar *from;
184
        gchar *to;
185
        gchar *cc;
186
        gchar *newsgroups;
187
        gchar *subject;
188
        gchar *msgid;
189
        gchar *inreplyto;
190

    
191
        GSList *references;
192

    
193
        FolderItem *folder;
194
        FolderItem *to_folder;
195

    
196
        gchar *xface;
197

    
198
        /* used only for temporary messages */
199
        gchar *file_path;
200

    
201
        /* used only for encrypted (and signed) messages */
202
        MsgEncryptInfo *encinfo;
203
};
204

    
205
struct _MsgFileInfo
206
{
207
        gchar *file;
208
        MsgFlags *flags;
209
};
210

    
211
struct _MsgEncryptInfo
212
{
213
        gchar *plaintext_file;
214
        gchar *sigstatus;
215
        gchar *sigstatus_full;
216
        gboolean decryption_failed;
217
};
218

    
219
typedef FILE * (*DecryptMessageFunc)                (MsgInfo        *msginfo,
220
                                                 MimeInfo      **mimeinfo);
221

    
222
GHashTable *procmsg_msg_hash_table_create        (GSList                *mlist);
223
void procmsg_msg_hash_table_append                (GHashTable        *msg_table,
224
                                                 GSList                *mlist);
225
GHashTable *procmsg_to_folder_hash_table_create        (GSList                *mlist);
226

    
227
gint procmsg_read_cache_data_str        (FILE                *fp,
228
                                         gchar               **str);
229

    
230
GSList *procmsg_read_cache                (FolderItem        *item,
231
                                         gboolean         scan_file);
232
void        procmsg_set_flags                (GSList                *mlist,
233
                                         FolderItem        *item);
234
void        procmsg_mark_all_read                (FolderItem        *item);
235
GSList *procmsg_sort_msg_list                (GSList                *mlist,
236
                                         FolderSortKey         sort_key,
237
                                         FolderSortType         sort_type);
238
gint        procmsg_get_last_num_in_msg_list(GSList                *mlist);
239
void        procmsg_msg_list_free                (GSList                *mlist);
240

    
241
void        procmsg_write_cache                (MsgInfo        *msginfo,
242
                                         FILE                *fp);
243
void        procmsg_write_flags                (MsgInfo        *msginfo,
244
                                         FILE                *fp);
245
void        procmsg_write_cache_list        (FolderItem        *item,
246
                                         GSList                *mlist);
247
void        procmsg_write_flags_list        (FolderItem        *item,
248
                                         GSList                *mlist);
249
void        procmsg_write_flags_for_multiple_folders
250
                                        (GSList                *mlist);
251

    
252
void        procmsg_flaginfo_list_free        (GSList                *flaglist);
253

    
254
void        procmsg_flush_mark_queue        (FolderItem        *item,
255
                                         FILE                *fp);
256
void        procmsg_add_mark_queue                (FolderItem        *item,
257
                                         gint                 num,
258
                                         MsgFlags         flags);
259
void        procmsg_flush_cache_queue        (FolderItem        *item,
260
                                         FILE                *fp);
261
void        procmsg_add_cache_queue                (FolderItem        *item,
262
                                         gint                 num,
263
                                         MsgInfo        *msginfo);
264

    
265
gboolean procmsg_flush_folder                (FolderItem        *item);
266
void        procmsg_flush_folder_foreach        (GHashTable        *folder_table);
267

    
268
void        procmsg_add_flags                (FolderItem        *item,
269
                                         gint                 num,
270
                                         MsgFlags         flags);
271

    
272
void        procmsg_get_mark_sum                (FolderItem        *item,
273
                                         gint                *new,
274
                                         gint                *unread,
275
                                         gint                *total,
276
                                         gint                *min,
277
                                         gint                *max,
278
                                         gint                 first);
279

    
280
FILE   *procmsg_open_data_file                (const gchar        *file,
281
                                         guint                 version,
282
                                         DataOpenMode         mode,
283
                                         gchar                *buf,
284
                                         size_t                 buf_size);
285

    
286
FILE   *procmsg_open_cache_file                (FolderItem        *item,
287
                                         DataOpenMode         mode);
288
FILE   *procmsg_open_mark_file                (FolderItem        *item,
289
                                         DataOpenMode         mode);
290

    
291
void        procmsg_clear_cache                (FolderItem        *item);
292
void        procmsg_clear_mark                (FolderItem        *item);
293

    
294
GNode  *procmsg_get_thread_tree                (GSList                *mlist);
295
guint        procmsg_get_thread_date                (GNode                *node);
296

    
297
gint        procmsg_move_messages                (GSList                *mlist);
298
gint        procmsg_copy_messages                (GSList                *mlist);
299

    
300
gint        procmsg_add_messages_from_queue        (FolderItem        *dest,
301
                                         GSList                *mlist,
302
                                         gboolean         is_move);
303

    
304
gchar  *procmsg_get_message_file_path        (MsgInfo        *msginfo);
305
gchar  *procmsg_get_message_file        (MsgInfo        *msginfo);
306
GSList *procmsg_get_message_file_list        (GSList                *mlist);
307
void        procmsg_message_file_list_free        (GSList                *file_list);
308
FILE   *procmsg_open_message                (MsgInfo        *msginfo);
309

    
310
void procmsg_set_decrypt_message_func        (DecryptMessageFunc         func);
311
void procmsg_set_auto_decrypt_message        (gboolean         enabled);
312
FILE   *procmsg_open_message_decrypted        (MsgInfo        *msginfo,
313
                                         MimeInfo      **mimeinfo);
314

    
315
gboolean procmsg_msg_exist                (MsgInfo        *msginfo);
316

    
317
gboolean procmsg_trash_messages_exist        (void);
318
void        procmsg_empty_trash                (FolderItem        *trash);
319
void        procmsg_empty_all_trash                (void);
320

    
321
void        procmsg_remove_all_cached_messages
322
                                        (Folder                *folder);
323

    
324
gint        procmsg_save_to_outbox                (FolderItem        *outbox,
325
                                         const gchar        *file);
326
void        procmsg_print_message                (MsgInfo        *msginfo,
327
                                         const gchar        *cmdline,
328
                                         gboolean         all_headers);
329
void        procmsg_print_message_part        (MsgInfo        *msginfo,
330
                                         MimeInfo        *partinfo,
331
                                         const gchar        *cmdline,
332
                                         gboolean         all_headers);
333

    
334
gint        procmsg_save_message_as_text        (MsgInfo        *msginfo,
335
                                         const gchar        *dest,
336
                                         const gchar        *encoding,
337
                                         gboolean         all_headers);
338

    
339
gint        procmsg_concat_partial_messages        (GSList                *mlist,
340
                                         const gchar        *file);
341

    
342
MsgInfo *procmsg_get_msginfo                (FolderItem        *item,
343
                                         gint                 num);
344

    
345
MsgInfo *procmsg_msginfo_copy                (MsgInfo        *msginfo);
346
MsgInfo *procmsg_msginfo_get_full_info        (MsgInfo        *msginfo);
347
gboolean procmsg_msginfo_equal                (MsgInfo        *msginfo_a,
348
                                         MsgInfo        *msginfo_b);
349
void         procmsg_msginfo_free                (MsgInfo        *msginfo);
350

    
351
gint procmsg_cmp_msgnum_for_sort        (gconstpointer         a,
352
                                         gconstpointer         b);
353

    
354
#endif /* __PROCMSG_H__ */