#!/bin/bash

# Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>

# just trying to ensure that thunderbird can work with sqlite:

rm -rf tbird-sqlite.profile tbird-sqlite.Xauthority
mkdir -m 0700 -p tbird-sqlite.profile/extensions
printf /usr/share/xul-ext/jsunit/ > tbird-sqlite.profile/extensions/jsunit@enigmail.net
cat > tbird-sqlite.profile/prefs.js <<EOF
user_pref("extensions.autoDisableScopes", 14);
user_pref("toolkit.telemetry.prompted", false);
user_pref("toolkit.telemetry.rejected", true);
user_pref("toolkit.telemetry.enabled", false);
EOF
printf '{"created":%d000}' "$(date '+%s')" >tbird-sqlite.profile/times.json

# set up a profile cleanly, ignoring messages to stderr
xvfb-run -a -f "$(pwd)/tbird-sqlite.Xauthority" /usr/bin/thunderbird -profile "$(pwd)/tbird-sqlite.profile" -jsunit debian/tests/no-test.js 2>&1

xvfb-run -a -f "$(pwd)/tbird-sqlite.Xauthority" /usr/bin/thunderbird -profile "$(pwd)/tbird-sqlite.profile" -jsunit debian/tests/tbird-sqlite.js
echo .dump | sqlite3 tbird-sqlite.profile/testing.sqlite
