1 /* GNU Mailutils -- a suite of utilities for electronic mail
2    Copyright (C) 1999-2021 Free Software Foundation, Inc.
3 
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 3 of the License, or (at your option) any later version.
8 
9    This library 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 GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General
15    Public License along with this library.  If not, see
16    <http://www.gnu.org/licenses/>. */
17 
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include <mailutils/types.h>
22 #include <mailutils/mailbox.h>
23 #include <mailutils/stream.h>
24 #include <mailutils/errno.h>
25 #include <mailutils/msgset.h>
26 #include <mailutils/sys/mailbox.h>
27 
28 int
mu_mailbox_msgset_copy(mu_mailbox_t mbox,mu_msgset_t msgset,const char * dest,int flags)29 mu_mailbox_msgset_copy (mu_mailbox_t mbox, mu_msgset_t msgset,
30 			const char *dest, int flags)
31 {
32   if (!mbox)
33     return EINVAL;
34   if (!mbox->_copy)
35     return ENOSYS;
36   return mbox->_copy (mbox, msgset, dest, flags);
37 }
38 
39 int
mu_mailbox_message_copy(mu_mailbox_t mbox,size_t msgno,const char * dest,int flags)40 mu_mailbox_message_copy (mu_mailbox_t mbox, size_t msgno,
41 			 const char *dest, int flags)
42 {
43   int rc;
44   mu_msgset_t msgset;
45   int mode;
46 
47   if (!mbox)
48     return EINVAL;
49   if (!mbox->_copy)
50     return ENOSYS;
51 
52   mode = flags & MU_MAILBOX_COPY_UID ? MU_MSGSET_UID : MU_MSGSET_NUM;
53   rc = mu_msgset_create (&msgset, mbox, mode);
54   if (rc)
55     return rc;
56   rc = mu_msgset_add_range (msgset, 1, 1, mode);
57   if (rc == 0)
58     rc = mbox->_copy (mbox, msgset, dest, flags);
59   mu_msgset_destroy (&msgset);
60   return rc;
61 }
62