mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Send mails for items
This commit is contained in:
@ -95,7 +95,9 @@ trait DoobieMeta {
|
||||
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(",")
|
||||
)
|
||||
}
|
||||
|
||||
object DoobieMeta extends DoobieMeta {
|
||||
|
@ -64,6 +64,26 @@ object RAttachment {
|
||||
q.query[RAttachment].to[Vector]
|
||||
}
|
||||
|
||||
def findByItemAndCollectiveWithMeta(
|
||||
id: Ident,
|
||||
coll: Ident
|
||||
): ConnectionIO[Vector[(RAttachment, FileMeta)]] = {
|
||||
import bitpeace.sql._
|
||||
|
||||
val cols = all.map(_.prefix("a")) ++ RFileMeta.Columns.all.map(_.prefix("m"))
|
||||
val afileMeta = fileId.prefix("a")
|
||||
val aItem = itemId.prefix("a")
|
||||
val mId = RFileMeta.Columns.id.prefix("m")
|
||||
val iId = RItem.Columns.id.prefix("i")
|
||||
val iColl = RItem.Columns.cid.prefix("i")
|
||||
|
||||
val from = table ++ fr"a INNER JOIN" ++ RFileMeta.table ++ fr"m ON" ++ afileMeta.is(mId) ++
|
||||
fr"INNER JOIN" ++ RItem.table ++ fr"i ON" ++ aItem.is(iId)
|
||||
val cond = Seq(aItem.is(id), iColl.is(coll))
|
||||
|
||||
selectSimple(cols, from, and(cond)).query[(RAttachment, FileMeta)].to[Vector]
|
||||
}
|
||||
|
||||
def findByItemWithMeta(id: Ident): ConnectionIO[Vector[(RAttachment, FileMeta)]] = {
|
||||
import bitpeace.sql._
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
package docspell.store.records
|
||||
|
||||
import doobie.implicits._
|
||||
import docspell.store.impl._
|
||||
|
||||
object RFileMeta {
|
||||
|
||||
val table = fr"filemeta"
|
||||
|
||||
object Columns {
|
||||
val id = Column("id")
|
||||
val timestamp = Column("timestamp")
|
||||
val mimetype = Column("mimetype")
|
||||
val length = Column("length")
|
||||
val checksum = Column("checksum")
|
||||
val chunks = Column("chunks")
|
||||
val chunksize = Column("chunksize")
|
||||
|
||||
val all = List(id, timestamp, mimetype, length, checksum, chunks, chunksize)
|
||||
|
||||
}
|
||||
}
|
@ -262,4 +262,7 @@ object RItem {
|
||||
|
||||
def deleteByIdAndCollective(itemId: Ident, coll: Ident): ConnectionIO[Int] =
|
||||
deleteFrom(table, and(id.is(itemId), cid.is(coll))).update.run
|
||||
|
||||
def existsById(itemId: Ident): ConnectionIO[Boolean] =
|
||||
selectCount(id, table, id.is(itemId)).query[Int].unique.map(_ > 0)
|
||||
}
|
||||
|
@ -1,12 +1,15 @@
|
||||
package docspell.store.records
|
||||
|
||||
import fs2.Stream
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
import doobie._
|
||||
import doobie.implicits._
|
||||
import docspell.common._
|
||||
import docspell.store.impl.Column
|
||||
import docspell.store.impl.Implicits._
|
||||
import emil.MailAddress
|
||||
import cats.data.OptionT
|
||||
|
||||
case class RSentMail(
|
||||
id: Ident,
|
||||
@ -21,17 +24,46 @@ case class RSentMail(
|
||||
|
||||
object RSentMail {
|
||||
|
||||
def apply[F[_]: Sync](
|
||||
uid: Ident,
|
||||
messageId: String,
|
||||
sender: MailAddress,
|
||||
subject: String,
|
||||
recipients: List[MailAddress],
|
||||
body: String
|
||||
): F[RSentMail] =
|
||||
for {
|
||||
id <- Ident.randomId[F]
|
||||
now <- Timestamp.current[F]
|
||||
} yield RSentMail(id, uid, messageId, sender, subject, recipients, body, now)
|
||||
|
||||
def forItem(
|
||||
itemId: Ident,
|
||||
accId: AccountId,
|
||||
messageId: String,
|
||||
sender: MailAddress,
|
||||
subject: String,
|
||||
recipients: List[MailAddress],
|
||||
body: String
|
||||
): OptionT[ConnectionIO, (RSentMail, RSentMailItem)] =
|
||||
for {
|
||||
user <- OptionT(RUser.findByAccount(accId))
|
||||
sm <- OptionT.liftF(RSentMail[ConnectionIO](user.uid, messageId, sender, subject, recipients, body))
|
||||
si <- OptionT.liftF(RSentMailItem[ConnectionIO](itemId, sm.id, Some(sm.created)))
|
||||
} yield (sm, si)
|
||||
|
||||
|
||||
val table = fr"sentmail"
|
||||
|
||||
object Columns {
|
||||
val id = Column("id")
|
||||
val uid = Column("uid")
|
||||
val messageId = Column("message_id")
|
||||
val sender = Column("sender")
|
||||
val subject = Column("subject")
|
||||
val recipients = Column("recipients")
|
||||
val id = Column("id")
|
||||
val uid = Column("uid")
|
||||
val messageId = Column("message_id")
|
||||
val sender = Column("sender")
|
||||
val subject = Column("subject")
|
||||
val recipients = Column("recipients")
|
||||
val body = Column("body")
|
||||
val created = Column("created")
|
||||
val created = Column("created")
|
||||
|
||||
val all = List(
|
||||
id,
|
||||
|
@ -17,13 +17,16 @@ case class RSentMailItem(
|
||||
|
||||
object RSentMailItem {
|
||||
|
||||
def create[F[_]: Sync](itemId: Ident, sentmailId: Ident, created: Option[Timestamp] = None): F[RSentMailItem] =
|
||||
def apply[F[_]: Sync](
|
||||
itemId: Ident,
|
||||
sentmailId: Ident,
|
||||
created: Option[Timestamp] = None
|
||||
): F[RSentMailItem] =
|
||||
for {
|
||||
id <- Ident.randomId[F]
|
||||
id <- Ident.randomId[F]
|
||||
now <- created.map(_.pure[F]).getOrElse(Timestamp.current[F])
|
||||
} yield RSentMailItem(id, itemId, sentmailId, now)
|
||||
|
||||
|
||||
val table = fr"sentmailitem"
|
||||
|
||||
object Columns {
|
||||
|
@ -8,7 +8,7 @@ import cats.data.OptionT
|
||||
import docspell.common._
|
||||
import docspell.store.impl.Column
|
||||
import docspell.store.impl.Implicits._
|
||||
import emil.{MailAddress, SSLType}
|
||||
import emil.{MailAddress, MailConfig, SSLType}
|
||||
|
||||
case class RUserEmail(
|
||||
id: Ident,
|
||||
@ -23,7 +23,19 @@ case class RUserEmail(
|
||||
mailFrom: MailAddress,
|
||||
mailReplyTo: Option[MailAddress],
|
||||
created: Timestamp
|
||||
) {}
|
||||
) {
|
||||
|
||||
def toMailConfig: MailConfig = {
|
||||
val port = smtpPort.map(p => s":$p").getOrElse("")
|
||||
MailConfig(
|
||||
s"smtp://$smtpHost$port",
|
||||
smtpUser.getOrElse(""),
|
||||
smtpPassword.map(_.pass).getOrElse(""),
|
||||
smtpSsl,
|
||||
!smtpCertCheck
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
object RUserEmail {
|
||||
|
||||
|
Reference in New Issue
Block a user