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