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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#include "config.h"
#include <stdio.h>
#include <string.h>
/**
* rfc822 - Parsing of RFC822 emails
*
* This code allows easy processing of RFC822/RFC2822/RFC5322
* formatted email messages. For now only read-only operation is
* supported.
*
* The important design goals are these:
* - Be lazy. Don't compute immediately compute fancy indexes for the
* message. Just reading messages into the system and then sending
* them out again should not incur a serious performance hit.
* - But cache. Once the user does request data that needs parsing,
* cache the results in suitable data structures so that if lots
* more lookups are done they're then fast.
* - Cope with ill-formatted messages. Even if the input is not
* RFC822 compliant, don't SEGV and try to return as much useful
* data as possible.
*
* Define TAL_USE_TALLOC to use libtalloc as the allocator, otherwise
* it will use ccan/tal (usually done on the cmdline, as tal/str will need
* it too).
*
* Example:
* // Given '' outputs 'body'
* // Given 'From' outputs ' <from@example.com>'
* // Given 'To' outputs ' <to@example.com>'
* char buf[] = "From: <from@example.com>\n"
* "To: <to@example.com>\n\n"
* "body\n";
* struct rfc822_msg *msg;
* struct bytestring out;
*
* msg = rfc822_start(NULL, buf, sizeof(buf));
* if (!argv[1] || !argv[1][0])
* out = rfc822_body(msg);
* else {
* struct rfc822_header *hdr;
* hdr = rfc822_first_header_of_name(msg, argv[1]);
* if (!hdr)
* exit(1);
* out = rfc822_header_unfolded_value(msg, hdr);
* }
* fwrite(out.ptr, 1, out.len, stdout);
* rfc822_free(msg);
*
* License: LGPL (v2.1 or any later version)
*
*/
int main(int argc, char *argv[])
{
/* Expect exactly one argument */
if (argc != 2)
return 1;
if (strcmp(argv[1], "depends") == 0) {
#ifdef TAL_USE_TALLOC
printf("ccan/tal/talloc\n");
#else
printf("ccan/tal\n");
#endif
printf("ccan/list\n");
printf("ccan/str\n");
printf("ccan/bytestring\n");
printf("ccan/mem\n");
return 0;
}
if (strcmp(argv[1], "testdepends") == 0) {
printf("ccan/failtest\n");
printf("ccan/foreach\n");
printf("ccan/array_size\n");
printf("ccan/tal/str\n");
return 0;
}
return 1;
}
|