Commit | Line | Data |
---|---|---|
d9898ee8 | 1 | /* |
2 | ** Copyright 1998 - 2006 Double Precision, Inc. | |
3 | ** See COPYING for distribution information. | |
4 | */ | |
5 | ||
6 | #include "rfc822.h" | |
b0322a85 | 7 | #include "rfc2047.h" |
d9898ee8 | 8 | #include <stdio.h> |
9 | #include <stdlib.h> | |
10 | ||
d9898ee8 | 11 | |
12 | static void print_func(char c, void *p) | |
13 | { | |
14 | p=p; | |
15 | putchar(c); | |
16 | } | |
17 | ||
18 | static void print_separator(const char *s, void *p) | |
19 | { | |
20 | p=p; | |
21 | printf("%s", s); | |
22 | } | |
23 | ||
24 | static struct rfc822t *tokenize(const char *p) | |
25 | { | |
26 | struct rfc822t *tp; | |
27 | int i; | |
28 | char buf[2]; | |
29 | ||
30 | printf("Tokenize: %s\n", p); | |
31 | tp=rfc822t_alloc_new(p, NULL, NULL); | |
32 | if (!tp) exit(0); | |
33 | buf[1]=0; | |
34 | for (i=0; i<tp->ntokens; i++) | |
35 | { | |
36 | buf[0]=tp->tokens[i].token; | |
37 | if (buf[0] == '\0' || buf[0] == '"' || buf[0] == '(') | |
38 | { | |
39 | printf("%s: ", buf[0] == '"' ? "Quote": | |
40 | buf[0] == '(' ? "Comment":"Atom"); | |
41 | if (fwrite(tp->tokens[i].ptr, tp->tokens[i].len, 1, | |
42 | stdout) != 1) | |
43 | exit(1); | |
44 | ||
45 | printf("\n"); | |
46 | } | |
47 | else printf("Token: %s\n", buf[0] ? buf:"atom"); | |
48 | } | |
49 | return (tp); | |
50 | } | |
51 | ||
52 | static struct rfc822a *doaddr(struct rfc822t *t) | |
53 | { | |
54 | struct rfc822a *a=rfc822a_alloc(t); | |
55 | ||
56 | if (!a) exit(0); | |
57 | printf("----\n"); | |
58 | rfc822_print(a, print_func, print_separator, NULL); | |
59 | printf("\n"); | |
d9898ee8 | 60 | return (a); |
61 | } | |
62 | ||
63 | int main() | |
64 | { | |
65 | struct rfc822t *t1, *t2, *t3, *t4, *t5; | |
66 | struct rfc822a *a1, *a2, *a3, *a4, *a5; | |
67 | ||
68 | t1=tokenize("nobody@example.com (Nobody (is) here\\) right)"); | |
69 | t2=tokenize("Distribution list: nobody@example.com daemon@example.com"); | |
70 | t3=tokenize("Mr Nobody <nobody@example.com>, Mr. Nobody <nobody@example.com>"); | |
71 | t4=tokenize("nobody@example.com, <nobody@example.com>, Mr. Nobody <nobody@example.com>"); | |
72 | ||
73 | t5=tokenize("=?UTF-8?Q?Test?= <nobody@example.com>, foo=bar <nobody@example.com>"); | |
74 | ||
75 | a1=doaddr(t1); | |
76 | a2=doaddr(t2); | |
77 | a3=doaddr(t3); | |
78 | a4=doaddr(t4); | |
79 | a5=doaddr(t5); | |
80 | ||
81 | rfc822a_free(a5); | |
82 | rfc822a_free(a4); | |
83 | rfc822a_free(a3); | |
84 | rfc822a_free(a2); | |
85 | rfc822a_free(a1); | |
86 | rfc822t_free(t5); | |
87 | rfc822t_free(t4); | |
88 | rfc822t_free(t3); | |
89 | rfc822t_free(t2); | |
90 | rfc822t_free(t1); | |
b0322a85 CE |
91 | |
92 | #define FIVEUTF8 "\xe2\x85\xa4" | |
93 | ||
94 | #define FIVETIMES4 FIVEUTF8 FIVEUTF8 FIVEUTF8 FIVEUTF8 | |
95 | ||
96 | #define FIVETIMES16 FIVETIMES4 FIVETIMES4 FIVETIMES4 FIVETIMES4 | |
97 | ||
98 | #define FIVEMAX FIVETIMES16 FIVETIMES4 FIVETIMES4 | |
99 | ||
100 | { | |
101 | char *p=rfc2047_encode_str(FIVEMAX, "utf-8", | |
102 | rfc2047_qp_allow_any); | |
103 | ||
104 | if (p) | |
105 | { | |
106 | printf("%s\n", p); | |
107 | free(p); | |
108 | } | |
109 | } | |
110 | ||
111 | { | |
112 | char *p=rfc2047_encode_str(FIVEMAX FIVEUTF8, "utf-8", | |
113 | rfc2047_qp_allow_any); | |
114 | ||
115 | if (p) | |
116 | { | |
117 | printf("%s\n", p); | |
118 | free(p); | |
119 | } | |
120 | } | |
121 | ||
122 | { | |
123 | char *p=rfc2047_encode_str(FIVEMAX "\xcc\x80", "utf-8", | |
124 | rfc2047_qp_allow_any); | |
125 | ||
126 | if (p) | |
127 | { | |
128 | printf("%s\n", p); | |
129 | free(p); | |
130 | } | |
131 | } | |
132 | ||
d9898ee8 | 133 | return (0); |
134 | } |