]> git.ozlabs.org Git - ccan/blob - ccan/rfc822/_info
rfc822: beef up _info example.
[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  * Example:
24  *      // Given '' outputs 'body'
25  *      // Given 'From' outputs ' <from@example.com>'
26  *      // Given 'To' outputs ' <to@example.com>'
27  *      char buf[] = "From: <from@example.com>\n"
28  *                   "To: <to@example.com>\n\n"
29  *                   "body\n";
30  *      struct rfc822_msg *msg;
31  *      struct bytestring out;
32  *
33  *      msg = rfc822_start(NULL, buf, sizeof(buf));
34  *      if (!argv[1] || !argv[1][0])
35  *              out = rfc822_body(msg);
36  *      else {
37  *              struct rfc822_header *hdr;
38  *              hdr = rfc822_first_header_of_name(msg, argv[1]);
39  *              if (!hdr)
40  *                      exit(1);
41  *              out = rfc822_header_unfolded_value(msg, hdr);
42  *      }
43  *      fwrite(out.ptr, 1, out.len, stdout);
44  *      rfc822_free(msg);
45  *
46  * License: LGPL (v2.1 or any later version)
47  *
48  */
49 int main(int argc, char *argv[])
50 {
51         /* Expect exactly one argument */
52         if (argc != 2)
53                 return 1;
54
55         if (strcmp(argv[1], "depends") == 0) {
56                 printf("ccan/talloc\n");
57                 printf("ccan/list\n");
58                 printf("ccan/str\n");
59                 printf("ccan/bytestring\n");
60                 return 0;
61         }
62
63         if (strcmp(argv[1], "testdepends") == 0) {
64                 printf("ccan/failtest\n");
65                 printf("ccan/foreach\n");
66                 printf("ccan/array_size\n");
67                 return 0;
68         }
69
70         return 1;
71 }