Refactor colors handling with more arrays
[claws.git] / src / procmime.h
blob5fae87a29b9d556fd2e97fb63af9aaebe812792c
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 "utils.h"
28 #include "proctypes.h"
29 typedef enum
31 ENC_7BIT,
32 ENC_8BIT,
33 ENC_BINARY,
34 ENC_QUOTED_PRINTABLE,
35 ENC_BASE64,
36 ENC_X_UUENCODE,
37 ENC_UNKNOWN
38 } EncodingType;
40 typedef enum
42 MIMETYPE_TEXT,
43 MIMETYPE_IMAGE,
44 MIMETYPE_AUDIO,
45 MIMETYPE_VIDEO,
46 MIMETYPE_APPLICATION,
47 MIMETYPE_MESSAGE,
48 MIMETYPE_MULTIPART,
49 MIMETYPE_UNKNOWN
50 } MimeMediaType;
52 typedef enum
54 DISPOSITIONTYPE_INLINE,
55 DISPOSITIONTYPE_ATTACHMENT,
56 DISPOSITIONTYPE_UNKNOWN
57 } DispositionType;
59 typedef enum
61 MIMECONTENT_EMPTY,
62 MIMECONTENT_FILE, /* the file contains all content including sub parts */
63 MIMECONTENT_MEM
64 } MimeContent;
66 #include <glib.h>
67 #include <stdio.h>
69 struct _PrivacyData;
71 struct _MimeType
73 gchar *type;
74 gchar *sub_type;
76 gchar *extension;
79 struct _MimeParser
81 MimeMediaType type;
82 const gchar *sub_type;
84 gboolean (*parse)(MimeParser *parser, MimeInfo *mimeinfo);
88 * An example of MimeInfo structure:
90 * 1: +- message/rfc822 (root)
91 * |
92 * 2: +- multipart/mixed (children of 1)
93 * |
94 * 3: +- multipart/alternative (children of 2)
95 * | |
96 * 4: | +- text/plain (children of 3)
97 * | |
98 * 5: | +- text/html (next of 4)
99 * |
100 * 6: +- message/rfc822 (next of 3)
101 * | |
102 * 7: | ... (children of 6)
104 * 8: +- image/jpeg (next of 6)
107 struct _MimeInfo
109 /* Internal data */
110 MimeContent content;
111 union
113 gchar *filename;
114 gchar *mem;
115 } data;
116 gboolean tmp;
118 GNode *node;
120 /* --- NEW MIME STUFF --- */
121 /* Content-Type */
122 MimeMediaType type;
123 gchar *subtype;
125 GHashTable *typeparameters;
127 /* Content-Transfer-Encoding */
128 EncodingType encoding_type;
130 /* Content-Description */
131 gchar *description;
133 /* Content-ID */
134 gchar *id;
136 /* Content-Location */
137 gchar *location;
139 guint offset;
140 guint length;
142 /* Content-Disposition */
143 DispositionType disposition;
144 GHashTable *dispositionparameters;
146 /* Privacy */
147 struct _PrivacyData *privacy;
149 gboolean broken;
152 #define IS_BOUNDARY(s, bnd, len) \
153 (bnd && s[0] == '-' && s[1] == '-' && !strncmp(s + 2, bnd, len))
155 #ifdef __cplusplus
156 extern "C" {
157 #endif /* __cplusplus */
159 /* MimeInfo handling */
161 MimeInfo *procmime_mimeinfo_new (void);
162 void procmime_mimeinfo_free_all (MimeInfo **mimeinfo_ptr);
164 MimeInfo *procmime_mimeinfo_insert (MimeInfo *parent,
165 MimeInfo *mimeinfo);
166 void procmime_mimeinfo_replace (MimeInfo *old_mimeinfo,
167 MimeInfo *new_mimeinfo);
169 MimeInfo *procmime_mimeinfo_parent (MimeInfo *mimeinfo);
170 MimeInfo *procmime_mimeinfo_next (MimeInfo *mimeinfo);
172 MimeInfo *procmime_scan_message (MsgInfo *msginfo);
173 MimeInfo *procmime_scan_message_short (MsgInfo *msginfo);
174 void procmime_scan_multipart_message (MimeInfo *mimeinfo,
175 FILE *fp);
176 const gchar *procmime_mimeinfo_get_parameter
177 (MimeInfo *mimeinfo,
178 const gchar *name);
180 /* scan headers */
182 void procmime_scan_encoding (MimeInfo *mimeinfo,
183 const gchar *encoding);
184 void procmime_scan_content_type (MimeInfo *mimeinfo,
185 const gchar *content_type);
186 void procmime_scan_content_disposition (MimeInfo *mimeinfo,
187 const gchar *content_disposition);
188 void procmime_scan_content_description (MimeInfo *mimeinfo,
189 const gchar *content_description);
190 void procmime_scan_subject (MimeInfo *mimeinfo,
191 const gchar *subject);
192 MimeInfo *procmime_scan_mime_header (FILE *fp);
194 gboolean procmime_decode_content (MimeInfo *mimeinfo);
195 gboolean procmime_encode_content (MimeInfo *mimeinfo, EncodingType encoding);
196 gint procmime_get_part (const gchar *outfile,
197 MimeInfo *mimeinfo);
198 FILE *procmime_get_first_text_content (MsgInfo *msginfo);
199 FILE *procmime_get_first_encrypted_text_content
200 (MsgInfo *msginfo);
202 gchar *procmime_get_tmp_file_name (MimeInfo *mimeinfo);
203 gchar *procmime_get_part_file_name (MimeInfo *mimeinfo);
205 gchar *procmime_get_mime_type (const gchar *filename);
207 GList *procmime_get_mime_type_list (void);
209 EncodingType procmime_get_encoding_for_charset (const gchar *charset);
210 EncodingType procmime_get_encoding_for_text_file(const gchar *file,
211 gboolean *has_binary);
212 const gchar *procmime_get_encoding_str (EncodingType encoding);
213 MimeInfo *procmime_scan_file (const gchar *filename);
214 MimeInfo *procmime_scan_queue_file (const gchar *filename);
215 const gchar *procmime_get_media_type_str (MimeMediaType type);
216 MimeMediaType procmime_get_media_type (const gchar *str);
217 gchar *procmime_get_content_type_str (MimeMediaType type,
218 const gchar *subtype);
219 void procmime_force_charset (const gchar *str);
220 void procmime_force_encoding (EncodingType encoding);
221 gboolean procmime_msginfo_is_encrypted (MsgInfo *msginfo);
222 int procmime_write_mime_header (MimeInfo *mimeinfo,
223 FILE *fp);
224 void renderer_read_config(void);
226 gint procmime_write_mimeinfo(MimeInfo *mimeinfo, FILE *fp);
228 void procmime_mimeparser_register(MimeParser *mimeparser);
229 void procmime_mimeparser_unregister(MimeParser *mimeparser);
230 FILE *procmime_get_text_content(MimeInfo *mimeinfo);
231 FILE *procmime_get_binary_content(MimeInfo *mimeinfo);
233 /* scans mimeinfo contents, calling scan_callback() once per line.
234 * return TRUE and scan is aborted if scan_callback returns TRUE.
235 * return TRUE on error.
236 * return FALSE if scan completed and scan_callback never returned TRUE.
238 gboolean procmime_scan_text_content(MimeInfo *mimeinfo,
239 gboolean (*scan_callback)(const gchar *str, gpointer cb_data),
240 gpointer cb_data);
241 #ifdef __cplusplus
243 #endif /* __cplusplus */
245 #endif /* __PROCMIME_H__ */