mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 18:08:25 +00:00
Starting with mail settings
This commit is contained in:
@ -0,0 +1,16 @@
|
||||
CREATE TABLE "useremail" (
|
||||
"id" varchar(254) not null primary key,
|
||||
"uid" varchar(254) not null,
|
||||
"name" varchar(254) not null,
|
||||
"smtp_host" varchar(254) not null,
|
||||
"smtp_port" int not null,
|
||||
"smtp_user" varchar(254) not null,
|
||||
"smtp_password" varchar(254) not null,
|
||||
"smtp_ssl" varchar(254) not null,
|
||||
"smtp_certcheck" boolean not null,
|
||||
"mail_from" varchar(254) not null,
|
||||
"mail_replyto" varchar(254),
|
||||
"created" timestamp not null,
|
||||
unique ("uid", "name"),
|
||||
foreign key ("uid") references "user_"("uid")
|
||||
);
|
@ -12,6 +12,8 @@ import doobie.implicits.legacy.instant._
|
||||
import doobie.util.log.Success
|
||||
import io.circe.{Decoder, Encoder}
|
||||
import docspell.common.syntax.all._
|
||||
import emil.{MailAddress, SSLType}
|
||||
import emil.javamail.syntax._
|
||||
|
||||
trait DoobieMeta {
|
||||
|
||||
@ -88,9 +90,31 @@ trait DoobieMeta {
|
||||
|
||||
implicit val metaLanguage: Meta[Language] =
|
||||
Meta[String].imap(Language.unsafe)(_.iso3)
|
||||
|
||||
implicit val sslType: Meta[SSLType] =
|
||||
Meta[String].imap(DoobieMeta.readSSLType)(DoobieMeta.sslTypeString)
|
||||
|
||||
implicit val mailAddress: Meta[MailAddress] =
|
||||
Meta[String].imap(str => MailAddress.parse(str).fold(sys.error, identity))(_.asUnicodeString)
|
||||
}
|
||||
|
||||
object DoobieMeta extends DoobieMeta {
|
||||
import org.log4s._
|
||||
private val logger = getLogger
|
||||
|
||||
private def readSSLType(str: String): SSLType =
|
||||
str.toLowerCase match {
|
||||
case "ssl" => SSLType.SSL
|
||||
case "starttls" => SSLType.StartTLS
|
||||
case "none" => SSLType.NoEncryption
|
||||
case _ => sys.error(s"Invalid ssl-type: $str")
|
||||
}
|
||||
|
||||
private def sslTypeString(st: SSLType): String =
|
||||
st match {
|
||||
case SSLType.SSL => "ssl"
|
||||
case SSLType.StartTLS => "starttls"
|
||||
case SSLType.NoEncryption => "none"
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,71 @@
|
||||
package docspell.store.records
|
||||
|
||||
import doobie._
|
||||
import doobie.implicits._
|
||||
import docspell.common._
|
||||
import docspell.store.impl.Column
|
||||
import docspell.store.impl.Implicits._
|
||||
import emil.{MailAddress, SSLType}
|
||||
|
||||
case class RUserEmail(
|
||||
id: Ident,
|
||||
uid: Ident,
|
||||
name: String,
|
||||
smtpHost: String,
|
||||
smtpPort: Int,
|
||||
smtpUser: String,
|
||||
smtpPassword: Password,
|
||||
smtpSsl: SSLType,
|
||||
smtpCertCheck: Boolean,
|
||||
mailFrom: MailAddress,
|
||||
mailReplyTo: Option[MailAddress],
|
||||
created: Timestamp
|
||||
) {}
|
||||
|
||||
object RUserEmail {
|
||||
|
||||
val table = fr"useremail"
|
||||
|
||||
object Columns {
|
||||
val id = Column("id")
|
||||
val uid = Column("uid")
|
||||
val name = Column("name")
|
||||
val smtpHost = Column("smtp_host")
|
||||
val smtpPort = Column("smtp_port")
|
||||
val smtpUser = Column("smtp_user")
|
||||
val smtpPass = Column("smtp_password")
|
||||
val smtpSsl = Column("smtp_ssl")
|
||||
val smtpCertCheck = Column("smtp_certcheck")
|
||||
val mailFrom = Column("mail_from")
|
||||
val mailReplyTo = Column("mail_replyto")
|
||||
val created = Column("created")
|
||||
|
||||
val all = List(
|
||||
id,
|
||||
uid,
|
||||
name,
|
||||
smtpHost,
|
||||
smtpPort,
|
||||
smtpUser,
|
||||
smtpPass,
|
||||
smtpSsl,
|
||||
smtpCertCheck,
|
||||
mailFrom,
|
||||
mailReplyTo,
|
||||
created
|
||||
)
|
||||
}
|
||||
|
||||
import Columns._
|
||||
|
||||
def insert(v: RUserEmail): ConnectionIO[Int] =
|
||||
insertRow(
|
||||
table,
|
||||
all,
|
||||
sql"${v.id},${v.uid},${v.name},${v.smtpHost},${v.smtpPort},${v.smtpUser},${v.smtpPassword},${v.smtpSsl},${v.smtpCertCheck},${v.mailFrom},${v.mailReplyTo},${v.created}"
|
||||
).update.run
|
||||
|
||||
def findByUser(userId: Ident): ConnectionIO[Vector[RUserEmail]] =
|
||||
selectSimple(all, table, uid.is(userId)).query[RUserEmail].to[Vector]
|
||||
|
||||
}
|
Reference in New Issue
Block a user