SED='s/UIDVALIDITY [0-9]*/UIDVALIDITY/;s/INTERNALDATE "[^"]*"/INTERNALDATE -DATE-/g;s/SNAPSHOT "[^"]*"/SNAPSHOT -SNAPSHOT-/g;s/SNAPSHOTEXISTS "[^"]*"/SNAPSHOTEXISTS -SNAPSHOT-/g;s:^-ERR .*:-ERR --error--:'

rm -rf confmdtest
../maildir/maildirmake confmdtest
i=0;
while test "$i" -lt 200
do
  ../maildir/deliverquota confmdtest <<EOF
Subject: test message

test message
EOF
  i=`expr $i + 1`
done

env IMAP_BROKENUIDV=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
OPEN INBOX
STORE 1-10 20-80 90-130 +FLAGS=DELETED
EXPUNGE
LOGOUT
EOF

rm -rf confmdtest
../maildir/maildirmake confmdtest
i=0;
while test "$i" -lt 200
do
  ../maildir/deliverquota confmdtest <<EOF
Subject: test message

test message
EOF
  i=`expr $i + 1`
done

env IMAP_BROKENUIDV=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
OPEN INBOX
EXPUNGE 1-10 20-80 90-130
LOGOUT
EOF

rm -rf confmdtest
../maildir/maildirmake confmdtest
../maildir/deliverquota confmdtest <<EOF
Subject: Test MIME message
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=aaa

--aaa
Content-Type: multipart/alternative; boundary=bbb

--bbb
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline

text/plain content

--bbb
Content-Type: text/html; charset=iso-8859-1
Content-Disposition: inline

text/html content

--bbb--

--aaa
Content-Type: message/rfc822

Mime-Version: 1.0
Subject: Attached message
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

Attached message

--aaa--
EOF

env IMAP_BROKENUIDV=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
OPEN INBOX
FETCH 1 CONTENTS.PEEK=MIME(Mime-Version,Content-Type,Content-Disposition)
FETCH 1 CONTENTS=MIME(Mime-Version,Content-Type,Content-Disposition)
FETCH 1 CONTENTS=HEADERS(Mime-Version,Content-Type)
FETCH 1 CONTENTS=HEADERS
FETCH 1 CONTENTS=HEADERS[1.1]
FETCH 1 CONTENTS=HEADERS[1.1.1]
FETCH 1 CONTENTS=HEADERS[1.1.2]
FETCH 1 CONTENTS=HEADERS[1.2]
FETCH 1 CONTENTS=HEADERS[1.2.0]
FETCH 1 CONTENTS=HEADERS[A]
FETCH 1 CONTENTS=HEADERS[2]
FETCH 1 CONTENTS=HEADERS[1.1.3]
FETCH 1 CONTENTS=HEADERS[1.2.1]
FETCH 1 CONTENTS=BODY
FETCH 1 CONTENTS=BODY[1.2.0]
LOGOUT
EOF

rm -rf confmdtest confmdtest2
../maildir/maildirmake confmdtest
../maildir/maildirmake confmdtest2
../maildir/maildirmake -f folder1 confmdtest2
../maildir/maildirmake --add test=`pwd`/confmdtest2 confmdtest
../maildir/maildirmake -q10C confmdtest
../maildir/deliverquota confmdtest <<EOF
Subject: testing body.decoded
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=zzz

--zzz
Content-Type: text/plain
Content-Transfer-Encoding: 8bit

This is a text/plain 8bit section

--zzz
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

This is =61 text/plain =
quoted-printable section

--zzz
Content-Type: text/plain
Content-Transfer-Encoding: base64

