Imported Upstream version 0.63.0
[hcoop/debian/courier-authlib.git] / rfc822 / reftest.c
1 /*
2 ** Copyright 2000 Double Precision, Inc.
3 ** See COPYING for distribution information.
4 */
5
6 /*
7 ** $Id: reftest.c,v 1.7 2003/05/30 01:24:16 mrsam Exp $
8 */
9
10 #include "config.h"
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <time.h>
16
17 #if HAVE_STRINGS_H
18 #include <strings.h>
19 #endif
20
21 #if HAVE_LOCALE_H
22 #include <locale.h>
23 #endif
24
25 #include "rfc822.h"
26 #include "imaprefs.h"
27
28
29 static void test1()
30 {
31 struct imap_refmsgtable *mt=rfc822_threadalloc();
32 char buf[20];
33 struct imap_refmsg *p;
34
35 strcpy(buf, "a@b");
36 p=rfc822_threadallocmsg(mt, buf);
37 strcpy(buf, "c@d");
38 p=rfc822_threadallocmsg(mt, buf);
39
40 printf("%s\n", (rfc822_threadsearchmsg(mt, "a@b")
41 ? "found":"not found"));
42 printf("%s\n", (rfc822_threadsearchmsg(mt, "c@d")
43 ? "found":"not found"));
44 printf("%s\n", (rfc822_threadsearchmsg(mt, "e@f")
45 ? "found":"not found"));
46
47 rfc822_threadfree(mt);
48 }
49
50 static void prtree(struct imap_refmsg *m)
51 {
52 printf("<%s>", m->msgid ? m->msgid:"");
53
54 if (m->isdummy)
55 {
56 printf(" (dummy)");
57 }
58
59 printf(".parent=");
60 if (m->parent)
61 printf("<%s>", m->parent->msgid ? m->parent->msgid:"");
62 else
63 printf("ROOT");
64
65 printf("\n");
66
67 for (m=m->firstchild; m; m=m->nextsib)
68 prtree(m);
69 }
70
71 static void prpc(struct imap_refmsgtable *mt)
72 {
73 struct imap_refmsg *root=rfc822_threadgetroot(mt), *m;
74
75 if (!root)
76 return;
77
78 for (m=root->firstchild; m; m=m->nextsib)
79 prtree(m);
80
81 printf("\n\n");
82 }
83
84 static void test2()
85 {
86 struct imap_refmsgtable *mt=rfc822_threadalloc();
87
88 rfc822_threadmsg(mt, "<1>", NULL,
89 "subject 1",
90 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
91
92 rfc822_threadmsg(mt, "<2>",
93 "<1>",
94 "subject 1",
95 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
96
97 rfc822_threadmsg(mt, "<4>",
98 "<1> <2> <3>",
99 "subject 1",
100 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
101
102 prpc(mt);
103 rfc822_threadfree(mt);
104 }
105
106 static void test3()
107 {
108 struct imap_refmsgtable *mt=rfc822_threadalloc();
109
110 rfc822_threadmsg(mt, "<4>",
111 "<2> <1> <3>",
112 "subject 1",
113 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
114
115 rfc822_threadmsg(mt, "<3>",
116 "<1> <2>",
117 "subject 1",
118 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
119
120 rfc822_threadmsg(mt, "<2>",
121 "<1>",
122 "subject 1",
123 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
124
125 rfc822_threadmsg(mt, "<1>", NULL,
126 "subject 1",
127 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
128
129 prpc(mt);
130 rfc822_threadfree(mt);
131 }
132
133 static void test4()
134 {
135 struct imap_refmsgtable *mt=rfc822_threadalloc();
136
137 rfc822_threadmsg(mt, "<1>", NULL,
138 "subject 1",
139 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
140
141 rfc822_threadmsg(mt, "<2>", "<1>",
142 "subject 1",
143 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
144
145 rfc822_threadmsg(mt, "<4>", "<1> <2> <3>",
146 "subject 1",
147 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
148
149 prpc(mt);
150 rfc822_threadprune(mt);
151 prpc(mt);
152 rfc822_threadfree(mt);
153 }
154
155 static void test5()
156 {
157 struct imap_refmsgtable *mt=rfc822_threadalloc();
158
159 rfc822_threadmsg(mt, "<4>", "<1> <2> <3>",
160 "subject 1",
161 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
162
163 rfc822_threadmsg(mt, "<3>", NULL,
164 "subject 1",
165 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
166
167 prpc(mt);
168 rfc822_threadprune(mt);
169 prpc(mt);
170 rfc822_threadfree(mt);
171 }
172
173 static void prsubj(struct imap_refmsgtable *p)
174 {
175 struct imap_subjlookup *s;
176 int i;
177
178 for (i=0; i<sizeof(p->subjtable)/sizeof(p->subjtable[0]); i++)
179 for (s=p->subjtable[i]; s; s=s->nextsubj)
180 printf("subject(%s)=<%s>\n", s->subj,
181 s->msg->msgid ? s->msg->msgid:"");
182 printf("\n\n");
183 }
184
185 static void test6()
186 {
187 struct imap_refmsgtable *mt=rfc822_threadalloc();
188
189 rfc822_threadmsg(mt, "<message1>", NULL,
190 "subject 1",
191 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
192
193 rfc822_threadmsg(mt, "<message10>", NULL,
194 "subject 2",
195 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 2);
196
197 rfc822_threadmsg(mt, "<message3>", "<message2>",
198 "subject 1",
199 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 3);
200
201 rfc822_threadmsg(mt, "<message11>", NULL,
202 "Re: subject 4",
203 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 4);
204
205 rfc822_threadmsg(mt, "<message12>", NULL,
206 "subject 4",
207 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 5);
208
209 rfc822_threadmsg(mt, "<message13>", NULL,
210 "subject 5",
211 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 6);
212
213 rfc822_threadmsg(mt, "<message14>", NULL,
214 "re: subject 5",
215 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 7);
216
217 rfc822_threadprune(mt);
218 rfc822_threadsortsubj(rfc822_threadgetroot(mt));
219 rfc822_threadgathersubj(mt, rfc822_threadgetroot(mt));
220 prpc(mt);
221 prsubj(mt);
222 rfc822_threadfree(mt);
223 }
224
225 static void test7()
226 {
227 struct imap_refmsgtable *mt=rfc822_threadalloc();
228
229 rfc822_threadmsg(mt, "<message1>", "<message1-dummy>",
230 "subject 1",
231 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
232
233 rfc822_threadmsg(mt, "<message2>", "<message2-dummy>",
234 "subject 1",
235 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
236 rfc822_threadprune(mt);
237 rfc822_threadsortsubj(rfc822_threadgetroot(mt));
238 rfc822_threadgathersubj(mt, rfc822_threadgetroot(mt));
239 prpc(mt);
240 prsubj(mt);
241 rfc822_threadmergesubj(mt, rfc822_threadgetroot(mt));
242 prpc(mt);
243 rfc822_threadfree(mt);
244 }
245
246 static void test8()
247 {
248 struct imap_refmsgtable *mt=rfc822_threadalloc();
249
250 rfc822_threadmsg(mt, "<message4>", NULL,
251 "subject 2",
252 "Thu, 29 Jun 2000 14:41:51 -0700", 0, 1);
253
254 rfc822_threadmsg(mt, "<message2>", NULL,
255 "subject 1",
256 "Thu, 29 Jun 2000 14:41:52 -0700", 0, 1);
257
258 rfc822_threadmsg(mt, "<message1>", "<message1-dummy>",
259 "subject 1",
260 "Thu, 29 Jun 2000 14:41:53 -0700", 0, 1);
261
262 rfc822_threadmsg(mt, "<message3>", NULL,
263 "Re: subject 2",
264 "Thu, 29 Jun 2000 14:41:54 -0700", 0, 1);
265
266 rfc822_threadmsg(mt, "<message10>", NULL,
267 "subject 10",
268 "Thu, 29 Jun 2000 14:41:55 -0700", 0, 1);
269
270 rfc822_threadmsg(mt, "<message11>", NULL,
271 "subject 10",
272 "Thu, 29 Jun 2000 14:41:56 -0700", 0, 1);
273
274 rfc822_threadprune(mt);
275 rfc822_threadsortsubj(rfc822_threadgetroot(mt));
276 rfc822_threadgathersubj(mt, rfc822_threadgetroot(mt));
277 prpc(mt);
278 prsubj(mt);
279 rfc822_threadmergesubj(mt, rfc822_threadgetroot(mt));
280 prpc(mt);
281 rfc822_threadfree(mt);
282 }
283
284 static void test9()
285 {
286 struct imap_refmsgtable *mt=rfc822_threadalloc();
287
288 rfc822_threadmsg(mt, "<message1>", NULL,
289 "subject 1",
290 "Thu, 20 Jun 2000 14:41:55 -0700", 0, 1);
291
292 rfc822_threadmsg(mt, "<message2>", NULL,
293 "subject 1",
294 "Thu, 19 Jun 2000 14:41:51 -0700", 0, 2);
295
296 rfc822_threadmsg(mt, "<message3>", NULL,
297 "subject 1",
298 "Thu, 21 Jun 2000 14:41:56 -0700", 0, 3);
299
300 rfc822_threadmsg(mt, "<message4>", "<message2>",
301 "subject 2",
302 "Thu, 21 Jun 2000 14:41:54 -0700", 0, 6);
303
304 rfc822_threadmsg(mt, "<message5>", "<message2>",
305 "subject 2",
306 "Thu, 21 Jun 2000 14:41:53 -0700", 0, 5);
307
308 rfc822_threadmsg(mt, "<message6>", "<message2>",
309 "subject 2",
310 "Thu, 20 Jun 2000 14:41:52 -0700", 0, 4);
311
312
313 rfc822_threadprune(mt);
314 rfc822_threadsortsubj(rfc822_threadgetroot(mt));
315 rfc822_threadgathersubj(mt, rfc822_threadgetroot(mt));
316 rfc822_threadmergesubj(mt, rfc822_threadgetroot(mt));
317 rfc822_threadsortbydate(mt);
318 prpc(mt);
319 rfc822_threadfree(mt);
320 }
321
322 static void test10()
323 {
324 struct imap_refmsgtable *mt=rfc822_threadalloc();
325
326 rfc822_threadmsg(mt, "<message1>", NULL,
327 "subject 1",
328 "Thu, 20 Jun 2000 14:41:58 -0700", 0, 1);
329
330 rfc822_threadmsg(mt, "<message4>", "<message1>",
331 "subject 2",
332 "Thu, 21 Jun 2000 14:41:58 -0700", 0, 6);
333
334 rfc822_threadmsg(mt, "<message1>", NULL,
335 "subject 2",
336 "Thu, 21 Jun 2000 14:41:58 -0700", 0, 5);
337
338 rfc822_threadmsg(mt, "<message4>", "<message1>",
339 "subject 2",
340 "Thu, 21 Jun 2000 14:41:58 -0700", 0, 6);
341
342 rfc822_threadprune(mt);
343 rfc822_threadsortsubj(rfc822_threadgetroot(mt));
344 rfc822_threadgathersubj(mt, rfc822_threadgetroot(mt));
345 rfc822_threadmergesubj(mt, rfc822_threadgetroot(mt));
346 rfc822_threadsortbydate(mt);
347 prpc(mt);
348 rfc822_threadfree(mt);
349 }
350
351 int main(int argc, char **argv)
352 {
353
354 #if HAVE_SETLOCALE
355 setlocale(LC_ALL, "C");
356 #endif
357
358 test1();
359 test2();
360 test3();
361 test4();
362 test5();
363 test6();
364 test7();
365 test8();
366 test9();
367 test10();
368 return (0);
369 }