Skip to content

Commit

Permalink
Merge pull request #66 from mailgun/jeremy/charset
Browse files Browse the repository at this point in the history
don't default to ascii charset for non-text Content-Types
  • Loading branch information
jeremyschlatter committed Oct 30, 2014
2 parents e362349 + 0367fc9 commit 5ffab73
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion flanker/mime/message/headers/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ def get_boundary_line(self, final=False):
self.get_boundary(), "--" if final else "")

def get_charset(self):
return self.params.get("charset", 'ascii').lower()
default = 'ascii' if self.main == 'text' else None
c = self.params.get("charset", default)
if c:
c = c.lower()
return c

def set_charset(self, value):
self.params["charset"] = value.lower()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


setup(name='flanker',
version='0.4.21',
version='0.4.22',
description='Mailgun Parsing Tools',
long_description=open('README.rst').read(),
classifiers=[],
Expand Down
10 changes: 10 additions & 0 deletions tests/mime/message/headers/wrappers_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from nose.tools import eq_

from flanker.mime.message.headers.wrappers import ContentType

def charset_test():
c = ContentType('text', 'plain')
eq_('ascii', c.get_charset())

c = ContentType('application', 'pdf')
eq_(None, c.get_charset())

0 comments on commit 5ffab73

Please sign in to comment.