Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
EASY-2512: fix incomplete pattern match (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanheest authored Jan 10, 2020
1 parent 427cd5b commit c426e9d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/scala/nl.knaw.dans.easy.deposit/Mailer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ case class Mailer(smtpHost: String,
email.setFrom(fromAddress)
email.setBounceAddress(bounceAddress)
bccs.foreach(email.addBcc)
attachments.foreach { case (name, content) if notEmpty(content) =>
email.attach(content, name, name)
attachments.foreach {
case (name, content) =>
if (notEmpty(content))
email.attach(content, name, name)
}
email.setHostName(smtpHost)
email.buildMimeMessage()
Expand Down
7 changes: 7 additions & 0 deletions src/test/scala/nl.knaw.dans.easy.deposit/MailerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ class MailerSpec extends TestSupportFixture {
.buildMessage(data, attachments, UUID.randomUUID(), msg4Datamanager = Option("")) shouldBe a[Success[_]]
}

it should "not add empty attachments" in {
val from = "[email protected]"
val theseAttachments = attachments + (Mailer.filesAttachmentName -> Mailer.dataSource("".getBytes, "text/plain"))
Mailer(smtpHost = "localhost", fromAddress = from, bounceAddress = from, bccs = Seq.empty, validTemplateDir, url)
.buildMessage(data, theseAttachments, UUID.randomUUID(), msg4Datamanager = Option("")) shouldBe a[Success[_]]
}

it should "report invalid address" in {
val from = "dans.knaw.nl"
Mailer(smtpHost = "localhost", fromAddress = from, bounceAddress = from, bccs = Seq.empty, validTemplateDir, url)
Expand Down

0 comments on commit c426e9d

Please sign in to comment.