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