cd309511dceb171376bae72c9781e3f8692d39b9
[claws.git] / src / procmime.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 Hiroyuki Yamamoto
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 2 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, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __PROCMIME_H__
21 #define __PROCMIME_H__
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif /* __cplusplus */
26
27 #ifdef HAVE_CONFIG_H
28 #  include "config.h"
29 #endif
30
31 typedef struct _MimeType        MimeType;
32 typedef struct _MimeInfo        MimeInfo;
33
34 typedef enum
35 {
36         ENC_7BIT,
37         ENC_8BIT,
38         ENC_BINARY,
39         ENC_QUOTED_PRINTABLE,
40         ENC_BASE64,
41         ENC_X_UUENCODE,
42         ENC_UNKNOWN
43 } EncodingType;
44
45 typedef enum
46 {
47         MIMETYPE_TEXT,
48         MIMETYPE_IMAGE,
49         MIMETYPE_AUDIO,
50         MIMETYPE_VIDEO,
51         MIMETYPE_APPLICATION,
52         MIMETYPE_MESSAGE,
53         MIMETYPE_MULTIPART,
54         MIMETYPE_UNKNOWN,
55 } MimeMediaType;
56
57 typedef enum
58 {
59         DISPOSITIONTYPE_INLINE,
60         DISPOSITIONTYPE_ATTACHMENT,
61         DISPOSITIONTYPE_UNKNOWN
62 } DispositionType;
63
64 #include <glib.h>
65 #include <stdio.h>
66
67 #include "procmsg.h"
68 #include "privacy.h"
69
70 struct _MimeType
71 {
72         gchar *type;
73         gchar *sub_type;
74
75         gchar *extension;
76 };
77
78 /*
79  * An example of MimeInfo structure:
80  *
81  * 1: +- message/rfc822                 (root)
82  *       |
83  * 2:    +- multipart/mixed             (children of 1)
84  *          |
85  * 3:       +- multipart/alternative    (children of 2)
86  *          |  |
87  * 4:       |  +- text/plain            (children of 3)
88  *          |  |
89  * 5:       |  +- text/html             (next of 4)
90  *          |
91  * 6:       +- message/rfc822           (next of 3)
92  *          |   |
93  * 7:       |   ...                     (children of 6)
94  *          |
95  * 8:       +- image/jpeg               (next of 6)
96  */
97
98 struct _MimeInfo
99 {
100         gchar *encoding;
101
102         gchar *name;
103
104         /* Internal data */
105         gchar *filename;
106         gboolean tmpfile;
107
108         GNode *node;
109
110         /* --- NEW MIME STUFF --- */
111         /* Content-Type */
112         MimeMediaType    type;
113         gchar           *subtype;
114
115         GHashTable      *parameters;
116
117         /* Content-Transfer-Encoding */
118         EncodingType     encoding_type;
119
120         /* Content-Description */
121         gchar           *description;
122
123         /* Content-ID */
124         gchar           *id;
125
126         guint            offset;
127         guint            length;
128
129         /* Content-Disposition */
130         DispositionType  disposition;
131
132         /* Privacy */
133         PrivacyData     *privacy;
134 };
135
136 #define IS_BOUNDARY(s, bnd, len) \
137         (bnd && s[0] == '-' && s[1] == '-' && !strncmp(s + 2, bnd, len))
138
139 /* MimeInfo handling */
140
141 MimeInfo *procmime_mimeinfo_new         (void);
142 void procmime_mimeinfo_free_all         (MimeInfo       *mimeinfo);
143
144 MimeInfo *procmime_mimeinfo_insert      (MimeInfo       *parent,
145                                          MimeInfo       *mimeinfo);
146 void procmime_mimeinfo_replace          (MimeInfo       *old_mimeinfo,
147                                          MimeInfo       *new_mimeinfo);
148
149 MimeInfo *procmime_mimeinfo_parent      (MimeInfo       *mimeinfo);
150 MimeInfo *procmime_mimeinfo_next        (MimeInfo       *mimeinfo);
151
152 MimeInfo *procmime_scan_message         (MsgInfo        *msginfo);
153 void procmime_scan_multipart_message    (MimeInfo       *mimeinfo,
154                                          FILE           *fp);
155 const gchar *procmime_mimeinfo_get_parameter
156                                         (MimeInfo       *mimeinfo,
157                                          const gchar    *name);
158
159 /* scan headers */
160
161 void procmime_scan_encoding             (MimeInfo       *mimeinfo,
162                                          const gchar    *encoding);
163 void procmime_scan_content_type         (MimeInfo       *mimeinfo,
164                                          const gchar    *content_type);
165 void procmime_scan_content_disposition  (MimeInfo       *mimeinfo,
166                                          const gchar    *content_disposition);
167 void procmime_scan_content_description  (MimeInfo       *mimeinfo,
168                                          const gchar    *content_description);
169 void procmime_scan_subject              (MimeInfo       *mimeinfo,
170                                          const gchar    *subject);
171 MimeInfo *procmime_scan_mime_header     (FILE           *fp);
172
173 gboolean procmime_decode_content        (MimeInfo       *mimeinfo);
174 gint procmime_get_part                  (const gchar    *outfile,
175                                          MimeInfo       *mimeinfo);
176 FILE *procmime_get_text_content         (MimeInfo       *mimeinfo);
177 FILE *procmime_get_first_text_content   (MsgInfo        *msginfo);
178
179 gboolean procmime_find_string_part      (MimeInfo       *mimeinfo,
180                                          const gchar    *filename,
181                                          const gchar    *str,
182                                          gboolean        case_sens);
183 gboolean procmime_find_string           (MsgInfo        *msginfo,
184                                          const gchar    *str,
185                                          gboolean        case_sens);
186
187 gchar *procmime_get_tmp_file_name       (MimeInfo       *mimeinfo);
188
189 gchar *procmime_get_mime_type           (const gchar    *filename);
190
191 GList *procmime_get_mime_type_list      (void);
192
193 EncodingType procmime_get_encoding_for_charset  (const gchar    *charset);
194 EncodingType procmime_get_encoding_for_file     (const gchar    *file);
195 const gchar *procmime_get_encoding_str          (EncodingType    encoding);
196 MimeInfo *procmime_scan_file                    (gchar          *filename);
197 MimeInfo *procmime_scan_queue_file              (gchar          *filename);
198 const gchar *procmime_get_type_str              (MimeMediaType   type);
199
200 void renderer_read_config(void);
201 void renderer_write_config(void);
202
203 #ifdef __cplusplus
204 }
205 #endif /* __cplusplus */
206
207 #endif /* __PROCMIME_H__ */