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