From 9a1b3d3461b23b53c7f659618101d99bfd42607d Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Fri, 27 Oct 2023 10:54:38 +0200 Subject: [PATCH 1/2] typesafe.org -> example.org (cherry picked from commit 66711f06c1d87b94d0bf931a94b648ef62204fdd) --- README.md | 4 +- .../libs/mailer/MailerPluginGuiceSpec.scala | 10 ++--- .../api/libs/mailer/MailerPluginSpec.scala | 40 +++++++++---------- .../app/controllers/ApplicationScala.scala | 2 +- .../app/controllers/ApplicationScala.scala | 2 +- .../CustomSMTPConfigurationProvider.scala | 2 +- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 007db006..565ac92d 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ Create a new file named `CustomSMTPConfigurationProvider.scala`: class CustomSMTPConfigurationProvider extends Provider[SMTPConfiguration] { override def get() = { // Custom configuration - new SMTPConfiguration("typesafe.org", 1234) + new SMTPConfiguration("example.org", 1234) } } @@ -192,7 +192,7 @@ You can also use the SMTPMailer constructor to create new instances with custom ```scala val email = Email("Simple email", "Mister FROM ") -new SMTPMailer(SMTPConfiguration("typesafe.org", 1234)).send(email) +new SMTPMailer(SMTPConfiguration("example.org", 1234)).send(email) new SMTPMailer(SMTPConfiguration("playframework.com", 5678)).send(email) ``` diff --git a/play-mailer-guice/src/test/scala/play/api/libs/mailer/MailerPluginGuiceSpec.scala b/play-mailer-guice/src/test/scala/play/api/libs/mailer/MailerPluginGuiceSpec.scala index 3697d6b0..f6a4d0b8 100644 --- a/play-mailer-guice/src/test/scala/play/api/libs/mailer/MailerPluginGuiceSpec.scala +++ b/play-mailer-guice/src/test/scala/play/api/libs/mailer/MailerPluginGuiceSpec.scala @@ -15,7 +15,7 @@ class MailerPluginGuiceSpec extends Specification { import play.libs.mailer.{ MailerClient => JMailerClient } val mockedConfigurationProvider = mock(classOf[SMTPConfigurationProvider]) - when(mockedConfigurationProvider.get()).thenReturn(SMTPConfiguration("typesafe.org", 25, mock = true)) + when(mockedConfigurationProvider.get()).thenReturn(SMTPConfiguration("example.org", 25, mock = true)) def createApp(additionalConfiguration: Map[String, _]): Application = { new GuiceApplicationBuilder() @@ -24,13 +24,13 @@ class MailerPluginGuiceSpec extends Specification { .build() } - val applicationWithMinimalMailerConfiguration = createApp(additionalConfiguration = Map("play.mailer.host" -> "typesafe.org", "play.mailer.port" -> 25)) + val applicationWithMinimalMailerConfiguration = createApp(additionalConfiguration = Map("play.mailer.host" -> "example.org", "play.mailer.port" -> 25)) val applicationWithMockedConfigurationProvider = new GuiceApplicationBuilder() .overrides(new ConfigModule) // Play 2.5.x "hack" .overrides(bind[SMTPConfiguration].to(mockedConfigurationProvider)) .build() - val applicationWithMoreMailerConfiguration = createApp(additionalConfiguration = Map("play.mailer.host" -> "typesafe.org", "play.mailer.port" -> 25, "play.mailer.user" -> "typesafe", "play.mailer.password" -> "typesafe")) + val applicationWithMoreMailerConfiguration = createApp(additionalConfiguration = Map("play.mailer.host" -> "example.org", "play.mailer.port" -> 25, "play.mailer.user" -> "typesafe", "play.mailer.password" -> "typesafe")) "provide the Scala mailer client" in new WithApplication(applicationWithMinimalMailerConfiguration) { override def running() = { @@ -54,7 +54,7 @@ class MailerPluginGuiceSpec extends Specification { } "call the configuration each time we send an email" in new WithApplication(applicationWithMockedConfigurationProvider) { override def running() = { - val mail = Email("Test Configurable Mailer", "root@typesafe.org") + val mail = Email("Test Configurable Mailer", "root@example.org") app.injector.instanceOf[MailerClient].send(mail) app.injector.instanceOf[MailerClient].send(mail) Mockito.verify(mockedConfigurationProvider, times(2)).get() @@ -62,7 +62,7 @@ class MailerPluginGuiceSpec extends Specification { } "validate the configuration" in new WithApplication(applicationWithMoreMailerConfiguration) { override def running() = { - app.injector.instanceOf(bind[SMTPConfiguration]) must ===(SMTPConfiguration("typesafe.org", 25, + app.injector.instanceOf(bind[SMTPConfiguration]) must ===(SMTPConfiguration("example.org", 25, user = Some("typesafe"), password = Some("typesafe"), props = ConfigFactory.parseString("ssl.checkserveridentity=true"))) } } diff --git a/play-mailer/src/test/scala/play/api/libs/mailer/MailerPluginSpec.scala b/play-mailer/src/test/scala/play/api/libs/mailer/MailerPluginSpec.scala index 48df448e..83dfbc89 100644 --- a/play-mailer/src/test/scala/play/api/libs/mailer/MailerPluginSpec.scala +++ b/play-mailer/src/test/scala/play/api/libs/mailer/MailerPluginSpec.scala @@ -28,7 +28,7 @@ class MailerPluginSpec extends Specification { class MockCommonsMailerWithProps(props: Config = ConfigFactory.empty()) extends MockCommonsMailerWithTimeouts(None, None, props) class MockCommonsMailerWithTimeouts(smtpTimeout: Option[Int], smtpConnectionTimeout: Option[Int], props: Config = ConfigFactory.empty()) - extends CommonsMailer(SMTPConfiguration("typesafe.org", 1234, ssl = true, tls = false, tlsRequired = false, Some("user"), Some("password"), debugMode = false, smtpTimeout, smtpConnectionTimeout, props, mock = false)) { + extends CommonsMailer(SMTPConfiguration("example.org", 1234, ssl = true, tls = false, tlsRequired = false, Some("user"), Some("password"), debugMode = false, smtpTimeout, smtpConnectionTimeout, props, mock = false)) { override def send(email: MultiPartEmail) = "" override def createMultiPartEmail(): MultiPartEmail = new MockMultiPartEmail override def createHtmlEmail(): HtmlEmail = new MockHtmlEmail @@ -39,12 +39,12 @@ class MailerPluginSpec extends Specification { val mailer = MockCommonsMailer val email = mailer.createEmail(Email( subject = "Subject", - from = "James Roper " + from = "John Doe " )) email.getSmtpPort mustEqual "1234" email.getSslSmtpPort mustEqual "1234" email.getMailSession.getProperty("mail.smtp.auth") mustEqual "true" - email.getMailSession.getProperty("mail.smtp.host") mustEqual "typesafe.org" + email.getMailSession.getProperty("mail.smtp.host") mustEqual "example.org" email.getMailSession.getProperty("mail.smtp.starttls.enable") mustEqual "false" email.getMailSession.getProperty("mail.smtp.starttls.required") mustEqual "false" email.getMailSession.getProperty("mail.smtp.localhost") must beNull @@ -55,7 +55,7 @@ class MailerPluginSpec extends Specification { val mailer = new MockCommonsMailerWithTimeouts(Some(10), Some(99)) val email = mailer.createEmail(Email( subject = "Subject", - from = "James Roper " + from = "John Doe " )) email.getSocketTimeout mustEqual 10 email.getSocketConnectionTimeout mustEqual 99 @@ -65,7 +65,7 @@ class MailerPluginSpec extends Specification { val mailer = new MockCommonsMailerWithTimeouts(None, None) val email = mailer.createEmail(Email( subject = "Subject", - from = "James Roper " + from = "John Doe " )) email.getSocketTimeout mustEqual EmailConstants.SOCKET_TIMEOUT_MS email.getSocketConnectionTimeout mustEqual EmailConstants.SOCKET_TIMEOUT_MS @@ -75,7 +75,7 @@ class MailerPluginSpec extends Specification { val mailer = new MockCommonsMailerWithProps(ConfigFactory.parseString("localhost=127.0.0.1")) val email = mailer.createEmail(Email( subject = "Subject", - from = "James Roper " + from = "John Doe " )) email.getMailSession.getProperty("mail.smtp.localhost") mustEqual "127.0.0.1" email.getMailSession.getProperty("mail.smtps.localhost") mustEqual "127.0.0.1" @@ -85,7 +85,7 @@ class MailerPluginSpec extends Specification { val mailer = MockCommonsMailer val messageId = mailer.send(Email( subject = "Subject", - from = "James Roper ", + from = "John Doe ", to = Seq("Guillaume Grossetie ") )) messageId mustEqual "" @@ -95,7 +95,7 @@ class MailerPluginSpec extends Specification { val mailer = MockCommonsMailer val email = mailer.createEmail(Email( subject = "Subject", - from = "James Roper ", + from = "John Doe ", to = Seq("Guillaume Grossetie "), replyTo = Seq("Aviv Shafir "), bodyText = Some("A text message"), @@ -112,7 +112,7 @@ class MailerPluginSpec extends Specification { val mailer = MockCommonsMailer val email = mailer.createEmail(Email( subject = "Subject", - from = "James Roper ", + from = "John Doe ", to = Seq("Guillaume Grossetie "), replyTo = Seq("Aviv Shafir "), bodyText = Some("A text message"), @@ -137,7 +137,7 @@ class MailerPluginSpec extends Specification { val cid = "1234" val email = mailer.createEmail(Email( subject = "Subject", - from = "James Roper ", + from = "John Doe ", to = Seq("Guillaume Grossetie "), replyTo = Seq("Aviv Shafir "), bodyHtml = Some(s"""

An html message with cid

"""), @@ -154,7 +154,7 @@ class MailerPluginSpec extends Specification { val mailer = MockCommonsMailer val email = mailer.createEmail(Email( subject = "Subject", - from = "James Roper ", + from = "John Doe ", to = Seq("Guillaume Grossetie "), replyTo = Seq("Aviv Shafir "), bodyText = Some("A text message"), @@ -178,14 +178,14 @@ class MailerPluginSpec extends Specification { val mailer = MockCommonsMailer val email = mailer.createEmail(Email( subject = "Subject", - from = "James Roper ", + from = "John Doe ", to = Seq("Guillaume Grossetie "), replyTo = Seq("Aviv Shafir "), cc = Seq("Guillaume Grossetie "), bcc = Seq("Guillaume Grossetie ") )) - email.getFromAddress.getAddress mustEqual "jroper@typesafe.com" - email.getFromAddress.getPersonal mustEqual "James Roper" + email.getFromAddress.getAddress mustEqual "john.doe@example.com" + email.getFromAddress.getPersonal mustEqual "John Doe" email.getToAddresses.get(0).getAddress mustEqual "ggrossetie@localhost.com" email.getToAddresses.get(0).getPersonal mustEqual "Guillaume Grossetie" email.getCcAddresses.get(0).getAddress mustEqual "ggrossetie@localhost.com" @@ -200,13 +200,13 @@ class MailerPluginSpec extends Specification { val mailer = MockCommonsMailer val email = mailer.createEmail(Email( subject = "Subject", - from = "jroper@typesafe.com", + from = "john.doe@example.com", to = Seq(""), cc = Seq("ggrossetie@localhost.com"), replyTo = Seq("avivshafir@github.com"), bcc = Seq("ggrossetie@localhost.com") )) - email.getFromAddress.getAddress mustEqual "jroper@typesafe.com" + email.getFromAddress.getAddress mustEqual "john.doe@example.com" email.getFromAddress.getPersonal must beNull email.getToAddresses.get(0).getAddress mustEqual "ggrossetie@localhost.com" email.getToAddresses.get(0).getPersonal must beNull @@ -223,7 +223,7 @@ class MailerPluginSpec extends Specification { "convert email from Java to Scala" in { val data = new play.libs.mailer.Email() data.setSubject("Subject") - data.setFrom("James Roper ") + data.setFrom("John Doe ") data.addTo("Guillaume Grossetie ") data.addCc("Daniel Spasojevic ") data.addBcc("Sparkbitpl ") @@ -238,7 +238,7 @@ class MailerPluginSpec extends Specification { val convert = SimpleMailerClient.convert(data) convert.subject mustEqual "Subject" - convert.from mustEqual "James Roper " + convert.from mustEqual "John Doe " convert.to.size mustEqual 1 convert.to.head mustEqual "Guillaume Grossetie " convert.cc.size mustEqual 1 @@ -272,8 +272,8 @@ class MailerPluginSpec extends Specification { def simpleEmailMust(email: MultiPartEmail): Unit = { email.getSubject mustEqual "Subject" - email.getFromAddress.getPersonal mustEqual "James Roper" - email.getFromAddress.getAddress mustEqual "jroper@typesafe.com" + email.getFromAddress.getPersonal mustEqual "John Doe" + email.getFromAddress.getAddress mustEqual "john.doe@example.com" email.getToAddresses must have size 1 email.getToAddresses.get(0).getPersonal mustEqual "Guillaume Grossetie" email.getToAddresses.get(0).getAddress mustEqual "ggrossetie@localhost.com" diff --git a/samples/compile-timeDI/app/controllers/ApplicationScala.scala b/samples/compile-timeDI/app/controllers/ApplicationScala.scala index 3ed93362..90b9613c 100644 --- a/samples/compile-timeDI/app/controllers/ApplicationScala.scala +++ b/samples/compile-timeDI/app/controllers/ApplicationScala.scala @@ -27,7 +27,7 @@ class ApplicationScala(mailer: MailerClient, environment: Environment, component } def configureAndSend = Action { - val mailer = new SMTPMailer(SMTPConfiguration("typesafe.org", 1234)) + val mailer = new SMTPMailer(SMTPConfiguration("example.org", 1234)) val id = mailer.send(Email("Simple email", "Mister FROM ", Seq("Miss TO "))) Ok(s"Email $id sent!") } diff --git a/samples/runtimeDI/app/controllers/ApplicationScala.scala b/samples/runtimeDI/app/controllers/ApplicationScala.scala index fee8a590..bcb26c11 100644 --- a/samples/runtimeDI/app/controllers/ApplicationScala.scala +++ b/samples/runtimeDI/app/controllers/ApplicationScala.scala @@ -28,7 +28,7 @@ class ApplicationScala @Inject()(mailer: MailerClient, environment: Environment, } def sendWithCustomMailer = Action { - val mailer = new SMTPMailer(SMTPConfiguration("typesafe.org", 1234)) + val mailer = new SMTPMailer(SMTPConfiguration("example.org", 1234)) val id = mailer.send(Email("Simple email", "Mister FROM ")) Ok(s"Email $id sent!") } diff --git a/samples/runtimeDI/app/controllers/CustomSMTPConfigurationProvider.scala b/samples/runtimeDI/app/controllers/CustomSMTPConfigurationProvider.scala index 853e6c16..efc4879f 100644 --- a/samples/runtimeDI/app/controllers/CustomSMTPConfigurationProvider.scala +++ b/samples/runtimeDI/app/controllers/CustomSMTPConfigurationProvider.scala @@ -7,7 +7,7 @@ import play.api.{Configuration, Environment} import play.api.inject.Module class CustomSMTPConfigurationProvider extends Provider[SMTPConfiguration] { - override def get() = new SMTPConfiguration("typesafe.org", 1234) + override def get() = new SMTPConfiguration("example.org", 1234) } class CustomMailerConfigurationModule extends Module { From d50276b6f1a0bf47740f507cc3df1bfe0631b557 Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Fri, 27 Oct 2023 10:56:17 +0200 Subject: [PATCH 2/2] Remove Typesafe in example/tests (cherry picked from commit 14127ddb133fb21e0f1ba789b18dc7ec5172da04) --- .../scala/play/api/libs/mailer/MailerPluginGuiceSpec.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/play-mailer-guice/src/test/scala/play/api/libs/mailer/MailerPluginGuiceSpec.scala b/play-mailer-guice/src/test/scala/play/api/libs/mailer/MailerPluginGuiceSpec.scala index f6a4d0b8..9617ccc3 100644 --- a/play-mailer-guice/src/test/scala/play/api/libs/mailer/MailerPluginGuiceSpec.scala +++ b/play-mailer-guice/src/test/scala/play/api/libs/mailer/MailerPluginGuiceSpec.scala @@ -30,7 +30,7 @@ class MailerPluginGuiceSpec extends Specification { .overrides(new ConfigModule) // Play 2.5.x "hack" .overrides(bind[SMTPConfiguration].to(mockedConfigurationProvider)) .build() - val applicationWithMoreMailerConfiguration = createApp(additionalConfiguration = Map("play.mailer.host" -> "example.org", "play.mailer.port" -> 25, "play.mailer.user" -> "typesafe", "play.mailer.password" -> "typesafe")) + val applicationWithMoreMailerConfiguration = createApp(additionalConfiguration = Map("play.mailer.host" -> "example.org", "play.mailer.port" -> 25, "play.mailer.user" -> "johndoe", "play.mailer.password" -> "randompw")) "provide the Scala mailer client" in new WithApplication(applicationWithMinimalMailerConfiguration) { override def running() = { @@ -63,7 +63,7 @@ class MailerPluginGuiceSpec extends Specification { "validate the configuration" in new WithApplication(applicationWithMoreMailerConfiguration) { override def running() = { app.injector.instanceOf(bind[SMTPConfiguration]) must ===(SMTPConfiguration("example.org", 25, - user = Some("typesafe"), password = Some("typesafe"), props = ConfigFactory.parseString("ssl.checkserveridentity=true"))) + user = Some("johndoe"), password = Some("randompw"), props = ConfigFactory.parseString("ssl.checkserveridentity=true"))) } } }