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