Ticket #24623: 24623_workaround_1.diff

File 24623_workaround_1.diff, 712 bytes (added by Konrad Świat, 9 years ago)
  • django/core/mail/message.py

    diff --git a/django/core/mail/message.py b/django/core/mail/message.py
    index e8d209c..53b2d4b 100644
    a b class EmailMessage(object):  
    309309    def attach_file(self, path, mimetype=None):
    310310        """Attaches a file from the filesystem."""
    311311        filename = os.path.basename(path)
    312         with open(path, 'rb') as f:
     312        if not mimetype:
     313            mimetype, _ = mimetypes.guess_type(filename)
     314        basetype, subtype = mimetype.split('/')
     315        readmode = 'r' if basetype == 'text' else 'rb'
     316        with open(path, readmode) as f:
    313317            content = f.read()
    314318        self.attach(filename, content, mimetype)
    315319
Back to Top