diff --git a/apimail/api/serializers.py b/apimail/api/serializers.py index 0d186486d37a16c845356c5509bb5bce6e00e9dd..2bdfd86930940d087ea76c114cd26dd264dde244 100644 --- a/apimail/api/serializers.py +++ b/apimail/api/serializers.py @@ -59,8 +59,10 @@ class ComposedMessageSerializer(serializers.ModelSerializer): model = ComposedMessage fields = [ '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', + 'headers_added', 'attachment_files', 'api_responses' ] diff --git a/apimail/management/commands/mailgun_send_messages.py b/apimail/management/commands/mailgun_send_messages.py index 790fffcf65c261f0f5c9a336f9d03dda23edaa6f..9aef99c15b6a5498e994bef716a6ccb8aa189fa7 100644 --- a/apimail/management/commands/mailgun_send_messages.py +++ b/apimail/management/commands/mailgun_send_messages.py @@ -28,6 +28,11 @@ class Command(BaseCommand): if 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())) for att in msg.attachment_files.all()] diff --git a/apimail/migrations/0025_composedmessage_headers_added.py b/apimail/migrations/0025_composedmessage_headers_added.py new file mode 100644 index 0000000000000000000000000000000000000000..2d8836149d65e7561b71cf219e30a38703e9c6d5 --- /dev/null +++ b/apimail/migrations/0025_composedmessage_headers_added.py @@ -0,0 +1,19 @@ +# 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), + ), + ] diff --git a/apimail/models/composed_message.py b/apimail/models/composed_message.py index 491d6ea7a48b096501040f3221d6845123bc811b..654f911d2f7ea6285c438650a5fe88fc37885bd9 100644 --- a/apimail/models/composed_message.py +++ b/apimail/models/composed_message.py @@ -64,6 +64,8 @@ class ComposedMessage(models.Model): body_text = models.TextField(blank=True) body_html = models.TextField(blank=True) + headers_added = JSONField(default=dict) + attachment_files = models.ManyToManyField( 'apimail.AttachmentFile', blank=True) diff --git a/apimail/static/apimail/assets/vue/components/MessageComposer.vue b/apimail/static/apimail/assets/vue/components/MessageComposer.vue index bf1442d5e30d8f95d4af4f9178bc29536054491e..cdfdbda6cd3b279e5422733b638e59da528012f9 100644 --- a/apimail/static/apimail/assets/vue/components/MessageComposer.vue +++ b/apimail/static/apimail/assets/vue/components/MessageComposer.vue @@ -330,6 +330,7 @@ export default { bcc_recipients: [], subject: '', body_html: '', + headers_added: {}, attachments: [], }, from_account_accesses: [], @@ -404,6 +405,7 @@ export default { 'subject': this.form.subject, 'body_text': this.form.body_html, // TODO: remove; only html emails 'body_html': this.sanitized_body_html, + 'headers_added': this.form.headers_added, 'attachment_uuids': attachment_uuids }) }) @@ -450,6 +452,16 @@ export default { else if (this.originalmessage) { this.form.from_account = this.accountSelected.pk 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') { this.form.to_recipient = this.originalmessage.data.sender this.form.cc_recipients = this.originalmessage.data.recipients.split(',')