1 /* GNU Mailutils -- a suite of utilities for electronic mail
2    Copyright (C) 2010-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 #ifdef HAVE_CONFIG_H
18 # include <config.h>
19 #endif
20 #include <mailutils/property.h>
21 #include <mailutils/iterator.h>
22 #include <mailutils/errno.h>
23 #include <mailutils/mh.h>
24 
25 mu_property_t mu_mh_profile;
26 mu_property_t mu_mh_context;
27 
28 const char *
mu_mhprop_get_value(mu_property_t prop,const char * name,const char * defval)29 mu_mhprop_get_value (mu_property_t prop, const char *name, const char *defval)
30 {
31   const char *p;
32 
33   if (!prop || mu_property_sget_value (prop, name, &p))
34     p = defval;
35   return p;
36 }
37 
38 int
mu_mhprop_iterate(mu_property_t prop,mu_mhprop_iterator_t fp,void * data)39 mu_mhprop_iterate (mu_property_t prop, mu_mhprop_iterator_t fp, void *data)
40 {
41   mu_iterator_t itr;
42   int rc;
43 
44   if (!prop)
45     return EINVAL;
46   rc = mu_property_get_iterator (prop, &itr);
47   if (rc)
48     return rc;
49   for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
50        mu_iterator_next (itr))
51     {
52       const char *name, *val;
53       mu_iterator_current_kv (itr, (const void **)&name, (void**)&val);
54       rc = fp (name, val, data);
55       if (rc)
56 	break;
57     }
58   mu_iterator_destroy (&itr);
59   return rc;
60 }
61