Using TestSessionEnvironment for saving emails

Easier debugging through JSON file inspection,
which can be logged in its entirety more easily
than a database table. It also keeps data in one place.
Note about PHP sessions
Changes required for persisting state directly on disk

applyState() used to persist in memory, which could lead
to outdated state depending on execution flow between CLI
and web requests. Since state is now in a JSON object,
it also fixes the array access.