]>
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 */
113 /* Content-MD5 info */
114 int c_digested
; /* have we seen this header before? */
115 unsigned char c_digest
[16]; /* decoded MD5 checksum */
117 /* pointers to content-specific structures */
118 void *c_ctparams
; /* content type specific data */
119 struct exbody
*c_ctexbody
; /* data for type message/external */
121 /* function pointers */
122 InitFunc c_ctinitfnx
; /* parse content body */
123 OpenCEFunc c_ceopenfnx
; /* get a stream to decoded contents */
124 CloseCEFunc c_ceclosefnx
; /* release stream */
125 SizeCEFunc c_cesizefnx
; /* size of decoded contents */
127 int c_umask
; /* associated umask */
128 pid_t c_pid
; /* process doing display */
129 int c_rfc934
; /* rfc934 compatibility flag */
131 char *c_showproc
; /* default, if not in profile */
132 char *c_termproc
; /* for charset madness... */
133 char *c_storeproc
; /* overrides profile entry, if any */
135 char *c_storage
; /* write contents (file) */
136 char *c_folder
; /* write contents (folder) */
140 * Flags for Content-Type (Content->c_type)
142 #define CT_UNKNOWN 0x00
143 #define CT_APPLICATION 0x01
144 #define CT_AUDIO 0x02
145 #define CT_IMAGE 0x03
146 #define CT_MESSAGE 0x04
147 #define CT_MULTIPART 0x05
149 #define CT_VIDEO 0x07
150 #define CT_EXTENSION 0x08
153 * Flags for Content-Transfer-Encoding (Content->c_encoding)
155 #define CE_UNKNOWN 0x00
156 #define CE_BASE64 0x01
157 #define CE_QUOTED 0x02
160 #define CE_BINARY 0x05
161 #define CE_EXTENSION 0x06
162 #define CE_EXTERNAL 0x07 /* for external-body */
168 /* Flags for subtypes of TEXT */
169 #define TEXT_UNKNOWN 0x00
170 #define TEXT_PLAIN 0x01
171 #define TEXT_RICHTEXT 0x02
172 #define TEXT_ENRICHED 0x03
174 /* Flags for character sets */
175 #define CHARSET_SPECIFIED 0x00
176 #define CHARSET_UNSPECIFIED 0x01 /* only needed when building drafts */
178 /* Structure for text content */
180 int tx_charset
; /* flag for character set */
187 /* Flags for subtypes of MULTIPART */
188 #define MULTI_UNKNOWN 0x00
189 #define MULTI_MIXED 0x01
190 #define MULTI_ALTERNATE 0x02
191 #define MULTI_DIGEST 0x03
192 #define MULTI_PARALLEL 0x04
194 /* Structure for subparts of a multipart content */
196 CT mp_part
; /* Content structure for subpart */
197 struct part
*mp_next
; /* pointer to next subpart structure */
200 /* Main structure for multipart content */
202 char *mp_start
; /* boundary string separating parts */
203 char *mp_stop
; /* terminating boundary string */
204 char *mp_content_before
; /* any content before the first subpart */
205 char *mp_content_after
; /* any content after the last subpart */
206 struct part
*mp_parts
; /* pointer to first subpart structure */
213 /* Flags for subtypes of MESSAGE */
214 #define MESSAGE_UNKNOWN 0x00
215 #define MESSAGE_RFC822 0x01
216 #define MESSAGE_PARTIAL 0x02
217 #define MESSAGE_EXTERNAL 0x03
219 /* Structure for message/partial */
228 /* Structure for message/external */
230 CT eb_parent
; /* pointer to controlling content structure */
231 CT eb_content
; /* pointer to internal content structure */
240 unsigned long eb_size
;
248 * APPLICATION content
251 /* Flags for subtype of APPLICATION */
252 #define APPLICATION_UNKNOWN 0x00
253 #define APPLICATION_OCTETS 0x01
254 #define APPLICATION_POSTSCRIPT 0x02
258 * Structures for mapping types to their internal flags
264 extern struct k2v SubText
[];
265 extern struct k2v Charset
[];
266 extern struct k2v SubMultiPart
[];
267 extern struct k2v SubMessage
[];
268 extern struct k2v SubApplication
[];
271 * Structures for mapping (content) types to
272 * the functions to handle them.
279 extern struct str2init str2cts
[];
280 extern struct str2init str2ces
[];
281 extern struct str2init str2methods
[];
287 CT
parse_mime (char *);
290 * Translate a composition file into a MIME data structure. Arguments are:
292 * infile - Name of input filename
293 * directives - A flag to control whether or not build directives are
294 * processed by default.
295 * encoding - The default encoding to use when doing RFC 2047 header
296 * encoding. Must be one of CE_UNKNOWN, CE_BASE64, or
299 * Returns a CT structure describing the resulting MIME message.
301 CT
build_mime (char *infile
, int directives
, int encoding
);
303 int add_header (CT
, char *, char *);
304 int get_ctinfo (char *, CT
, int);
305 int params_external (CT
, int);
306 int open7Bit (CT
, char **);
307 void close_encoding (CT
);
308 void free_content (CT
);
309 char *ct_type_str (int);
310 char *ct_subtype_str (int, int);
311 const struct str2init
*get_ct_init (int);
312 const char *ce_str (int);
313 const struct str2init
*get_ce_method (const char *);
314 int parse_header_attrs (const char *, int, char **, CI
, int *);
316 extern int checksw
; /* Add Content-MD5 field */