Integrate test_header in test_view_mail and various coding style modifications
[rmail.git] / src / utils / test_mime.c
blob3c58542458ada5e5e615fcdb3ff2223396ca9909
1 /* MIME types
3 * http://www.iana.org/assignments/media-types/index.html
5 */
7 #define _BSD_SOURCE
9 #include <stdio.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <errno.h>
13 #include <fcntl.h>
14 #include <time.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
19 #include "mime.h"
21 static void parse_file(FILE *fh, struct mime_header *hdr)
23 char buf[1000];
25 /* Scan all lines */
26 while (fgets(buf, sizeof(buf), fh)) {
27 if (!strncmp(buf, "Content-Type:", 13)) {
28 mime_content_type(buf, hdr);
29 } else if (!strncmp(buf, "Content-Disposition:", 20)) {
30 hdr->disposition = mime_content_disposition(buf);
31 } else if (!strncmp(buf, "Content-Transfer-Encoding:", 26)) {
32 hdr->transfer_encoding = mime_content_transfer_encoding(buf);
33 } else {
34 /*printf("[SKIP] ------- %s", buf); */
39 int main(int argc, char **argv)
41 FILE *fh;
42 struct mime_header hdr;
43 const char *file;
45 if (argc < 2) {
46 fprintf(stderr, "Usage: mime <file>\n");
47 return -1;
50 file = argv[1];
52 fh = fopen(file, "r");
53 if (!fh) {
54 return -1;
57 /* Init MIME header struct */
58 hdr.type = MIME_TYPE_TEXT;
59 hdr.disposition = MIME_DISPOSITION_UNKNOWN;
60 hdr.transfer_encoding = MIME_ENCODING_UNKNOWN;
62 parse_file(fh, &hdr);
64 fprintf(stderr, "-------------------------------------------\n");
65 fprintf(stderr, "Test file: %s\n", file);
66 fprintf(stderr, "-------------------------------------------\n");
68 debug_mime_header(&hdr);
70 fclose(fh);
72 return 0;