diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-12-12 01:48:21 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-12-12 01:50:58 +0200 |
commit | eae05c42b532d99b2b946eeb04e442d462d223b5 (patch) | |
tree | 25b3bc45ca0d9217bb020992899f8710b2426aa7 | |
parent | 61378abc8e046b457365a30c6b80559b0540177e (diff) | |
download | mailutils-eae05c42b532d99b2b946eeb04e442d462d223b5.tar.gz mailutils-eae05c42b532d99b2b946eeb04e442d462d223b5.tar.bz2 |
Fix UID generation in mboxes (complements f9a034c7)
* libproto/mbox/mboxscan.c (mbox_scan_internal): Fix UID generation.
* testsuite/lstuid.c: New test program.
* testsuite/lstuid00.at: New test case.
* testsuite/lstuid01.at: Likewise.
* testsuite/lstuid02.at: Likewise.
* testsuite/Makefile.am: Add new test cases.
* testsuite/testsuite.at: Likewise.
-rw-r--r-- | libproto/mbox/mboxscan.c | 10 | ||||
-rw-r--r-- | testsuite/Makefile.am | 4 | ||||
-rw-r--r-- | testsuite/lstuid.c | 54 | ||||
-rw-r--r-- | testsuite/lstuid00.at | 31 | ||||
-rw-r--r-- | testsuite/lstuid01.at | 40 | ||||
-rw-r--r-- | testsuite/lstuid02.at | 40 | ||||
-rw-r--r-- | testsuite/testsuite.at | 3 |
7 files changed, 175 insertions, 7 deletions
diff --git a/libproto/mbox/mboxscan.c b/libproto/mbox/mboxscan.c index 4fcceeaf4..d0c5aceaf 100644 --- a/libproto/mbox/mboxscan.c +++ b/libproto/mbox/mboxscan.c @@ -367,14 +367,12 @@ mbox_scan_internal (mu_mailbox_t mailbox, mbox_message_t mum, mum->body_end = total - n - newline; mum->body_lines = --lines - newline; - if (mum->uid <= min_uid) + if (mum->uid == 0) { mum->uid = ++min_uid; /* Note that modification for when expunging. */ mum->attr_flags |= MU_ATTRIBUTE_MODIFIED; } - else - min_uid = mum->uid; if (flags & MBOX_SCAN_ONEMSG) break; @@ -403,7 +401,7 @@ mbox_scan_internal (mu_mailbox_t mailbox, mbox_message_t mum, { char *p; unsigned long n = strtoul (buf + 6, &p, 10); - if (*p == 0 || mu_isspace (*p)) + if ((*p == 0 || mu_isspace (*p)) && n > min_uid) mum->uid = min_uid = n; } else if (mud->messages_count == 1 && IS_X_IMAPBASE (buf)) @@ -451,14 +449,12 @@ mbox_scan_internal (mu_mailbox_t mailbox, mbox_message_t mum, mum->body_end = total - newline; mum->body_lines = lines - newline; - if (mum->uid <= min_uid) + if (mum->uid == 0) { mum->uid = ++min_uid; /* Note that modification for when expunging. */ mum->attr_flags |= MU_ATTRIBUTE_MODIFIED; } - else - min_uid = mum->uid; if (flags & MBOX_SCAN_NOTIFY) DISPATCH_ADD_MSG (mailbox, mud); diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index 61144e3e7..17079857e 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -50,6 +50,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac INCLUDES = @MU_LIB_COMMON_INCLUDES@ noinst_PROGRAMS = \ + lstuid\ mbdel\ mimetest\ smtpsend\ @@ -77,6 +78,9 @@ smtpsend_LDADD = \ ## ------------ ## TESTSUITE_AT = \ + lstuid00.at\ + lstuid01.at\ + lstuid02.at\ mbdel.at\ mime.at\ ufms.at\ diff --git a/testsuite/lstuid.c b/testsuite/lstuid.c new file mode 100644 index 000000000..95274cd8f --- /dev/null +++ b/testsuite/lstuid.c @@ -0,0 +1,54 @@ +/* lstuid.c: List UIDs in mailbox + Copyright (C) 2011 Free Software Foundation, Inc. + + GNU Mailutils is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + GNU Mailutils is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <mailutils/mailutils.h> + +int +main (int argc, char **argv) +{ + mu_mailbox_t mbox; + size_t i, count; + mu_message_t msg; + + if (argc != 2) + { + fprintf (stderr, "usage: %s MBOX\n", argv[0]); + return 1; + } + + mu_registrar_record (mu_mbox_record); + + /* Open the mailbox */ + MU_ASSERT (mu_mailbox_create (&mbox, argv[1])); + MU_ASSERT (mu_mailbox_open (mbox, MU_STREAM_RDWR)); + mu_mailbox_messages_count (mbox, &count); + for (i = 1; i <= count; i++) + { + size_t uid; + MU_ASSERT (mu_mailbox_get_message (mbox, i, &msg)); + MU_ASSERT (mu_message_get_uid (msg, &uid)); + printf ("%lu: %lu\n", (unsigned long) i, (unsigned long) uid); + } + mu_mailbox_close (mbox); + mu_mailbox_destroy (&mbox); + return 0; +} diff --git a/testsuite/lstuid00.at b/testsuite/lstuid00.at new file mode 100644 index 000000000..ee3718902 --- /dev/null +++ b/testsuite/lstuid00.at @@ -0,0 +1,31 @@ +# This file is part of GNU Mailutils. -*- Autotest -*- +# Copyright (C) 2011 Free Software Foundation, Inc. +# +# GNU Mailutils is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3, or (at +# your option) any later version. +# +# GNU Mailutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. + +AT_SETUP([Assigning UIDs]) + +AT_CHECK([ +MUT_MBCOPY($abs_top_srcdir/testsuite/spool/mbox1) +lstuid mbox:mbox1 +], +[0], +[1: 1 +2: 2 +3: 3 +4: 4 +5: 5 +]) + +AT_CLEANUP
\ No newline at end of file diff --git a/testsuite/lstuid01.at b/testsuite/lstuid01.at new file mode 100644 index 000000000..06c13a757 --- /dev/null +++ b/testsuite/lstuid01.at @@ -0,0 +1,40 @@ +# This file is part of GNU Mailutils. -*- Autotest -*- +# Copyright (C) 2011 Free Software Foundation, Inc. +# +# GNU Mailutils is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3, or (at +# your option) any later version. +# +# GNU Mailutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. + +AT_SETUP([Assigning UIDs (with gaps)]) + +AT_DATA([x-uid.sed], +[/^Subject: Jabberwocky/a\ +X-UID: 2 + +/^Subject: Simple MIME/a\ +X-UID: 10 + +]) + +AT_CHECK([ +sed -f x-uid.sed $abs_top_srcdir/testsuite/spool/mbox1 > mbox1 +lstuid mbox:mbox1 +], +[0], +[1: 2 +2: 3 +3: 10 +4: 11 +5: 12 +]) + +AT_CLEANUP
\ No newline at end of file diff --git a/testsuite/lstuid02.at b/testsuite/lstuid02.at new file mode 100644 index 000000000..42d972962 --- /dev/null +++ b/testsuite/lstuid02.at @@ -0,0 +1,40 @@ +# This file is part of GNU Mailutils. -*- Autotest -*- +# Copyright (C) 2011 Free Software Foundation, Inc. +# +# GNU Mailutils is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3, or (at +# your option) any later version. +# +# GNU Mailutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. + +AT_SETUP([Assigning UIDs (with fixups)]) + +AT_DATA([x-uid.sed], +[/^Subject: Jabberwocky/a\ +X-UID: 2 + +/^Subject: Simple MIME/a\ +X-UID: 1 + +]) + +AT_CHECK([ +sed -f x-uid.sed $abs_top_srcdir/testsuite/spool/mbox1 > mbox1 +lstuid mbox:mbox1 +], +[0], +[1: 2 +2: 3 +3: 4 +4: 5 +5: 6 +]) + +AT_CLEANUP
\ No newline at end of file diff --git a/testsuite/testsuite.at b/testsuite/testsuite.at index 92e9c5402..48bbe1aa7 100644 --- a/testsuite/testsuite.at +++ b/testsuite/testsuite.at @@ -18,6 +18,9 @@ m4_include([testsuite.inc]) AT_INIT +m4_include([lstuid00.at]) +m4_include([lstuid01.at]) +m4_include([lstuid02.at]) m4_include([mime.at]) m4_include([mbdel.at]) m4_include([ufms.at]) |