summaryrefslogtreecommitdiff
path: root/libmailutils
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-12-26 14:06:57 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2011-12-26 20:34:13 +0200
commite072a2734eaf1bffdacfc20fcb598d79a50d11e7 (patch)
tree62b91a5c1e240aee855bc87431ad75b73ca32367 /libmailutils
parentd16a3de50d8c43f7b45f18db1704fa784ee4cb7b (diff)
downloadmailutils-e072a2734eaf1bffdacfc20fcb598d79a50d11e7.tar.gz
mailutils-e072a2734eaf1bffdacfc20fcb598d79a50d11e7.tar.bz2
Add functions for operations on message sets.
* configure.ac: Build libmailutils/msgset/Makefile * include/mailutils/msgset.h: New file. * include/mailutils/Makefile.am (pkginclude_HEADERS): Add msgset.h * include/mailutils/mailutils.h: Include mailutils/msgset.h * include/mailutils/sys/msgset.h: New file. * include/mailutils/sys/Makefile.am (sysinclude_HEADERS): Add msgset.h * include/mailutils/types.hin (mu_msgset_t): New type. * libmailutils/Makefile.am (SUBDIRS): Add msgset. (libmailutils_la_LIBADD): Add libmsgset.la * libmailutils/msgset/Makefile.am: New file. * libmailutils/msgset/add.c: New file. * libmailutils/msgset/aggr.c: New file. * libmailutils/msgset/clear.c: New file. * libmailutils/msgset/create.c: New file. * libmailutils/msgset/free.c: New file. * libmailutils/msgset/getitr.c: New file. * libmailutils/msgset/getlist.c: New file. * libmailutils/msgset/locate.c: New file. * libmailutils/msgset/parse.c: New file. * libmailutils/msgset/print.c: New file. * libmailutils/msgset/sub.c: New file. * libmailutils/tests/msgset.at: New file. * libmailutils/tests/msgset.c: New file. * libmailutils/tests/Makefile.am (noinst_PROGRAMS): Add msgset. (TESTSUITE_AT): Add msgset.at. * libmailutils/tests/testsuite.at: Include msgset.at. * testsuite/msgset.c: New file. * testsuite/Makefile.am (noinst_PROGRAMS): Add msgset.
Diffstat (limited to 'libmailutils')
-rw-r--r--libmailutils/Makefile.am3
-rw-r--r--libmailutils/msgset/Makefile.am34
-rw-r--r--libmailutils/msgset/add.c43
-rw-r--r--libmailutils/msgset/aggr.c169
-rw-r--r--libmailutils/msgset/clear.c32
-rw-r--r--libmailutils/msgset/create.c60
-rw-r--r--libmailutils/msgset/free.c42
-rw-r--r--libmailutils/msgset/getitr.c30
-rw-r--r--libmailutils/msgset/getlist.c33
-rw-r--r--libmailutils/msgset/locate.c32
-rw-r--r--libmailutils/msgset/parse.c179
-rw-r--r--libmailutils/msgset/print.c74
-rw-r--r--libmailutils/msgset/sub.c233
-rw-r--r--libmailutils/tests/Makefile.am2
-rw-r--r--libmailutils/tests/msgset.at175
-rw-r--r--libmailutils/tests/msgset.c125
-rw-r--r--libmailutils/tests/testsuite.at2
17 files changed, 1267 insertions, 1 deletions
diff --git a/libmailutils/Makefile.am b/libmailutils/Makefile.am
index c01b32176..bbc844768 100644
--- a/libmailutils/Makefile.am
+++ b/libmailutils/Makefile.am
@@ -18,7 +18,7 @@
18 18
19SUBDIRS = \ 19SUBDIRS = \
20 auth base address list sockaddr cidr cfg diag\ 20 auth base address list sockaddr cidr cfg diag\
21 filter mailbox mailer mime server string stream stdstream\ 21 filter mailbox mailer mime msgset server string stream stdstream\
22 property url imapio datetime . tests 22 property url imapio datetime . tests
23 23
24lib_LTLIBRARIES = libmailutils.la 24lib_LTLIBRARIES = libmailutils.la
@@ -41,6 +41,7 @@ libmailutils_la_LIBADD = \
41 mailbox/libmailbox.la\ 41 mailbox/libmailbox.la\
42 mailer/libmailer.la\ 42 mailer/libmailer.la\
43 mime/libmime.la\ 43 mime/libmime.la\
44 msgset/libmsgset.la\
44 property/libproperty.la\ 45 property/libproperty.la\
45 server/libserver.la\ 46 server/libserver.la\
46 string/libstring.la\ 47 string/libstring.la\
diff --git a/libmailutils/msgset/Makefile.am b/libmailutils/msgset/Makefile.am
new file mode 100644
index 000000000..398806d49
--- /dev/null
+++ b/libmailutils/msgset/Makefile.am
@@ -0,0 +1,34 @@
1# GNU Mailutils -- a suite of utilities for electronic mail
2# Copyright (C) 2011 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
18noinst_LTLIBRARIES = libmsgset.la
19
20libmsgset_la_SOURCES = \
21 add.c\
22 aggr.c\
23 clear.c\
24 create.c\
25 getitr.c\
26 getlist.c\
27 free.c\
28 locate.c\
29 parse.c\
30 print.c\
31 sub.c
32
33INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
34
diff --git a/libmailutils/msgset/add.c b/libmailutils/msgset/add.c
new file mode 100644
index 000000000..9d9770735
--- /dev/null
+++ b/libmailutils/msgset/add.c
@@ -0,0 +1,43 @@
1/* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2011 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
25int
26mu_msgset_add_range (mu_msgset_t mset, size_t beg, size_t end)
27{
28 int rc;
29 struct mu_msgrange *range;
30
31 if (!mset || beg == 0)
32 return EINVAL;
33 range = calloc (1, sizeof (*range));
34 if (!range)
35 return ENOMEM;
36 range->msg_beg = beg;
37 range->msg_end = end;
38 rc = mu_list_append (mset->list, range);
39 if (rc)
40 free (range);
41 mset->flags &= ~_MU_MSGSET_AGGREGATED;
42 return rc;
43}
diff --git a/libmailutils/msgset/aggr.c b/libmailutils/msgset/aggr.c
new file mode 100644
index 000000000..a6fe7aa19
--- /dev/null
+++ b/libmailutils/msgset/aggr.c
@@ -0,0 +1,169 @@
1/* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2011 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/iterator.h>
23#include <mailutils/msgset.h>
24#include <mailutils/sys/msgset.h>
25
26/* Comparator function for sorting the message set list. */
27static int
28compare_msgrange (const void *a, const void *b)
29{
30 struct mu_msgrange const *sa = a;
31 struct mu_msgrange const *sb = b;
32
33 if (sa->msg_end != sb->msg_end)
34 {
35 if (sa->msg_end == MU_MSGNO_LAST)
36 return 1;
37 if (sb->msg_end == MU_MSGNO_LAST)
38 return -1;
39 }
40
41 if (sa->msg_beg < sb->msg_beg)
42 return -1;
43 if (sa->msg_beg > sb->msg_beg)
44 return 1;
45
46 if (sa->msg_end == sb->msg_end)
47 return 0;
48
49 if (sa->msg_end < sb->msg_end)
50 return -1;
51 return 1;
52}
53
54int
55mu_msgset_aggregate (mu_msgset_t mset)
56{
57 int rc;
58 mu_iterator_t itr;
59 size_t count;
60 struct mu_msgrange *prev = NULL, *mr;
61 int dir;
62
63 if (!mset)
64 return EINVAL;
65
66 if (mset->flags & _MU_MSGSET_AGGREGATED)
67 return 0; /* nothing to do */
68
69 rc = mu_list_count (mset->list, &count);
70 if (rc)
71 return rc;
72 if (count < 2)
73 return 0;
74
75 mu_list_sort (mset->list, compare_msgrange);
76
77 rc = mu_list_get_iterator (mset->list, &itr);
78 if (rc)
79 return rc;
80 /* Set backward direction */
81 dir = 1;
82 rc = mu_iterator_ctl (itr, mu_itrctl_set_direction, &dir);
83 if (rc)
84 {
85 mu_iterator_destroy (&itr);
86 return rc;
87 }
88
89 mu_iterator_first (itr);
90 mu_iterator_current (itr, (void **)&mr);