Commit c24348b6 authored by Lars Kruse's avatar Lars Kruse Committed by Robert

mail handling: add LMTP-based receiver

parent 57753186
This diff is collapsed.
......@@ -120,6 +120,30 @@ class ParsedMailMessage(collections.namedtuple(
message.to_addresses, from_address, message.get_email_object(), message.id,
tuple(attachments))
@classmethod
def from_email_object(cls, email_obj, from_address=None):
""" convert an email.message.EmailMessage into a ParsedMailMessage """
if from_address is None:
from_address = email_obj.get('From')
if email_obj.is_multipart():
body_part = email_obj.get_body(preferencelist=('html', 'text'))
attachments = tuple(
ParsedMailAttachment(part.get_content_type(), part.get_filename(),
part.get_payload(decode=True), None)
for part in email_obj.iter_attachments())
else:
body_part = email_obj
attachments = ()
# parse and convert the body_part (containing the text or html message)
content = body_part.get_payload(decode=True).decode()
if body_part.get_content_type() == "text/html":
text_content = html2text.html2text(content)
else:
text_content = content
return cls(email_obj.get('Subject') or cls.MISSING_SUBJECT_DEFAULT, text_content,
email_obj.get_all('To'), from_address, email_obj,
email_obj.get('Message-ID'), attachments)
class ContributionMailProcessor:
""" process an incoming contribution mail
......@@ -136,6 +160,16 @@ class ContributionMailProcessor:
self.response_from_address = response_from_address
self._ignore_log_message_emitted = False
def is_mail_domain(self, domain):
return domain == self._reply_domain
def is_valid_groupname(self, group_name):
try:
groups.Group.objects.get(slug=group_name)
return True
except groups.Group.DoesNotExist:
return False
def parse_authentication_token_text(self, address):
""" parse a potential authentication token from a recipient address without checking it """
match = self.auth_token_regex.match(address)
......
aiosmtpd # debian: python3-aiosmtpd
bleach # debian: python3-bleach
django # debian: python3-django
django-allauth # debian (buster): python3-django-allauth
......@@ -16,6 +17,7 @@ markdown # debian: python3-markdown
mdx_unimoji # NOT IN DEBIAN
pillow # debian: python-pil
pymdown-extensions # NOT IN DEBIAN
aiosmtplib # NOT IN DEBIAN
schulze # NOT IN DEBIAN
randomcolor # NOT IN DEBIAN
raven # debian (buster): python3-raven
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment