about summary refs log tree commit diff
path: root/unmime.c
blob: 8c0c14791637c6262cdf52e7e5d6497e0c5ffc2c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <wchar.h>

#include "blaze822.h"

void
recmime(struct message *msg, int depth)
{
	struct message *imsg = 0;
	char *ct, *body, *bodychunk;
	size_t bodylen;

	if (blaze822_mime_body(msg, &ct, &body, &bodylen, &bodychunk)) {
		printf("%*.sbody %s len %d\n", depth*2, "", ct, bodylen);
		if (strncmp(ct, "multipart/", 10) == 0) {
			while (blaze822_multipart(msg, &imsg))
				recmime(imsg, depth+1);
		} else if (strncmp(ct, "text/", 5) == 0) {
			printf("---\n");
			fwrite(body, bodylen, 1, stdout);
			printf("---\n");
		}
		free(bodychunk);
	}
}

void
unmime(char *file)
{
	struct message *msg;

	msg = blaze822_file(file);
	if (!msg)
		return;

	if (blaze822_check_mime(msg))
		printf("a mime message\n");
	else
		return;

	recmime(msg, 0);

	blaze822_free(msg);
}

int
main(int argc, char *argv[])
{
	blaze822_loop(argc-1, argv+1, unmime);

	return 0;
}