1 /* GNU Mailutils -- a suite of utilities for electronic mail
2    Copyright (C) 1999-2021 Free Software Foundation, Inc.
3 
4    GNU Mailutils is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3, or (at your option)
7    any later version.
8 
9    GNU Mailutils is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
16 
17 #include <mailutils/mailutils.h>
18 
19 struct mu_cli_setup cli = {
20   NULL,
21   NULL,
22   "compute mailbox size",
23   "MBOX"
24 };
25 
26 static char *capa[] = {
27   "debug",
28   NULL
29 };
30 
31 int
main(int argc,char ** argv)32 main (int argc, char **argv)
33 {
34   int rc;
35   mu_mailbox_t mbox;
36   mu_off_t size;
37   char *name;
38 
39   mu_register_all_mbox_formats ();
40 
41   mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
42 
43   if (argc != 1)
44     {
45       mu_error ("wrong number of arguments");
46       return 1;
47     }
48   name = argv[0];
49 
50   rc = mu_mailbox_create_default (&mbox, name);
51   if (rc)
52     {
53       mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_create_default",
54 		       name, rc);
55       return 1;
56     }
57 
58   rc = mu_mailbox_open (mbox, MU_STREAM_READ);
59   if (rc)
60     {
61       mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_open", name, rc);
62       return 1;
63     }
64 
65   rc = mu_mailbox_get_size (mbox, &size);
66   if (rc)
67     {
68       mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_get_size", name, rc);
69       return 1;
70     }
71 
72   mu_printf ("%" MU_PRI_OFF_T "\n", size);
73 
74   return 0;
75 }
76 
77 
78 
79 
80