mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-07 07:35:59 +00:00
Add stub for scan-mailbox task
This commit is contained in:
parent
ebe65c7624
commit
a4be63fd77
@ -6,6 +6,7 @@ import emil.javamail._
|
|||||||
import docspell.common._
|
import docspell.common._
|
||||||
import docspell.joex.hk._
|
import docspell.joex.hk._
|
||||||
import docspell.joex.notify._
|
import docspell.joex.notify._
|
||||||
|
import docspell.joex.scanmailbox._
|
||||||
import docspell.joex.process.ItemHandler
|
import docspell.joex.process.ItemHandler
|
||||||
import docspell.joex.scheduler._
|
import docspell.joex.scheduler._
|
||||||
import docspell.joexapi.client.JoexClient
|
import docspell.joexapi.client.JoexClient
|
||||||
@ -67,6 +68,7 @@ object JoexAppImpl {
|
|||||||
queue <- JobQueue(store)
|
queue <- JobQueue(store)
|
||||||
pstore <- PeriodicTaskStore.create(store)
|
pstore <- PeriodicTaskStore.create(store)
|
||||||
nodeOps <- ONode(store)
|
nodeOps <- ONode(store)
|
||||||
|
javaEmil = JavaMailEmil(blocker)
|
||||||
sch <- SchedulerBuilder(cfg.scheduler, blocker, store)
|
sch <- SchedulerBuilder(cfg.scheduler, blocker, store)
|
||||||
.withQueue(queue)
|
.withQueue(queue)
|
||||||
.withTask(
|
.withTask(
|
||||||
@ -79,10 +81,17 @@ object JoexAppImpl {
|
|||||||
.withTask(
|
.withTask(
|
||||||
JobTask.json(
|
JobTask.json(
|
||||||
NotifyDueItemsArgs.taskName,
|
NotifyDueItemsArgs.taskName,
|
||||||
NotifyDueItemsTask[F](cfg.sendMail, JavaMailEmil(blocker)),
|
NotifyDueItemsTask[F](cfg.sendMail, javaEmil),
|
||||||
NotifyDueItemsTask.onCancel[F]
|
NotifyDueItemsTask.onCancel[F]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.withTask(
|
||||||
|
JobTask.json(
|
||||||
|
ScanMailboxArgs.taskName,
|
||||||
|
ScanMailboxTask[F](javaEmil),
|
||||||
|
ScanMailboxTask.onCancel[F]
|
||||||
|
)
|
||||||
|
)
|
||||||
.withTask(
|
.withTask(
|
||||||
JobTask.json(
|
JobTask.json(
|
||||||
HouseKeepingTask.taskName,
|
HouseKeepingTask.taskName,
|
||||||
|
@ -7,6 +7,7 @@ import docspell.common._
|
|||||||
import docspell.store.queries.QItem
|
import docspell.store.queries.QItem
|
||||||
import docspell.joex.notify.YamuscaConverter._
|
import docspell.joex.notify.YamuscaConverter._
|
||||||
|
|
||||||
|
/** The context for rendering the e-mail template. */
|
||||||
case class MailContext(
|
case class MailContext(
|
||||||
items: List[MailContext.ItemData],
|
items: List[MailContext.ItemData],
|
||||||
more: Boolean,
|
more: Boolean,
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
package docspell.joex.scanmailbox
|
||||||
|
|
||||||
|
import cats.implicits._
|
||||||
|
import cats.effect._
|
||||||
|
import emil._
|
||||||
|
//import emil.javamail.syntax._
|
||||||
|
|
||||||
|
import docspell.common._
|
||||||
|
import docspell.store.records._
|
||||||
|
import docspell.joex.scheduler.{Context, Task}
|
||||||
|
|
||||||
|
object ScanMailboxTask {
|
||||||
|
val maxItems: Long = 7
|
||||||
|
type Args = ScanMailboxArgs
|
||||||
|
|
||||||
|
def apply[F[_]: Sync](emil: Emil[F]): Task[F, Args, Unit] =
|
||||||
|
Task { ctx =>
|
||||||
|
for {
|
||||||
|
_ <- ctx.logger.info(
|
||||||
|
s"Start importing mails for user ${ctx.args.account.user.id}"
|
||||||
|
)
|
||||||
|
mailCfg <- getMailSettings(ctx)
|
||||||
|
folders = ctx.args.folders.mkString(", ")
|
||||||
|
userId = ctx.args.account.user
|
||||||
|
imapConn = ctx.args.imapConnection
|
||||||
|
_ <- ctx.logger.info(
|
||||||
|
s"Reading mails for user ${userId.id} from ${imapConn.id}/${folders}"
|
||||||
|
)
|
||||||
|
_ <- importMails(mailCfg, emil, ctx)
|
||||||
|
} yield ()
|
||||||
|
}
|
||||||
|
|
||||||
|
def onCancel[F[_]: Sync]: Task[F, ScanMailboxArgs, Unit] =
|
||||||
|
Task.log(_.warn("Cancelling scan-mailbox task"))
|
||||||
|
|
||||||
|
def getMailSettings[F[_]: Sync](ctx: Context[F, Args]): F[RUserImap] =
|
||||||
|
ctx.store
|
||||||
|
.transact(RUserImap.getByName(ctx.args.account, ctx.args.imapConnection))
|
||||||
|
.flatMap {
|
||||||
|
case Some(c) => c.pure[F]
|
||||||
|
case None =>
|
||||||
|
Sync[F].raiseError(
|
||||||
|
new Exception(
|
||||||
|
s"No imap configuration found for: ${ctx.args.imapConnection.id}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
def importMails[F[_]: Sync](
|
||||||
|
cfg: RUserImap,
|
||||||
|
emil: Emil[F],
|
||||||
|
ctx: Context[F, Args]
|
||||||
|
): F[Unit] =
|
||||||
|
Sync[F].delay(println(s"$emil $ctx $cfg"))
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user