Statistics
| Revision:

root / src / procmime.h @ 1

History | View | Annotate | Download (4.28 KB)

1
/*
2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 1999-2004 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
#include "utils.h"
35

    
36
typedef enum
37
{
38
        ENC_7BIT,
39
        ENC_8BIT,
40
        ENC_QUOTED_PRINTABLE,
41
        ENC_BASE64,
42
        ENC_X_UUENCODE,
43
        ENC_UNKNOWN
44
} EncodingType;
45

    
46
typedef enum
47
{
48
        MIME_TEXT,
49
        MIME_TEXT_HTML,
50
        MIME_MESSAGE_RFC822,
51
        MIME_APPLICATION,
52
        MIME_APPLICATION_OCTET_STREAM,
53
        MIME_MULTIPART,
54
        MIME_IMAGE,
55
        MIME_AUDIO,
56
        MIME_UNKNOWN
57
} ContentType;
58

    
59
struct _MimeType
60
{
61
        gchar *type;
62
        gchar *sub_type;
63

    
64
        gchar *extension;
65
};
66

    
67
/*
68
 * An example of MimeInfo structure:
69
 *
70
 * multipart/mixed            root  <-+ parent
71
 *                                    |
72
 *   multipart/alternative      children <-+ parent
73
 *                                         |
74
 *     text/plain                 children  --+
75
 *                                            |
76
 *     text/html                  next      <-+
77
 *
78
 *   message/rfc822             next  <-+ main
79
 *                                      |
80
 *                                sub (capsulated message)
81
 *
82
 *   image/jpeg                 next
83
 */
84

    
85
struct _MimeInfo
86
{
87
        gchar *encoding;
88

    
89
        EncodingType encoding_type;
90
        ContentType  mime_type;
91

    
92
        gchar *content_type;
93
        gchar *charset;
94
        gchar *name;
95
        gchar *boundary;
96

    
97
        gchar *content_disposition;
98
        gchar *filename;
99

    
100
        glong fpos;
101
        guint size;
102

    
103
        MimeInfo *main;
104
        MimeInfo *sub;
105

    
106
        MimeInfo *next;
107
        MimeInfo *parent;
108
        MimeInfo *children;
109

    
110
#if USE_GPGME
111
        MimeInfo *plaintext;
112
        gchar *plaintextfile;
113
        gchar *sigstatus;
114
        gchar *sigstatus_full;
115
#endif
116

    
117
        gint level;
118
};
119

    
120
#define IS_BOUNDARY(s, bnd, len) \
121
        (bnd && s[0] == '-' && s[1] == '-' && !strncmp(s + 2, bnd, len))
122

    
123
/* MimeInfo handling */
124

    
125
MimeInfo *procmime_mimeinfo_new                (void);
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
                                         StrFindFunc         find_func);
163
gboolean procmime_find_string                (MsgInfo        *msginfo,
164
                                         const gchar        *str,
165
                                         StrFindFunc         find_func);
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
EncodingType procmime_get_encoding_for_charset        (const gchar        *charset);
173
EncodingType procmime_get_encoding_for_text_file(const gchar        *file);
174
const gchar *procmime_get_encoding_str                (EncodingType         encoding);
175

    
176
#endif /* __PROCMIME_H__ */