new file, implementation of elm messages command
Showing
1 changed file
with
78 additions
and
0 deletions
messages/messages.c
0 → 100644
1 | #include "config.h" | ||
2 | #include <mailutils/mailutils.h> | ||
3 | #include <stdio.h> | ||
4 | #include <argp.h> | ||
5 | |||
6 | const char *argp_program_version = "messages (" PACKAGE ") " VERSION; | ||
7 | const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; | ||
8 | static char doc[] = "GNU messages -- count the number of messages in a mailbox"; | ||
9 | static char args_doc[] = "[mailbox...]"; | ||
10 | |||
11 | static struct argp_option options[] = { | ||
12 | { 0 } | ||
13 | }; | ||
14 | |||
15 | struct arguments | ||
16 | { | ||
17 | char **args; | ||
18 | }; | ||
19 | |||
20 | static error_t | ||
21 | parse_opt (int key, char *arg, struct argp_state *state) | ||
22 | { | ||
23 | return 0; | ||
24 | } | ||
25 | |||
26 | static struct argp argp = { options, parse_opt, args_doc, doc }; | ||
27 | |||
28 | int | ||
29 | main (int argc, char **argv) | ||
30 | { | ||
31 | int i = 1; | ||
32 | list_t bookie; | ||
33 | mailbox_t mbox; | ||
34 | int count; | ||
35 | int err = 0; | ||
36 | struct arguments args; | ||
37 | args.args = NULL; | ||
38 | |||
39 | argp_parse (&argp, argc, argv, 0, 0, &args); | ||
40 | |||
41 | registrar_get_list (&bookie); | ||
42 | list_append (bookie, path_record); | ||
43 | |||
44 | /* FIXME: if argc < 2, check on $MAIL and exit */ | ||
45 | |||
46 | for (i=1; i < argc; i++) | ||
47 | { | ||
48 | if (mailbox_create_default (&mbox, argv[i]) != 0) | ||
49 | { | ||
50 | fprintf (stderr, "Couldn't create mailbox %s.\n", argv[i]); | ||
51 | err = 1; | ||
52 | continue; | ||
53 | } | ||
54 | if (mailbox_open (mbox, MU_STREAM_READ) != 0) | ||
55 | { | ||
56 | fprintf (stderr, "Couldn't open mailbox %s.\n", argv[i]); | ||
57 | err = 1; | ||
58 | continue; | ||
59 | } | ||
60 | if (mailbox_messages_count (mbox, &count) != 0) | ||
61 | { | ||
62 | fprintf (stderr, "Couldn't count messages in %s.\n", argv[i]); | ||
63 | err = 1; | ||
64 | continue; | ||
65 | } | ||
66 | |||
67 | printf ("Number of messages in %s: %d\n", argv[i], count); | ||
68 | |||
69 | if (mailbox_close (mbox) != 0) | ||
70 | { | ||
71 | fprintf (stderr, "Couldn't close %s.\n", argv[i]); | ||
72 | err = 1; | ||
73 | continue; | ||
74 | } | ||
75 | mailbox_destroy (&mbox); | ||
76 | } | ||
77 | return 0; | ||
78 | } |
-
Please register or sign in to post a comment