Properly handle text attachment encodings for thumbnail generation.

Uploading a utf-16le encoded text file as an attachment would cause a
traceback, since it can't be coerced to unicode using the default encoding.
Since we have the mimetype, we can pull the encoding out of that, and decode
properly.

Testing done: Ran unit tests and tested uploading file through the web UI.

Fixes bug 3282.

Reviewed at https://reviews.reviewboard.org/r/5630/