Skip to content

Commit

Permalink
PI-2646 remove moj footer if present
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-britton-moj committed Jan 10, 2025
1 parent 133373b commit 68bfdf6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"receivedDateTime": "2025-01-10T10:24:56Z[Europe/London]"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<EmailMessage>("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 [email protected] 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<EmailMessage>("successful-long-message"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 68bfdf6

Please sign in to comment.