File: reftest.c

package info (click to toggle)
courier 0.60.0-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 52,288 kB
  • ctags: 12,677
  • sloc: ansic: 165,348; cpp: 24,820; sh: 16,410; perl: 6,839; makefile: 3,621; yacc: 289; sed: 16
file content (369 lines) | stat: -rw-r--r-- 8,031 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/*
** Copyright 2000 Double Precision, Inc.
** See COPYING for distribution information.
*/

/*
** $Id: reftest.c,v 1.7 2003/05/30 01:24:16 mrsam Exp $
*/

#include	"config.h"

#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#include	<time.h>

#if	HAVE_STRINGS_H
#include	<strings.h>
#endif

#if	HAVE_LOCALE_H
#include	<locale.h>
#endif

#include	"rfc822.h"
#include	"imaprefs.h"


static void test1()
{
struct imap_refmsgtable *mt=rfc822_threadalloc();
char	buf[20];
struct imap_refmsg *p;

        strcpy(buf, "a@b");
        p=rfc822_threadallocmsg(mt, buf);
        strcpy(buf, "c@d");
        p=rfc822_threadallocmsg(mt, buf);

	printf("%s\n", (rfc822_threadsearchmsg(mt, "a@b")
			? "found":"not found"));
	printf("%s\n", (rfc822_threadsearchmsg(mt, "c@d")
			? "found":"not found"));
	printf("%s\n", (rfc822_threadsearchmsg(mt, "e@f")
			? "found":"not found"));

	rfc822_threadfree(mt);
}

static void prtree(struct imap_refmsg *m)
{
	printf("<%s>", m->msgid ? m->msgid:"");

	if (m->isdummy)
	{
		printf(" (dummy)");
	}

	printf(".parent=");
	if (m->parent)
		printf("<%s>", m->parent->msgid ? m->parent->msgid:"");
	else
		printf("ROOT");

	printf("\n");

	for (m=m->firstchild; m; m=m->nextsib)
		prtree(m);
}

static void prpc(struct imap_refmsgtable *mt)
{
	struct imap_refmsg *root=rfc822_threadgetroot(mt), *m;

	if (!root)
		return;

	for (m=root->firstchild; m; m=m->nextsib)
		prtree(m);

	printf("\n\n");
}

static void test2()
{
	struct imap_refmsgtable *mt=rfc822_threadalloc();

	rfc822_threadmsg(mt, "<1>", NULL,
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);

	rfc822_threadmsg(mt, "<2>",
			 "<1>",
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);

	rfc822_threadmsg(mt, "<4>",
			 "<1> <2> <3>",
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);

	prpc(mt);
	rfc822_threadfree(mt);
}

static void test3()
{
	struct imap_refmsgtable *mt=rfc822_threadalloc();

	rfc822_threadmsg(mt, "<4>",
			 "<2> <1> <3>",
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);

	rfc822_threadmsg(mt, "<3>",
			 "<1> <2>",
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);

	rfc822_threadmsg(mt, "<2>",
			 "<1>",
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);

	rfc822_threadmsg(mt, "<1>", NULL,
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);

	prpc(mt);
	rfc822_threadfree(mt);
}

static void test4()
{
	struct imap_refmsgtable *mt=rfc822_threadalloc();

	rfc822_threadmsg(mt, "<1>", NULL,
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);

	rfc822_threadmsg(mt, "<2>", "<1>",
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);

	rfc822_threadmsg(mt, "<4>", "<1> <2> <3>",
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);

	prpc(mt);
	rfc822_threadprune(mt);
	prpc(mt);
	rfc822_threadfree(mt);
}

static void test5()
{
	struct imap_refmsgtable *mt=rfc822_threadalloc();

	rfc822_threadmsg(mt, "<4>", "<1> <2> <3>",
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);

	rfc822_threadmsg(mt, "<3>", NULL,
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);

	prpc(mt);
	rfc822_threadprune(mt);
	prpc(mt);
	rfc822_threadfree(mt);
}

static void prsubj(struct imap_refmsgtable *p)
{
	struct imap_subjlookup *s;
	int i;

	for (i=0; i<sizeof(p->subjtable)/sizeof(p->subjtable[0]); i++)
		for (s=p->subjtable[i]; s; s=s->nextsubj)
			printf("subject(%s)=<%s>\n", s->subj,
			       s->msg->msgid ? s->msg->msgid:"");
	printf("\n\n");
}

static void test6()
{
	struct imap_refmsgtable *mt=rfc822_threadalloc();

	rfc822_threadmsg(mt, "<message1>", NULL,
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);

	rfc822_threadmsg(mt, "<message10>", NULL,
			 "subject 2",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 2);

	rfc822_threadmsg(mt, "<message3>", "<message2>",
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 3);

	rfc822_threadmsg(mt, "<message11>", NULL,
			 "Re: subject 4",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 4);

	rfc822_threadmsg(mt, "<message12>", NULL,
			 "subject 4",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 5);

	rfc822_threadmsg(mt, "<message13>", NULL,
			 "subject 5",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 6);

	rfc822_threadmsg(mt, "<message14>", NULL,
			 "re: subject 5",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 7);

	rfc822_threadprune(mt);
	rfc822_threadsortsubj(rfc822_threadgetroot(mt));
	rfc822_threadgathersubj(mt, rfc822_threadgetroot(mt));
	prpc(mt);
	prsubj(mt);
	rfc822_threadfree(mt);
}