YWNsb2NhbC5tNAkJICAgIGltYXBkLm8JCSAgICAgbXNnZW52ZWxvcGUubwphdXRoZW50aWNhdGVf
YXV0aC5jCSAgICBpbWFwZC5wYW0JCSAgICAgbXlzaWduYWwuYwphdXRoZW50aWNhdGVfYXV0aC5j
Ln4xLjYufiAgaW1hcGQuc2dtbAkJICAgICBteXNpZ25hbC5oCmF1dGhlbnRpY2F0ZV9hdXRoLm8J
ICAgIGltYXBkLXNzbC5kaXN0CSAgICAgbXlzaWduYWwubwphdXRoZW50aWNhdGVfc3R1Yi5jCSAg
ICBpbWFwZC1zc2wuZGlzdC5pbgkgICAgIG91dGJveC5jCm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QuOAkJCSAgICBta2ltYXBkY2VydC5pbgkgICAgIHN0b3JlaW5mby5oCmltYXBkLjguaW4J
CSAgICBta2ltYXBkY2VydC5zZ21sCSAgICAgc3RvcmVpbmZvLm8KaW1hcGQuYXV0aHBhbQkJICAg
IG1rcG9wM2RjZXJ0CQkgICAgIHN5c3RlbS1hdXRoLmF1dGhwYW0KaW1hcGQuYwkJCSAgICBta3Bv
cDNkY2VydC44CSAgICAgdAppbWFwZC5jLn4xLjk1Ln4JCSAgICBta3BvcDNkY2VydC44LmluCSAg
ICAgdGVzdHN1aXRlCmltYXBkLmNuZgkJICAgIG1rcG9wM2RjZXJ0Lmh0bWwJICAgICB0ZXN0c3Vp
dGVmaXgucGwKaW1hcGQuY25mLmluCQkgICAgbWtwb3AzZGNlcnQuaHRtbC5pbiAgICAgIHRlc3Rz
dWl0ZWZpeC5wbC5pbgppbWFwZC5kaXN0CQkgICAgbWtwb3AzZGNlcnQuaW4JICAgICB0ZXN0c3Vp
dGUudHh0CmltYXBkLmRpc3QuaW4JCSAgICBta3BvcDNkY2VydC5zZ21sCSAgICAgdGhyZWFkLmMK
aW1hcGQuaAkJCSAgICBtc2dib2R5c3RydWN0dXJlLmMJICAgICB0aHJlYWQuaAppbWFwZC5odG1s
CQkgICAgbXNnYm9keXN0cnVjdHVyZS5vCSAgICAgdGhyZWFkLm8KaW1hcGQuaHRtbC5pbgkJICAg
IG1zZ2VudmVsb3BlLmMK

--zzz--
EOF

env IMAP_BROKENUIDV=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
open INBOX
FETCH 1 CONTENTS=BODY[1.1]
FETCH 1 CONTENTS=BODY.DECODED[1.1]
FETCH 1 CONTENTS=BODY[1.2]
FETCH 1 CONTENTS=BODY.DECODED[1.2]
FETCH 1 CONTENTS=BODY[1.3]
FETCH 1 CONTENTS=BODY.DECODED[1.3]
ADD FOLDER INBOX "" FLAGS=SEEN "INTERNALDATE=03 Aug 2003 03:00:00 -0500"
ADD {.100}
Subject: test add
Mime-Version: 1.0

This is a test of the
.add command.
.
NOOP
COPY 1-2 "" INBOX
NOOP
COPY 1-4 "" INBOX
NOOP
COPY 1-4 "" INBOX
COPY 1-2 "" INBOX
NOOP
ADD FOLDER INBOX "" FLAGS=SEEN "INTERNALDATE=03 Aug 2003 03:00:00 -0500"
ADD {.100}
Subject: test add
Mime-Version: 1.0

This is a test of the
.add command.
.
open INBOX
fetch 10 CONTENTS=HEADERS(Mime-Version)
LOGOUT
EOF

rm -f confmdtest/maildirsize
env IMAP_BROKENUIDV=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
open INBOX
COPY 1-10 "" INBOX
NOOP
COPY 1-20 "" INBOX
NOOP
COPY 1-40 "" INBOX
NOOP
COPY 1-80 "" INBOX
NOOP
COPY 1-160 "" INBOX
NOOP
COPY 1-320 "" INBOX
NOOP
LOGOUT
EOF

(
echo "open INBOX"
n=0
while test $n -lt 64
do
	m=$n
	if test "$m" = ""
	then
		m=""
	fi

	echo "STORE ${m}3-${m}5 ${m}7 ${m}9 +FLAGS=DELETED"
	n=`expr $n + 1`
done
echo "LOGOUT"
) | env IMAP_BROKENUIDV=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd | sed "$SED"

env IMAP_BROKENUIDV=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
open INBOX
SEARCH UNMARKED NOT DELETED
SEARCH MARKED NOT DELETED
SEARCH UNMARKED DELETED
STORE 1-10 +FLAGS=DRAFT
STORE 15-25 30 +FLAGS=SEEN
SEARCH UNMARKED DRAFT
SEARCH UNMARKED SEEN
EXPUNGE 1-640
ADD FOLDER INBOX "" FLAGS=SEEN "INTERNALDATE=03 Aug 2003 03:00:00 -0500"
ADD {.100}
Subject: iso-8859-1 encoding test: =?iso-8859-1?Q?S=E2m?=
Date: 03 Aug 2003 03:00:00 -0500
Mime-Version: 1.0

