Add missing parts of previous commit.
Encode attachment body only if its a unicode string.