Imported Upstream version 0.63.0
[hcoop/debian/courier-authlib.git] / rfc822 / testsuite.c
CommitLineData
d9898ee8 1/*
2** Copyright 1998 - 2006 Double Precision, Inc.
3** See COPYING for distribution information.
4*/
5
6#include "rfc822.h"
7#include <stdio.h>
8#include <stdlib.h>
9
8d138742 10static const char rcsid[]="$Id: testsuite.c,v 1.8 2009/11/22 18:46:53 mrsam Exp $";
d9898ee8 11
12static void print_func(char c, void *p)
13{
14 p=p;
15 putchar(c);
16}
17
18static void print_separator(const char *s, void *p)
19{
20 p=p;
21 printf("%s", s);
22}
23
24static struct rfc822t *tokenize(const char *p)
25{
26struct rfc822t *tp;
27int i;
28char 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
52static struct rfc822a *doaddr(struct rfc822t *t)
53{
54struct 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
63int 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);
91 return (0);
92}