This is a test of the
.add command.
.
NOOP
ADD FOLDER INBOX "" FLAGS=SEEN "INTERNALDATE=08 Aug 2003 03:00:00 -0500"
ADD {.100}
Subject: iso-8859-1 encoding test: =?iso-8859-1?Q?S=E2m?=
Date: 05 Aug 2003 05:00:00 -0500
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Mime-Version: 1.0

S=E2m This is a ttest of the
.add command.
.
NOOP
SEARCH UNMARKED SUBJECT "sâm"
SEARCH UNMARKED HEADER DATE "05 AUG"
SEARCH UNMARKED TEXT "ttest"
SEARCH UNMARKED BODY "sâm"
SEARCH UNMARKED TEXT "sâm"
SEARCH UNMARKED ON "08-Aug-2003"
SEARCH UNMARKED ON "03-Aug-2003"
SEARCH UNMARKED SENTON "05-Aug-2003"
SEARCH UNMARKED SMALLER "200"
SEARCH UNMARKED NOT SMALLER "200"
SEARCH UNMARKED INVALID
LOGOUT
EOF

rm -rf confmdtest confmdtest2
../maildir/maildirmake confmdtest
../maildir/maildirmake confmdtest2
../maildir/maildirmake -f folder1 confmdtest2
../maildir/maildirmake --add test=`pwd`/confmdtest2 confmdtest
../maildir/maildirmake -q20C confmdtest
../maildir/deliverquota confmdtest <<EOF
Subject: testing body.decoded
Mime-Version: 1.0
Content-Type: text/plain

Test
EOF

env IMAP_BROKENUIDV=1 MOVE_EXPUNGE_TO_TRASH=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
open INBOX
COPY 1 "" INBOX
NOOP
open INBOX
CREATE INBOX Trash
copy 1 "" INBOX Trash
CREATE INBOX a
MOVE 2 "" INBOX a
LOGOUT
EOF
cat confmdtest/maildirsize
env IMAP_BROKENUIDV=1 MOVE_EXPUNGE_TO_TRASH=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
open INBOX a
LOGOUT
EOF
cat confmdtest/maildirsize

env IMAP_BROKENUIDV=1 MOVE_EXPUNGE_TO_TRASH=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
sopen "" INBOX a
NOOP
NOOP
STORE 1 FLAGS=REPLIED
NOOP
NOOP
STORE 1 FLAGS=REPLIED
NOOP
NOOP
STORE 1 FLAGS=DELETED
EXPUNGE
EXPUNGE
NOOP
NOOP
EXPUNGE 1
NOOP
LOGOUT
EOF
echo `ls confmdtest/.a/courierimapsnapshots | wc -l`

env IMAP_BROKENUIDV=1 MOVE_EXPUNGE_TO_TRASH=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
delete INBOX a
sopen "" INBOX
NOOP
CLOSE
sopen "" INBOX
NOOP
CLOSE
sopen "" INBOX
NOOP
CLOSE
sopen "" INBOX
NOOP
CLOSE
sopen "" INBOX
NOOP
CLOSE
sopen "" INBOX
NOOP
CLOSE
sopen "" INBOX
NOOP
CLOSE
sopen "" INBOX
NOOP
CLOSE
sopen "" INBOX
NOOP
CLOSE
sopen "" INBOX
NOOP
CLOSE
sopen "" INBOX
NOOP
CLOSE
LOGOUT
EOF
echo `ls confmdtest/courierimapsnapshots | wc -l`
touch -t 199901010000 `ls confmdtest/courierimapsnapshots/* | sed -n 1p`

env IMAP_BROKENUIDV=1 MOVE_EXPUNGE_TO_TRASH=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
sopen "" INBOX
CLOSE
LOGOUT
EOF
echo `ls confmdtest/courierimapsnapshots | wc -l`

rm -rf confmdtest
../maildir/maildirmake confmdtest

  ../maildir/deliverquota confmdtest <<EOF
Received: by localhost
Subject: test message
From: nobody@localhost
Cc: nobody@localhost
Mime-Version: 1.0
Content-Type: multipart/mixed;
    boundary=abc


--abc
Content-Type: text/plain; charset=iso-8859-1
X-Comment: foo

Mary had a little lamb, its fleece was white as snow.
--abc--

test message
EOF

env IMAP_BROKENUIDV=1 MOVE_EXPUNGE_TO_TRASH=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
open INBOX
FETCH 1 CONTENTS=HEADERS
FETCH 1 CONTENTS=RAWHEADERS
FETCH 1 CONTENTS=MIME
FETCH 1 CONTENTS=MIME(Content-Type)
FETCH 1 CONTENTS=HEADERS(Content-Type)
FETCH 1 CONTENTS=HEADERS(:ENVELOPE)
FETCH 1 CONTENTS=HEADERS(:ENVELOPE,Received)
FETCH 1 CONTENTS=HEADERS(Received,:ENVELOPE)
FETCH 1 CONTENTS=HEADERS(:MIME)
FETCH 1 CONTENTS=MIME(:MIME)
LOGOUT
EOF

