mbox-check.c
1.52 KB
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
#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;
}