Back to index

courier  0.68.2
maildirkwtest.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2003 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #if    HAVE_CONFIG_H
00007 #include      "config.h"
00008 #endif
00009 #include      <stdio.h>
00010 #include      <stdlib.h>
00011 #include      <string.h>
00012 #include      <errno.h>
00013 #if    HAVE_UNISTD_H
00014 #include      <unistd.h>
00015 #endif
00016 #include      "maildir/maildirkeywords.h"
00017 
00018 static struct libmail_kwHashtable h;
00019 
00020 int smapflag=0;
00021 
00022 static int count_flags(struct libmail_keywordEntry *dummy1, void *dummy)
00023 {
00024        ++*(size_t *)dummy;
00025 
00026        return 0;
00027 }
00028 
00029 static struct libmail_kwMessage *msgs[3];
00030 static const char * const flags[]={"apple", "banana", "pear", "grape"};
00031 
00032 
00033 static int dump()
00034 {
00035        size_t cnt=0;
00036 
00037        if (libmail_kwEnumerate(&h, &count_flags, &cnt))
00038               return -1;
00039 
00040        printf("%d flags\n", (int)cnt);
00041 
00042        for (cnt=0; cnt<sizeof(msgs)/sizeof(msgs[0]); cnt++)
00043        {
00044               struct libmail_kwMessageEntry *e;
00045 
00046               printf("%d:", (int)cnt);
00047 
00048               for (e=msgs[cnt]->firstEntry; e; e=e->next)
00049                      printf(" %s", keywordName(e->libmail_keywordEntryPtr));
00050               printf("\n");
00051        }
00052        return 0;
00053 
00054 }
00055 
00056 int main()
00057 {
00058        size_t i;
00059 
00060        libmail_kwhInit(&h);
00061 
00062        for (i=0; i<sizeof(msgs)/sizeof(msgs[0]); i++)
00063        {
00064               if ((msgs[i]=libmail_kwmCreate()) == NULL)
00065               {
00066                      perror("malloc");
00067                      exit(1);
00068               }
00069 
00070               msgs[i]->u.userNum=i;
00071        }
00072 
00073        if (libmail_kwmSetName(&h, msgs[0], flags[0]) >= 0 &&
00074            libmail_kwmSetName(&h, msgs[1], flags[1]) >= 0 &&
00075            libmail_kwmSetName(&h, msgs[2], flags[2]) >= 0 &&
00076            libmail_kwmSetName(&h, msgs[0], flags[0]) >= 0 &&
00077            libmail_kwmSetName(&h, msgs[0], flags[1]) >= 0 &&
00078            libmail_kwmSetName(&h, msgs[1], flags[2]) >= 0 &&
00079            libmail_kwmSetName(&h, msgs[2], flags[3]) >= 0)
00080        {
00081 
00082               if (dump() == 0)
00083               {
00084                      libmail_kwmClearName(msgs[2], flags[3]);
00085                      libmail_kwmClearName(msgs[2], flags[3]);
00086                      libmail_kwmClearName(msgs[0], flags[1]);
00087 
00088                      if (dump() == 0)
00089                             exit(0);
00090               }
00091 
00092        }
00093 
00094        perror("ERROR");
00095        exit(1);
00096        return 0;
00097 }