wildduck/imap-core/test/prepare.sh

78 lines
2.6 KiB
Bash
Raw Normal View History

#!/bin/bash
2022-11-24 22:45:07 +08:00
echo "which mongo"
which mongo
DBNAME="$1"
2018-12-27 23:44:38 +08:00
echo "Clearing DB"
mongo "$DBNAME" --eval "db.getCollectionNames().forEach(function(key){db[key].deleteMany({});})" > /dev/null
2018-12-27 23:44:38 +08:00
echo "Creating user"
2019-08-27 21:20:23 +08:00
USERRESPONSE=`curl --silent -XPOST http://127.0.0.1:8080/users \
-H 'Content-type: application/json' \
-d '{
"username": "testuser",
"password": "pass",
"name": "Test User"
}'`
2018-12-27 23:44:38 +08:00
echo "UR: $USERRESPONSE"
USERID=`echo "$USERRESPONSE" | jq -r '.id'`
2018-12-27 23:44:38 +08:00
echo "Reading Mailbox ID"
2019-08-27 21:20:23 +08:00
MAILBOXLIST=`curl --silent "http://127.0.0.1:8080/users/$USERID/mailboxes"`
2018-12-27 23:44:38 +08:00
echo "ML: $MAILBOXLIST"
echo "$MAILBOXLIST" | jq
INBOXID=`echo "$MAILBOXLIST" | jq -r '.results[0].id'`
SENTID=`echo "$MAILBOXLIST" | jq -r '.results[3].id'`
2019-08-27 21:20:23 +08:00
curl --silent -XPUT "http://127.0.0.1:8080/users/$USERID/mailboxes/$SENTID" \
-H 'Content-type: application/json' \
-d '{
"path": "[Gmail]/Sent Mail"
2018-12-27 23:44:38 +08:00
}'
2019-08-27 21:20:23 +08:00
MAILBOXLIST=`curl --silent "http://127.0.0.1:8080/users/$USERID/mailboxes"`
2018-12-27 23:44:38 +08:00
echo "$MAILBOXLIST" | jq
2019-08-27 21:20:23 +08:00
curl --silent -XPOST "http://127.0.0.1:8080/users/$USERID/mailboxes/$INBOXID/messages?date=14-Sep-2013%2021%3A22%3A28%20-0300&unseen=true" \
-H 'Content-type: message/rfc822' \
2018-12-27 23:44:38 +08:00
--data-binary "@fixtures/fix1.eml"
2019-08-27 21:20:23 +08:00
curl --silent -XPOST "http://127.0.0.1:8080/users/$USERID/mailboxes/$INBOXID/messages?unseen=false" \
-H 'Content-type: message/rfc822' \
2018-12-27 23:44:38 +08:00
--data-binary "@fixtures/fix2.eml"
2019-08-27 21:20:23 +08:00
curl --silent -XPOST "http://127.0.0.1:8080/users/$USERID/mailboxes/$INBOXID/messages?unseen=false" \
-H 'Content-type: message/rfc822' \
2018-12-27 23:44:38 +08:00
--data-binary "@fixtures/fix3.eml"
2019-08-27 21:20:23 +08:00
curl --silent -XPOST "http://127.0.0.1:8080/users/$USERID/mailboxes/$INBOXID/messages?unseen=true" \
-H 'Content-type: message/rfc822' \
2018-12-27 23:44:38 +08:00
--data-binary "@fixtures/fix4.eml"
2019-08-27 21:20:23 +08:00
curl --silent -XPOST "http://127.0.0.1:8080/users/$USERID/mailboxes/$INBOXID/messages?unseen=true" \
-H 'Content-type: message/rfc822' \
--data-binary "from: sender@example.com
to: receiver@example.com
subject: test5
hello 5
2018-12-27 23:44:38 +08:00
"
2019-08-27 21:20:23 +08:00
curl --silent -XPOST "http://127.0.0.1:8080/users/$USERID/mailboxes/$INBOXID/messages?unseen=true" \
-H 'Content-type: message/rfc822' \
--data-binary "from: sender@example.com
to: receiver@example.com
subject: test6
hello 6
2018-12-27 23:44:38 +08:00
"
mongo "$DBNAME" --eval "db.mailboxes.updateOne({_id: ObjectId('$INBOXID')}, {\$set:{modifyIndex: 5000, uidNext: 1000}});
db.messages.updateOne({mailbox: ObjectId('$INBOXID'), uid:1}, {\$set:{modseq: 100}});
db.messages.updateOne({mailbox: ObjectId('$INBOXID'), uid:2}, {\$set:{modseq: 5000}});
db.messages.updateMany({}, {\$inc:{uid: 100}});" > /dev/null
2019-08-27 21:20:23 +08:00
# curl --silent "http://127.0.0.1:8080/users/$USERID/mailboxes/$INBOXID/messages" | jq