added a check in the make_reply function to ensure that mails have a body
This commit is contained in:
parent
8a181f7fa5
commit
c056e6880f
20 changed files with 9636 additions and 53 deletions
|
@ -124,19 +124,12 @@ TEMPLATES = [
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
WSGI_APPLICATION = 'core.wsgi.application'
|
ASGI_APPLICATION = 'core.asgi.application'
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
||||||
|
|
||||||
if 'test' in sys.argv:
|
if os.getenv('DB_HOST') is not None:
|
||||||
DATABASES = {
|
|
||||||
'default': {
|
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
|
||||||
'NAME': ':memory:',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.mysql',
|
'ENGINE': 'django.db.backends.mysql',
|
||||||
|
@ -149,6 +142,20 @@ else:
|
||||||
'charset': 'utf8mb4',
|
'charset': 'utf8mb4',
|
||||||
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
|
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
elif os.getenv('DB_FILE') is not None:
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
|
'NAME': os.getenv('DB_FILE', 'local.db'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
|
'NAME': ':memory:',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
Subject: test
|
||||||
|
From: test1@test
|
||||||
|
To: test2@test
|
||||||
|
Message-ID: <1@test>
|
||||||
|
Content-Type: multipart/alternative; boundary="abc"
|
||||||
|
|
||||||
|
--abc
|
||||||
|
Content-Type: text/plain; charset=utf-8
|
||||||
|
|
||||||
|
test1
|
||||||
|
|
||||||
|
--abc
|
||||||
|
Content-Type: image/jpeg; name="test.jpg"
|
||||||
|
Content-Disposition: inline; filename="test.jpg"
|
||||||
|
Content-Transfer-Encoding: base64
|
||||||
|
Content-ID: <1>
|
||||||
|
X-Attachment-Id: 1
|
||||||
|
|
||||||
|
dGVzdGltYWdl
|
||||||
|
|
||||||
|
--abc
|
||||||
|
Content-Type: text/plain; charset=utf-8
|
||||||
|
|
||||||
|
test2
|
||||||
|
|
||||||
|
--abc--
|
|
@ -0,0 +1,5 @@
|
||||||
|
Subject: test
|
||||||
|
From: <test1@test>
|
||||||
|
To: test2@test
|
||||||
|
Message-ID: <1@test>
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
Subject: test
|
||||||
|
From: test1@test
|
||||||
|
To: test2@test
|
||||||
|
Message-ID: <1@test>
|
||||||
|
Content-Type: text/html; charset=utf-8
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
|
hello =C3=A4=C3=B6=C3=BC
|
|
@ -0,0 +1,6 @@
|
||||||
|
Subject: test
|
||||||
|
From: test3@test
|
||||||
|
To: test4@localhost
|
||||||
|
Message-ID: <1@test>
|
||||||
|
|
||||||
|
test
|
|
@ -0,0 +1,6 @@
|
||||||
|
Subject: =?UTF-8?Q?suche_M=C3=BCtze?=
|
||||||
|
From: test3@test
|
||||||
|
To: test4@test
|
||||||
|
Message-ID: <1@test>
|
||||||
|
|
||||||
|
Text mit Quoted-Printable-Kodierung: =?utf-8?Q?=C3=A4=C3=B6=C3=BC=C3=9F?=
|
|
@ -0,0 +1,7 @@
|
||||||
|
Subject: test
|
||||||
|
From: test1@test
|
||||||
|
To: test2@test
|
||||||
|
Message-ID: <1@test>
|
||||||
|
Content-Type: text/html; charset=iso-8859-1
|
||||||
|
|
||||||
|
hello äöü
|
|
@ -0,0 +1,21 @@
|
||||||
|
Subject: test
|
||||||
|
From: test1@test
|
||||||
|
To: test2@test
|
||||||
|
Message-ID: <1@test>
|
||||||
|
Content-Type: multipart/mixed; boundary="abc"
|
||||||
|
|
||||||
|
--abc
|
||||||
|
Content-Type: text/plain; charset=utf-8
|
||||||
|
|
||||||
|
test1
|
||||||
|
|
||||||
|
--abc
|
||||||
|
Content-Type: image/jpeg; name="test.jpg"
|
||||||
|
Content-Disposition: attachment; filename="test.jpg"
|
||||||
|
Content-Transfer-Encoding: base64
|
||||||
|
Content-ID: <1>
|
||||||
|
X-Attachment-Id: 1
|
||||||
|
|
||||||
|
dGVzdGltYWdl
|
||||||
|
|
||||||
|
--abc--
|
|
@ -0,0 +1,11 @@
|
||||||
|
Subject: test
|
||||||
|
From: test1@test
|
||||||
|
To: test2@test
|
||||||
|
Message-ID: <1@test>
|
||||||
|
Content-Type: text/html; charset=utf-8
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<p>test</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -0,0 +1,6 @@
|
||||||
|
Subject: test =?utf-8?Q?=C3=A4?=
|
||||||
|
From: test3@test
|
||||||
|
To: test4@test
|
||||||
|
Message-ID: <1@test>
|
||||||
|
|
||||||
|
Text mit Quoted-Printable-Kodierung: =?utf-8?Q?=C3=A4=C3=B6=C3=BC=C3=9F?=
|
|
@ -0,0 +1,6 @@
|
||||||
|
Subject: =?utf-8?B?dGVzdA==?=
|
||||||
|
From: test3@test
|
||||||
|
To: test4@test
|
||||||
|
Message-ID: <1@test>
|
||||||
|
|
||||||
|
Text mit Base64-Kodierung: =?utf-8?B?w6TDtsO8w58=?=
|
|
@ -0,0 +1,6 @@
|
||||||
|
Subject: test
|
||||||
|
From: test1@test
|
||||||
|
To: test_event@localhost
|
||||||
|
Message-ID: <1@test>
|
||||||
|
|
||||||
|
test
|
|
@ -0,0 +1,5 @@
|
||||||
|
From: noreply@test
|
||||||
|
To: test2@test
|
||||||
|
Message-ID: <1@test>
|
||||||
|
|
||||||
|
test
|
|
@ -0,0 +1,7 @@
|
||||||
|
Subject: test
|
||||||
|
From: test1@test
|
||||||
|
To: test2@test
|
||||||
|
Message-ID: <1@test>
|
||||||
|
Content-Type: text/html; charset=utf-8
|
||||||
|
|
||||||
|
thank you =?utf-8?Q?=F0=9F=98=8A?=
|
|
@ -81,11 +81,11 @@ def make_reply(reply_email, references=None, event=None):
|
||||||
reply_email.save()
|
reply_email.save()
|
||||||
if references:
|
if references:
|
||||||
reply["References"] = " ".join(references)
|
reply["References"] = " ".join(references)
|
||||||
|
if reply_email.body != "":
|
||||||
reply.set_content(reply_email.body)
|
reply.set_content(reply_email.body)
|
||||||
|
return reply
|
||||||
return reply
|
else:
|
||||||
|
raise SpecialMailException("mail content emty")
|
||||||
|
|
||||||
async def send_smtp(message):
|
async def send_smtp(message):
|
||||||
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)
|
||||||
|
@ -268,10 +268,10 @@ class LMTPHandler:
|
||||||
systemevent = await database_sync_to_async(SystemEvent.objects.create)(type='email received',
|
systemevent = await database_sync_to_async(SystemEvent.objects.create)(type='email received',
|
||||||
reference=email.id)
|
reference=email.id)
|
||||||
log.info(f"Created system event {systemevent.id}")
|
log.info(f"Created system event {systemevent.id}")
|
||||||
channel_layer = get_channel_layer()
|
#channel_layer = get_channel_layer()
|
||||||
await channel_layer.group_send(
|
#await channel_layer.group_send(
|
||||||
'general', {"type": "generic.event", "name": "send_message_to_frontend", "event_id": systemevent.id,
|
# 'general', {"type": "generic.event", "name": "send_message_to_frontend", "event_id": systemevent.id,
|
||||||
"message": "email received"})
|
# "message": "email received"})
|
||||||
log.info(f"Sent message to frontend")
|
log.info(f"Sent message to frontend")
|
||||||
if new and reply:
|
if new and reply:
|
||||||
log.info('Sending message to %s' % reply['To'])
|
log.info('Sending message to %s' % reply['To'])
|
||||||
|
|
0
core/testdata.py
Normal file
0
core/testdata.py
Normal file
|
@ -102,12 +102,6 @@ def manual_ticket(request, event_slug):
|
||||||
subject=request.data['name'],
|
subject=request.data['name'],
|
||||||
body=request.data['body'],
|
body=request.data['body'],
|
||||||
)
|
)
|
||||||
systemevent = SystemEvent.objects.create(type='email received', reference=email.id)
|
|
||||||
channel_layer = get_channel_layer()
|
|
||||||
async_to_sync(channel_layer.group_send)(
|
|
||||||
'general', {"type": "generic.event", "name": "send_message_to_frontend", "event_id": systemevent.id,
|
|
||||||
"message": "email received"}
|
|
||||||
)
|
|
||||||
|
|
||||||
return Response(IssueSerializer(issue).data, status=status.HTTP_201_CREATED)
|
return Response(IssueSerializer(issue).data, status=status.HTTP_201_CREATED)
|
||||||
|
|
||||||
|
@ -133,12 +127,6 @@ def add_comment(request, pk):
|
||||||
issue_thread=issue,
|
issue_thread=issue,
|
||||||
comment=request.data['comment'],
|
comment=request.data['comment'],
|
||||||
)
|
)
|
||||||
systemevent = SystemEvent.objects.create(type='comment added', reference=comment.id)
|
|
||||||
channel_layer = get_channel_layer()
|
|
||||||
async_to_sync(channel_layer.group_send)(
|
|
||||||
'general', {"type": "generic.event", "name": "send_message_to_frontend", "event_id": systemevent.id,
|
|
||||||
"message": "comment added"}
|
|
||||||
)
|
|
||||||
return Response(CommentSerializer(comment).data, status=status.HTTP_201_CREATED)
|
return Response(CommentSerializer(comment).data, status=status.HTTP_201_CREATED)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,20 +3,16 @@ services:
|
||||||
build:
|
build:
|
||||||
context: ../../core
|
context: ../../core
|
||||||
dockerfile: ../deploy/dev/Dockerfile.backend
|
dockerfile: ../deploy/dev/Dockerfile.backend
|
||||||
command: bash -c 'python manage.py migrate && python manage.py runserver 0.0.0.0:8000'
|
command: bash -c 'python manage.py migrate && python testdata.py && python manage.py runserver 0.0.0.0:8000'
|
||||||
environment:
|
environment:
|
||||||
- HTTP_HOST=core
|
- HTTP_HOST=core
|
||||||
- DB_HOST=db
|
- DB_FILE=dev.db
|
||||||
- DB_PORT=3306
|
- DEBUG_MODE_ACTIVE=true
|
||||||
- DB_NAME=system3
|
|
||||||
- DB_USER=system3
|
|
||||||
- DB_PASSWORD=system3
|
|
||||||
volumes:
|
volumes:
|
||||||
- ../../core:/code
|
- ../../core:/code
|
||||||
|
- ../testdata.py:/code/testdata.py
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
build:
|
build:
|
||||||
|
@ -31,18 +27,3 @@ services:
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
depends_on:
|
depends_on:
|
||||||
- core
|
- core
|
||||||
|
|
||||||
db:
|
|
||||||
image: mariadb
|
|
||||||
environment:
|
|
||||||
MARIADB_RANDOM_ROOT_PASSWORD: true
|
|
||||||
MARIADB_DATABASE: system3
|
|
||||||
MARIADB_USER: system3
|
|
||||||
MARIADB_PASSWORD: system3
|
|
||||||
volumes:
|
|
||||||
- mariadb_data:/var/lib/mysql
|
|
||||||
ports:
|
|
||||||
- "3306:3306"
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
mariadb_data:
|
|
88
deploy/testdata.py
Normal file
88
deploy/testdata.py
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def setup():
|
||||||
|
from authentication.models import ExtendedUser, EventPermission
|
||||||
|
from inventory.models import Event
|
||||||
|
from django.contrib.auth.models import Permission, Group
|
||||||
|
permissions = ['add_item', 'view_item', 'view_file', 'delete_item', 'change_item']
|
||||||
|
if not ExtendedUser.objects.filter(username='admin').exists():
|
||||||
|
admin = ExtendedUser.objects.create_superuser('admin', 'admin@example.com', 'admin')
|
||||||
|
admin.set_password('admin')
|
||||||
|
admin.user_permissions.add(*Permission.objects.all())
|
||||||
|
admin.save()
|
||||||
|
|
||||||
|
if not ExtendedUser.objects.filter(username='testuser').exists():
|
||||||
|
testuser = ExtendedUser.objects.create_user('testuser', 'testuser@example.com', 'testuser')
|
||||||
|
testuser.set_password('testuser')
|
||||||
|
testuser.user_permissions.add(*Permission.objects.all())
|
||||||
|
testuser.save()
|
||||||
|
|
||||||
|
team = Group.objects.get(name='Team')
|
||||||
|
team.permissions.add(
|
||||||
|
*Permission.objects.all()
|
||||||
|
)
|
||||||
|
|
||||||
|
if not ExtendedUser.objects.filter(username='testuser2').exists():
|
||||||
|
testuser2 = ExtendedUser.objects.create_user('testuser2', 'testuser2@example.com', 'testuser2')
|
||||||
|
testuser2.set_password('testuser2')
|
||||||
|
testuser2.groups.add(team)
|
||||||
|
testuser2.save()
|
||||||
|
|
||||||
|
event1 = Event.objects.get_or_create(id=1, name='first test event', slug='TEST1',
|
||||||
|
start='2023-12-18 00:00:00.000000', end='2023-12-27 00:00:00.000000',
|
||||||
|
pre_start='2023-12-31 00:00:00.000000', post_end='2024-01-04 00:00:00.000000')[
|
||||||
|
0]
|
||||||
|
|
||||||
|
event2 = Event.objects.get_or_create(id=2, name='second test event', slug='TEST2',
|
||||||
|
start='2024-12-18 00:00:00.000000', end='2024-12-27 00:00:00.000000',
|
||||||
|
pre_start='2024-12-31 00:00:00.000000', post_end='2025-01-04 00:00:00.000000')[
|
||||||
|
0]
|
||||||
|
|
||||||
|
# for permission in permissions:
|
||||||
|
# EventPermission.objects.create(event=event_37c3, user=foo,
|
||||||
|
# permission=Permission.objects.get(codename=permission))
|
||||||
|
|
||||||
|
from tickets.models import IssueThread
|
||||||
|
|
||||||
|
from mail.models import Email
|
||||||
|
|
||||||
|
issue_thread = IssueThread.objects.get_or_create(
|
||||||
|
id=1,
|
||||||
|
name="test",
|
||||||
|
event=Event.objects.get(slug='TEST1')
|
||||||
|
)[0]
|
||||||
|
mail1 = Email.objects.get_or_create(
|
||||||
|
id=1,
|
||||||
|
subject='test subject',
|
||||||
|
body='test',
|
||||||
|
sender='test1@test',
|
||||||
|
recipient='test2@test',
|
||||||
|
issue_thread=issue_thread,
|
||||||
|
)[0]
|
||||||
|
mail1_reply = Email.objects.get_or_create(
|
||||||
|
id=2,
|
||||||
|
subject='Message received',
|
||||||
|
body='Thank you for your message.',
|
||||||
|
sender='test2@test',
|
||||||
|
recipient='test1@test',
|
||||||
|
in_reply_to=mail1.reference,
|
||||||
|
issue_thread=issue_thread,
|
||||||
|
)[0]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
|
||||||
|
import django
|
||||||
|
|
||||||
|
django.setup()
|
||||||
|
|
||||||
|
from django.core.management import call_command
|
||||||
|
call_command('migrate')
|
||||||
|
|
||||||
|
setup()
|
||||||
|
print('testdata initialised')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
9399
web/package-lock.json
generated
Normal file
9399
web/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue