]>
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
;
22 typedef struct Parameter
*PM
;
25 * type for Init function (both type and transfer encoding)
27 typedef int (*InitFunc
) (CT
);
30 * types for various transfer encoding access functions
32 typedef int (*OpenCEFunc
) (CT
, char **);
33 typedef void (*CloseCEFunc
) (CT
);
34 typedef unsigned long (*SizeCEFunc
) (CT
);
37 * Structure for storing/encoding/decoding
38 * a header field and its value.
41 char *name
; /* field name */
42 char *value
; /* field body */
43 int hf_encoding
; /* internal flag for transfer encoding to use */
44 HF next
; /* link to next header field */
48 * Structure for holding MIME parameter elements.
51 char *pm_name
; /* Parameter name */
52 char *pm_value
; /* Parameter value */
53 char *pm_charset
; /* Parameter character set (optional) */
54 char *pm_lang
; /* Parameter language tag (optional) */
55 PM pm_next
; /* Pointer to next element */
59 * Structure for storing parsed elements
60 * of the Content-Type component.
63 char *ci_type
; /* content type */
64 char *ci_subtype
; /* content subtype */
65 PM ci_first_pm
; /* Pointer to first MIME parameter */
66 PM ci_last_pm
; /* Pointer to last MIME parameter */
67 char *ci_comment
; /* RFC-822 comments */
72 * Structure for storing decoded contents after
73 * removing Content-Transfer-Encoding.
76 char *ce_file
; /* decoded content (file) */
77 FILE *ce_fp
; /* decoded content (stream) */
78 int ce_unlink
; /* remove file when done? */
82 * Primary structure for handling Content (Entity)
84 * Some more explanation of this:
86 * This structure recursively describes a complete MIME message.
87 * At the top level, the c_first_hf list has a list of all message
88 * headers. If the content-type is multipart (c_type == CT_MULTIPART)
89 * then c_ctparams will contain a pointer to a struct multipart.
90 * A struct multipart contains (among other trhings) a linked list
91 * of struct part elements, and THOSE contain a pointer to the sub-part's
95 /* source (read) file */
96 char *c_file
; /* read contents (file) */
97 FILE *c_fp
; /* read contents (stream) */
98 int c_unlink
; /* remove file when done? */
100 long c_begin
; /* where content body starts in file */
101 long c_end
; /* where content body ends in file */
103 /* linked list of header fields */
104 HF c_first_hf
; /* pointer to first header field */
105 HF c_last_hf
; /* pointer to last header field */
107 /* copies of MIME related header fields */
108 char *c_vrsn
; /* MIME-Version: */
109 char *c_ctline
; /* Content-Type: */
110 char *c_celine
; /* Content-Transfer-Encoding: */
111 char *c_id
; /* Content-ID: */
112 char *c_descr
; /* Content-Description: */
113 char *c_dispo
; /* Content-Disposition: */
114 char *c_dispo_type
; /* Type of Content-Disposition */
115 PM c_dispo_first
; /* Pointer to first disposition parm */
116 PM c_dispo_last
; /* Pointer to last disposition parm */
117 char *c_partno
; /* within multipart content */
119 /* Content-Type info */
120 struct CTinfo c_ctinfo
; /* parsed elements of Content-Type */
121 int c_type
; /* internal flag for content type */
122 int c_subtype
; /* internal flag for content subtype */
124 /* Content-Transfer-Encoding info (decoded contents) */
125 struct cefile c_cefile
; /* structure holding decoded content */
126 int c_encoding
; /* internal flag for encoding type */
127 int c_reqencoding
; /* Requested encoding (by mhbuild) */
129 /* Content-MD5 info */
130 int c_digested
; /* have we seen this header before? */
131 unsigned char c_digest
[16]; /* decoded MD5 checksum */
133 /* pointers to content-specific structures */
134 void *c_ctparams
; /* content type specific data */
135 struct exbody
*c_ctexbody
; /* data for type message/external */
137 /* function pointers */
138 InitFunc c_ctinitfnx
; /* parse content body */
139 OpenCEFunc c_ceopenfnx
; /* get a stream to decoded contents */
140 CloseCEFunc c_ceclosefnx
; /* release stream */
141 SizeCEFunc c_cesizefnx
; /* size of decoded contents */
143 int c_umask
; /* associated umask */
144 int c_rfc934
; /* rfc934 compatibility flag */
146 char *c_showproc
; /* default, if not in profile */
147 char *c_termproc
; /* for charset madness... */
148 char *c_storeproc
; /* overrides profile entry, if any */
150 char *c_storage
; /* write contents (file) */
151 char *c_folder
; /* write contents (folder) */
155 * Flags for Content-Type (Content->c_type)
157 #define CT_UNKNOWN 0x00
158 #define CT_APPLICATION 0x01
159 #define CT_AUDIO 0x02
160 #define CT_IMAGE 0x03
161 #define CT_MESSAGE 0x04
162 #define CT_MULTIPART 0x05
164 #define CT_VIDEO 0x07
165 #define CT_EXTENSION 0x08
168 * Flags for Content-Transfer-Encoding (Content->c_encoding)
170 #define CE_UNKNOWN 0x00
171 #define CE_BASE64 0x01
172 #define CE_QUOTED 0x02
175 #define CE_BINARY 0x05
176 #define CE_EXTENSION 0x06
177 #define CE_EXTERNAL 0x07 /* for external-body */
183 /* Flags for subtypes of TEXT */
184 #define TEXT_UNKNOWN 0x00
185 #define TEXT_PLAIN 0x01
186 #define TEXT_RICHTEXT 0x02
187 #define TEXT_ENRICHED 0x03
189 /* Flags for character sets */
190 #define CHARSET_SPECIFIED 0x00
191 #define CHARSET_UNSPECIFIED 0x01 /* only needed when building drafts */
193 /* Structure for text content */
195 int tx_charset
; /* flag for character set */
202 /* Flags for subtypes of MULTIPART */
203 #define MULTI_UNKNOWN 0x00
204 #define MULTI_MIXED 0x01
205 #define MULTI_ALTERNATE 0x02
206 #define MULTI_DIGEST 0x03
207 #define MULTI_PARALLEL 0x04
209 /* Structure for subparts of a multipart content */
211 CT mp_part
; /* Content structure for subpart */
212 struct part
*mp_next
; /* pointer to next subpart structure */
215 /* Main structure for multipart content */
217 char *mp_start
; /* boundary string separating parts */
218 char *mp_stop
; /* terminating boundary string */
219 char *mp_content_before
; /* any content before the first subpart */
220 char *mp_content_after
; /* any content after the last subpart */
221 struct part
*mp_parts
; /* pointer to first subpart structure */
228 /* Flags for subtypes of MESSAGE */
229 #define MESSAGE_UNKNOWN 0x00
230 #define MESSAGE_RFC822 0x01
231 #define MESSAGE_PARTIAL 0x02
232 #define MESSAGE_EXTERNAL 0x03
234 /* Structure for message/partial */
243 /* Structure for message/external */
245 CT eb_parent
; /* pointer to controlling content structure */
246 CT eb_content
; /* pointer to internal content structure */
255 unsigned long eb_size
;
263 * APPLICATION content
266 /* Flags for subtype of APPLICATION */
267 #define APPLICATION_UNKNOWN 0x00
268 #define APPLICATION_OCTETS 0x01
269 #define APPLICATION_POSTSCRIPT 0x02
273 * Structures for mapping types to their internal flags
279 extern struct k2v SubText
[];
280 extern struct k2v Charset
[];
281 extern struct k2v SubMultiPart
[];
282 extern struct k2v SubMessage
[];
283 extern struct k2v SubApplication
[];
286 * Structures for mapping (content) types to
287 * the functions to handle them.
294 extern struct str2init str2cts
[];
295 extern struct str2init str2ces
[];
296 extern struct str2init str2methods
[];
301 CT
parse_mime (char *);
304 * Translate a composition file into a MIME data structure. Arguments are:
306 * infile - Name of input filename
307 * autobuild - A flag to indicate if the composition file parser is
308 * being run in automatic mode or not. In auto mode,
309 * if a MIME-Version header is encountered it is assumed
310 * that the composition file is already in MIME format
311 * and will not be processed further. Otherwise, an
312 * error is generated.
313 * dist - A flag to indicate if we are being run by "dist". In
314 * that case, add no MIME headers to the message. Existing
315 * headers will still be encoded by RFC 2047.
316 * directives - A flag to control whether or not build directives are
317 * processed by default.
318 * encoding - The default encoding to use when doing RFC 2047 header
319 * encoding. Must be one of CE_UNKNOWN, CE_BASE64, or
321 * maxunencoded - The maximum line length before the default encoding for
322 * text parts is quoted-printable.
323 * verbose - If 1, output verbose information during message composition
325 * Returns a CT structure describing the resulting MIME message. If the
326 * -auto flag is set and a MIME-Version header is encountered, the return
329 CT
build_mime (char *infile
, int autobuild
, int dist
, int directives
,
330 int encoding
, size_t maxunencoded
, int verbose
);
332 int add_header (CT
, char *, char *);
333 int get_ctinfo (char *, CT
, int);
334 int params_external (CT
, int);
335 int open7Bit (CT
, char **);
336 void close_encoding (CT
);
337 void free_content (CT
);
338 char *ct_type_str (int);
339 char *ct_subtype_str (int, int);
340 const struct str2init
*get_ct_init (int);
341 const char *ce_str (int);
342 const struct str2init
*get_ce_method (const char *);
343 char *content_charset (CT
);
344 int convert_charset (CT
, char *, int *);
347 * Given a content structure, return true if the content has a disposition
352 * ct - Content structure to examine
354 int is_inline(CT ct
);
357 * Given a list of messages, display information about them on standard
362 * cts - An array of CT elements of messages that need to be
363 * displayed. Array is terminated by a NULL.
364 * headsw - If 1, display a column header.
365 * sizesw - If 1, display the size of the part.
366 * verbosw - If 1, display verbose information
367 * debugsw - If 1, turn on debugging for the output.
368 * disposw - If 1, display MIME part disposition information.
371 void list_all_messages(CT
*cts
, int headsw
, int sizesw
, int verbosw
,
372 int debugsw
, int disposw
);
375 * List the content information of a single MIME part on stdout.
379 * ct - MIME Content structure to display.
380 * toplevel - If set, we're at the top level of a message
381 * realsize - If set, determine the real size of the content
382 * verbose - If set, output verbose information
383 * debug - If set, turn on debugging for the output
384 * dispo - If set, display MIME part disposition information.
386 * Returns OK on success, NOTOK otherwise.
388 int list_content(CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
392 * Display content-appropriate information on MIME parts, decending recursively
393 * into multipart content if appropriate. Uses list_content() for displaying
394 * generic information.
396 * Arguments and return value are the same as list_content().
398 int list_switch(CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
402 * Given a linked list of parameters, build an output string for them. This
403 * string is designed to be concatenated on an already-built header.
407 * initialwidth - Current width of the header. Used to compute when to wrap
408 * parameters on the first line. The following lines will
409 * be prefixed by a tab (\t) character.
410 * params - Pointer to head of linked list of parameters.
411 * offsetout - The final line offset after all the parameters have been
412 * output. May be NULL.
413 * external - If set, outputting an external-body type and will not
414 * output a "body" parameter.
416 * Returns a pointer to the resulting parameter string. This string must
417 * be free()'d by the caller. Returns NULL on error.
419 char *output_params(size_t initialwidth
, PM params
, int *offsetout
,
423 * Add a parameter to the parameter linked list.
427 * first - Pointer to head of linked list
428 * last - Pointer to tail of linked list
429 * name - Name of parameter
430 * value - Value of parameter
431 * nocopy - If set, will use the pointer values directly for "name"
432 * and "value" instead of making their own copy. These
433 * pointers will be free()'d later by the MIME routines, so
434 * they should not be used after calling this function!
436 * Returns allocated parameter element
438 PM
add_param(PM
*first
, PM
*last
, char *name
, char *value
, int nocopy
);
441 * Replace (or add) a parameter to the parameter linked list.
443 * If the named parameter already exists on the parameter linked list,
444 * replace the value with the new one. Otherwise add it to the linked
445 * list. All parameters are identical to add_param().
447 PM
replace_param(PM
*first
, PM
*last
, char *name
, char *value
, int nocopy
);
450 * Retrieve a parameter value from a parameter linked list. Convert to the
451 * local character set if required.
455 * first - Pointer to head of parameter linked list.
456 * name - Name of parameter.
457 * replace - If characters in the parameter list cannot be converted to
458 * the local character set, replace with this character.
459 * fetchonly - If true, return pointer to original value, no conversion
462 * Returns parameter value if found, NULL otherwise. Memory must be free()'d
463 * unless fetchonly is set.
466 char *get_param(PM first
, const char *name
, char replace
, int fetchonly
);
469 * Fetch a parameter value from a parameter structure, converting it to
470 * the local character set.
474 * pm - Pointer to parameter structure
475 * replace - If characters in the parameter list cannot be converted to
476 * the local character set, replace with this character.
478 * Returns a pointer to the parameter value. Memory is stored in an
479 * internal buffer, so the returned value is only valid until the next
480 * call to get_param_value() or get_param() (get_param() uses get_param_value()
483 char *get_param_value(PM pm
, char replace
);
486 * Display MIME message(s) on standard out.
490 * cts - NULL terminated array of CT structures for messages
492 * concat - If true, concatenate all MIME parts. If false, show each
493 * MIME part under a separate pager.
494 * textonly - If true, only display "text" MIME parts
495 * inlineonly - If true, only display MIME parts that are marked with
496 * a disposition of "inline" (includes parts that lack a
497 * Content-Disposition header).
498 * markerform - The name of a file containg mh-format(5) code used to
499 * display markers about non-displayed MIME parts.
501 void show_all_messages(CT
*cts
, int concat
, int textonly
, int inlineonly
,
504 extern int checksw
; /* Add Content-MD5 field */