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