Changeset - 29e10c6a1551
[Not reviewed]
0 1 0
Lance Edgar (lance) - 7 years ago 2018-02-22 13:15:54
lance@edbob.org
Add email attachment MIME type for MS Word .doc files
1 file changed with 1 insertions and 0 deletions:
0 comments (0 inline, 0 general)
rattail/mail.py
Show inline comments
 
@@ -434,24 +434,25 @@ class Email(object):
 
                except TopLevelLookupException:
 
                    pass
 

	
 
    def normalize_attachments(self, attachments):
 
        normalized = []
 
        for attachment in attachments:
 
            if isinstance(attachment, six.string_types):
 
                attachment = self.normalize_attachment(attachment)
 
            normalized.append(attachment)
 
        return normalized
 

	
 
    ATTACHMENT_MIME_MAP = {
 
        '.doc': 'application/msword',
 
        '.pdf': 'pdf',
 
        '.xls': 'vnd.ms-excel',
 
    }
 

	
 
    def normalize_attachment(self, path):
 
        root, ext = os.path.splitext(path)
 
        ext = ext.lower()
 
        if ext == '.csv':
 
            with open(path, 'rb') as f:
 
                part = MIMEText(f.read(), 'csv', 'utf_8')
 
            filename = os.path.basename(path)
 
            part.add_header('Content-Disposition', 'attachment; filename="{}"'.format(filename))
0 comments (0 inline, 0 general)