Fix unicode attachments

This is based on latest upstream master. Can we merge this safely?

@wojcikstefan  @anemitz