1 |
/* GNU mailutils - a suite of utilities for electronic mail |
/* GNU Mailutils -- a suite of utilities for electronic mail |
2 |
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. |
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
GNU Mailutils is free software; you can redistribute it and/or modify |
5 |
it under the terms of the GNU General Library Public License as published by |
it under the terms of the GNU General Library Public License as published by |
6 |
the Free Software Foundation; either version 2, or (at your option) |
the Free Software Foundation; either version 2, or (at your option) |
7 |
any later version. |
any later version. |
8 |
|
|
9 |
This program is distributed in the hope that it will be useful, |
GNU Mailutils is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU Library General Public License for more details. |
GNU Library General Public License for more details. |
13 |
|
|
14 |
You should have received a copy of the GNU Library General Public License |
You should have received a copy of the GNU Library General Public License |
15 |
along with this program; if not, write to the Free Software |
along with GNU Mailutils; if not, write to the Free Software |
16 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
17 |
|
|
18 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
31 |
static int messages_count (const char *); |
static int messages_count (const char *); |
32 |
|
|
33 |
const char *argp_program_version = "messages (" PACKAGE_STRING ")"; |
const char *argp_program_version = "messages (" PACKAGE_STRING ")"; |
34 |
static char doc[] = "GNU messages -- count the number of messages in a mailbox"; |
static char doc[] = N_("GNU messages -- count the number of messages in a mailbox"); |
35 |
static char args_doc[] = "[mailbox...]"; |
static char args_doc[] = N_("[mailbox...]"); |
36 |
|
|
37 |
static struct argp_option options[] = { |
static struct argp_option options[] = { |
38 |
{NULL, 0, NULL, 0, |
{ NULL, 0, NULL, 0, N_("messages specific switches:"), 0}, |
39 |
"messages specific switches:", 0}, |
{"quiet", 'q', 0, 0, N_("Only display number of messages")}, |
40 |
{"quiet", 'q', 0, 0, "Only display number of messages"}, |
{"silent", 's', 0, 0, N_("Same as -q")}, |
|
{"silent", 's', 0, 0, "Same as -q"}, |
|
41 |
{ 0 } |
{ 0 } |
42 |
}; |
}; |
43 |
|
|
97 |
int err = 0; |
int err = 0; |
98 |
struct arguments args = {0, NULL}; |
struct arguments args = {0, NULL}; |
99 |
|
|
100 |
|
/* Native Language Support */ |
101 |
|
mu_init_nls (); |
102 |
|
|
103 |
mu_argp_parse (&argp, &argc, &argv, 0, argp_capa, NULL, &args); |
mu_argp_parse (&argp, &argc, &argv, 0, argp_capa, NULL, &args); |
104 |
|
|
105 |
registrar_get_list (&bookie); |
registrar_get_list (&bookie); |
128 |
|
|
129 |
if (mailbox_create_default (&mbox, box) != 0) |
if (mailbox_create_default (&mbox, box) != 0) |
130 |
{ |
{ |
131 |
fprintf (stderr, "Couldn't create mailbox %s.\n", (box) ? box : ""); |
fprintf (stderr, _("Couldn't create mailbox %s.\n"), (box) ? box : ""); |
132 |
return -1; |
return -1; |
133 |
} |
} |
134 |
|
|
137 |
|
|
138 |
if (mailbox_open (mbox, MU_STREAM_READ) != 0) |
if (mailbox_open (mbox, MU_STREAM_READ) != 0) |
139 |
{ |
{ |
140 |
fprintf (stderr, "Couldn't open mailbox %s.\n", box); |
fprintf (stderr, _("Couldn't open mailbox %s.\n"), box); |
141 |
return -1; |
return -1; |
142 |
} |
} |
143 |
|
|
144 |
if (mailbox_messages_count (mbox, &count) != 0) |
if (mailbox_messages_count (mbox, &count) != 0) |
145 |
{ |
{ |
146 |
fprintf (stderr, "Couldn't count messages in %s.\n", box); |
fprintf (stderr, _("Couldn't count messages in %s.\n"), box); |
147 |
return -1; |
return -1; |
148 |
} |
} |
149 |
|
|
150 |
if (silent) |
if (silent) |
151 |
printf ("%d\n", count); |
printf ("%d\n", count); |
152 |
else |
else |
153 |
printf ("Number of messages in %s: %d\n", box, count); |
printf (_("Number of messages in %s: %d\n"), box, count); |
154 |
|
|
155 |
if (mailbox_close (mbox) != 0) |
if (mailbox_close (mbox) != 0) |
156 |
{ |
{ |
157 |
fprintf (stderr, "Couldn't close %s.\n", box); |
fprintf (stderr, _("Couldn't close %s.\n"), box); |
158 |
return -1; |
return -1; |
159 |
} |
} |
160 |
mailbox_destroy (&mbox); |
mailbox_destroy (&mbox); |