diff --git a/flanker/_email.py b/flanker/_email.py index a25538d..0e969fa 100644 --- a/flanker/_email.py +++ b/flanker/_email.py @@ -82,10 +82,6 @@ def decode_quoted_printable(val): return email.quoprimime.header_decode(val) -def detect_audio_type(val): - return audio._whatsnd(val) - - def make_message_id(): return make_msgid() diff --git a/flanker/mime/message/part.py b/flanker/mime/message/part.py index 0bc83d2..ef75a21 100644 --- a/flanker/mime/message/part.py +++ b/flanker/mime/message/part.py @@ -1,10 +1,11 @@ import base64 -import imghdr import logging import mimetypes import quopri from contextlib import closing from os import path +from email.mime.image import MIMEImage +from email.mime.audio import MIMEAudio import six from six.moves import StringIO @@ -113,14 +114,20 @@ def adjust_content_type(content_type, body=None, filename=None): if six.PY3 and isinstance(body, six.text_type): image_preamble = image_preamble.encode('utf-8', 'ignore') - sub = imghdr.what(None, image_preamble) - if sub: - content_type = ContentType('image', sub) + try: + mime = MIMEImage(image_preamble) + except TypeError: + pass + else: + content_type = ContentType(*mime.get_content_type().split('/')) elif content_type.main == 'audio' and body: - sub = _email.detect_audio_type(body) - if sub: - content_type = ContentType('audio', sub) + try: + mime = MIMEAudio(body) + except TypeError: + pass + else: + content_type = ContentType(*mime.get_content_type().split('/')) return content_type