SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit f73b8a1b authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Add extra MIME headers to ComposedMessage

parent 89da161e
No related branches found
No related tags found
No related merge requests found
...@@ -59,8 +59,10 @@ class ComposedMessageSerializer(serializers.ModelSerializer): ...@@ -59,8 +59,10 @@ class ComposedMessageSerializer(serializers.ModelSerializer):
model = ComposedMessage model = ComposedMessage
fields = [ fields = [
'uuid', 'author', 'created_on', 'status', 'uuid', 'author', 'created_on', 'status',
'from_account', 'from_email', 'to_recipient', 'cc_recipients', 'bcc_recipients', 'from_account', 'from_email',
'to_recipient', 'cc_recipients', 'bcc_recipients',
'subject', 'body_text', 'body_html', 'subject', 'body_text', 'body_html',
'headers_added',
'attachment_files', 'api_responses' 'attachment_files', 'api_responses'
] ]
......
...@@ -28,6 +28,11 @@ class Command(BaseCommand): ...@@ -28,6 +28,11 @@ class Command(BaseCommand):
if msg.bcc_recipients: if msg.bcc_recipients:
data['bcc'] = msg.bcc_recipients data['bcc'] = msg.bcc_recipients
# RFC 2822 MIME headers:
for key, val in msg.headers_added.items():
h_key = "h:%s" % key
data[h_key] = val
files = [('attachment', (att.data['name'], att.file.read())) files = [('attachment', (att.data['name'], att.file.read()))
for att in msg.attachment_files.all()] for att in msg.attachment_files.all()]
......
# Generated by Django 2.2.16 on 2020-10-23 06:15
import django.contrib.postgres.fields.jsonb
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('apimail', '0024_auto_20201017_1658'),
]
operations = [
migrations.AddField(
model_name='composedmessage',
name='headers_added',
field=django.contrib.postgres.fields.jsonb.JSONField(default=dict),
),
]
...@@ -64,6 +64,8 @@ class ComposedMessage(models.Model): ...@@ -64,6 +64,8 @@ class ComposedMessage(models.Model):
body_text = models.TextField(blank=True) body_text = models.TextField(blank=True)
body_html = models.TextField(blank=True) body_html = models.TextField(blank=True)
headers_added = JSONField(default=dict)
attachment_files = models.ManyToManyField( attachment_files = models.ManyToManyField(
'apimail.AttachmentFile', 'apimail.AttachmentFile',
blank=True) blank=True)
......
...@@ -330,6 +330,7 @@ export default { ...@@ -330,6 +330,7 @@ export default {
bcc_recipients: [], bcc_recipients: [],
subject: '', subject: '',
body_html: '', body_html: '',
headers_added: {},
attachments: [], attachments: [],
}, },
from_account_accesses: [], from_account_accesses: [],
...@@ -404,6 +405,7 @@ export default { ...@@ -404,6 +405,7 @@ export default {
'subject': this.form.subject, 'subject': this.form.subject,
'body_text': this.form.body_html, // TODO: remove; only html emails 'body_text': this.form.body_html, // TODO: remove; only html emails
'body_html': this.sanitized_body_html, 'body_html': this.sanitized_body_html,
'headers_added': this.form.headers_added,
'attachment_uuids': attachment_uuids 'attachment_uuids': attachment_uuids
}) })
}) })
...@@ -450,6 +452,16 @@ export default { ...@@ -450,6 +452,16 @@ export default {
else if (this.originalmessage) { else if (this.originalmessage) {
this.form.from_account = this.accountSelected.pk this.form.from_account = this.accountSelected.pk
this.form.body_html = ('<br><br><blockquote>') this.form.body_html = ('<br><br><blockquote>')
this.form.headers_added['Reply-To'] = this.accountSelected.email
this.form.headers_added['In-Reply-To'] = this.originalmessage.data['Message-Id']
if (this.originalmessage.data['References']) {
this.form.headers_added['References'] = (
this.originalmessage.data['References'] + " "
+ this.originalmessage.data['Message-Id'])
}
else {
this.form.headers_added['References'] = this.originalmessage.data['Message-Id']
}
if (this.action == 'reply') { if (this.action == 'reply') {
this.form.to_recipient = this.originalmessage.data.sender this.form.to_recipient = this.originalmessage.data.sender
this.form.cc_recipients = this.originalmessage.data.recipients.split(',') this.form.cc_recipients = this.originalmessage.data.recipients.split(',')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment