diff --git a/src/main/scala/util/Notifier.scala b/src/main/scala/util/Notifier.scala index 4fc4652..483ba64 100644 --- a/src/main/scala/util/Notifier.scala +++ b/src/main/scala/util/Notifier.scala @@ -9,6 +9,7 @@ import service.{AccountService, RepositoryService, IssuesService, SystemSettingsService} import servlet.Database import SystemSettingsService.Smtp +import _root_.util.ControlUtil.defining trait Notifier extends RepositoryService with AccountService with IssuesService { def toNotify(r: RepositoryService.RepositoryInfo, issueId: Int, content: String) @@ -68,30 +69,33 @@ val database = Database(context.request.getServletContext) val f = future { - val email = new HtmlEmail - email.setHostName(smtp.host) - email.setSmtpPort(smtp.port.get) - smtp.user.foreach { user => - email.setAuthenticator(new DefaultAuthenticator(user, smtp.password.getOrElse(""))) - } - smtp.ssl.foreach { ssl => - email.setSSLOnConnect(ssl) - } - smtp.fromAddress - .map (_ -> smtp.fromName.orNull) - .orElse (Some("notifications@gitbucket.com" -> context.loginAccount.get.userName)) - .foreach { case (address, name) => - email.setFrom(address, name) - } - email.setHtmlMsg(msg(view.Markdown.toHtml(content, r, false, true))) - // TODO Can we use the Database Session in other than Transaction Filter? database withSession { getIssue(r.owner, r.name, issueId.toString) foreach { issue => - email.setSubject(s"[${r.name}] ${issue.title} (#${issueId})") - recipients(issue) { - email.getToAddresses.clear - email.addTo(_).send + defining( + s"[${r.name}] ${issue.title} (#${issueId})" -> + msg(view.Markdown.toHtml(content, r, false, true))) { case (subject, msg) => + recipients(issue) { + val email = new HtmlEmail + email.setHostName(smtp.host) + email.setSmtpPort(smtp.port.get) + smtp.user.foreach { user => + email.setAuthenticator(new DefaultAuthenticator(user, smtp.password.getOrElse(""))) + } + smtp.ssl.foreach { ssl => + email.setSSLOnConnect(ssl) + } + smtp.fromAddress + .map (_ -> smtp.fromName.orNull) + .orElse (Some("notifications@gitbucket.com" -> context.loginAccount.get.userName)) + .foreach { case (address, name) => + email.setFrom(address, name) + } + email.setSubject(subject) + email.setHtmlMsg(msg) + + email.addTo(_).send + } } } }