static void test7()
{
	struct imap_refmsgtable *mt=rfc822_threadalloc();

	rfc822_threadmsg(mt, "<message1>", "<message1-dummy>",
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);

	rfc822_threadmsg(mt, "<message2>", "<message2-dummy>",
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
	rfc822_threadprune(mt);
	rfc822_threadsortsubj(rfc822_threadgetroot(mt));
	rfc822_threadgathersubj(mt, rfc822_threadgetroot(mt));
	prpc(mt);
	prsubj(mt);
	rfc822_threadmergesubj(mt, rfc822_threadgetroot(mt));
	prpc(mt);
	rfc822_threadfree(mt);
}

static void test8()
{
	struct imap_refmsgtable *mt=rfc822_threadalloc();

	rfc822_threadmsg(mt, "<message4>", NULL,
			 "subject 2",
			 "Thu, 29 Jun 2000 14:41:51 -0700", 0, 1);

	rfc822_threadmsg(mt, "<message2>", NULL,
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:52 -0700", 0, 1);

	rfc822_threadmsg(mt, "<message1>", "<message1-dummy>",
			 "subject 1",
			 "Thu, 29 Jun 2000 14:41:53 -0700", 0, 1);

	rfc822_threadmsg(mt, "<message3>", NULL,
			 "Re: subject 2",
			 "Thu, 29 Jun 2000 14:41:54 -0700", 0, 1);

	rfc822_threadmsg(mt, "<message10>", NULL,
			 "subject 10",
			 "Thu, 29 Jun 2000 14:41:55 -0700", 0, 1);

	rfc822_threadmsg(mt, "<message11>", NULL,
			 "subject 10",
			 "Thu, 29 Jun 2000 14:41:56 -0700", 0, 1);

	rfc822_threadprune(mt);
	rfc822_threadsortsubj(rfc822_threadgetroot(mt));
	rfc822_threadgathersubj(mt, rfc822_threadgetroot(mt));
	prpc(mt);
	prsubj(mt);
	rfc822_threadmergesubj(mt, rfc822_threadgetroot(mt));
	prpc(mt);
	rfc822_threadfree(mt);
}

static void test9()
{
	struct imap_refmsgtable *mt=rfc822_threadalloc();

	rfc822_threadmsg(mt, "<message1>", NULL,
			 "subject 1",
			 "Thu, 20 Jun 2000 14:41:55 -0700", 0, 1);

	rfc822_threadmsg(mt, "<message2>", NULL,
			 "subject 1",
			 "Thu, 19 Jun 2000 14:41:51 -0700", 0, 2);

	rfc822_threadmsg(mt, "<message3>", NULL,
			 "subject 1",
			 "Thu, 21 Jun 2000 14:41:56 -0700", 0, 3);

	rfc822_threadmsg(mt, "<message4>", "<message2>",
			 "subject 2",
			 "Thu, 21 Jun 2000 14:41:54 -0700", 0, 6);

	rfc822_threadmsg(mt, "<message5>", "<message2>",
			 "subject 2",
			 "Thu, 21 Jun 2000 14:41:53 -0700", 0, 5);

	rfc822_threadmsg(mt, "<message6>", "<message2>",
			 "subject 2",
			 "Thu, 20 Jun 2000 14:41:52 -0700", 0, 4);


	rfc822_threadprune(mt);
	rfc822_threadsortsubj(rfc822_threadgetroot(mt));
	rfc822_threadgathersubj(mt, rfc822_threadgetroot(mt));
	rfc822_threadmergesubj(mt, rfc822_threadgetroot(mt));
	rfc822_threadsortbydate(mt);
	prpc(mt);
	rfc822_threadfree(mt);
}

static void test10()
{
	struct imap_refmsgtable *mt=rfc822_threadalloc();

	rfc822_threadmsg(mt, "<message1>", NULL,
			 "subject 1",
			 "Thu, 20 Jun 2000 14:41:58 -0700", 0, 1);

	rfc822_threadmsg(mt, "<message4>", "<message1>",
			 "subject 2",
			 "Thu, 21 Jun 2000 14:41:58 -0700", 0, 6);

	rfc822_threadmsg(mt, "<message1>", NULL,
			 "subject 2",
			 "Thu, 21 Jun 2000 14:41:58 -0700", 0, 5);

	rfc822_threadmsg(mt, "<message4>", "<message1>",
			 "subject 2",
			 "Thu, 21 Jun 2000 14:41:58 -0700", 0, 6);

	rfc822_threadprune(mt);
	rfc822_threadsortsubj(rfc822_threadgetroot(mt));
	rfc822_threadgathersubj(mt, rfc822_threadgetroot(mt));
	rfc822_threadmergesubj(mt, rfc822_threadgetroot(mt));
	rfc822_threadsortbydate(mt);
	prpc(mt);
	rfc822_threadfree(mt);
}

int main(int argc, char **argv)
{

#if HAVE_SETLOCALE
	setlocale(LC_ALL, "C");
#endif

	test1();
	test2();
	test3();
	test4();
	test5();
	test6();
	test7();
	test8();
	test9();
	test10();
	return (0);
}