summaryrefslogtreecommitdiff
path: root/libsylph/procmime.h
diff options
context:
space:
mode:
Diffstat (limited to 'libsylph/procmime.h')
-rw-r--r--libsylph/procmime.h213
1 files changed, 213 insertions, 0 deletions
diff --git a/libsylph/procmime.h b/libsylph/procmime.h
new file mode 100644
index 0000000..0242d34
--- /dev/null
+++ b/libsylph/procmime.h
@@ -0,0 +1,213 @@
1/*
2 * LibSylph -- E-Mail client library
3 * Copyright (C) 1999-2010 Hiroyuki Yamamoto
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library 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 GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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
30typedef struct _MimeType MimeType;
31typedef struct _MailCap MailCap;
32typedef struct _MimeInfo MimeInfo;
33
34#include "procmsg.h"
35#include "utils.h"
36
37typedef enum
38{
39 ENC_7BIT,
40 ENC_8BIT,
41 ENC_QUOTED_PRINTABLE,
42 ENC_BASE64,
43 ENC_X_UUENCODE,
44 ENC_UNKNOWN
45} EncodingType;
46
47typedef enum
48{
49 MIME_TEXT,
50 MIME_TEXT_HTML,
51 MIME_MESSAGE_RFC822,
52 MIME_APPLICATION,
53 MIME_APPLICATION_OCTET_STREAM,
54 MIME_MULTIPART,
55 MIME_IMAGE,
56 MIME_AUDIO,
57 MIME_VIDEO,
58 MIME_UNKNOWN
59} ContentType;
60
61struct _MimeType
62{
63 gchar *type;
64 gchar *sub_type;
65
66 gchar *extension;
67};
68
69struct _MailCap
70{
71 gchar *mime_type;
72 gchar *cmdline_fmt;
73 gboolean needs_terminal;
74};
75
76/*
77 * An example of MimeInfo structure:
78 *
79 * multipart/mixed root <-+ parent
80 * |
81 * multipart/alternative children <-+ parent
82 * |
83 * text/plain children --+
84 * |
85 * text/html next <-+
86 *
87 * message/rfc822 next <-+ main
88 * |
89 * sub (capsulated message)
90 *
91 * image/jpeg next
92 */
93
94struct _MimeInfo
95{
96 gchar *encoding;
97
98 EncodingType encoding_type;
99 ContentType mime_type;
100
101 gchar *content_type;
102 gchar *charset;
103 gchar *name;
104 gchar *boundary;
105
106 gchar *content_disposition;
107 gchar *filename;
108
109 glong fpos;
110 guint size;
111 guint content_size;
112
113 MimeInfo *main;
114 MimeInfo *sub;
115
116 MimeInfo *next;
117 MimeInfo *parent;
118 MimeInfo *children;
119
120 MimeInfo *plaintext;
121 gchar *sigstatus;
122 gchar *sigstatus_full;
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
132MimeInfo *procmime_mimeinfo_new (void);
133void procmime_mimeinfo_free_all (MimeInfo *mimeinfo);
134
135MimeInfo *procmime_mimeinfo_insert (MimeInfo *parent,
136 MimeInfo *mimeinfo);
137#if 0
138void procmime_mimeinfo_replace (MimeInfo *old,
139 MimeInfo *new);
140#endif
141
142MimeInfo *procmime_mimeinfo_next (MimeInfo *mimeinfo);
143
144MimeInfo *procmime_scan_message (MsgInfo *msginfo);
145MimeInfo *procmime_scan_message_stream (FILE *fp);
146void procmime_scan_multipart_message (MimeInfo *mimeinfo,
147 FILE *fp);
148
149/* scan headers */
150
151void procmime_scan_encoding (MimeInfo *mimeinfo,
152 const gchar *encoding);
153void procmime_scan_content_type (MimeInfo *mimeinfo,
154 const gchar *content_type);
155void procmime_scan_content_type_str (const gchar *content_type,
156 gchar **mime_type,
157 gchar **charset,
158 gchar **name,
159 gchar **boundary);
160void procmime_scan_content_type_partial (const gchar *content_type,
161 gint *total,
162 gchar **part_id,
163 gint *number);
164void procmime_scan_content_disposition (MimeInfo *mimeinfo,
165 const gchar *content_disposition);
166MimeInfo *procmime_scan_mime_header (FILE *fp);
167
168FILE *procmime_decode_content (FILE *outfp,
169 FILE *infp,
170 MimeInfo *mimeinfo);
171gint procmime_get_part (const gchar *outfile,
172 const gchar *infile,
173 MimeInfo *mimeinfo);
174gint procmime_get_part_fp (const gchar *outfile,
175 FILE *infp,
176 MimeInfo *mimeinfo);
177FILE *procmime_get_part_fp_fp (FILE *outfp,
178 FILE *infp,
179 MimeInfo *mimeinfo);
180gint procmime_get_all_parts (const gchar *dir,
181 const gchar *infile,
182 MimeInfo *mimeinfo);
183FILE *procmime_get_text_content (MimeInfo *mimeinfo,
184 FILE *infp,
185 const gchar *encoding);
186FILE *procmime_get_first_text_content (MsgInfo *msginfo,
187 const gchar *encoding);
188
189gboolean procmime_find_string_part (MimeInfo *mimeinfo,
190 const gchar *filename,
191 const gchar *str,
192 StrFindFunc find_func);
193gboolean procmime_find_string (MsgInfo *msginfo,
194 const gchar *str,
195 StrFindFunc find_func);
196
197gchar *procmime_get_part_file_name (MimeInfo *mimeinfo);
198gchar *procmime_get_tmp_file_name (MimeInfo *mimeinfo);
199gchar *procmime_get_tmp_file_name_for_user
200 (MimeInfo *mimeinfo);
201
202ContentType procmime_scan_mime_type (const gchar *mime_type);
203gchar *procmime_get_mime_type (const gchar *filename);
204
205gint procmime_execute_open_file (const gchar *file,
206 const gchar *mime_type);
207
208EncodingType procmime_get_encoding_for_charset (const gchar *charset);
209EncodingType procmime_get_encoding_for_text_file(const gchar *file);
210EncodingType procmime_get_encoding_for_str (const gchar *str);
211const gchar *procmime_get_encoding_str (EncodingType encoding);
212
213#endif /* __PROCMIME_H__ */