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