2008-08-16 [colin] 3.5.0cvs61
[claws.git] / src / procmime.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
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 3 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, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifndef __PROCMIME_H__
21 #define __PROCMIME_H__
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 typedef struct _MimeType        MimeType;
28 typedef struct _MimeInfo        MimeInfo;
29 typedef struct _MimeParser      MimeParser;
30
31 #include "procmsg.h"
32 #include "utils.h"
33
34 typedef enum
35 {
36         ENC_7BIT,
37         ENC_8BIT,
38         ENC_BINARY,
39         ENC_QUOTED_PRINTABLE,
40         ENC_BASE64,
41         ENC_X_UUENCODE,
42         ENC_UNKNOWN
43 } EncodingType;
44
45 typedef enum
46 {
47         MIMETYPE_TEXT,
48         MIMETYPE_IMAGE,
49         MIMETYPE_AUDIO,
50         MIMETYPE_VIDEO,
51         MIMETYPE_APPLICATION,
52         MIMETYPE_MESSAGE,
53         MIMETYPE_MULTIPART,
54         MIMETYPE_UNKNOWN
55 } MimeMediaType;
56
57 typedef enum
58 {
59         DISPOSITIONTYPE_INLINE,
60         DISPOSITIONTYPE_ATTACHMENT,
61         DISPOSITIONTYPE_UNKNOWN
62 } DispositionType;
63
64 typedef enum
65 {
66         MIMECONTENT_EMPTY,
67         MIMECONTENT_FILE,               /* the file contains all content including sub parts */
68         MIMECONTENT_MEM
69 } MimeContent;
70
71 #include <glib.h>
72 #include <stdio.h>
73
74 #include "procmsg.h"
75 #include "privacy.h"
76
77 struct _MimeType
78 {
79         gchar *type;
80         gchar *sub_type;
81
82         gchar *extension;
83 };
84
85 struct _MimeParser
86 {
87         MimeMediaType type;
88         const gchar *sub_type;
89
90         gboolean (*parse)(MimeParser *parser, MimeInfo *mimeinfo);
91 };
92
93 /*
94  * An example of MimeInfo structure:
95  *
96  * 1: +- message/rfc822                 (root)
97  *       |
98  * 2:    +- multipart/mixed             (children of 1)
99  *          |
100  * 3:       +- multipart/alternative    (children of 2)
101  *          |  |
102  * 4:       |  +- text/plain            (children of 3)
103  *          |  |
104  * 5:       |  +- text/html             (next of 4)
105  *          |
106  * 6:       +- message/rfc822           (next of 3)
107  *          |   |
108  * 7:       |   ...                     (children of 6)
109  *          |
110  * 8:       +- image/jpeg               (next of 6)
111  */
112
113 struct _MimeInfo
114 {
115         /* Internal data */
116         MimeContent content;
117         union
118         {
119                 gchar *filename;
120                 gchar *mem;
121         } data;
122         gboolean tmp;
123
124         GNode *node;
125
126         /* --- NEW MIME STUFF --- */
127         /* Content-Type */
128         MimeMediaType    type;
129         gchar           *subtype;
130
131         GHashTable      *typeparameters;
132
133         /* Content-Transfer-Encoding */
134         EncodingType     encoding_type;
135
136         /* Content-Description */
137         gchar           *description;
138
139         /* Content-ID */
140         gchar           *id;
141
142         /* Content-Location */
143         gchar           *location;
144
145         guint            offset;
146         guint            length;
147
148         /* Content-Disposition */
149         DispositionType  disposition;
150         GHashTable      *dispositionparameters;
151
152         /* Privacy */
153         PrivacyData     *privacy;
154 };
155
156 #define IS_BOUNDARY(s, bnd, len) \
157         (bnd && s[0] == '-' && s[1] == '-' && !strncmp(s + 2, bnd, len))
158
159 #ifdef __cplusplus
160 extern "C" {
161 #endif /* __cplusplus */
162
163 /* MimeInfo handling */
164
165 MimeInfo *procmime_mimeinfo_new         (void);
166 void procmime_mimeinfo_free_all         (MimeInfo       *mimeinfo);
167
168 MimeInfo *procmime_mimeinfo_insert      (MimeInfo       *parent,
169                                          MimeInfo       *mimeinfo);
170 void procmime_mimeinfo_replace          (MimeInfo       *old_mimeinfo,
171                                          MimeInfo       *new_mimeinfo);
172
173 MimeInfo *procmime_mimeinfo_parent      (MimeInfo       *mimeinfo);
174 MimeInfo *procmime_mimeinfo_next        (MimeInfo       *mimeinfo);
175
176 MimeInfo *procmime_scan_message         (MsgInfo        *msginfo);
177 MimeInfo *procmime_scan_message_short   (MsgInfo        *msginfo);
178 void procmime_scan_multipart_message    (MimeInfo       *mimeinfo,
179                                          FILE           *fp);
180 const gchar *procmime_mimeinfo_get_parameter
181                                         (MimeInfo       *mimeinfo,
182                                          const gchar    *name);
183
184 /* scan headers */
185
186 void procmime_scan_encoding             (MimeInfo       *mimeinfo,
187                                          const gchar    *encoding);
188 void procmime_scan_content_type         (MimeInfo       *mimeinfo,
189                                          const gchar    *content_type);
190 void procmime_scan_content_disposition  (MimeInfo       *mimeinfo,
191                                          const gchar    *content_disposition);
192 void procmime_scan_content_description  (MimeInfo       *mimeinfo,
193                                          const gchar    *content_description);
194 void procmime_scan_subject              (MimeInfo       *mimeinfo,
195                                          const gchar    *subject);
196 MimeInfo *procmime_scan_mime_header     (FILE           *fp);
197
198 gboolean procmime_decode_content        (MimeInfo       *mimeinfo);
199 gboolean procmime_encode_content        (MimeInfo       *mimeinfo, EncodingType encoding);
200 gint procmime_get_part                  (const gchar    *outfile,
201                                          MimeInfo       *mimeinfo);
202 FILE *procmime_get_first_text_content   (MsgInfo        *msginfo);
203 FILE *procmime_get_first_encrypted_text_content
204                                         (MsgInfo        *msginfo);
205
206 gboolean procmime_find_string           (MsgInfo        *msginfo,
207                                          const gchar    *str,
208                                          StrFindFunc     find_func);
209
210 gchar *procmime_get_tmp_file_name       (MimeInfo       *mimeinfo);
211 gchar *procmime_get_part_file_name      (MimeInfo       *mimeinfo);
212
213 gchar *procmime_get_mime_type           (const gchar    *filename);
214
215 GList *procmime_get_mime_type_list      (void);
216
217 EncodingType procmime_get_encoding_for_charset  (const gchar    *charset);
218 EncodingType procmime_get_encoding_for_text_file(const gchar    *file,
219                                                  gboolean       *has_binary);
220 const gchar *procmime_get_encoding_str          (EncodingType    encoding);
221 MimeInfo *procmime_scan_file                    (const gchar    *filename);
222 MimeInfo *procmime_scan_queue_file              (const gchar    *filename);
223 const gchar *procmime_get_media_type_str        (MimeMediaType   type);
224 MimeMediaType procmime_get_media_type           (const gchar    *str);
225 gchar *procmime_get_content_type_str            (MimeMediaType   type,
226                                                  const gchar    *subtype);
227 void procmime_force_charset                     (const gchar    *str);
228 void procmime_force_encoding                    (EncodingType    encoding);
229 gboolean procmime_msginfo_is_encrypted          (MsgInfo        *msginfo);
230 int procmime_write_mime_header                  (MimeInfo       *mimeinfo, 
231                                                  FILE           *fp);
232 void renderer_read_config(void);
233
234 gint procmime_write_mimeinfo(MimeInfo *mimeinfo, FILE *fp);
235
236 void procmime_mimeparser_register(MimeParser *mimeparser);
237 void procmime_mimeparser_unregister(MimeParser *mimeparser);
238
239 #ifdef __cplusplus
240 }
241 #endif /* __cplusplus */
242
243 #endif /* __PROCMIME_H__ */