Commit 9022da8a 9022da8a9477fa9d596dac74f2e6d5f2ff17f7f6 by Alain Magloire

Test program.

1 parent 99f8c68a
1 #include <stdio.h>
2 #include <mailutils/address.h>
3
4 static int use_zero = 1;
5
6 static int parse(const char* str)
7 {
8 size_t no = 0;
9 size_t pcount;
10
11 char buf[BUFSIZ];
12
13 address_t address = NULL;
14
15 if(use_zero)
16 address_create0(&address, str);
17 else
18 address_create(&address, str);
19
20 address_get_count(address, &pcount);
21
22 printf("%s=> pcount %d\n", str, pcount);
23
24 for(no = 1; no <= pcount; no++) {
25 size_t got = 0;
26 printf("%d ", no);
27
28 address_get_email(address, no, buf, sizeof(buf), 0);
29
30 printf("email <%s>\n", buf);
31
32 address_get_personal(address, no, buf, sizeof(buf), &got);
33
34 if(got) printf(" personal <%s>\n", buf);
35
36 address_get_comments(address, no, buf, sizeof(buf), &got);
37
38 if(got) printf(" comments <%s>\n", buf);
39
40 address_get_local_part(address, no, buf, sizeof(buf), &got);
41
42 if(got) printf(" local-part <%s>", buf);
43
44 address_get_domain(address, no, buf, sizeof(buf), &got);
45
46 if(got) printf(" domain <%s>\n", buf);
47
48 address_get_route(address, no, buf, sizeof(buf), &got);
49
50 if(got) printf(" route <%s>\n", buf);
51 }
52 address_destroy(&address);
53
54 printf("\n");
55
56 return 0;
57 }
58
59 static int parseinput(void)
60 {
61 char buf[BUFSIZ];
62
63 while(fgets(buf, sizeof(buf), stdin) != 0) {
64 buf[strlen(buf) - 1] = 0;
65 parse(buf);
66 }
67
68 return 0;
69 }
70
71 int main(int argc, const char *argv[])
72 {
73 argc = 1;
74
75 if(argv[argc] && strcmp(argv[argc], "-1") == 0) {
76 use_zero = 0;
77 argc++;
78 }
79 if(argv[argc] && strcmp(argv[argc], "-0") == 0) {
80 use_zero = 1;
81 argc++;
82 }
83 if(!argv[argc]) {
84 return parseinput();
85 }
86 for(; argv[argc]; argc++) {
87 if(strcmp(argv[argc], "-") == 0) {
88 parseinput();
89 } else {
90 parse(argv[argc]);
91 }
92 }
93
94 return 0;
95 }