env IMAP_KEYWORDS=1 IMAP_BROKENUIDV=1 MOVE_EXPUNGE_TO_TRASH=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF >testsuite.tmp
open INBOX
CREATE INBOX a
COPY 1 "" INBOX a
OPEN INBOX a
STORE 1 +FLAGS=DELETED +KEYWORDS=-Label1
ADD FOLDER INBOX a
ADD FLAGS=SEEN
ADD KEYWORDS=-Label2
ADD {.}
Subject: test

test

test
.
EXPUNGE
FETCH 1 FLAGS KEYWORDS
COPY 1 "" INBOX
OPEN INBOX
FETCH 1-2 FLAGS KEYWORDS
MOVE 2 "" INBOX a
SOPEN "" INBOX a
FETCH 1-2 FLAGS KEYWORDS
NOOP
EXPUNGE 1
STORE 1 KEYWORDS=-Label3
LOGOUT
EOF

SNAPSHOT=`fgrep '* SNAPSHOT ' testsuite.tmp | cut -c12-`
sed "$SED" <testsuite.tmp
rm -f testsuite.tmp

env IMAP_BROKENUIDV=1 IMAP_KEYWORDS=1 MOVE_EXPUNGE_TO_TRASH=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
SOPEN $SNAPSHOT INBOX a
COPY 1 "" INBOX a
NOOP
COPY 1-2 "" INBOX a
NOOP
FETCH 1-4 FLAGS KEYWORDS
STORE 3-4 -KEYWORDS=-Label2
STORE 3-4 -KEYWORDS=-Label3
SEARCH UNMARKED SEEN
SEARCH UNMARKED KEYWORD -Label2
SEARCH UNMARKED KEYWORD -Label3
SEARCH UNMARKED NOT KEYWORD -Label3
LOGOUT
EOF

env IMAP_BROKENUIDV=1 IMAP_KEYWORDS=1 MOVE_EXPUNGE_TO_TRASH=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
OPEN INBOX
STORE 1 KEYWORDS=Junk*Junk
LOGOUT
EOF

env IMAP_BROKENUIDV=1 IMAP_KEYWORDS=1 MOVE_EXPUNGE_TO_TRASH=1 MAILDIR=confmdtest ./imapd <<EOF | sed 's/UIDVALIDITY [0-9]*/UIDVALIDITY/'
a1 SELECT INBOX
a2 FETCH 1 FLAGS
a3 STORE 1 FLAGS (\Seen Abra,Cadabra)
a3 LOGOUT
EOF

env IMAP_BROKENUIDV=1 IMAP_KEYWORDS=1 MOVE_EXPUNGE_TO_TRASH=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
OPEN INBOX
FETCH 1 FLAGS KEYWORDS
COPY 1 "" INBOX
NOOP
STORE 2 +FLAGS=MARKED
SEARCH UNMARKED SEEN
SEARCH MARKED SEEN
SEARCH ALL SEEN
LOGOUT
EOF

rm -rf confmdtest*
../maildir/maildirmake confmdtest || exit 1
../maildir/maildirmake confmdtest2 || exit 1
../maildir/maildirmake confmdtest3 || exit 1
mkdir confmdtest4 || exit 1
cat >confmdtest4/index <<EOF || exit 1
confmdtest	1	1	`pwd`	confmdtest
a	*	indexa
b	*	indexb
EOF
echo "confmdtest2	1	1	`pwd`	confmdtest2" >confmdtest4/indexa || exit 1
echo "aashared	1	1	`pwd`	confmdtest5" >>confmdtest4/indexa || exit 1
echo "confmdtest3	1	1	`pwd`	confmdtest3" >confmdtest4/indexb || exit 1

../maildir/maildirmake -f x confmdtest2
../maildir/maildiracl -set confmdtest2 INBOX.x user=confmdtest aceilrstwx
../maildir/maildiracl -set confmdtest3 INBOX user=confmdtest aceilrstwx

