]> git.ozlabs.org Git - ccan/blob - ccan/rfc822/_info
Merge branch 'rfc822'
[ccan] / ccan / rfc822 / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * rfc822 - Parsing of RFC822 emails
7  *
8  * This code allows easy processing of RFC822/RFC2822/RFC5322
9  * formatted email messages.  For now only read-only operation is
10  * supported.
11  *
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
21  *   data as possible.
22  *
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
25  * it too).
26  *
27  * Example:
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"
33  *                   "body\n";
34  *      struct rfc822_msg *msg;
35  *      struct bytestring out;
36  *
37  *      msg = rfc822_start(NULL, buf, sizeof(buf));
38  *      if (!argv[1] || !argv[1][0])
39  *              out = rfc822_body(msg);
40  *      else {
41  *              struct rfc822_header *hdr;
42  *              hdr = rfc822_first_header_of_name(msg, argv[1]);
43  *              if (!hdr)
44  *                      exit(1);
45  *              out = rfc822_header_unfolded_value(msg, hdr);
46  *      }
47  *      fwrite(out.ptr, 1, out.len, stdout);
48  *      rfc822_free(msg);
49  *
50  * License: LGPL (v2.1 or any later version)
51  *
52  */
53 int main(int argc, char *argv[])
54 {
55         /* Expect exactly one argument */
56         if (argc != 2)
57                 return 1;
58
59         if (strcmp(argv[1], "depends") == 0) {
60 #ifdef TAL_USE_TALLOC
61                 printf("ccan/tal/talloc\n");
62 #else
63                 printf("ccan/tal\n");
64 #endif
65                 printf("ccan/list\n");
66                 printf("ccan/str\n");
67                 printf("ccan/bytestring\n");
68                 return 0;
69         }
70
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");
76                 return 0;
77         }
78
79         return 1;
80 }