Commit 33dff02c 33dff02c09308d64461dff673f92a9a0a6533bbb by Sergey Poznyakoff

Commit missing file

1 parent 455554b8
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2017 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 <config.h>
18 #include <stdlib.h>
19 #include <mailutils/types.h>
20 #include <mailutils/errno.h>
21 #include <mailutils/list.h>
22 #include <mailutils/msgset.h>
23 #include <mailutils/sys/msgset.h>
24
25 static int
26 copy_range (void *item, void *data)
27 {
28 struct mu_msgrange const *range = item;
29 mu_list_t list = data;
30 struct mu_msgrange *copy;
31
32 copy = malloc (sizeof (*copy));
33 if (!copy)
34 return ENOMEM;
35 *copy = *range;
36 return mu_list_append (list, copy);
37 }
38
39 int
40 mu_msgset_copy (mu_msgset_t src, mu_msgset_t dst)
41 {
42 mu_list_t list;
43 int rc;
44
45 if (!src || !dst)
46 return EINVAL;
47
48 rc = mu_list_create (&list);
49 if (rc)
50 return rc;
51
52 rc = mu_list_foreach (src->list, copy_range, list);
53 if (rc == 0)
54 mu_list_append_list (dst->list, list);
55 mu_list_destroy (&list);
56
57 return rc;
58 }