markup email handle encoded headers

This commit is contained in:
2019-10-30 15:46:23 -07:00
parent a1aff2cb99
commit 14003e9dc2
2 changed files with 13 additions and 4 deletions

View File

@ -11,6 +11,7 @@ from pathlib import Path
from email.feedparser import FeedParser
from email.message import EmailMessage
from email.header import decode_header, make_header
import django
from django.conf import settings
@ -33,15 +34,18 @@ def process_message(path):
parser.feed(line)
msg = parser.close()
frm = str(make_header(decode_header(msg['From'])))
subject = str(make_header(decode_header(msg['Subject'])))
found_pdf = False
if msg.is_multipart():
for attach in msg.walk():
if attach.get_content_type() == 'application/pdf':
process_attachment(msg['From'], msg['Subject'], attach)
found_pdf = True
process_attachment(frm, subject, attach)
if not found_pdf:
reply_missing(msg['From'], msg['Subject'])
reply_missing(frm, subject)
def process_attachment(from_address, subject, attachment):