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 /* MH message sets. */
18
19 #include <mh.h>
20
21 /* Default value for missing "cur". Valid values are 0 and 1. */
22 int mh_mailbox_cur_default = 0;
23
24 void
mh_mailbox_get_cur(mu_mailbox_t mbox,size_t * pcur)25 mh_mailbox_get_cur (mu_mailbox_t mbox, size_t *pcur)
26 {
27 mu_property_t prop = NULL;
28 const char *s;
29 int rc = mu_mailbox_get_property (mbox, &prop);
30 if (rc)
31 {
32 mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_get_property", NULL, rc);
33 exit (1);
34 }
35 rc = mu_property_sget_value (prop, "cur", &s);
36 if (rc == MU_ERR_NOENT)
37 *pcur = mh_mailbox_cur_default;
38 else if (rc == 0)
39 {
40 char *p;
41 *pcur = strtoul (s, &p, 10);
42 if (*p)
43 p = mu_str_skip_class (p, MU_CTYPE_SPACE);
44 if (*p)
45 {
46 mu_error (_("invalid \"cur\" value (%s)"), s);
47 *pcur = 1;
48 }
49 }
50 else
51 {
52 mu_diag_funcall (MU_DIAG_ERROR, "mu_property_sget_value", NULL, rc);
53 exit (1);
54 }
55 }
56
57 void
mh_mailbox_set_cur(mu_mailbox_t mbox,size_t cur)58 mh_mailbox_set_cur (mu_mailbox_t mbox, size_t cur)
59 {
60 mu_property_t prop = NULL;
61 int rc = mu_mailbox_get_property (mbox, &prop);
62 if (rc)
63 {
64 mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_get_property", NULL, rc);
65 exit (1);
66 }
67 rc = mu_property_set_value (prop, "cur", mu_umaxtostr (0, cur), 1);
68 if (rc)
69 {
70 mu_diag_funcall (MU_DIAG_ERROR, "mu_property_set_value", NULL, rc);
71 exit (1);
72 }
73 }
74
75
76