* src/messageview.c
[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 #include "procmsg.h"
38
39 typedef enum
40 {
41         ENC_7BIT,
42         ENC_8BIT,
43         ENC_BINARY,
44         ENC_QUOTED_PRINTABLE,
45         ENC_BASE64,
46         ENC_X_UUENCODE,
47         ENC_UNKNOWN
48 } EncodingType;
49
50 typedef enum
51 {
52         MIME_TEXT,
53         MIME_TEXT_HTML,
54         MIME_MESSAGE_RFC822,
55         MIME_APPLICATION,
56         MIME_APPLICATION_OCTET_STREAM,
57         MIME_MULTIPART,
58         MIME_IMAGE,
59         MIME_AUDIO,
60         MIME_TEXT_ENRICHED,
61         MIME_UNKNOWN
62 } ContentType;
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 #endif
123
124         gint level;
125 };
126
127 #define IS_BOUNDARY(s, bnd, len) \
128         (bnd && s[0] == '-' && s[1] == '-' && !strncmp(s + 2, bnd, len))
129
130 /* MimeInfo handling */
131
132 MimeInfo *procmime_mimeinfo_new         (void);
133 void procmime_mimeinfo_free_all         (MimeInfo       *mimeinfo);
134
135 MimeInfo *procmime_mimeinfo_insert      (MimeInfo       *parent,
136                                          MimeInfo       *mimeinfo);
137 void procmime_mimeinfo_replace          (MimeInfo       *old_mimeinfo,
138                                          MimeInfo       *new_mimeinfo);
139
140 MimeInfo *procmime_mimeinfo_next        (MimeInfo       *mimeinfo);
141
142 MimeInfo *procmime_scan_message         (MsgInfo        *msginfo);
143 void procmime_scan_multipart_message    (MimeInfo       *mimeinfo,
144                                          FILE           *fp);
145
146 /* scan headers */
147
148 void procmime_scan_encoding             (MimeInfo       *mimeinfo,
149                                          const gchar    *encoding);
150 void procmime_scan_content_type         (MimeInfo       *mimeinfo,
151                                          const gchar    *content_type);
152 void procmime_scan_content_disposition  (MimeInfo       *mimeinfo,
153                                          const gchar    *content_disposition);
154 void procmime_scan_content_description  (MimeInfo       *mimeinfo,
155                                          const gchar    *content_description);
156 void procmime_scan_subject              (MimeInfo       *mimeinfo,
157                                          const gchar    *subject);
158 MimeInfo *procmime_scan_mime_header     (FILE           *fp);
159
160 FILE *procmime_decode_content           (FILE           *outfp,
161                                          FILE           *infp,
162                                          MimeInfo       *mimeinfo);
163 gint procmime_get_part                  (const gchar    *outfile,
164                                          const gchar    *infile,
165                                          MimeInfo       *mimeinfo);
166 FILE *procmime_get_text_content         (MimeInfo       *mimeinfo,
167                                          FILE           *infp);
168 FILE *procmime_get_first_text_content   (MsgInfo        *msginfo);
169
170 gboolean procmime_find_string_part      (MimeInfo       *mimeinfo,
171                                          const gchar    *filename,
172                                          const gchar    *str,
173                                          gboolean        case_sens);
174 gboolean procmime_find_string           (MsgInfo        *msginfo,
175                                          const gchar    *str,
176                                          gboolean        case_sens);
177
178 gchar *procmime_get_tmp_file_name       (MimeInfo       *mimeinfo);
179
180 ContentType procmime_scan_mime_type     (const gchar    *mime_type);
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
189 void renderer_read_config(void);
190 void renderer_write_config(void);
191
192 #ifdef __cplusplus
193 }
194 #endif /* __cplusplus */
195
196 #endif /* __PROCMIME_H__ */