diff --git a/projects/justice-email-and-delius/src/dev/resources/messages/successful-message-with-footer.json b/projects/justice-email-and-delius/src/dev/resources/messages/successful-message-with-footer.json new file mode 100644 index 000000000..f289d2d80 --- /dev/null +++ b/projects/justice-email-and-delius/src/dev/resources/messages/successful-message-with-footer.json @@ -0,0 +1,7 @@ +{ + "id": "00000000-0000-0000-0000-000000000000", + "subject": "A000001 was involved in an incident", + "bodyContent": "Example message\n\nThis e-mail and any attachments is intended only for the attention of the addressee(s). Its unauthorised use, disclosure, storage or copying is not permitted. If you are not the intended recipient, please destroy all copies and inform the sender by return e-mail. Internet e-mail is not a secure medium. Any reply to this message could be intercepted and read by someone else. Please bear that in mind when deciding whether to send material in response to this message by e-mail. This e-mail (whether you are the sender or the recipient) may be monitored, recorded and retained by the Ministry of Justice. Monitoring / blocking software may be used, and e-mail content may be read at any time. You have a responsibility to ensure laws are not broken when composing or forwarding e-mails and their contents.", + "fromEmailAddress": "example@justice.gov.uk", + "receivedDateTime": "2025-01-10T10:24:56Z[Europe/London]" +} \ No newline at end of file diff --git a/projects/justice-email-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt b/projects/justice-email-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt index 72be4f83a..1838d8a11 100644 --- a/projects/justice-email-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt +++ b/projects/justice-email-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt @@ -64,6 +64,34 @@ internal class IntegrationTest { assertThat(contact.providerId, equalTo(Data.MANAGER.providerId)) } + @Test + fun `moj footer is removed if present`() { + val notification = Notification(get("successful-message-with-footer")) + handler.handle(notification) + verify(telemetryService).notificationReceived(notification) + + val contact = verifyContactCreated() + assertThat(contact.type.code, equalTo(EMAIL.code)) + assertThat(contact.description, equalTo("Email - was involved in an incident")) + assertThat( + contact.notes, equalTo( + """ + |This contact was created automatically from a forwarded email sent by example@justice.gov.uk at 10:24 on 10/01/2025. + |Subject: A000001 was involved in an incident + | + |Example message + |""".trimMargin() + ) + ) + assertThat( + contact.externalReference, + equalTo("urn:uk:gov:hmpps:justice-email:00000000-0000-0000-0000-000000000000") + ) + assertThat(contact.staffId, equalTo(Data.STAFF.id)) + assertThat(contact.teamId, equalTo(Data.MANAGER.teamId)) + assertThat(contact.providerId, equalTo(Data.MANAGER.providerId)) + } + @Test fun `description is truncated if over 200 chars`() { val notification = Notification(get("successful-long-message")) diff --git a/projects/justice-email-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/EmailMessage.kt b/projects/justice-email-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/EmailMessage.kt index 8030a4a9e..3bdf15251 100644 --- a/projects/justice-email-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/EmailMessage.kt +++ b/projects/justice-email-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/EmailMessage.kt @@ -11,3 +11,6 @@ data class EmailMessage( val fromEmailAddress: String, val receivedDateTime: ZonedDateTime, ) + +private const val EMAIL_FOOTER = "This e-mail and any attachments is intended only for the attention of the addressee(s). Its unauthorised use, disclosure, storage or copying is not permitted. If you are not the intended recipient, please destroy all copies and inform the sender by return e-mail. Internet e-mail is not a secure medium. Any reply to this message could be intercepted and read by someone else. Please bear that in mind when deciding whether to send material in response to this message by e-mail. This e-mail (whether you are the sender or the recipient) may be monitored, recorded and retained by the Ministry of Justice. Monitoring / blocking software may be used, and e-mail content may be read at any time. You have a responsibility to ensure laws are not broken when composing or forwarding e-mails and their contents." +internal fun String.withoutFooter() = this.replace(EMAIL_FOOTER, "") diff --git a/projects/justice-email-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/projects/justice-email-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt index 021599e49..7923dd6c1 100644 --- a/projects/justice-email-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt +++ b/projects/justice-email-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt @@ -58,7 +58,7 @@ class Handler( |This contact was created automatically from a forwarded email sent by ${message.fromEmailAddress} ${message.onAt}. |Subject: ${message.subject} | - |${htmlToMarkdownConverter.convert(message.bodyContent)} + |${htmlToMarkdownConverter.convert(message.bodyContent.withoutFooter())} """.trimMargin() val contact = contactRepository.save( Contact(