Commit eae05c42 eae05c42b532d99b2b946eeb04e442d462d223b5 by Sergey Poznyakoff

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.
1 parent 61378abc
......@@ -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);
......
......@@ -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\
......
/* 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;
}
# 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
# 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
# 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
......@@ -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])
......