Add %(unmailto) format function for List-Post headers
[mmh] / h / mhparse.h
1 /*
2 ** mhparse.h -- definitions for parsing/building of MIME content
3 **           -- (mhparse.c/mhbuild.c)
4 */
5
6 #define NPARTS  50
7 #define NTYPES  20
8 #define NPARMS  10
9
10 /*
11 ** Abstract type for header fields
12 */
13 typedef struct hfield *HF;
14
15 /*
16 ** Abstract types for MIME parsing/building
17 */
18 typedef struct cefile  *CE;
19 typedef struct CTinfo  *CI;
20 typedef struct Content *CT;
21
22 /*
23 ** type for Init function (both type and transfer encoding)
24 */
25 typedef int (*InitFunc) (CT);
26
27 /*
28 ** types for various transfer encoding access functions
29 */
30 typedef int (*OpenCEFunc) (CT, char **);
31 typedef void (*CloseCEFunc) (CT);
32 typedef unsigned long (*SizeCEFunc) (CT);
33
34 /*
35 ** Structure for storing/encoding/decoding
36 ** a header field and its value.
37 */
38 struct hfield {
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 */
43 };
44
45 /*
46 ** Structure for storing parsed elements
47 ** of the Content-Type component.
48 */
49 struct CTinfo {
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 */
55         char *ci_magic;
56 };
57
58 /*
59 ** Structure for storing decoded contents after
60 ** removing Content-Transfer-Encoding.
61 */
62 struct cefile {
63         char *ce_file;   /* decoded content (file)   */
64         FILE *ce_fp;     /* decoded content (stream) */
65         int ce_unlink;   /* remove file when done?   */
66 };
67
68 /*
69 ** Primary structure for handling Content (Entity)
70 */
71 struct Content {
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?            */
76
77         long c_begin;                /* where content body starts in file */
78         long c_end;                  /* where content body ends in file   */
79
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      */
83
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          */
92
93         /* Content-Type info */
94         struct CTinfo c_ctinfo;      /* parsed elements of Content-Type   */
95         int c_type;                  /* internal flag for content type    */
96         int c_subtype;               /* internal flag for content subtype */
97         char *c_charset;             /* charset string                    */
98
99         /* Content-Transfer-Encoding info (decoded contents) */
100         CE c_cefile;                 /* structure holding decoded content */
101         int c_encoding;              /* internal flag for encoding type   */
102
103         /* pointers to content-specific structures */
104         void *c_ctparams;            /* content type specific data        */
105
106         /* function pointers */
107         InitFunc    c_ctinitfnx;     /* parse content body                */
108         OpenCEFunc  c_ceopenfnx;     /* get a stream to decoded contents  */
109         CloseCEFunc c_ceclosefnx;    /* release stream                    */
110         SizeCEFunc  c_cesizefnx;     /* size of decoded contents          */
111
112         int c_umask;                 /* associated umask                  */
113
114         char *c_showproc;            /* default, if not in profile        */
115         char *c_storeproc;           /* overrides profile entry, if any   */
116
117         char *c_storage;             /* write contents (file)             */
118         char *c_folder;              /* write contents (folder)           */
119 };
120
121 /*
122 ** Flags for Content-Type (Content->c_type)
123 */
124 #define CT_UNKNOWN      0x00
125 #define CT_APPLICATION  0x01
126 #define CT_AUDIO        0x02
127 #define CT_IMAGE        0x03
128 #define CT_MESSAGE      0x04
129 #define CT_MULTIPART    0x05
130 #define CT_TEXT         0x06
131 #define CT_VIDEO        0x07
132 #define CT_EXTENSION    0x08
133
134 /*
135 ** Flags for Content-Transfer-Encoding (Content->c_encoding)
136 */
137 #define CE_UNKNOWN      0x00
138 #define CE_BASE64       0x01
139 #define CE_QUOTED       0x02
140 #define CE_8BIT         0x03
141 #define CE_7BIT         0x04
142 #define CE_BINARY       0x05
143 #define CE_EXTENSION    0x06
144 #define CE_EXTERNAL     0x07    /* for external-body */
145
146 /*
147 ** TEXT content
148 */
149
150 /* Flags for subtypes of TEXT */
151 #define TEXT_UNKNOWN    0x00
152 #define TEXT_PLAIN      0x01
153 #define TEXT_RICHTEXT   0x02
154 #define TEXT_ENRICHED   0x03
155
156 /* Flags for character sets */
157 #define CHARSET_UNKNOWN      0x00
158 #define CHARSET_UNSPECIFIED  0x01  /* only needed when building drafts */
159 #define CHARSET_USASCII      0x01
160 #define CHARSET_LATIN        0x02
161
162 /* Structure for text content */
163 struct text {
164         int tx_charset;    /* flag for character set */
165 };
166
167 /*
168 ** MULTIPART content
169 */
170
171 /* Flags for subtypes of MULTIPART */
172 #define MULTI_UNKNOWN    0x00
173 #define MULTI_MIXED      0x01
174 #define MULTI_ALTERNATE  0x02
175 #define MULTI_DIGEST     0x03
176 #define MULTI_PARALLEL   0x04
177
178 /* Structure for subparts of a multipart content */
179 struct part {
180         CT mp_part;             /* Content structure for subpart     */
181         struct part *mp_next;   /* pointer to next subpart structure */
182 };
183
184 /* Main structure for multipart content */
185 struct multipart {
186         char *mp_start;         /* boundary string separating parts   */
187         char *mp_stop;          /* terminating boundary string        */
188         struct part *mp_parts;  /* pointer to first subpart structure */
189 };
190
191 /*
192 ** MESSAGE content
193 */
194
195 /* Flags for subtypes of MESSAGE */
196 #define MESSAGE_UNKNOWN   0x00
197 #define MESSAGE_RFC822    0x01
198 #define MESSAGE_PARTIAL   0x02
199 #define MESSAGE_EXTERNAL  0x03
200
201 /* Structure for message/partial */
202 struct partial {
203         char *pm_partid;
204         int pm_partno;
205         int pm_maxno;
206         int pm_marked;
207         int pm_stored;
208 };
209
210 /*
211 ** APPLICATION content
212 */
213
214 /* Flags for subtype of APPLICATION */
215 #define APPLICATION_UNKNOWN     0x00
216 #define APPLICATION_OCTETS      0x01
217 #define APPLICATION_POSTSCRIPT  0x02
218
219
220 /*
221 ** Structures for mapping types to their internal flags
222 */
223 struct k2v {
224         char *kv_key;
225         int kv_value;
226 };
227 extern struct k2v SubText[];
228 extern struct k2v Charset[];
229 extern struct k2v SubMultiPart[];
230 extern struct k2v SubMessage[];
231 extern struct k2v SubApplication[];
232
233 /*
234 ** Structures for mapping (content) types to
235 ** the functions to handle them.
236 */
237 struct str2init {
238         char *si_key;
239         int si_val;
240         InitFunc si_init;
241 };
242 extern struct str2init str2cts[];
243 extern struct str2init str2ces[];
244
245 /*
246 ** prototypes
247 */
248 int pidcheck(int);
249 CT parse_mime(char *);
250 int add_header(CT, char *, char *);
251 int get_ctinfo(unsigned char *, CT, int);
252 int open7Bit(CT, char **);
253 void close_encoding(CT);
254 char *extract_name_value(char *, char *);