Properly encode mime data for python3
More python3 fixes