keep all attachments (fixes #12849)

This commit is contained in:
Benjamin Dauvergne 2016-08-09 22:08:32 +02:00 committed by Serghei Mihai
parent 834bb8ebcf
commit e61e5a5381
1 changed files with 10 additions and 14 deletions

View File

@ -36,21 +36,17 @@ def parse_header(header_text):
headers[i] = unicode(text, charset or default_charset, errors='replace')
return u' '.join(headers)
def parse_attachment(data):
disposition = data.get('Content-Disposition')
if disposition:
dispositions = disposition.strip().split(";")
if dispositions[0] == "attachment":
file_data = data.get_payload(decode=True)
with tempfile.NamedTemporaryFile(delete=False) as attachment:
attachment.write(file_data)
attachment.flush()
temp = tempfile.NamedTemporaryFile(delete=False)
attachment = {'path': attachment.name,
'content_type': data.get_content_type(),
'filename': parse_header(data.get_filename())}
return attachment
return None
file_data = data.get_payload(decode=True)
with tempfile.NamedTemporaryFile(delete=False) as attachment:
attachment.write(file_data)
attachment.flush()
attachment = {'path': attachment.name,
'content_type': data.get_content_type(),
'filename': parse_header(data.get_filename())}
return attachment
def send_mail(to, subject, message):
s = smtplib.SMTP('localhost')