fix email data binding, add test

The text part wasn't getting the right variable scope, is fixed now; I've also added a rudimentary test and refactored slightly.

Fixes #158.