2 ** mhparse.h -- definitions for parsing/building of MIME content
3 ** -- (mhparse.c/mhbuild.c)
11 ** Abstract type for header fields
13 typedef struct hfield *HF;
16 ** Abstract types for MIME parsing/building
18 typedef struct cefile *CE;
19 typedef struct CTinfo *CI;
20 typedef struct Content *CT;
23 ** type for Init function (both type and transfer encoding)
25 typedef int (*InitFunc) (CT);
28 ** types for various transfer encoding access functions
30 typedef int (*OpenCEFunc) (CT, char **);
31 typedef void (*CloseCEFunc) (CT);
32 typedef unsigned long (*SizeCEFunc) (CT);
35 ** Structure for storing/encoding/decoding
36 ** a header field and its value.
39 char *name; /* field name */
40 char *value; /* field body */
41 int hf_encoding; /* internal flag for transfer encoding to use */
42 HF next; /* link to next header field */
46 ** Structure for storing parsed elements
47 ** of the Content-Type component.
50 char *ci_type; /* content type */
51 char *ci_subtype; /* content subtype */
52 char *ci_attrs[NPARMS + 2]; /* attribute names */
53 char *ci_values[NPARMS]; /* attribute values */
54 char *ci_comment; /* RFC-822 comments */
59 ** Structure for storing decoded contents after
60 ** removing Content-Transfer-Encoding.
63 char *ce_file; /* decoded content (file) */
64 FILE *ce_fp; /* decoded content (stream) */
65 int ce_unlink; /* remove file when done? */
69 ** Primary structure for handling Content (Entity)
72 /* source (read) file */
73 char *c_file; /* read contents (file) */
74 FILE *c_fp; /* read contents (stream) */
75 int c_unlink; /* remove file when done? */
77 long c_begin; /* where content body starts in file */
78 long c_end; /* where content body ends in file */
80 /* linked list of header fields */
81 HF c_first_hf; /* pointer to first header field */
82 HF c_last_hf; /* pointer to last header field */
84 /* copies of MIME related header fields */
85 char *c_vrsn; /* MIME-Version: */
86 char *c_ctline; /* Content-Type: */
87 char *c_celine; /* Content-Transfer-Encoding: */
88 char *c_id; /* Content-ID: */
89 char *c_descr; /* Content-Description: */
90 char *c_dispo; /* Content-Disposition: */
91 char *c_partno; /* within multipart content */
93 /* Content-Type info */
94 boolean crlf; /* are the line ending CRLF */
95 struct CTinfo c_ctinfo; /* parsed elements of Content-Type */
96 int c_type; /* internal flag for content type */
97 int c_subtype; /* internal flag for content subtype */
98 char *c_charset; /* charset string */
100 /* Content-Transfer-Encoding info (decoded contents) */
101 CE c_cefile; /* structure holding decoded content */
102 int c_encoding; /* internal flag for encoding type */
104 /* pointers to content-specific structures */
105 void *c_ctparams; /* content type specific data */
107 /* function pointers */
108 InitFunc c_ctinitfnx; /* parse content body */
109 OpenCEFunc c_ceopenfnx; /* get a stream to decoded contents */
110 CloseCEFunc c_ceclosefnx; /* release stream */
111 SizeCEFunc c_cesizefnx; /* size of decoded contents */
113 int c_umask; /* associated umask */
115 char *c_showproc; /* default, if not in profile */
116 char *c_storeproc; /* overrides profile entry, if any */
118 char *c_storage; /* write contents (file) */
119 char *c_folder; /* write contents (folder) */
123 ** Flags for Content-Type (Content->c_type)
125 #define CT_UNKNOWN 0x00
126 #define CT_APPLICATION 0x01
127 #define CT_AUDIO 0x02
128 #define CT_IMAGE 0x03
129 #define CT_MESSAGE 0x04
130 #define CT_MULTIPART 0x05
132 #define CT_VIDEO 0x07
133 #define CT_EXTENSION 0x08
136 ** Flags for Content-Transfer-Encoding (Content->c_encoding)
138 #define CE_UNKNOWN 0x00
139 #define CE_BASE64 0x01
140 #define CE_QUOTED 0x02
143 #define CE_BINARY 0x05
144 #define CE_EXTENSION 0x06
145 #define CE_EXTERNAL 0x07 /* for external-body */
151 /* Flags for subtypes of TEXT */
152 #define TEXT_UNKNOWN 0x00
153 #define TEXT_PLAIN 0x01
154 #define TEXT_RICHTEXT 0x02
155 #define TEXT_ENRICHED 0x03
157 /* Flags for character sets */
158 #define CHARSET_UNKNOWN 0x00
159 #define CHARSET_UNSPECIFIED 0x01 /* only needed when building drafts */
160 #define CHARSET_USASCII 0x01
161 #define CHARSET_LATIN 0x02
163 /* Structure for text content */
165 int tx_charset; /* flag for character set */
172 /* Flags for subtypes of MULTIPART */
173 #define MULTI_UNKNOWN 0x00
174 #define MULTI_MIXED 0x01
175 #define MULTI_ALTERNATE 0x02
176 #define MULTI_DIGEST 0x03
177 #define MULTI_PARALLEL 0x04
179 /* Structure for subparts of a multipart content */
181 CT mp_part; /* Content structure for subpart */
182 struct part *mp_next; /* pointer to next subpart structure */
185 /* Main structure for multipart content */
187 char *mp_start; /* boundary string separating parts */
188 char *mp_stop; /* terminating boundary string */
189 struct part *mp_parts; /* pointer to first subpart structure */
196 /* Flags for subtypes of MESSAGE */
197 #define MESSAGE_UNKNOWN 0x00
198 #define MESSAGE_RFC822 0x01
199 #define MESSAGE_PARTIAL 0x02
200 #define MESSAGE_EXTERNAL 0x03
202 /* Structure for message/partial */
212 ** APPLICATION content
215 /* Flags for subtype of APPLICATION */
216 #define APPLICATION_UNKNOWN 0x00
217 #define APPLICATION_OCTETS 0x01
218 #define APPLICATION_POSTSCRIPT 0x02
222 ** Structures for mapping types to their internal flags
228 extern struct k2v SubText[];
229 extern struct k2v Charset[];
230 extern struct k2v SubMultiPart[];
231 extern struct k2v SubMessage[];
232 extern struct k2v SubApplication[];
235 ** Structures for mapping (content) types to
236 ** the functions to handle them.
243 extern struct str2init str2cts[];
244 extern struct str2init str2ces[];
250 CT parse_mime(char *);
251 int add_header(CT, char *, char *);
252 int get_ctinfo(unsigned char *, CT, int);
253 int open7Bit(CT, char **);
254 void close_encoding(CT);
255 char *extract_name_value(char *, char *);