markup email handle encoded headers
This commit is contained in:
@ -5,6 +5,8 @@ import smtplib
|
||||
from pathlib import Path
|
||||
from mailbox import Maildir
|
||||
from email.message import EmailMessage
|
||||
from email.utils import formatdate
|
||||
from email.header import Header, make_header
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
@ -59,11 +61,14 @@ def send(frm, subj, msg):
|
||||
msg['From'] = 'Keen ProCatalog Markup Bot <support@procatalog.io>'
|
||||
msg['To'] = frm
|
||||
msg['Bcc'] = 'alx-markup@procatalog.io'
|
||||
msg['Subject'] = f'Re: {subj}'
|
||||
|
||||
subj = f'Re: {subj}'
|
||||
msg['Subject'] = Header(subj).encode()
|
||||
|
||||
msg['Message-ID'] = msgid()
|
||||
|
||||
maildir = Maildir('/tmp/markup_submit_mail')
|
||||
maildir.add(msg)
|
||||
maildir.add(msg.as_bytes())
|
||||
|
||||
log.info(f'sending email to "{frm}": {subj}')
|
||||
|
||||
|
||||
@ -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):
|
||||
|
||||
Reference in New Issue
Block a user