Back to index

courier  0.68.2
reftest.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2000 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 /*
00007 */
00008 
00009 #include      "config.h"
00010 
00011 #include      <stdio.h>
00012 #include      <stdlib.h>
00013 #include      <string.h>
00014 #include      <time.h>
00015 
00016 #if    HAVE_STRINGS_H
00017 #include      <strings.h>
00018 #endif
00019 
00020 #if    HAVE_LOCALE_H
00021 #include      <locale.h>
00022 #endif
00023 
00024 #include      "rfc822.h"
00025 #include      "imaprefs.h"
00026 
00027 
00028 static void test1()
00029 {
00030 struct imap_refmsgtable *mt=rfc822_threadalloc();
00031 char   buf[20];
00032 
00033         strcpy(buf, "a@b");
00034         rfc822_threadallocmsg(mt, buf);
00035         strcpy(buf, "c@d");
00036         rfc822_threadallocmsg(mt, buf);
00037 
00038        printf("%s\n", (rfc822_threadsearchmsg(mt, "a@b")
00039                      ? "found":"not found"));
00040        printf("%s\n", (rfc822_threadsearchmsg(mt, "c@d")
00041                      ? "found":"not found"));
00042        printf("%s\n", (rfc822_threadsearchmsg(mt, "e@f")
00043                      ? "found":"not found"));
00044 
00045        rfc822_threadfree(mt);
00046 }
00047 
00048 static void prtree(struct imap_refmsg *m)
00049 {
00050        printf("<%s>", m->msgid ? m->msgid:"");
00051 
00052        if (m->isdummy)
00053        {
00054               printf(" (dummy)");
00055        }
00056 
00057        printf(".parent=");
00058        if (m->parent)
00059               printf("<%s>", m->parent->msgid ? m->parent->msgid:"");
00060        else
00061               printf("ROOT");
00062 
00063        printf("\n");
00064 
00065        for (m=m->firstchild; m; m=m->nextsib)
00066               prtree(m);
00067 }
00068 
00069 static void prpc(struct imap_refmsgtable *mt)
00070 {
00071        struct imap_refmsg *root=rfc822_threadgetroot(mt), *m;
00072 
00073        if (!root)
00074               return;
00075 
00076        for (m=root->firstchild; m; m=m->nextsib)
00077               prtree(m);
00078 
00079        printf("\n\n");
00080 }
00081 
00082 static void test2()
00083 {
00084        struct imap_refmsgtable *mt=rfc822_threadalloc();
00085 
00086        rfc822_threadmsg(mt, "<1>", NULL,
00087                       "subject 1",
00088                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
00089 
00090        rfc822_threadmsg(mt, "<2>",
00091                       "<1>",
00092                       "subject 1",
00093                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
00094 
00095        rfc822_threadmsg(mt, "<4>",
00096                       "<1> <2> <3>",
00097                       "subject 1",
00098                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
00099 
00100        prpc(mt);
00101        rfc822_threadfree(mt);
00102 }
00103 
00104 static void test3()
00105 {
00106        struct imap_refmsgtable *mt=rfc822_threadalloc();
00107 
00108        rfc822_threadmsg(mt, "<4>",
00109                       "<2> <1> <3>",
00110                       "subject 1",
00111                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
00112 
00113        rfc822_threadmsg(mt, "<3>",
00114                       "<1> <2>",
00115                       "subject 1",
00116                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
00117 
00118        rfc822_threadmsg(mt, "<2>",
00119                       "<1>",
00120                       "subject 1",
00121                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
00122 
00123        rfc822_threadmsg(mt, "<1>", NULL,
00124                       "subject 1",
00125                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
00126 
00127        prpc(mt);
00128        rfc822_threadfree(mt);
00129 }
00130 
00131 static void test4()
00132 {
00133        struct imap_refmsgtable *mt=rfc822_threadalloc();
00134 
00135        rfc822_threadmsg(mt, "<1>", NULL,
00136                       "subject 1",
00137                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
00138 
00139        rfc822_threadmsg(mt, "<2>", "<1>",
00140                       "subject 1",
00141                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
00142 
00143        rfc822_threadmsg(mt, "<4>", "<1> <2> <3>",
00144                       "subject 1",
00145                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
00146 
00147        prpc(mt);
00148        rfc822_threadprune(mt);
00149        prpc(mt);
00150        rfc822_threadfree(mt);
00151 }
00152 
00153 static void test5()
00154 {
00155        struct imap_refmsgtable *mt=rfc822_threadalloc();
00156 
00157        rfc822_threadmsg(mt, "<4>", "<1> <2> <3>",
00158                       "subject 1",
00159                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
00160 
00161        rfc822_threadmsg(mt, "<3>", NULL,
00162                       "subject 1",
00163                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
00164 
00165        prpc(mt);
00166        rfc822_threadprune(mt);
00167        prpc(mt);
00168        rfc822_threadfree(mt);
00169 }
00170 
00171 static void prsubj(struct imap_refmsgtable *p)
00172 {
00173        struct imap_subjlookup *s;
00174        int i;
00175 
00176        for (i=0; i<sizeof(p->subjtable)/sizeof(p->subjtable[0]); i++)
00177               for (s=p->subjtable[i]; s; s=s->nextsubj)
00178                      printf("subject(%s)=<%s>\n", s->subj,
00179                             s->msg->msgid ? s->msg->msgid:"");
00180        printf("\n\n");
00181 }
00182 
00183 static void test6()
00184 {
00185        struct imap_refmsgtable *mt=rfc822_threadalloc();
00186 
00187        rfc822_threadmsg(mt, "<message1>", NULL,
00188                       "subject 1",
00189                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
00190 
00191        rfc822_threadmsg(mt, "<message10>", NULL,
00192                       "subject 2",
00193                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 2);
00194 
00195        rfc822_threadmsg(mt, "<message3>", "<message2>",
00196                       "subject 1",
00197                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 3);
00198 
00199        rfc822_threadmsg(mt, "<message11>", NULL,
00200                       "Re: subject 4",
00201                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 4);
00202 
00203        rfc822_threadmsg(mt, "<message12>", NULL,
00204                       "subject 4",
00205                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 5);
00206 
00207        rfc822_threadmsg(mt, "<message13>", NULL,
00208                       "subject 5",
00209                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 6);
00210 
00211        rfc822_threadmsg(mt, "<message14>", NULL,
00212                       "re: subject 5",
00213                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 7);
00214 
00215        rfc822_threadprune(mt);
00216        rfc822_threadsortsubj(rfc822_threadgetroot(mt));
00217        rfc822_threadgathersubj(mt, rfc822_threadgetroot(mt));
00218        prpc(mt);
00219        prsubj(mt);
00220        rfc822_threadfree(mt);
00221 }
00222 
00223 static void test7()
00224 {
00225        struct imap_refmsgtable *mt=rfc822_threadalloc();
00226 
00227        rfc822_threadmsg(mt, "<message1>", "<message1-dummy>",
00228                       "subject 1",
00229                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
00230 
00231        rfc822_threadmsg(mt, "<message2>", "<message2-dummy>",
00232                       "subject 1",
00233                       "Thu, 29 Jun 2000 14:41:58 -0700", 0, 1);
00234        rfc822_threadprune(mt);
00235        rfc822_threadsortsubj(rfc822_threadgetroot(mt));
00236        rfc822_threadgathersubj(mt, rfc822_threadgetroot(mt));
00237        prpc(mt);
00238        prsubj(mt);
00239        rfc822_threadmergesubj(mt, rfc822_threadgetroot(mt));
00240        prpc(mt);
00241        rfc822_threadfree(mt);
00242 }
00243 
00244 static void test8()
00245 {
00246        struct imap_refmsgtable *mt=rfc822_threadalloc();
00247 
00248        rfc822_threadmsg(mt, "<message4>", NULL,
00249                       "subject 2",
00250                       "Thu, 29 Jun 2000 14:41:51 -0700", 0, 1);
00251 
00252        rfc822_threadmsg(mt, "<message2>", NULL,
00253                       "subject 1",
00254                       "Thu, 29 Jun 2000 14:41:52 -0700", 0, 1);
00255 
00256        rfc822_threadmsg(mt, "<message1>", "<message1-dummy>",
00257                       "subject 1",
00258                       "Thu, 29 Jun 2000 14:41:53 -0700", 0, 1);
00259 
00260        rfc822_threadmsg(mt, "<message3>", NULL,
00261                       "Re: subject 2",
00262                       "Thu, 29 Jun 2000 14:41:54 -0700", 0, 1);
00263 
00264        rfc822_threadmsg(mt, "<message10>", NULL,
00265                       "subject 10",
00266                       "Thu, 29 Jun 2000 14:41:55 -0700", 0, 1);
00267 
00268        rfc822_threadmsg(mt, "<message11>", NULL,
00269                       "subject 10",
00270                       "Thu, 29 Jun 2000 14:41:56 -0700", 0, 1);
00271 
00272        rfc822_threadprune(mt);
00273        rfc822_threadsortsubj(rfc822_threadgetroot(mt));
00274        rfc822_threadgathersubj(mt, rfc822_threadgetroot(mt));
00275        prpc(mt);
00276        prsubj(mt);
00277        rfc822_threadmergesubj(mt, rfc822_threadgetroot(mt));
00278        prpc(mt);
00279        rfc822_threadfree(mt);
00280 }
00281 
00282 static void test9()
00283 {
00284        struct imap_refmsgtable *mt=rfc822_threadalloc();
00285 
00286        rfc822_threadmsg(mt, "<message1>", NULL,
00287                       "subject 1",
00288                       "Thu, 20 Jun 2000 14:41:55 -0700", 0, 1);
00289 
00290        rfc822_threadmsg(mt, "<message2>", NULL,
00291                       "subject 1",
00292                       "Thu, 19 Jun 2000 14:41:51 -0700", 0, 2);
00293 
00294        rfc822_threadmsg(mt, "<message3>", NULL,
00295                       "subject 1",
00296                       "Thu, 21 Jun 2000 14:41:56 -0700", 0, 3);
00297 
00298        rfc822_threadmsg(mt, "<message4>", "<message2>",
00299                       "subject 2",
00300                       "Thu, 21 Jun 2000 14:41:54 -0700", 0, 6);
00301 
00302        rfc822_threadmsg(mt, "<message5>", "<message2>",
00303                       "subject 2",
00304                       "Thu, 21 Jun 2000 14:41:53 -0700", 0, 5);
00305 
00306        rfc822_threadmsg(mt, "<message6>", "<message2>",
00307                       "subject 2",
00308                       "Thu, 20 Jun 2000 14:41:52 -0700", 0, 4);
00309 
00310 
00311        rfc822_threadprune(mt);
00312        rfc822_threadsortsubj(rfc822_threadgetroot(mt));
00313        rfc822_threadgathersubj(mt, rfc822_threadgetroot(mt));
00314        rfc822_threadmergesubj(mt, rfc822_threadgetroot(mt));
00315        rfc822_threadsortbydate(mt);
00316        prpc(mt);
00317        rfc822_threadfree(mt);
00318 }
00319 
00320 static void test10()
00321 {
00322        struct imap_refmsgtable *mt=rfc822_threadalloc();
00323 
00324        rfc822_threadmsg(mt, "<message1>", NULL,
00325                       "subject 1",
00326                       "Thu, 20 Jun 2000 14:41:58 -0700", 0, 1);
00327 
00328        rfc822_threadmsg(mt, "<message4>", "<message1>",
00329                       "subject 2",
00330                       "Thu, 21 Jun 2000 14:41:58 -0700", 0, 6);
00331 
00332        rfc822_threadmsg(mt, "<message1>", NULL,
00333                       "subject 2",
00334                       "Thu, 21 Jun 2000 14:41:58 -0700", 0, 5);
00335 
00336        rfc822_threadmsg(mt, "<message4>", "<message1>",
00337                       "subject 2",
00338                       "Thu, 21 Jun 2000 14:41:58 -0700", 0, 6);
00339 
00340        rfc822_threadprune(mt);
00341        rfc822_threadsortsubj(rfc822_threadgetroot(mt));
00342        rfc822_threadgathersubj(mt, rfc822_threadgetroot(mt));
00343        rfc822_threadmergesubj(mt, rfc822_threadgetroot(mt));
00344        rfc822_threadsortbydate(mt);
00345        prpc(mt);
00346        rfc822_threadfree(mt);
00347 }
00348 
00349 int main(int argc, char **argv)
00350 {
00351 
00352 #if HAVE_SETLOCALE
00353        setlocale(LC_ALL, "C");
00354 #endif
00355 
00356        test1();
00357        test2();
00358        test3();
00359        test4();
00360        test5();
00361        test6();
00362        test7();
00363        test8();
00364        test9();
00365        test10();
00366        return (0);
00367 }