]>
diplodocus.org Git - nmh/blob - h/mhparse.h
3 * mhparse.h -- definitions for parsing/building of MIME content
4 * -- (mhparse.c/mhbuildsbr.c)
12 * Abstract type for header fields
14 typedef struct hfield
*HF
;
17 * Abstract types for MIME parsing/building
19 typedef struct cefile
*CE
;
20 typedef struct CTinfo
*CI
;
21 typedef struct Content
*CT
;
24 * type for Init function (both type and transfer encoding)
26 typedef int (*InitFunc
) (CT
);
29 * types for various transfer encoding access functions
31 typedef int (*OpenCEFunc
) (CT
, char **);
32 typedef void (*CloseCEFunc
) (CT
);
33 typedef unsigned long (*SizeCEFunc
) (CT
);
36 * Structure for storing/encoding/decoding
37 * a header field and its value.
40 char *name
; /* field name */
41 char *value
; /* field body */
42 int hf_encoding
; /* internal flag for transfer encoding to use */
43 HF next
; /* link to next header field */
47 * Structure for storing parsed elements
48 * of the Content-Type component.
51 char *ci_type
; /* content type */
52 char *ci_subtype
; /* content subtype */
53 char *ci_attrs
[NPARMS
+ 2]; /* attribute names */
54 char *ci_values
[NPARMS
]; /* attribute values */
55 char *ci_comment
; /* RFC-822 comments */
60 * Structure for storing decoded contents after
61 * removing Content-Transfer-Encoding.
64 char *ce_file
; /* decoded content (file) */
65 FILE *ce_fp
; /* decoded content (stream) */
66 int ce_unlink
; /* remove file when done? */
70 * Primary structure for handling Content (Entity)
72 * Some more explanation of this:
74 * This structure recursively describes a complete MIME message.
75 * At the top level, the c_first_hf list has a list of all message
76 * headers. If the content-type is multipart (c_type == CT_MULTIPART)
77 * then c_ctparams will contain a pointer to a struct multipart.
78 * A struct multipart contains (among other trhings) a linked list
79 * of struct part elements, and THOSE contain a pointer to the sub-part's
83 /* source (read) file */
84 char *c_file
; /* read contents (file) */
85 FILE *c_fp
; /* read contents (stream) */
86 int c_unlink
; /* remove file when done? */
88 long c_begin
; /* where content body starts in file */
89 long c_end
; /* where content body ends in file */
91 /* linked list of header fields */
92 HF c_first_hf
; /* pointer to first header field */
93 HF c_last_hf
; /* pointer to last header field */
95 /* copies of MIME related header fields */
96 char *c_vrsn
; /* MIME-Version: */
97 char *c_ctline
; /* Content-Type: */
98 char *c_celine
; /* Content-Transfer-Encoding: */
99 char *c_id
; /* Content-ID: */
100 char *c_descr
; /* Content-Description: */
101 char *c_dispo
; /* Content-Disposition: */
102 char *c_partno
; /* within multipart content */
104 /* Content-Type info */
105 struct CTinfo c_ctinfo
; /* parsed elements of Content-Type */
106 int c_type
; /* internal flag for content type */
107 int c_subtype
; /* internal flag for content subtype */
109 /* Content-Transfer-Encoding info (decoded contents) */
110 struct cefile c_cefile
; /* structure holding decoded content */
111 int c_encoding
; /* internal flag for encoding type */
112 int c_reqencoding
; /* Requested encoding (by mhbuild) */
114 /* Content-MD5 info */
115 int c_digested
; /* have we seen this header before? */
116 unsigned char c_digest
[16]; /* decoded MD5 checksum */
118 /* pointers to content-specific structures */
119 void *c_ctparams
; /* content type specific data */
120 struct exbody
*c_ctexbody
; /* data for type message/external */
122 /* function pointers */
123 InitFunc c_ctinitfnx
; /* parse content body */
124 OpenCEFunc c_ceopenfnx
; /* get a stream to decoded contents */
125 CloseCEFunc c_ceclosefnx
; /* release stream */
126 SizeCEFunc c_cesizefnx
; /* size of decoded contents */
128 int c_umask
; /* associated umask */
129 pid_t c_pid
; /* process doing display */
130 int c_rfc934
; /* rfc934 compatibility flag */
132 char *c_showproc
; /* default, if not in profile */
133 char *c_termproc
; /* for charset madness... */
134 char *c_storeproc
; /* overrides profile entry, if any */
136 char *c_storage
; /* write contents (file) */
137 char *c_folder
; /* write contents (folder) */
141 * Flags for Content-Type (Content->c_type)
143 #define CT_UNKNOWN 0x00
144 #define CT_APPLICATION 0x01
145 #define CT_AUDIO 0x02
146 #define CT_IMAGE 0x03
147 #define CT_MESSAGE 0x04
148 #define CT_MULTIPART 0x05
150 #define CT_VIDEO 0x07
151 #define CT_EXTENSION 0x08
154 * Flags for Content-Transfer-Encoding (Content->c_encoding)
156 #define CE_UNKNOWN 0x00
157 #define CE_BASE64 0x01
158 #define CE_QUOTED 0x02
161 #define CE_BINARY 0x05
162 #define CE_EXTENSION 0x06
163 #define CE_EXTERNAL 0x07 /* for external-body */
169 /* Flags for subtypes of TEXT */
170 #define TEXT_UNKNOWN 0x00
171 #define TEXT_PLAIN 0x01
172 #define TEXT_RICHTEXT 0x02
173 #define TEXT_ENRICHED 0x03
175 /* Flags for character sets */
176 #define CHARSET_SPECIFIED 0x00
177 #define CHARSET_UNSPECIFIED 0x01 /* only needed when building drafts */
179 /* Structure for text content */
181 int tx_charset
; /* flag for character set */
188 /* Flags for subtypes of MULTIPART */
189 #define MULTI_UNKNOWN 0x00
190 #define MULTI_MIXED 0x01
191 #define MULTI_ALTERNATE 0x02
192 #define MULTI_DIGEST 0x03
193 #define MULTI_PARALLEL 0x04
195 /* Structure for subparts of a multipart content */
197 CT mp_part
; /* Content structure for subpart */
198 struct part
*mp_next
; /* pointer to next subpart structure */
201 /* Main structure for multipart content */
203 char *mp_start
; /* boundary string separating parts */
204 char *mp_stop
; /* terminating boundary string */
205 char *mp_content_before
; /* any content before the first subpart */
206 char *mp_content_after
; /* any content after the last subpart */
207 struct part
*mp_parts
; /* pointer to first subpart structure */
214 /* Flags for subtypes of MESSAGE */
215 #define MESSAGE_UNKNOWN 0x00
216 #define MESSAGE_RFC822 0x01
217 #define MESSAGE_PARTIAL 0x02
218 #define MESSAGE_EXTERNAL 0x03
220 /* Structure for message/partial */
229 /* Structure for message/external */
231 CT eb_parent
; /* pointer to controlling content structure */
232 CT eb_content
; /* pointer to internal content structure */
241 unsigned long eb_size
;
249 * APPLICATION content
252 /* Flags for subtype of APPLICATION */
253 #define APPLICATION_UNKNOWN 0x00
254 #define APPLICATION_OCTETS 0x01
255 #define APPLICATION_POSTSCRIPT 0x02
259 * Structures for mapping types to their internal flags
265 extern struct k2v SubText
[];
266 extern struct k2v Charset
[];
267 extern struct k2v SubMultiPart
[];
268 extern struct k2v SubMessage
[];
269 extern struct k2v SubApplication
[];
272 * Structures for mapping (content) types to
273 * the functions to handle them.
280 extern struct str2init str2cts
[];
281 extern struct str2init str2ces
[];
282 extern struct str2init str2methods
[];
288 CT
parse_mime (char *);
291 * Translate a composition file into a MIME data structure. Arguments are:
293 * infile - Name of input filename
294 * autobuild - A flag to indicate if the composition file parser is
295 * being run in automatic mode or not. In auto mode,
296 * if a MIME-Version header is encountered it is assumed
297 * that the composition file is already in MIME format
298 * and will not be processed further. Otherwise, an
299 * error is generated.
300 * dist - A flag to indicate if we are being run by "dist". In
301 * that case, add no MIME headers to the message. Existing
302 * headers will still be encoded by RFC 2047.
303 * directives - A flag to control whether or not build directives are
304 * processed by default.
305 * encoding - The default encoding to use when doing RFC 2047 header
306 * encoding. Must be one of CE_UNKNOWN, CE_BASE64, or
308 * maxunencoded - The maximum line length before the default encoding for
309 * text parts is quoted-printable.
311 * Returns a CT structure describing the resulting MIME message. If the
312 * -auto flag is set and a MIME-Version header is encountered, the return
315 CT
build_mime (char *infile
, int autobuild
, int dist
, int directives
,
316 int encoding
, size_t maxunencoded
);
318 int add_header (CT
, char *, char *);
319 int get_ctinfo (char *, CT
, int);
320 int params_external (CT
, int);
321 int open7Bit (CT
, char **);
322 void close_encoding (CT
);
323 void free_content (CT
);
324 char *ct_type_str (int);
325 char *ct_subtype_str (int, int);
326 const struct str2init
*get_ct_init (int);
327 const char *ce_str (int);
328 const struct str2init
*get_ce_method (const char *);
329 int parse_header_attrs (const char *, int, char **, CI
, int *);
330 char *update_attr (char *, const char *, const char *e
);
331 char *content_charset (CT
);
332 int convert_charset (CT
, char *, int *);
334 extern int checksw
; /* Add Content-MD5 field */