This commit is contained in:
j3d1 2023-12-06 05:06:26 +01:00
parent 76dd805262
commit 470541d239
4 changed files with 27 additions and 13 deletions

View file

@ -46,12 +46,12 @@ async def send_smtp(message, log):
await aiosmtplib.send(message, hostname="127.0.0.1", port=25, use_tls=False, start_tls=False) 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): def find_active_issue_thread(in_reply_to, subject=None):
reply_to = Email.objects.filter(reference=in_reply_to) reply_to = Email.objects.filter(reference=in_reply_to)
if reply_to.exists(): if reply_to.exists():
return reply_to.first().issue_thread return reply_to.first().issue_thread
else: else:
return IssueThread.objects.create() return IssueThread.objects.create(name=subject)
class LMTPHandler: class LMTPHandler:
@ -102,6 +102,7 @@ class LMTPHandler:
recipient = envelope.rcpt_tos[0] recipient = envelope.rcpt_tos[0]
sender = envelope.mail_from sender = envelope.mail_from
subject = parsed.get('Subject')
target_event = None target_event = None
try: try:
address_map = await sync_to_async(EventAddress.objects.get)(address=recipient) address_map = await sync_to_async(EventAddress.objects.get)(address=recipient)
@ -110,12 +111,12 @@ class LMTPHandler:
except EventAddress.DoesNotExist: except EventAddress.DoesNotExist:
pass pass
active_issue_thread = await sync_to_async(find_active_issue_thread)(header_in_reply_to) active_issue_thread = await sync_to_async(find_active_issue_thread)(header_in_reply_to, subject)
email = await sync_to_async(Email.objects.create)(sender=sender, email = await sync_to_async(Email.objects.create)(sender=sender,
recipient=recipient, recipient=recipient,
body=body.decode('utf-8'), body=body.decode('utf-8'),
subject=parsed.get('Subject'), subject=subject,
reference=header_message_id, reference=header_message_id,
in_reply_to=header_in_reply_to, in_reply_to=header_in_reply_to,
raw=envelope.content.decode('utf-8'), raw=envelope.content.decode('utf-8'),

View file

@ -83,11 +83,16 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
self.assertTrue(Email.objects.all()[1].reference.startswith("<")) self.assertTrue(Email.objects.all()[1].reference.startswith("<"))
self.assertTrue(Email.objects.all()[1].reference.endswith("@localhost>")) self.assertTrue(Email.objects.all()[1].reference.endswith("@localhost>"))
self.assertEqual(Email.objects.all()[1].in_reply_to, "<1@test>") self.assertEqual(Email.objects.all()[1].in_reply_to, "<1@test>")
self.assertEqual(IssueThread.objects.all()[0].name, 'test')
self.assertEqual(IssueThread.objects.all()[0].state, 'new')
self.assertEqual(IssueThread.objects.all()[0].assigned_to, None)
def test_handle_client_reply(self): def test_handle_client_reply(self):
issue_thread = IssueThread.objects.create() issue_thread = IssueThread.objects.create(
name="test",
)
mail1 = Email.objects.create( mail1 = Email.objects.create(
subject='test', subject='test subject',
body='test', body='test',
sender='test1@test', sender='test1@test',
recipient='test2@test', recipient='test2@test',
@ -134,6 +139,9 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
self.assertTrue(Email.objects.all()[3].reference.startswith("<")) self.assertTrue(Email.objects.all()[3].reference.startswith("<"))
self.assertTrue(Email.objects.all()[3].reference.endswith("@localhost>")) self.assertTrue(Email.objects.all()[3].reference.endswith("@localhost>"))
self.assertEqual(Email.objects.all()[3].in_reply_to, "<3@test>") self.assertEqual(Email.objects.all()[3].in_reply_to, "<3@test>")
self.assertEqual(IssueThread.objects.all()[0].name, 'test')
self.assertEqual(IssueThread.objects.all()[0].state, 'new')
self.assertEqual(IssueThread.objects.all()[0].assigned_to, None)
# class AsyncLMTPTestCase(TestCase): # class AsyncLMTPTestCase(TestCase):
# #

View file

@ -17,7 +17,9 @@ class IssueApiTest(TestCase):
def test_issues(self): def test_issues(self):
now = datetime.now() now = datetime.now()
issue = IssueThread.objects.create() issue = IssueThread.objects.create(
name="test issue",
)
mail1 = Email.objects.create( mail1 = Email.objects.create(
subject='test', subject='test',
body='test', body='test',
@ -50,9 +52,9 @@ class IssueApiTest(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json()), 1) self.assertEqual(len(response.json()), 1)
self.assertEqual(response.json()[0]['id'], issue.id) self.assertEqual(response.json()[0]['id'], issue.id)
self.assertEqual(response.json()[0]['name'], issue.name) self.assertEqual(response.json()[0]['name'], "test issue")
self.assertEqual(response.json()[0]['state'], issue.state) self.assertEqual(response.json()[0]['state'], "new")
self.assertEqual(response.json()[0]['assigned_to'], issue.assigned_to) self.assertEqual(response.json()[0]['assigned_to'], None)
self.assertEqual(response.json()[0]['last_activity'], issue.last_activity.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) self.assertEqual(response.json()[0]['last_activity'], issue.last_activity.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
self.assertEqual(len(response.json()[0]['timeline']), 4) self.assertEqual(len(response.json()[0]['timeline']), 4)
self.assertEqual(response.json()[0]['timeline'][0]['type'], 'mail') self.assertEqual(response.json()[0]['timeline'][0]['type'], 'mail')

View file

@ -17,7 +17,7 @@
import Navbar from '@/components/Navbar'; import Navbar from '@/components/Navbar';
import AddItemModal from '@/components/AddItemModal'; import AddItemModal from '@/components/AddItemModal';
import Toast from './components/Toast'; import Toast from './components/Toast';
import {mapState, mapMutations} from 'vuex'; import {mapState, mapMutations, mapActions} from 'vuex';
export default { export default {
name: 'app', name: 'app',
@ -30,6 +30,7 @@ export default {
}), }),
methods: { methods: {
...mapMutations(['removeToast', 'createToast']), ...mapMutations(['removeToast', 'createToast']),
...mapActions(['loadItems', 'loadTickets']),
openAddModal() { openAddModal() {
this.addModalOpen = true; this.addModalOpen = true;
}, },
@ -90,14 +91,16 @@ export default {
}; };
this.notify_socket.onmessage = (e) => { this.notify_socket.onmessage = (e) => {
let data = JSON.parse(e.data); let data = JSON.parse(e.data);
console.log(data); //this.loadItems()
this.loadTickets()
} }
} }
}, },
}, },
created: function () { created: function () {
//this.tryConnect(); this.tryConnect();
} }
}; };
</script> </script>