Improve notify mail template

This commit is contained in:
Eike Kettner 2020-04-23 23:15:58 +02:00
parent af4e5f161d
commit 315ea63f44
3 changed files with 26 additions and 11 deletions

View File

@ -39,7 +39,8 @@ object MailContext {
dueDate: Option[Timestamp],
source: String,
overDue: Boolean,
dueIn: Option[String]
dueIn: Option[String],
corrOrg: Option[String]
)
object ItemData {
@ -47,11 +48,22 @@ object MailContext {
def apply(now: Timestamp)(i: QItem.ListItem): ItemData = {
val dueIn = i.dueDate.map(dt => Timestamp.daysBetween(now, dt))
val dueInLabel = dueIn.map {
case 0 => "**today**"
case 1 => "**tomorrow**"
case n => s"in $n days"
case 0 => "**today**"
case 1 => "**tomorrow**"
case -1 => s"**yesterday**"
case n if n > 0 => s"in $n days"
case n if n < 0 => s"${n * -1} days ago"
}
ItemData(i.id, i.name, i.date, i.dueDate, i.source, dueIn.exists(_ < 0), dueInLabel)
ItemData(
i.id,
i.name,
i.date,
i.dueDate,
i.source,
dueIn.exists(_ < 0),
dueInLabel,
i.corrOrg.map(_.name)
)
}
implicit def yamusca: ValueConverter[ItemData] =

View File

@ -5,22 +5,22 @@ import yamusca.implicits._
object MailTemplate {
val text = mustache"""
## Hello {{{ username }}},
Hello {{{ username }}},
this is Docspell informing you about your next due items coming up.
{{#itemUri}}
{{#items}}
- {{#overDue}}**(OVERDUE)** {{/overDue}}[{{name}}]({{itemUri}}/{{id}}),
due {{dueIn}} on *{{dueDate}}*
(received on {{date}} via {{source}})
{{#overDue}}was {{/overDue}}due {{dueIn}} on *{{dueDate}}*; {{#corrOrg}}from {{corrOrg}}{{/corrOrg}}
received on {{date}} via {{source}}
{{/items}}
{{/itemUri}}
{{^itemUri}}
{{#items}}
- {{#overDue}}**(OVERDUE)** {{/overDue}}*{{name}}*,
due {{dueIn}} on *{{dueDate}}*
(received on {{date}} via {{source}})
{{#overDue}}was {{/overDue}}due {{dueIn}} on *{{dueDate}}*; {{#corrOrg}}from {{corrOrg}}{{/corrOrg}}
received on {{date}} via {{source}}
{{/items}}
{{/itemUri}}
{{#more}}
@ -29,6 +29,7 @@ this is Docspell informing you about your next due items coming up.
Sincerely yours,
Docspell
"""

View File

@ -100,7 +100,9 @@ object NotifyDueItemsTask {
From(cfg.mailFrom),
Tos(recp),
Subject("Next due items"),
MarkdownBody[F](md)
MarkdownBody[F](md).withConfig(
MarkdownConfig("body { font-size: 10pt; font-family: sans-serif; }")
)
)
}
}