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