Fix CID 1596595: Resource leak
[claws.git] / src / procmime.h
blobba385cca8ce5ccf36dfffe60e05e5d8c2fdc784a
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2023 the Claws Mail team and Hiroyuki Yamamoto
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>
28 #include <gtk/gtk.h>
30 #include "utils.h"
31 #include "proctypes.h"
32 #include "privacy.h"
33 typedef enum
35 ENC_7BIT,
36 ENC_8BIT,
37 ENC_BINARY,
38 ENC_QUOTED_PRINTABLE,
39 ENC_BASE64,
40 ENC_X_UUENCODE,
41 ENC_UNKNOWN
42 } EncodingType;
44 typedef enum
46 MIMETYPE_TEXT,
47 MIMETYPE_IMAGE,
48 MIMETYPE_AUDIO,
49 MIMETYPE_VIDEO,
50 MIMETYPE_APPLICATION,
51 MIMETYPE_MESSAGE,
52 MIMETYPE_MULTIPART,
53 MIMETYPE_FONT,
54 MIMETYPE_MODEL,
55 MIMETYPE_CHEMICAL,
56 MIMETYPE_UNKNOWN
57 } MimeMediaType;
59 typedef enum
61 DISPOSITIONTYPE_INLINE,
62 DISPOSITIONTYPE_ATTACHMENT,
63 DISPOSITIONTYPE_UNKNOWN
64 } DispositionType;
66 typedef enum
68 MIMECONTENT_EMPTY,
69 MIMECONTENT_FILE, /* the file contains all content including sub parts */
70 MIMECONTENT_MEM
71 } MimeContent;
73 #include <glib.h>
74 #include <stdio.h>
76 struct _PrivacyData;
78 struct _MimeType
80 gchar *type;
81 gchar *sub_type;
83 gchar *extension;
86 struct _MimeParser
88 MimeMediaType type;
89 const gchar *sub_type;
91 gboolean (*parse)(MimeParser *parser, MimeInfo *mimeinfo);
95 * An example of MimeInfo structure:
97 * 1: +- message/rfc822 (root)
98 * |
99 * 2: +- multipart/mixed (children of 1)
101 * 3: +- multipart/alternative (children of 2)
102 * | |
103 * 4: | +- text/plain (children of 3)
104 * | |
105 * 5: | +- text/html (next of 4)
107 * 6: +- message/rfc822 (next of 3)
108 * | |
109 * 7: | ... (children of 6)
111 * 8: +- image/jpeg (next of 6)
114 struct _MimeInfo
116 /* Internal data */
117 MimeContent content;
118 union
120 gchar *filename;
121 gchar *mem;
122 } data;
123 gboolean tmp;
125 GNode *node;
127 /* --- NEW MIME STUFF --- */
128 /* Content-Type */
129 MimeMediaType type;
130 gchar *subtype;
132 GHashTable *typeparameters;
134 /* Content-Transfer-Encoding */
135 EncodingType encoding_type;
137 /* Content-Description */
138 gchar *description;
140 /* Content-ID */
141 gchar *id;
143 /* Content-Location */
144 gchar *location;
146 guint offset;
147 guint length;
149 /* Content-Disposition */
150 DispositionType disposition;
151 GHashTable *dispositionparameters;
153 /* Privacy */
154 struct _PrivacyData *privacy;
155 GTask *last_sig_check_task;
156 SignatureData *sig_data;
158 gboolean broken;
161 #define IS_BOUNDARY(s, bnd, len) \
162 (bnd && s[0] == '-' && s[1] == '-' && !strncmp(s + 2, bnd, len))
164 #ifdef __cplusplus
165 extern "C" {
166 #endif /* __cplusplus */
168 /* MimeInfo handling */
170 MimeInfo *procmime_mimeinfo_new (void);
171 void procmime_mimeinfo_free_all (MimeInfo **mimeinfo_ptr);
173 MimeInfo *procmime_mimeinfo_insert (MimeInfo *parent,
174 MimeInfo *mimeinfo);
175 void procmime_mimeinfo_replace (MimeInfo *old_mimeinfo,
176 MimeInfo *new_mimeinfo);
178 MimeInfo *procmime_mimeinfo_parent (MimeInfo *mimeinfo);
179 MimeInfo *procmime_mimeinfo_next (MimeInfo *mimeinfo);
181 MimeInfo *procmime_scan_message (MsgInfo *msginfo);
182 MimeInfo *procmime_scan_message_short (MsgInfo *msginfo);
183 void procmime_scan_multipart_message (MimeInfo *mimeinfo,
184 FILE *fp);
185 const gchar *procmime_mimeinfo_get_parameter
186 (MimeInfo *mimeinfo,
187 const gchar *name);
189 /* scan headers */
191 void procmime_scan_encoding (MimeInfo *mimeinfo,
192 const gchar *encoding);
193 void procmime_scan_content_type (MimeInfo *mimeinfo,
194 const gchar *content_type);
195 void procmime_scan_content_disposition (MimeInfo *mimeinfo,
196 const gchar *content_disposition);
197 void procmime_scan_content_description (MimeInfo *mimeinfo,
198 const gchar *content_description);
199 void procmime_scan_subject (MimeInfo *mimeinfo,
200 const gchar *subject);
201 MimeInfo *procmime_scan_mime_header (FILE *fp);
203 gboolean procmime_decode_content (MimeInfo *mimeinfo);
204 gboolean procmime_encode_content (MimeInfo *mimeinfo, EncodingType encoding);
205 gint procmime_get_part (const gchar *outfile,
206 MimeInfo *mimeinfo);
207 FILE *procmime_get_first_text_content (MsgInfo *msginfo);
208 FILE *procmime_get_first_encrypted_text_content
209 (MsgInfo *msginfo);
211 gchar *procmime_get_tmp_file_name (MimeInfo *mimeinfo);
212 gchar *procmime_get_part_file_name (MimeInfo *mimeinfo);
214 gchar *procmime_get_mime_type (const gchar *filename);
216 GList *procmime_get_mime_type_list (void);
218 EncodingType procmime_get_encoding_for_charset (const gchar *charset);
219 EncodingType procmime_get_encoding_for_text_file(const gchar *file,
220 gboolean *has_binary);
221 const gchar *procmime_get_encoding_str (EncodingType encoding);
222 MimeInfo *procmime_scan_file (const gchar *filename);
223 MimeInfo *procmime_scan_queue_file (const gchar *filename);
224 const gchar *procmime_get_media_type_str (MimeMediaType type);
225 MimeMediaType procmime_get_media_type (const gchar *str);
226 gchar *procmime_get_content_type_str (MimeMediaType type,
227 const gchar *subtype);
228 void procmime_force_charset (const gchar *str);
229 void procmime_force_encoding (EncodingType encoding);
230 gboolean procmime_msginfo_is_encrypted (MsgInfo *msginfo);
231 int procmime_write_mime_header (MimeInfo *mimeinfo,
232 FILE *fp);
233 void renderer_read_config(void);
235 gint procmime_write_mimeinfo(MimeInfo *mimeinfo, FILE *fp);
237 void procmime_mimeparser_register(MimeParser *mimeparser);
238 void procmime_mimeparser_unregister(MimeParser *mimeparser);
239 FILE *procmime_get_text_content(MimeInfo *mimeinfo);
240 FILE *procmime_get_binary_content(MimeInfo *mimeinfo);
242 /* scans mimeinfo contents, calling scan_callback() once per line.
243 * return TRUE and scan is aborted if scan_callback returns TRUE.
244 * return TRUE on error.
245 * return FALSE if scan completed and scan_callback never returned TRUE.
247 gboolean procmime_scan_text_content(MimeInfo *mimeinfo,
248 gboolean (*scan_callback)(const gchar *str, gpointer cb_data),
249 gpointer cb_data);
250 void *procmime_get_part_as_string(MimeInfo *mimeinfo,
251 gboolean null_terminate);
252 GInputStream *procmime_get_part_as_inputstream(MimeInfo *mimeinfo);
253 GdkPixbuf *procmime_get_part_as_pixbuf(MimeInfo *mimeinfo, GError **error);
255 #ifdef __cplusplus
257 #endif /* __cplusplus */
259 #endif /* __PROCMIME_H__ */