mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Use doobie support from emil project
This commit is contained in:
@ -1,38 +0,0 @@
|
||||
package docspell.store
|
||||
|
||||
import cats.implicits._
|
||||
import emil._
|
||||
import emil.javamail.syntax._
|
||||
|
||||
object EmilUtil {
|
||||
|
||||
def readSSLType(str: String): Either[String, SSLType] =
|
||||
str.toLowerCase match {
|
||||
case "ssl" => Right(SSLType.SSL)
|
||||
case "starttls" => Right(SSLType.StartTLS)
|
||||
case "none" => Right(SSLType.NoEncryption)
|
||||
case _ => Left(s"Invalid ssl-type: $str")
|
||||
}
|
||||
|
||||
def unsafeReadSSLType(str: String): SSLType =
|
||||
readSSLType(str).fold(sys.error, identity)
|
||||
|
||||
def sslTypeString(st: SSLType): String =
|
||||
st match {
|
||||
case SSLType.SSL => "ssl"
|
||||
case SSLType.StartTLS => "starttls"
|
||||
case SSLType.NoEncryption => "none"
|
||||
}
|
||||
|
||||
def readMailAddress(str: String): Either[String, MailAddress] =
|
||||
MailAddress.parse(str)
|
||||
|
||||
def unsafeReadMailAddress(str: String): MailAddress =
|
||||
readMailAddress(str).fold(sys.error, identity)
|
||||
|
||||
def readMultipleAddresses(str: String): Either[String, List[MailAddress]] =
|
||||
str.split(',').toList.map(_.trim).traverse(readMailAddress)
|
||||
|
||||
def mailAddressString(ma: MailAddress): String =
|
||||
ma.asUnicodeString
|
||||
}
|
@ -6,14 +6,13 @@ import io.circe.{Decoder, Encoder}
|
||||
import doobie._
|
||||
import doobie.implicits.legacy.instant._
|
||||
import doobie.util.log.Success
|
||||
import emil.{MailAddress, SSLType}
|
||||
import emil.doobie.EmilDoobieMeta
|
||||
import com.github.eikek.calev.CalEvent
|
||||
|
||||
import docspell.common._
|
||||
import docspell.common.syntax.all._
|
||||
import docspell.store.EmilUtil
|
||||
|
||||
trait DoobieMeta {
|
||||
trait DoobieMeta extends EmilDoobieMeta {
|
||||
|
||||
implicit val sqlLogging = LogHandler({
|
||||
case e @ Success(_, _, _, _) =>
|
||||
@ -89,16 +88,6 @@ trait DoobieMeta {
|
||||
implicit val metaLanguage: Meta[Language] =
|
||||
Meta[String].imap(Language.unsafe)(_.iso3)
|
||||
|
||||
implicit val sslType: Meta[SSLType] =
|
||||
Meta[String].imap(EmilUtil.unsafeReadSSLType)(EmilUtil.sslTypeString)
|
||||
|
||||
implicit val mailAddress: Meta[MailAddress] =
|
||||
Meta[String].imap(EmilUtil.unsafeReadMailAddress)(EmilUtil.mailAddressString)
|
||||
|
||||
implicit def mailAddressList: Meta[List[MailAddress]] =
|
||||
Meta[String].imap(str => str.split(',').toList.map(_.trim).map(EmilUtil.unsafeReadMailAddress))(
|
||||
lma => lma.map(EmilUtil.mailAddressString).mkString(",")
|
||||
)
|
||||
|
||||
implicit val metaCalEvent: Meta[CalEvent] =
|
||||
Meta[String].timap(CalEvent.unsafe)(_.asString)
|
||||
|
Reference in New Issue
Block a user