Compare commits
1 commit
c19ef0991b
...
fe15939f06
Author | SHA1 | Date | |
---|---|---|---|
fe15939f06 |
4 changed files with 22 additions and 16 deletions
16
core/core/wsgi.py
Normal file
16
core/core/wsgi.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
WSGI config for core project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
|
||||
|
||||
application = get_wsgi_application()
|
|
@ -29,13 +29,13 @@ class Email(SoftDeleteModel):
|
|||
self.save()
|
||||
|
||||
def train_spam(self):
|
||||
if ACTIVE_SPAM_TRAINING and self.raw_file.path:
|
||||
if ACTIVE_SPAM_TRAINING:
|
||||
import subprocess
|
||||
path = self.raw_file.path
|
||||
subprocess.run(["rspamc", "learn_spam", path])
|
||||
|
||||
def train_ham(self):
|
||||
if ACTIVE_SPAM_TRAINING and self.raw_file.path:
|
||||
if ACTIVE_SPAM_TRAINING:
|
||||
import subprocess
|
||||
path = self.raw_file.path
|
||||
subprocess.run(["rspamc", "learn_ham", path])
|
||||
|
|
|
@ -91,7 +91,7 @@ async def send_smtp(message):
|
|||
await aiosmtplib.send(message, hostname="127.0.0.1", port=25, use_tls=False, start_tls=False)
|
||||
|
||||
|
||||
def find_active_issue_thread(in_reply_to, address, subject, event):
|
||||
def find_active_issue_thread(in_reply_to, address, subject):
|
||||
from re import match
|
||||
uuid_match = match(r'^ticket\+([a-f0-9-]{36})@', address)
|
||||
if uuid_match:
|
||||
|
@ -102,7 +102,7 @@ def find_active_issue_thread(in_reply_to, address, subject, event):
|
|||
if reply_to.exists():
|
||||
return reply_to.first().issue_thread, False
|
||||
else:
|
||||
issue = IssueThread.objects.create(name=subject, event=event)
|
||||
issue = IssueThread.objects.create(name=subject)
|
||||
return issue, True
|
||||
|
||||
|
||||
|
@ -205,14 +205,11 @@ def receive_email(envelope, log=None):
|
|||
target_event = find_target_event(recipient)
|
||||
log.info("found {}".format(target_event))
|
||||
|
||||
active_issue_thread, new = find_active_issue_thread(header_in_reply_to, recipient, subject, target_event)
|
||||
|
||||
from hashlib import sha256
|
||||
random_filename = 'mail-' + sha256(envelope.content).hexdigest()
|
||||
active_issue_thread, new = find_active_issue_thread(header_in_reply_to, recipient, subject)
|
||||
|
||||
email = Email.objects.create(
|
||||
sender=sender, recipient=recipient, body=body, subject=subject, reference=header_message_id,
|
||||
in_reply_to=header_in_reply_to, raw_file=ContentFile(envelope.content, name=random_filename), event=target_event,
|
||||
in_reply_to=header_in_reply_to, raw_file=ContentFile(envelope.content), event=target_event,
|
||||
issue_thread=active_issue_thread)
|
||||
for attachment in attachments:
|
||||
email.attachments.add(attachment)
|
||||
|
@ -261,7 +258,6 @@ class LMTPHandler:
|
|||
log.setLevel(logging.DEBUG)
|
||||
log.info('Message from %s' % envelope.mail_from)
|
||||
log.info('Message for %s' % envelope.rcpt_tos)
|
||||
log.info('CTX for {}, {}'.format(server, session))
|
||||
log.info('Message data:\n')
|
||||
|
||||
content = None
|
||||
|
|
|
@ -142,7 +142,6 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
|
|||
aiosmtplib.send.assert_called_once()
|
||||
self.assertEqual('test ä', Email.objects.all()[0].subject)
|
||||
self.assertEqual('Text mit Quoted-Printable-Kodierung: äöüß', Email.objects.all()[0].body)
|
||||
self.assertTrue( Email.objects.all()[0].raw_file.path)
|
||||
|
||||
def test_handle_quoted_printable_2(self):
|
||||
from aiosmtpd.smtp import Envelope
|
||||
|
@ -163,7 +162,6 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
|
|||
aiosmtplib.send.assert_called_once()
|
||||
self.assertEqual('suche_Mütze', Email.objects.all()[0].subject)
|
||||
self.assertEqual('Text mit Quoted-Printable-Kodierung: äöüß', Email.objects.all()[0].body)
|
||||
self.assertTrue( Email.objects.all()[0].raw_file.path)
|
||||
|
||||
def test_handle_base64(self):
|
||||
from aiosmtpd.smtp import Envelope
|
||||
|
@ -184,7 +182,6 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
|
|||
aiosmtplib.send.assert_called_once()
|
||||
self.assertEqual('test', Email.objects.all()[0].subject)
|
||||
self.assertEqual('Text mit Base64-Kodierung: äöüß', Email.objects.all()[0].body)
|
||||
self.assertTrue( Email.objects.all()[0].raw_file.path)
|
||||
|
||||
def test_handle_client_reply(self):
|
||||
issue_thread = IssueThread.objects.create(
|
||||
|
@ -232,7 +229,6 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
|
|||
self.assertEqual(IssueThread.objects.all()[0].name, 'test')
|
||||
self.assertEqual(IssueThread.objects.all()[0].state, 'pending_new')
|
||||
self.assertEqual(IssueThread.objects.all()[0].assigned_to, None)
|
||||
self.assertTrue( Email.objects.all()[2].raw_file.path)
|
||||
|
||||
def test_handle_client_reply_2(self):
|
||||
issue_thread = IssueThread.objects.create(
|
||||
|
@ -285,7 +281,6 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
|
|||
self.assertEqual(IssueThread.objects.all()[0].name, 'test')
|
||||
self.assertEqual(IssueThread.objects.all()[0].state, 'pending_open')
|
||||
self.assertEqual(IssueThread.objects.all()[0].assigned_to, None)
|
||||
self.assertTrue( Email.objects.all()[2].raw_file.path)
|
||||
|
||||
def test_mail_reply(self):
|
||||
issue_thread = IssueThread.objects.create(
|
||||
|
@ -389,7 +384,6 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
|
|||
states = StateChange.objects.filter(issue_thread=IssueThread.objects.all()[0])
|
||||
self.assertEqual(1, len(states))
|
||||
self.assertEqual('pending_new', states[0].state)
|
||||
self.assertEqual(event, IssueThread.objects.all()[0].event)
|
||||
|
||||
def test_mail_html_body(self):
|
||||
from aiosmtpd.smtp import Envelope
|
||||
|
|
Loading…
Reference in a new issue