messages.c
1.6 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
73
74
75
76
77
78
#include "config.h"
#include <mailutils/mailutils.h>
#include <stdio.h>
#include <argp.h>
const char *argp_program_version = "messages (" PACKAGE ") " VERSION;
const char *argp_program_bug_address = "<bug-mailutils@gnu.org>";
static char doc[] = "GNU messages -- count the number of messages in a mailbox";
static char args_doc[] = "[mailbox...]";
static struct argp_option options[] = {
{ 0 }
};
struct arguments
{
char **args;
};
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
return 0;
}
static struct argp argp = { options, parse_opt, args_doc, doc };
int
main (int argc, char **argv)
{
int i = 1;
list_t bookie;
mailbox_t mbox;
int count;
int err = 0;
struct arguments args;
args.args = NULL;
argp_parse (&argp, argc, argv, 0, 0, &args);
registrar_get_list (&bookie);
list_append (bookie, path_record);
/* FIXME: if argc < 2, check on $MAIL and exit */
for (i=1; i < argc; i++)
{
if (mailbox_create_default (&mbox, argv[i]) != 0)
{
fprintf (stderr, "Couldn't create mailbox %s.\n", argv[i]);
err = 1;
continue;
}
if (mailbox_open (mbox, MU_STREAM_READ) != 0)
{
fprintf (stderr, "Couldn't open mailbox %s.\n", argv[i]);
err = 1;
continue;
}
if (mailbox_messages_count (mbox, &count) != 0)
{
fprintf (stderr, "Couldn't count messages in %s.\n", argv[i]);
err = 1;
continue;
}
printf ("Number of messages in %s: %d\n", argv[i], count);
if (mailbox_close (mbox) != 0)
{
fprintf (stderr, "Couldn't close %s.\n", argv[i]);
err = 1;
continue;
}
mailbox_destroy (&mbox);
}
return 0;
}