3 * http://www.iana.org/assignments/media-types/index.html
13 static void mime_content_subtype_text(const char *buf
, struct mime_header
*hdr
)
16 hdr
->subtype
= MIME_SUBTYPE_UNKNOWN
;
22 if (!strncasecmp(buf
, "plain", 5)) {
23 hdr
->subtype
= MIME_SUBTYPE_PLAIN
;
24 } else if (!strncasecmp(buf
, "html", 4)) {
25 hdr
->subtype
= MIME_SUBTYPE_HTML
;
27 hdr
->subtype
= MIME_SUBTYPE_UNKNOWN
;
32 * multipart/mixed: MIME E-mail; Defined in RFC 2045 and RFC 2046
33 * multipart/alternative: MIME E-mail; Defined in RFC 2045 and RFC 2046
34 * multipart/related: MIME E-mail; Defined in RFC 2387 and used by MHTML (HTML mail)
35 * multipart/form-data: MIME Webform; Defined in RFC 2388
36 * multipart/signed: Defined in RFC 1847
37 * multipart/encrypted: Defined in RFC 1847
40 static void mime_content_subtype_multipart(const char *buf
, struct mime_header
*hdr
)
43 hdr
->subtype
= MIME_SUBTYPE_UNKNOWN
;
49 if (!strncasecmp(buf
, "alternative", 11))
50 hdr
->subtype
= MIME_SUBTYPE_ALTERNATIVE
;
51 else if (!strncasecmp(buf
, "mixed", 5))
52 hdr
->subtype
= MIME_SUBTYPE_MIXED
;
53 else if (!strncasecmp(buf
, "related", 7))
54 hdr
->subtype
= MIME_SUBTYPE_RELATED
;
55 else if (!strncasecmp(buf
, "form-data", 9))
56 hdr
->subtype
= MIME_SUBTYPE_FORM_DATA
;
57 else if (!strncasecmp(buf
, "signed", 6))
58 hdr
->subtype
= MIME_SUBTYPE_SIGNED
;
59 else if (!strncasecmp(buf
, "encrypted", 9))
60 hdr
->subtype
= MIME_SUBTYPE_ENCRYPTED
;
62 else if (!strncasecmp(buf
, "byteranges", 10))
63 hdr
->subtype
= MIME_SUBTYPE_BYTERANGES
;
64 else if (!strncasecmp(buf
, "digest", 6))
65 hdr
->subtype
= MIME_SUBTYPE_DIGEST
;
66 else if (!strncasecmp(buf
, "header-set", 10))
67 hdr
->subtype
= MIME_SUBTYPE_HEADER_SET
;
68 else if (!strncasecmp(buf
, "parallel", 8))
69 hdr
->subtype
= MIME_SUBTYPE_PARALLEL
;
70 else if (!strncasecmp(buf
, "report", 6))
71 hdr
->subtype
= MIME_SUBTYPE_REPORT
;
72 else if (!strncasecmp(buf
, "appledouble", 11))
73 hdr
->subtype
= MIME_SUBTYPE_APPLEDOUBLE
;
74 else if (!strncasecmp(buf
, "voice-message", 13))
75 hdr
->subtype
= MIME_SUBTYPE_VOICE_MESSAGE
;
77 hdr
->subtype
= MIME_SUBTYPE_UNKNOWN
;
80 void mime_content_type(const char *buf
, struct mime_header
*hdr
)
87 while (*p
!= '\0' && isspace(*p
)) {
88 if (*p
== '\n' || *p
== '\r') {
89 hdr
->type
= MIME_TYPE_UNKNOWN
;
96 /* text/plain is the default for e-mail */
97 if (!strncasecmp(p
, "text", 4)) {
98 hdr
->type
= MIME_TYPE_TEXT
;
100 mime_content_subtype_text(p
, hdr
);
101 } else if (!strncasecmp(p
, "multipart", 9)) {
102 hdr
->type
= MIME_TYPE_MULTIPART
;
104 mime_content_subtype_multipart(p
, hdr
);
105 } else if (!strncasecmp(p
, "application", 11)) {
106 hdr
->type
= MIME_TYPE_APPLICATION
;
108 } else if (!strncasecmp(p
, "audio", 5)) {
109 hdr
->type
= MIME_TYPE_AUDIO
;
111 } else if (!strncasecmp(p
, "example", 7)) {
112 hdr
->type
= MIME_TYPE_EXAMPLE
;
114 } else if (!strncasecmp(p
, "image", 5)) {
115 hdr
->type
= MIME_TYPE_IMAGE
;
117 } else if (!strncasecmp(p
, "message", 7)) {
118 hdr
->type
= MIME_TYPE_MESSAGE
;
120 } else if (!strncasecmp(p
, "model", 5)) {
121 hdr
->type
= MIME_TYPE_MODEL
;
123 } else if (!strncasecmp(p
, "video", 5)) {
124 hdr
->type
= MIME_TYPE_VIDEO
;
127 hdr
->type
= MIME_TYPE_UNKNOWN
;
131 void mime_content_disposition(const char *buf
, struct mime_header
*hdr
)
135 p
= strchr(buf
, ':');
138 while (*p
!= '\0' && isspace(*p
)) {
139 if (*p
== '\n' || *p
== '\r') {
140 hdr
->disposition
= MIME_DISPOSITION_UNKNOWN
;
146 /* text/plain is the default */
147 if (!strncasecmp(p
, "inline", 6)) {
148 hdr
->disposition
= MIME_DISPOSITION_INLINE
;
149 } else if (!strncasecmp(p
, "attachment", 10)) {
150 hdr
->disposition
= MIME_DISPOSITION_ATTACHMENT
;
152 hdr
->disposition
= MIME_DISPOSITION_UNKNOWN
;
156 void mime_content_transfer_encoding(const char *buf
, struct mime_header
*hdr
)
160 p
= strchr(buf
, ':');
163 while (*p
!= '\0' && isspace(*p
)) {
164 if (*p
== '\n' || *p
== '\r') {
165 hdr
->transfer_encoding
= MIME_ENCODING_7BIT
;
171 if (!strncasecmp(p
, "7bit", 4)) {
172 hdr
->transfer_encoding
= MIME_ENCODING_7BIT
;
173 } else if (!strncasecmp(p
, "quoted-printable", 16)) {
174 hdr
->transfer_encoding
= MIME_ENCODING_QUOTED_PRINTABLE
;
175 } else if (!strncasecmp(p
, "base64", 6)) {
176 hdr
->transfer_encoding
= MIME_ENCODING_BASE64
;
177 } else if (!strncasecmp(p
, "8bit", 4)) {
178 hdr
->transfer_encoding
= MIME_ENCODING_8BIT
;
179 } else if (!strncasecmp(p
, "binary", 6)) {
180 hdr
->transfer_encoding
= MIME_ENCODING_BINARY
;
182 hdr
->transfer_encoding
= MIME_ENCODING_UNKNOWN
;
188 static void debug_mime_text(const struct mime_header
*hdr
)
190 fprintf(stderr
, "text/");
192 switch (hdr
->subtype
) {
193 case MIME_SUBTYPE_PLAIN
:
194 fprintf(stderr
, "plain");
196 case MIME_SUBTYPE_HTML
:
197 fprintf(stderr
, "html");
199 case MIME_SUBTYPE_UNKNOWN
:
200 fprintf(stderr
, "UNKNOWN");
203 fprintf(stderr
, "%d", hdr
->subtype
);
206 fprintf(stderr
, "\n");
209 static void debug_mime_multipart(const struct mime_header
*hdr
)
211 fprintf(stderr
, "multipart/");
213 switch (hdr
->subtype
) {
214 case MIME_SUBTYPE_ALTERNATIVE
:
215 fprintf(stderr
, "alternative");
217 case MIME_SUBTYPE_MIXED
:
218 fprintf(stderr
, "mixed");
220 case MIME_SUBTYPE_RELATED
:
221 fprintf(stderr
, "related");
223 case MIME_SUBTYPE_FORM_DATA
:
224 fprintf(stderr
, "form-data");
226 case MIME_SUBTYPE_SIGNED
:
227 fprintf(stderr
, "signed");
229 case MIME_SUBTYPE_ENCRYPTED
:
230 fprintf(stderr
, "encrypted");
232 case MIME_SUBTYPE_UNKNOWN
:
233 fprintf(stderr
, "UNKNOWN");
236 fprintf(stderr
, "%d", hdr
->subtype
);
239 fprintf(stderr
, "\n");
242 static void debug_mime_application(const struct mime_header
*hdr
)
244 fprintf(stderr
, "application/");
246 switch (hdr
->subtype
) {
247 case MIME_SUBTYPE_UNKNOWN
:
248 fprintf(stderr
, "UNKNOWN");
251 fprintf(stderr
, "%d", hdr
->subtype
);
254 fprintf(stderr
, "\n");
257 static void debug_mime_audio(const struct mime_header
*hdr
)
259 fprintf(stderr
, "audio/");
260 switch (hdr
->subtype
) {
261 case MIME_SUBTYPE_UNKNOWN
:
262 fprintf(stderr
, "UNKNOWN");
265 fprintf(stderr
, "%d", hdr
->subtype
);
268 fprintf(stderr
, "\n");
272 static void debug_mime_image(const struct mime_header
*hdr
)
274 fprintf(stderr
, "image/");
275 switch (hdr
->subtype
) {
276 case MIME_SUBTYPE_UNKNOWN
:
277 fprintf(stderr
, "UNKNOWN");
280 fprintf(stderr
, "%d", hdr
->subtype
);
283 fprintf(stderr
, "\n");
287 static void debug_mime_message(const struct mime_header
*hdr
)
289 fprintf(stderr
, "message/");
290 switch (hdr
->subtype
) {
291 case MIME_SUBTYPE_UNKNOWN
:
292 fprintf(stderr
, "UNKNOWN");
295 fprintf(stderr
, "%d", hdr
->subtype
);
298 fprintf(stderr
, "\n");
301 static void debug_mime_model(const struct mime_header
*hdr
)
303 fprintf(stderr
, "model/");
304 switch (hdr
->subtype
) {
305 case MIME_SUBTYPE_UNKNOWN
:
306 fprintf(stderr
, "UNKNOWN");
309 fprintf(stderr
, "%d", hdr
->subtype
);
312 fprintf(stderr
, "\n");
315 static void debug_mime_video(const struct mime_header
*hdr
)
317 fprintf(stderr
, "video/");
318 switch (hdr
->subtype
) {
319 case MIME_SUBTYPE_UNKNOWN
:
320 fprintf(stderr
, "UNKNOWN");
323 fprintf(stderr
, "%d", hdr
->subtype
);
326 fprintf(stderr
, "\n");
329 void debug_mime_header(const struct mime_header
*hdr
)
331 fprintf(stderr
, "MIME Header:\n");
333 /* MIME Content-Type */
334 fprintf(stderr
, " Content-Type.............: ");
337 debug_mime_text(hdr
);
339 case MIME_TYPE_MULTIPART
:
340 debug_mime_multipart(hdr
);
342 case MIME_TYPE_APPLICATION
:
343 debug_mime_application(hdr
);
345 case MIME_TYPE_AUDIO
:
346 debug_mime_audio(hdr
);
348 case MIME_TYPE_EXAMPLE
:
349 fprintf(stderr
, "example\n");
351 case MIME_TYPE_IMAGE
:
352 debug_mime_image(hdr
);
354 case MIME_TYPE_MESSAGE
:
355 debug_mime_message(hdr
);
357 case MIME_TYPE_MODEL
:
358 debug_mime_model(hdr
);
360 case MIME_TYPE_VIDEO
:
361 debug_mime_video(hdr
);
363 case MIME_TYPE_UNKNOWN
:
365 fprintf(stderr
, "Unknown\n");
369 /* MIME Content-Disposition */
370 fprintf(stderr
, " Content-Disposition......: ");
371 switch (hdr
->disposition
) {
372 case MIME_DISPOSITION_INLINE
:
373 fprintf(stderr
, "inline\n");
375 case MIME_DISPOSITION_ATTACHMENT
:
376 fprintf(stderr
, "attachment\n");
378 case MIME_DISPOSITION_UNKNOWN
:
380 fprintf(stderr
, "Unknown\n");
384 /* MIME Content-Transfer-Encoding */
385 fprintf(stderr
, " Content-Transfer-Encoding: ");
386 switch (hdr
->transfer_encoding
) {
387 case MIME_ENCODING_7BIT
:
388 fprintf(stderr
, "7bit\n");
390 case MIME_ENCODING_QUOTED_PRINTABLE
:
391 fprintf(stderr
, "quoted-printable\n");
393 case MIME_ENCODING_BASE64
:
394 fprintf(stderr
, "base64\n");
396 case MIME_ENCODING_8BIT
:
397 fprintf(stderr
, "8bit\n");
399 case MIME_ENCODING_BINARY
:
400 fprintf(stderr
, "binary\n");
402 case MIME_ENCODING_UNKNOWN
:
404 fprintf(stderr
, "Unknown\n");