IMAP_SHAREDINDEXFILE=`pwd`/confmdtest4/index
export IMAP_SHAREDINDEXFILE
env AUTHENTICATED=confmdtest IMAP_BROKENUIDV=1 IMAP_KEYWORDS=1 MOVE_EXPUNGE_TO_TRASH=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
LIST public
LIST public a
LIST public b
LIST public a confmdtest2
GETACL INBOX
SETACL INBOX "" owner -stwx
SETACL INBOX "" owner aceilrstw
SETACL INBOX "" owner +x
SETACL INBOX "" owner -l
SETACL INBOX "" -owner a
SETACL INBOX "" user=testuser1 ace
SETACL INBOX "" user=testuser1 +x
SETACL INBOX "" user=testuser1 -x
SETACL INBOX "" user=testuser1 -ace
SETACL INBOX "" user=testuser1 ace
DELETEACL INBOX "" user=testuser2
DELETEACL INBOX "" user=testuser1
DELETEACL INBOX "" owner
ACL INBOX
GETACL public b confmdtest3
ACL public b confmdtest3
GETACL public a confmdtest2 x
ACL public a confmdtest2 x
ACL public
ACL public a
OPEN INBOX
ADD FOLDER INBOX "" FLAGS=SEEN,DELETED,MARKED KEYWORDS=keyword1
ADD {.}
Subject: test message 1

test message 1
.
NOOP
FETCH 1 FLAGS KEYWORDS
SETACL INBOX "" owner -w
ADD FOLDER INBOX "" FLAGS=SEEN,DELETED,MARKED KEYWORDS=keyword1
ADD {.}
Subject: test message 1

test message 1
.
NOOP
FETCH 2 FLAGS KEYWORDS
SETACL INBOX "" owner +w owner -s
ADD FOLDER INBOX "" FLAGS=SEEN,DELETED,MARKED KEYWORDS=keyword1
ADD {.}
Subject: test message 1

test message 1
.
NOOP
FETCH 3 FLAGS KEYWORDS
SETACL INBOX "" owner +s owner -t
ADD FOLDER INBOX "" FLAGS=SEEN,DELETED,MARKED KEYWORDS=keyword1
ADD {.}
Subject: test message 1

test message 1
.
NOOP
FETCH 4 FLAGS KEYWORDS
SETACL INBOX "" owner +t owner -i
ADD FOLDER INBOX ""
SETACL INBOX "" owner +i
SETACL public b confmdtest3 "" user=confmdtest -l
STATUS CHEAP public b confmdtest3
SETACL public b confmdtest3 "" user=confmdtest +l
STATUS CHEAP public b confmdtest3
DELETE public b confmdtest3
CREATE INBOX c
SETACL INBOX c "" owner -x
DELETE INBOX c
SETACL INBOX c "" owner +x
DELETE INBOX c
SETACL INBOX "" -owner r
OPEN INBOX
DELETEACL INBOX "" -owner
OPEN INBOX
SETACL INBOX "" -owner i
COPY 1-4 "" INBOX
DELETEACL INBOX "" -owner
COPY 1-4 "" INBOX
CLOSE
CREATE INBOX a
MKDIR INBOX b
SETACL INBOX b "" owner -c
RENAME INBOX a "" INBOX b a
SETACL INBOX b "" owner +c
RENAME INBOX a "" INBOX b a
SETACL INBOX b "" owner -x
RENAME INBOX b "" INBOX a
SETACL INBOX b "" owner +x
RENAME INBOX b "" INBOX a
OPEN INBOX
FETCH 1 FLAGS KEYWORDS
SETACL INBOX "" owner -w
STORE 1 FLAGS=SEEN KEYWORDS=
SETACL INBOX "" owner +w owner -t
STORE 1 FLAGS=MARKED,SEEN,DELETED KEYWORDS=keyword2
SETACL INBOX "" owner +t owner -s
STORE 1 -FLAGS=SEEN,MARKED
SETACL INBOX "" owner +s owner -e
STORE 1 FLAGS=DELETED
EXPUNGE
SETACL INBOX "" owner +e
EXPUNGE
SETACL INBOX "" owner -t
EXPUNGE 1
SETACL INBOX "" owner +t
EXPUNGE 1
LOGOUT
EOF

rm -rf confmdtest*
../maildir/maildirmake confmdtest || exit 1

n=0
while test $n -lt 256
do
	filename=`expr $n + 1000`
	filename="$filename,test:2,S"
	if test `expr $n % 2` = 1
	then
		filename="$filename""T"
	fi
	cat >confmdtest/cur/$filename <<EOF
Subject: test message

test message
EOF
	n=`expr $n + 1`
done
env AUTHENTICATED=confmdtest IMAP_BROKENUIDV=1 IMAP_KEYWORDS=1 MOVE_EXPUNGE_TO_TRASH=1 MAILDIR=confmdtest PROTOCOL=SMAP1 ./imapd <<EOF | sed "$SED"
OPEN INBOX
EXPUNGE
LOGOUT
EOF
