0.9.6claws1
[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 typedef enum
49 {
50         MIME_TEXT,
51         MIME_TEXT_HTML,
52         MIME_MESSAGE_RFC822,
53         MIME_APPLICATION,
54         MIME_APPLICATION_OCTET_STREAM,
55         MIME_MULTIPART,
56         MIME_IMAGE,
57         MIME_AUDIO,
58         MIME_TEXT_ENRICHED,
59         MIME_UNKNOWN
60 } ContentType;
61
62 #include "procmsg.h"
63
64 struct _MimeType
65 {
66         gchar *type;
67         gchar *sub_type;
68
69         gchar *extension;
70 };
71
72 /*
73  * An example of MimeInfo structure:
74  *
75  * multipart/mixed            root  <-+ parent
76  *                                    |
77  *   multipart/alternative      children <-+ parent
78  *                                         |
79  *     text/plain                 children  --+
80  *                                            |
81  *     text/html                  next      <-+
82  *
83  *   message/rfc822             next  <-+ main
84  *                                      |
85  *                                sub (capsulated message)
86  *
87  *   image/jpeg                 next
88  */
89
90 struct _MimeInfo
91 {
92         gchar *encoding;
93
94         EncodingType encoding_type;
95         ContentType  mime_type;
96
97         gchar *content_type;
98         gchar *charset;
99         gchar *name;
100         gchar *boundary;
101
102         gchar *content_disposition;
103         gchar *filename;
104         gchar *description;
105
106         glong fpos;
107         guint size;
108
109         MimeInfo *main;
110         MimeInfo *sub;
111
112         MimeInfo *next;
113         MimeInfo *parent;
114         MimeInfo *children;
115
116 #if USE_GPGME
117         MimeInfo *plaintext;
118         gchar *plaintextfile;
119         gchar *sigstatus;
120         gchar *sigstatus_full;
121         gboolean sig_ok;
122         gboolean sig_unknown;
123         gboolean sig_expired;
124         gboolean key_expired;
125 #endif
126
127         gint level;
128 };
129
130 #define IS_BOUNDARY(s, bnd, len) \
131         (bnd && s[0] == '-' && s[1] == '-' && !strncmp(s + 2, bnd, len))
132
133 /* MimeInfo handling */
134
135 MimeInfo *procmime_mimeinfo_new         (void);
136 void procmime_mimeinfo_free_all         (MimeInfo       *mimeinfo);
137
138 MimeInfo *procmime_mimeinfo_insert      (MimeInfo       *parent,
139                                          MimeInfo       *mimeinfo);
140 void procmime_mimeinfo_replace          (MimeInfo       *old_mimeinfo,
141                                          MimeInfo       *new_mimeinfo);
142
143 MimeInfo *procmime_mimeinfo_next        (MimeInfo       *mimeinfo);
144
145 MimeInfo *procmime_scan_message         (MsgInfo        *msginfo);
146 void procmime_scan_multipart_message    (MimeInfo       *mimeinfo,
147                                          FILE           *fp);
148
149 /* scan headers */
150
151 void procmime_scan_encoding             (MimeInfo       *mimeinfo,
152                                          const gchar    *encoding);
153 void procmime_scan_content_type         (MimeInfo       *mimeinfo,
154                                          const gchar    *content_type);
155 void procmime_scan_content_disposition  (MimeInfo       *mimeinfo,
156                                          const gchar    *content_disposition);
157 void procmime_scan_content_description  (MimeInfo       *mimeinfo,
158                                          const gchar    *content_description);
159 void procmime_scan_subject              (MimeInfo       *mimeinfo,
160                                          const gchar    *subject);
161 MimeInfo *procmime_scan_mime_header     (FILE           *fp);
162
163 FILE *procmime_decode_content           (FILE           *outfp,
164                                          FILE           *infp,
165                                          MimeInfo       *mimeinfo);
166 gint procmime_get_part                  (const gchar    *outfile,
167                                          const gchar    *infile,
168                                          MimeInfo       *mimeinfo);
169 FILE *procmime_get_text_content         (MimeInfo       *mimeinfo,
170                                          FILE           *infp);
171 FILE *procmime_get_first_text_content   (MsgInfo        *msginfo);
172
173 gboolean procmime_find_string_part      (MimeInfo       *mimeinfo,
174                                          const gchar    *filename,
175                                          const gchar    *str,
176                                          gboolean        case_sens);
177 gboolean procmime_find_string           (MsgInfo        *msginfo,
178                                          const gchar    *str,
179                                          gboolean        case_sens);
180
181 gchar *procmime_get_tmp_file_name       (MimeInfo       *mimeinfo);
182
183 ContentType procmime_scan_mime_type     (const gchar    *mime_type);
184 gchar *procmime_get_mime_type           (const gchar    *filename);
185
186 GList *procmime_get_mime_type_list      (void);
187
188 EncodingType procmime_get_encoding_for_charset  (const gchar    *charset);
189 EncodingType procmime_get_encoding_for_file     (const gchar    *file);
190 const gchar *procmime_get_encoding_str          (EncodingType    encoding);
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__ */