recognise model/* mime type
[claws.git] / src / procmime.h
blobac734471a69e4d974d606e192dc56b9afd64a26d
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
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.
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.
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/>.
20 #ifndef __PROCMIME_H__
21 #define __PROCMIME_H__
23 #ifdef HAVE_CONFIG_H
24 #include "claws-features.h"
25 #endif
27 #include <gio/gio.h>
29 #include "utils.h"
30 #include "proctypes.h"
31 typedef enum
33 ENC_7BIT,
34 ENC_8BIT,
35 ENC_BINARY,
36 ENC_QUOTED_PRINTABLE,
37 ENC_BASE64,
38 ENC_X_UUENCODE,
39 ENC_UNKNOWN
40 } EncodingType;
42 typedef enum
44 MIMETYPE_TEXT,
45 MIMETYPE_IMAGE,
46 MIMETYPE_AUDIO,
47 MIMETYPE_VIDEO,
48 MIMETYPE_APPLICATION,
49 MIMETYPE_MESSAGE,
50 MIMETYPE_MULTIPART,
51 MIMETYPE_MODEL,
52 MIMETYPE_UNKNOWN
53 } MimeMediaType;
55 typedef enum
57 DISPOSITIONTYPE_INLINE,
58 DISPOSITIONTYPE_ATTACHMENT,
59 DISPOSITIONTYPE_UNKNOWN
60 } DispositionType;
62 typedef enum
64 MIMECONTENT_EMPTY,
65 MIMECONTENT_FILE, /* the file contains all content including sub parts */
66 MIMECONTENT_MEM
67 } MimeContent;
69 #include <glib.h>
70 #include <stdio.h>
72 struct _PrivacyData;
74 struct _MimeType
76 gchar *type;
77 gchar *sub_type;
79 gchar *extension;
82 struct _MimeParser
84 MimeMediaType type;
85 const gchar *sub_type;
87 gboolean (*parse)(MimeParser *parser, MimeInfo *mimeinfo);
91 * An example of MimeInfo structure:
93 * 1: +- message/rfc822 (root)
94 * |
95 * 2: +- multipart/mixed (children of 1)
96 * |
97 * 3: +- multipart/alternative (children of 2)
98 * | |
99 * 4: | +- text/plain (children of 3)
100 * | |
101 * 5: | +- text/html (next of 4)
103 * 6: +- message/rfc822 (next of 3)
104 * | |
105 * 7: | ... (children of 6)
107 * 8: +- image/jpeg (next of 6)
110 struct _MimeInfo
112 /* Internal data */
113 MimeContent content;
114 union
116 gchar *filename;
117 gchar *mem;
118 } data;
119 gboolean tmp;
121 GNode *node;
123 /* --- NEW MIME STUFF --- */
124 /* Content-Type */
125 MimeMediaType type;
126 gchar *subtype;
128 GHashTable *typeparameters;
130 /* Content-Transfer-Encoding */
131 EncodingType encoding_type;
133 /* Content-Description */
134 gchar *description;
136 /* Content-ID */
137 gchar *id;
139 /* Content-Location */
140 gchar *location;
142 guint offset;
143 guint length;
145 /* Content-Disposition */
146 DispositionType disposition;
147 GHashTable *dispositionparameters;
149 /* Privacy */
150 struct _PrivacyData *privacy;
152 gboolean broken;
155 #define IS_BOUNDARY(s, bnd, len) \
156 (bnd && s[0] == '-' && s[1] == '-' && !strncmp(s + 2, bnd, len))
158 #ifdef __cplusplus
159 extern "C" {
160 #endif /* __cplusplus */
162 /* MimeInfo handling */
164 MimeInfo *procmime_mimeinfo_new (void);
165 void procmime_mimeinfo_free_all (MimeInfo **mimeinfo_ptr);
167 MimeInfo *procmime_mimeinfo_insert (MimeInfo *parent,
168 MimeInfo *mimeinfo);
169 void procmime_mimeinfo_replace (MimeInfo *old_mimeinfo,
170 MimeInfo *new_mimeinfo);
172 MimeInfo *procmime_mimeinfo_parent (MimeInfo *mimeinfo);
173 MimeInfo *procmime_mimeinfo_next (MimeInfo *mimeinfo);
175 MimeInfo *procmime_scan_message (MsgInfo *msginfo);
176 MimeInfo *procmime_scan_message_short (MsgInfo *msginfo);
177 void procmime_scan_multipart_message (MimeInfo *mimeinfo,
178 FILE *fp);
179 const gchar *procmime_mimeinfo_get_parameter
180 (MimeInfo *mimeinfo,
181 const gchar *name);
183 /* scan headers */
185 void procmime_scan_encoding (MimeInfo *mimeinfo,
186 const gchar *encoding);
187 void procmime_scan_content_type (MimeInfo *mimeinfo,
188 const gchar *content_type);
189 void procmime_scan_content_disposition (MimeInfo *mimeinfo,
190 const gchar *content_disposition);
191 void procmime_scan_content_description (MimeInfo *mimeinfo,
192 const gchar *content_description);
193 void procmime_scan_subject (MimeInfo *mimeinfo,
194 const gchar *subject);
195 MimeInfo *procmime_scan_mime_header (FILE *fp);
197 gboolean procmime_decode_content (MimeInfo *mimeinfo);
198 gboolean procmime_encode_content (MimeInfo *mimeinfo, EncodingType encoding);
199 gint procmime_get_part (const gchar *outfile,
200 MimeInfo *mimeinfo);
201 FILE *procmime_get_first_text_content (MsgInfo *msginfo);
202 FILE *procmime_get_first_encrypted_text_content
203 (MsgInfo *msginfo);
205 gchar *procmime_get_tmp_file_name (MimeInfo *mimeinfo);
206 gchar *procmime_get_part_file_name (MimeInfo *mimeinfo);
208 gchar *procmime_get_mime_type (const gchar *filename);
210 GList *procmime_get_mime_type_list (void);
212 EncodingType procmime_get_encoding_for_charset (const gchar *charset);
213 EncodingType procmime_get_encoding_for_text_file(const gchar *file,
214 gboolean *has_binary);
215 const gchar *procmime_get_encoding_str (EncodingType encoding);
216 MimeInfo *procmime_scan_file (const gchar *filename);
217 MimeInfo *procmime_scan_queue_file (const gchar *filename);
218 const gchar *procmime_get_media_type_str (MimeMediaType type);
219 MimeMediaType procmime_get_media_type (const gchar *str);
220 gchar *procmime_get_content_type_str (MimeMediaType type,
221 const gchar *subtype);
222 void procmime_force_charset (const gchar *str);
223 void procmime_force_encoding (EncodingType encoding);
224 gboolean procmime_msginfo_is_encrypted (MsgInfo *msginfo);
225 int procmime_write_mime_header (MimeInfo *mimeinfo,
226 FILE *fp);
227 void renderer_read_config(void);
229 gint procmime_write_mimeinfo(MimeInfo *mimeinfo, FILE *fp);
231 void procmime_mimeparser_register(MimeParser *mimeparser);
232 void procmime_mimeparser_unregister(MimeParser *mimeparser);
233 FILE *procmime_get_text_content(MimeInfo *mimeinfo);
234 FILE *procmime_get_binary_content(MimeInfo *mimeinfo);
236 /* scans mimeinfo contents, calling scan_callback() once per line.
237 * return TRUE and scan is aborted if scan_callback returns TRUE.
238 * return TRUE on error.
239 * return FALSE if scan completed and scan_callback never returned TRUE.
241 gboolean procmime_scan_text_content(MimeInfo *mimeinfo,
242 gboolean (*scan_callback)(const gchar *str, gpointer cb_data),
243 gpointer cb_data);
244 void *procmime_get_part_as_string(MimeInfo *mimeinfo,
245 gboolean null_terminate);
246 GInputStream *procmime_get_part_as_inputstream(MimeInfo *mimeinfo,
247 GError **error);
249 #ifdef __cplusplus
251 #endif /* __cplusplus */
253 #endif /* __PROCMIME_H__ */