do not send an auto reply to 'noreply*' addresses
This commit is contained in:
parent
1804939407
commit
c79b3185e5
3 changed files with 38 additions and 9 deletions
|
@ -182,7 +182,7 @@ def receive_email(envelope, log=None):
|
||||||
if new:
|
if new:
|
||||||
# auto reply if new issue
|
# auto reply if new issue
|
||||||
references = collect_references(active_issue_thread)
|
references = collect_references(active_issue_thread)
|
||||||
|
if not sender.startswith('noreply'):
|
||||||
reply_email = Email.objects.create(
|
reply_email = Email.objects.create(
|
||||||
sender=recipient, recipient=sender, body="Thank you for your message.", subject="Message received",
|
sender=recipient, recipient=sender, body="Thank you for your message.", subject="Message received",
|
||||||
in_reply_to=header_message_id, event=target_event, issue_thread=active_issue_thread)
|
in_reply_to=header_message_id, event=target_event, issue_thread=active_issue_thread)
|
||||||
|
@ -223,7 +223,7 @@ class LMTPHandler:
|
||||||
"message": "email received"}
|
"message": "email received"}
|
||||||
)
|
)
|
||||||
log.info(f"Sent message to frontend")
|
log.info(f"Sent message to frontend")
|
||||||
if new:
|
if new and reply:
|
||||||
await send_smtp(reply, log)
|
await send_smtp(reply, log)
|
||||||
log.info("Sent auto reply")
|
log.info("Sent auto reply")
|
||||||
|
|
||||||
|
|
|
@ -491,3 +491,33 @@ dGVzdGltYWdl
|
||||||
file_content = EmailAttachment.objects.all()[0].file.read()
|
file_content = EmailAttachment.objects.all()[0].file.read()
|
||||||
self.assertEqual(b'testimage', file_content)
|
self.assertEqual(b'testimage', file_content)
|
||||||
|
|
||||||
|
def test_mail_noreply(self):
|
||||||
|
from aiosmtpd.smtp import Envelope
|
||||||
|
from asgiref.sync import async_to_sync
|
||||||
|
import aiosmtplib
|
||||||
|
aiosmtplib.send = make_mocked_coro()
|
||||||
|
handler = LMTPHandler()
|
||||||
|
server = mock.Mock()
|
||||||
|
session = mock.Mock()
|
||||||
|
envelope = Envelope()
|
||||||
|
envelope.mail_from = 'noreply@test'
|
||||||
|
envelope.rcpt_tos = ['test2@test']
|
||||||
|
envelope.content = b'Subject: test\nFrom: noreply@test\nTo: test2@test\nMessage-ID: <1@test>\n\ntest'
|
||||||
|
result = async_to_sync(handler.handle_DATA)(server, session, envelope)
|
||||||
|
self.assertEqual(result, '250 Message accepted for delivery')
|
||||||
|
self.assertEqual(len(Email.objects.all()), 1)
|
||||||
|
self.assertEqual(len(IssueThread.objects.all()), 1)
|
||||||
|
aiosmtplib.send.assert_not_called()
|
||||||
|
self.assertEqual('test', Email.objects.all()[0].subject)
|
||||||
|
self.assertEqual('noreply@test', Email.objects.all()[0].sender)
|
||||||
|
self.assertEqual('test2@test', Email.objects.all()[0].recipient)
|
||||||
|
self.assertEqual('test', Email.objects.all()[0].body)
|
||||||
|
self.assertEqual(IssueThread.objects.all()[0], Email.objects.all()[0].issue_thread)
|
||||||
|
self.assertEqual('<1@test>', Email.objects.all()[0].reference)
|
||||||
|
self.assertEqual(None, Email.objects.all()[0].in_reply_to)
|
||||||
|
self.assertEqual('test', IssueThread.objects.all()[0].name)
|
||||||
|
self.assertEqual('pending_new', IssueThread.objects.all()[0].state)
|
||||||
|
self.assertEqual(None, IssueThread.objects.all()[0].assigned_to)
|
||||||
|
states = StateChange.objects.filter(issue_thread=IssueThread.objects.all()[0])
|
||||||
|
self.assertEqual(1, len(states))
|
||||||
|
self.assertEqual('pending_new', states[0].state)
|
||||||
|
|
|
@ -143,7 +143,6 @@ class IssueApiTest(TestCase):
|
||||||
self.assertEqual(comment.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
|
self.assertEqual(comment.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
|
||||||
response.json()[2]['timeline'][1]['timestamp'])
|
response.json()[2]['timeline'][1]['timestamp'])
|
||||||
|
|
||||||
|
|
||||||
def test_manual_creation(self):
|
def test_manual_creation(self):
|
||||||
response = self.client.post('/api/2/tickets/manual/',
|
response = self.client.post('/api/2/tickets/manual/',
|
||||||
{'name': 'test issue', 'sender': 'test', 'recipient': 'test', 'body': 'test'},
|
{'name': 'test issue', 'sender': 'test', 'recipient': 'test', 'body': 'test'},
|
||||||
|
|
Loading…
Reference in a new issue