Statistics
| Branch: | Tag: | Revision:

root / libsylph / procmime.h @ aebfd4cc

History | View | Annotate | Download (4.45 KB)

1
/*
2
 * LibSylph -- E-Mail client library
3
 * Copyright (C) 1999-2011 Hiroyuki Yamamoto
4
 */
5

    
6
#ifndef __PROCMIME_H__
7
#define __PROCMIME_H__
8

    
9
#ifdef HAVE_CONFIG_H
10
#  include "config.h"
11
#endif
12

    
13
#include <glib.h>
14
#include <stdio.h>
15

    
16
typedef struct _MimeType        MimeType;
17
typedef struct _MailCap                MailCap;
18
typedef struct _MimeInfo        MimeInfo;
19

    
20
#include "procmsg.h"
21
#include "utils.h"
22

    
23
typedef enum
24
{
25
        ENC_7BIT,
26
        ENC_8BIT,
27
        ENC_QUOTED_PRINTABLE,
28
        ENC_BASE64,
29
        ENC_X_UUENCODE,
30
        ENC_UNKNOWN
31
} EncodingType;
32

    
33
typedef enum
34
{
35
        MIME_TEXT,
36
        MIME_TEXT_HTML,
37
        MIME_MESSAGE_RFC822,
38
        MIME_APPLICATION,
39
        MIME_APPLICATION_OCTET_STREAM,
40
        MIME_MULTIPART,
41
        MIME_IMAGE,
42
        MIME_AUDIO,
43
        MIME_VIDEO,
44
        MIME_UNKNOWN
45
} ContentType;
46

    
47
struct _MimeType
48
{
49
        gchar *type;
50
        gchar *sub_type;
51

    
52
        gchar *extension;
53
};
54

    
55
struct _MailCap
56
{
57
        gchar *mime_type;
58
        gchar *cmdline_fmt;
59
        gboolean needs_terminal;
60
};
61

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

    
80
struct _MimeInfo
81
{
82
        gchar *encoding;
83

    
84
        EncodingType encoding_type;
85
        ContentType  mime_type;
86

    
87
        gchar *content_type;
88
        gchar *charset;
89
        gchar *name;
90
        gchar *boundary;
91

    
92
        gchar *content_disposition;
93
        gchar *filename;
94

    
95
        glong fpos;
96
        guint size;
97
        guint content_size;
98

    
99
        MimeInfo *main;
100
        MimeInfo *sub;
101

    
102
        MimeInfo *next;
103
        MimeInfo *parent;
104
        MimeInfo *children;
105

    
106
        MimeInfo *plaintext;
107
        gchar *sigstatus;
108
        gchar *sigstatus_full;
109

    
110
        gint level;
111
};
112

    
113
#define IS_BOUNDARY(s, bnd, len) \
114
        (bnd && s[0] == '-' && s[1] == '-' && !strncmp(s + 2, bnd, len))
115

    
116
/* MimeInfo handling */
117

    
118
MimeInfo *procmime_mimeinfo_new                (void);
119
void procmime_mimeinfo_free_all                (MimeInfo        *mimeinfo);
120

    
121
MimeInfo *procmime_mimeinfo_insert        (MimeInfo        *parent,
122
                                         MimeInfo        *mimeinfo);
123
#if 0
124
void procmime_mimeinfo_replace                (MimeInfo        *old,
125
                                         MimeInfo        *new);
126
#endif
127

    
128
MimeInfo *procmime_mimeinfo_next        (MimeInfo        *mimeinfo);
129

    
130
MimeInfo *procmime_scan_message                (MsgInfo        *msginfo);
131
void procmime_scan_multipart_message        (MimeInfo        *mimeinfo,
132
                                         FILE                *fp);
133

    
134
/* scan headers */
135

    
136
void procmime_scan_encoding                (MimeInfo        *mimeinfo,
137
                                         const gchar        *encoding);
138
void procmime_scan_content_type                (MimeInfo        *mimeinfo,
139
                                         const gchar        *content_type);
140
void procmime_scan_content_type_str        (const gchar        *content_type,
141
                                         gchar               **mime_type,
142
                                         gchar               **charset,
143
                                         gchar               **name,
144
                                         gchar               **boundary);
145
void procmime_scan_content_type_partial        (const gchar        *content_type,
146
                                         gint                *total,
147
                                         gchar               **part_id,
148
                                         gint                *number);
149
void procmime_scan_content_disposition        (MimeInfo        *mimeinfo,
150
                                         const gchar        *content_disposition);
151
MimeInfo *procmime_scan_mime_header        (FILE                *fp);
152

    
153
FILE *procmime_decode_content                (FILE                *outfp,
154
                                         FILE                *infp,
155
                                         MimeInfo        *mimeinfo);
156
gint procmime_get_part                        (const gchar        *outfile,
157
                                         const gchar        *infile,
158
                                         MimeInfo        *mimeinfo);
159
gint procmime_get_part_fp                (const gchar        *outfile,
160
                                         FILE                *infp,
161
                                         MimeInfo        *mimeinfo);
162
FILE *procmime_get_part_fp_fp                (FILE                *outfp,
163
                                         FILE                *infp,
164
                                         MimeInfo        *mimeinfo);
165
gint procmime_get_all_parts                (const gchar        *dir,
166
                                         const gchar        *infile,
167
                                         MimeInfo        *mimeinfo);
168
FILE *procmime_get_text_content                (MimeInfo        *mimeinfo,
169
                                         FILE                *infp,
170
                                         const gchar        *encoding);
171
FILE *procmime_get_first_text_content        (MsgInfo        *msginfo,
172
                                         const gchar        *encoding);
173

    
174
gboolean procmime_find_string_part        (MimeInfo        *mimeinfo,
175
                                         const gchar        *filename,
176
                                         const gchar        *str,
177
                                         StrFindFunc         find_func);
178
gboolean procmime_find_string                (MsgInfo        *msginfo,
179
                                         const gchar        *str,
180
                                         StrFindFunc         find_func);
181

    
182
gchar *procmime_get_part_file_name        (MimeInfo        *mimeinfo);
183
gchar *procmime_get_tmp_file_name        (MimeInfo        *mimeinfo);
184

    
185
ContentType procmime_scan_mime_type        (const gchar        *mime_type);
186
gchar *procmime_get_mime_type                (const gchar        *filename);
187

    
188
EncodingType procmime_get_encoding_for_charset        (const gchar        *charset);
189
EncodingType procmime_get_encoding_for_text_file(const gchar        *file);
190
EncodingType procmime_get_encoding_for_str        (const gchar        *str);
191
const gchar *procmime_get_encoding_str                (EncodingType         encoding);
192

    
193
#endif /* __PROCMIME_H__ */