6 * rfc822 - Parsing of RFC822 emails
8 * This code allows easy processing of RFC822/RFC2822/RFC5322
9 * formatted email messages. For now only read-only operation is
12 * The important design goals are these:
13 * - Be lazy. Don't compute immediately compute fancy indexes for the
14 * message. Just reading messages into the system and then sending
15 * them out again should not incur a serious performance hit.
16 * - But cache. Once the user does request data that needs parsing,
17 * cache the results in suitable data structures so that if lots
18 * more lookups are done they're then fast.
19 * - Cope with ill-formatted messages. Even if the input is not
20 * RFC822 compliant, don't SEGV and try to return as much useful
23 * Define TAL_USE_TALLOC to use libtalloc as the allocator, otherwise
24 * it will use ccan/tal (usually done on the cmdline, as tal/str will need
28 * // Given '' outputs 'body'
29 * // Given 'From' outputs ' <from@example.com>'
30 * // Given 'To' outputs ' <to@example.com>'
31 * char buf[] = "From: <from@example.com>\n"
32 * "To: <to@example.com>\n\n"
34 * struct rfc822_msg *msg;
35 * struct bytestring out;
37 * msg = rfc822_start(NULL, buf, sizeof(buf));
38 * if (!argv[1] || !argv[1][0])
39 * out = rfc822_body(msg);
41 * struct rfc822_header *hdr;
42 * hdr = rfc822_first_header_of_name(msg, argv[1]);
45 * out = rfc822_header_unfolded_value(msg, hdr);
47 * fwrite(out.ptr, 1, out.len, stdout);
50 * License: LGPL (v2.1 or any later version)
53 int main(int argc, char *argv[])
55 /* Expect exactly one argument */
59 if (strcmp(argv[1], "depends") == 0) {
61 printf("ccan/tal/talloc\n");
65 printf("ccan/list\n");
67 printf("ccan/bytestring\n");
71 if (strcmp(argv[1], "testdepends") == 0) {
72 printf("ccan/failtest\n");
73 printf("ccan/foreach\n");
74 printf("ccan/array_size\n");
75 printf("ccan/tal/str\n");