Statistics
| Revision:

root / libsylph / procmsg.h @ 3245

History | View | Annotate | Download (10.1 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_FLAG_CHANGED        (1U << 27)
93
#define MSG_CACHED                (1U << 28)
94
#define MSG_MIME                (1U << 29)
95
#define MSG_INVALID                (1U << 30)
96
#define MSG_RECEIVED                (1U << 31)
97

    
98
#define MSG_CACHED_FLAG_MASK        (MSG_MIME)
99

    
100
typedef guint32 MsgTmpFlags;
101

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

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

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

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

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

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

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

    
163
struct _MsgFlags
164
{
165
        MsgPermFlags perm_flags;
166
        MsgTmpFlags  tmp_flags;
167
};
168

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

    
176
        MsgFlags flags;
177

    
178
        gchar *fromname;
179

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

    
189
        GSList *references;
190

    
191
        FolderItem *folder;
192
        FolderItem *to_folder;
193

    
194
        gchar *xface;
195

    
196
        /* used only for temporary messages */
197
        gchar *file_path;
198

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

    
203
struct _MsgFileInfo
204
{
205
        gchar *file;
206
        MsgFlags *flags;
207
};
208

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

    
217
typedef FILE * (*DecryptMessageFunc)                (MsgInfo        *msginfo,
218
                                                 MimeInfo      **mimeinfo);
219

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

    
225
gint procmsg_read_cache_data_str        (FILE                *fp,
226
                                         gchar               **str);
227

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

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

    
250
void        procmsg_flaginfo_list_free        (GSList                *flaglist);
251

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

    
263
gboolean procmsg_flush_folder                (FolderItem        *item);
264
void        procmsg_flush_folder_foreach        (GHashTable        *folder_table);
265

    
266
void        procmsg_add_flags                (FolderItem        *item,
267
                                         gint                 num,
268
                                         MsgFlags         flags);
269

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

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

    
284
FILE   *procmsg_open_cache_file                (FolderItem        *item,
285
                                         DataOpenMode         mode);
286
FILE   *procmsg_open_mark_file                (FolderItem        *item,
287
                                         DataOpenMode         mode);
288

    
289
void        procmsg_clear_cache                (FolderItem        *item);
290
void        procmsg_clear_mark                (FolderItem        *item);
291

    
292
GNode  *procmsg_get_thread_tree                (GSList                *mlist);
293
guint        procmsg_get_thread_date                (GNode                *node);
294

    
295
gint        procmsg_move_messages                (GSList                *mlist);
296
gint        procmsg_copy_messages                (GSList                *mlist);
297

    
298
gint        procmsg_add_messages_from_queue        (FolderItem        *dest,
299
                                         GSList                *mlist,
300
                                         gboolean         is_move);
301

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

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

    
313
gboolean procmsg_msg_exist                (MsgInfo        *msginfo);
314

    
315
gboolean procmsg_trash_messages_exist        (void);
316
void        procmsg_empty_trash                (FolderItem        *trash);
317
void        procmsg_empty_all_trash                (void);
318

    
319
void        procmsg_remove_all_cached_messages
320
                                        (Folder                *folder);
321

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

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

    
337
gint        procmsg_concat_partial_messages        (GSList                *mlist,
338
                                         const gchar        *file);
339

    
340
MsgInfo *procmsg_get_msginfo                (FolderItem        *item,
341
                                         gint                 num);
342

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

    
349
gint procmsg_cmp_msgnum_for_sort        (gconstpointer         a,
350
                                         gconstpointer         b);
351

    
352
#endif /* __PROCMSG_H__ */