Commit 33fdea47 33fdea476cfc31d1a1e2e4b55fac3f1ee462e25c by Sam Roberts

Added new example, mbox-check.c

1 parent b6e19557
...@@ -2,14 +2,18 @@ ...@@ -2,14 +2,18 @@
2 2
3 CFLAGS = -g -I../include -Wall 3 CFLAGS = -g -I../include -Wall
4 LDFLAGS = -g -static 4 LDFLAGS = -g -static
5 LDLIBS = ../mailbox/.libs/libmailbox.a ../lib/libmailutils.a -lsocket 5 LDLIBS = -lsocket
6 6
7 EXES = addr mbox-explode mbox-dates mbox-auth url-parse 7 MULIBS = ../mailbox/.libs/libmailbox.a ../lib/libmailutils.a
8 8
9 $(EXES): $(LDLIBS) 9 EXES = addr mbox-explode mbox-dates mbox-auth url-parse mbox-check
10
11 $(EXES): $(MULIBS)
10 12
11 default: $(EXES) 13 default: $(EXES)
12 14
15 $(EXES): $(MBOXLIB)
16
13 # example of parsing the date fields, prints all the incorrectly 17 # example of parsing the date fields, prints all the incorrectly
14 # formatted dates in a mailbox. 18 # formatted dates in a mailbox.
15 19
......
1 #include <sys/types.h>
2 #include <sys/stat.h>
3
4 #include <errno.h>
5 #include <fcntl.h>
6 #include <limits.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <time.h>
11 #include <unistd.h>
12
13 #include <mailutils/mailbox.h>
14 #include <mailutils/address.h>
15 #include <mailutils/registrar.h>
16 #include <mailutils/parse822.h>
17
18 int
19 main (int argc, char **argv)
20 {
21 mailbox_t mbox;
22 size_t count = 0;
23 char *mboxname = argv[1];
24 int status;
25
26 /* Register desired mailbox formats. */
27 {
28 list_t bookie;
29 registrar_get_list (&bookie);
30 list_append (bookie, path_record);
31 list_append (bookie, pop_record);
32 list_append (bookie, imap_record);
33 }
34
35 if ((status = mailbox_create_default (&mbox, mboxname)) != 0)
36 {
37 fprintf (stderr, "could not create <%s>: %s\n",
38 mboxname, strerror (status));
39 return status;
40 }
41
42 {
43 mu_debug_t debug;
44 mailbox_get_debug (mbox, &debug);
45 mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT);
46 }
47
48 if ((status = mailbox_open (mbox, MU_STREAM_READ)) != 0)
49 {
50 fprintf (stderr, "could not open <%s>: %s\n",
51 mboxname, strerror (status));
52 mailbox_destroy (&mbox);
53 exit (1);
54 }
55
56 if ((status = mailbox_messages_count (mbox, &count)) != 0)
57 {
58 fprintf (stderr, "could not count <%s>: %s\n",
59 mboxname, strerror (status));
60 mailbox_close (mbox);
61 mailbox_destroy (&mbox);
62 exit (1);
63 }
64
65 mailbox_close (mbox);
66 mailbox_destroy (&mbox);
67
68 printf("count %d messages in <%s>\n", count, mboxname);
69
70 return 0;
71 }
72