code cleanup; bug fixes
[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 #include <glib.h>
58 #include <stdio.h>
59
60 #include "procmsg.h"
61 #include "privacy.h"
62
63 struct _MimeType
64 {
65         gchar *type;
66         gchar *sub_type;
67
68         gchar *extension;
69 };
70
71 /*
72  * An example of MimeInfo structure:
73  *
74  * 1: +- message/rfc822                 (root)
75  *       |
76  * 2:    +- multipart/mixed             (children of 1)
77  *          |
78  * 3:       +- multipart/alternative    (children of 2)
79  *          |  |
80  * 4:       |  +- text/plain            (children of 3)
81  *          |  |
82  * 5:       |  +- text/html             (next of 4)
83  *          |
84  * 6:       +- message/rfc822           (next of 3)
85  *          |   |
86  * 7:       |   ...                     (children of 6)
87  *          |
88  * 8:       +- image/jpeg               (next of 6)
89  */
90
91 struct _MimeInfo
92 {
93         gchar *encoding;
94
95         gchar *name;
96
97         gchar *content_disposition;
98
99         /* Internal data */
100         gchar *filename;
101         gboolean tmpfile;
102
103         GNode *node;
104
105         /* --- NEW MIME STUFF --- */
106         /* Content-Type */
107         MimeMediaType    type;
108         gchar           *subtype;
109
110         GHashTable      *parameters;
111
112         /* Content-Transfer-Encoding */
113         EncodingType     encoding_type;
114
115         /* Content-Description */
116         gchar           *description;
117
118         /* Content-ID */
119         gchar           *id;
120
121         guint            offset;
122         guint            length;
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 /* MimeInfo handling */
132
133 MimeInfo *procmime_mimeinfo_new         (void);
134 void procmime_mimeinfo_free_all         (MimeInfo       *mimeinfo);
135
136 MimeInfo *procmime_mimeinfo_insert      (MimeInfo       *parent,
137                                          MimeInfo       *mimeinfo);
138 void procmime_mimeinfo_replace          (MimeInfo       *old_mimeinfo,
139                                          MimeInfo       *new_mimeinfo);
140
141 MimeInfo *procmime_mimeinfo_parent      (MimeInfo       *mimeinfo);
142 MimeInfo *procmime_mimeinfo_next        (MimeInfo       *mimeinfo);
143
144 MimeInfo *procmime_scan_message         (MsgInfo        *msginfo);
145 void procmime_scan_multipart_message    (MimeInfo       *mimeinfo,
146                                          FILE           *fp);
147 const gchar *procmime_mimeinfo_get_parameter
148                                         (MimeInfo       *mimeinfo,
149                                          const gchar    *name);
150
151 /* scan headers */
152
153 void procmime_scan_encoding             (MimeInfo       *mimeinfo,
154                                          const gchar    *encoding);
155 void procmime_scan_content_type         (MimeInfo       *mimeinfo,
156                                          const gchar    *content_type);
157 void procmime_scan_content_disposition  (MimeInfo       *mimeinfo,
158                                          const gchar    *content_disposition);
159 void procmime_scan_content_description  (MimeInfo       *mimeinfo,
160                                          const gchar    *content_description);
161 void procmime_scan_subject              (MimeInfo       *mimeinfo,
162                                          const gchar    *subject);
163 MimeInfo *procmime_scan_mime_header     (FILE           *fp);
164
165 gboolean procmime_decode_content        (MimeInfo       *mimeinfo);
166 gint procmime_get_part                  (const gchar    *outfile,
167                                          MimeInfo       *mimeinfo);
168 FILE *procmime_get_text_content         (MimeInfo       *mimeinfo);
169 FILE *procmime_get_first_text_content   (MsgInfo        *msginfo);
170
171 gboolean procmime_find_string_part      (MimeInfo       *mimeinfo,
172                                          const gchar    *filename,
173                                          const gchar    *str,
174                                          gboolean        case_sens);
175 gboolean procmime_find_string           (MsgInfo        *msginfo,
176                                          const gchar    *str,
177                                          gboolean        case_sens);
178
179 gchar *procmime_get_tmp_file_name       (MimeInfo       *mimeinfo);
180
181 gchar *procmime_get_mime_type           (const gchar    *filename);
182
183 GList *procmime_get_mime_type_list      (void);
184
185 EncodingType procmime_get_encoding_for_charset  (const gchar    *charset);
186 EncodingType procmime_get_encoding_for_file     (const gchar    *file);
187 const gchar *procmime_get_encoding_str          (EncodingType    encoding);
188 MimeInfo *procmime_scan_file                    (gchar          *filename);
189 MimeInfo *procmime_scan_queue_file              (gchar          *filename);
190 const gchar *procmime_get_type_str              (MimeMediaType   type);
191
192 void renderer_read_config(void);
193 void renderer_write_config(void);
194
195 #ifdef __cplusplus
196 }
197 #endif /* __cplusplus */
198
199 #endif /* __PROCMIME_H__ */