Commit 33fdea47 33fdea476cfc31d1a1e2e4b55fac3f1ee462e25c by Sam Roberts

Added new example, mbox-check.c

1 parent b6e19557
......@@ -2,14 +2,18 @@
CFLAGS = -g -I../include -Wall
LDFLAGS = -g -static
LDLIBS = ../mailbox/.libs/libmailbox.a ../lib/libmailutils.a -lsocket
LDLIBS = -lsocket
EXES = addr mbox-explode mbox-dates mbox-auth url-parse
MULIBS = ../mailbox/.libs/libmailbox.a ../lib/libmailutils.a
$(EXES): $(LDLIBS)
EXES = addr mbox-explode mbox-dates mbox-auth url-parse mbox-check
$(EXES): $(MULIBS)
default: $(EXES)
$(EXES): $(MBOXLIB)
# example of parsing the date fields, prints all the incorrectly
# formatted dates in a mailbox.
......
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <mailutils/mailbox.h>
#include <mailutils/address.h>
#include <mailutils/registrar.h>
#include <mailutils/parse822.h>
int
main (int argc, char **argv)
{
mailbox_t mbox;
size_t count = 0;
char *mboxname = argv[1];
int status;
/* Register desired mailbox formats. */
{
list_t bookie;
registrar_get_list (&bookie);
list_append (bookie, path_record);
list_append (bookie, pop_record);
list_append (bookie, imap_record);
}
if ((status = mailbox_create_default (&mbox, mboxname)) != 0)
{
fprintf (stderr, "could not create <%s>: %s\n",
mboxname, strerror (status));
return status;
}
{
mu_debug_t debug;
mailbox_get_debug (mbox, &debug);
mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT);
}
if ((status = mailbox_open (mbox, MU_STREAM_READ)) != 0)
{
fprintf (stderr, "could not open <%s>: %s\n",
mboxname, strerror (status));
mailbox_destroy (&mbox);
exit (1);
}
if ((status = mailbox_messages_count (mbox, &count)) != 0)
{
fprintf (stderr, "could not count <%s>: %s\n",
mboxname, strerror (status));
mailbox_close (mbox);
mailbox_destroy (&mbox);
exit (1);
}
mailbox_close (mbox);
mailbox_destroy (&mbox);
printf("count %d messages in <%s>\n", count, mboxname);
return 0;
}