From 315ea63f44aa1d8e46389d48ecdf8f3b8f39d5fc Mon Sep 17 00:00:00 2001
From: Eike Kettner <eike.kettner@posteo.de>
Date: Thu, 23 Apr 2020 23:15:58 +0200
Subject: [PATCH] Improve notify mail template

---
 .../docspell/joex/notify/MailContext.scala    | 22 ++++++++++++++-----
 .../docspell/joex/notify/MailTemplate.scala   | 11 +++++-----
 .../joex/notify/NotifyDueItemsTask.scala      |  4 +++-
 3 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/modules/joex/src/main/scala/docspell/joex/notify/MailContext.scala b/modules/joex/src/main/scala/docspell/joex/notify/MailContext.scala
index de50600e..e34134a1 100644
--- a/modules/joex/src/main/scala/docspell/joex/notify/MailContext.scala
+++ b/modules/joex/src/main/scala/docspell/joex/notify/MailContext.scala
@@ -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] =
diff --git a/modules/joex/src/main/scala/docspell/joex/notify/MailTemplate.scala b/modules/joex/src/main/scala/docspell/joex/notify/MailTemplate.scala
index ed167bec..73f80f99 100644
--- a/modules/joex/src/main/scala/docspell/joex/notify/MailTemplate.scala
+++ b/modules/joex/src/main/scala/docspell/joex/notify/MailTemplate.scala
@@ -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
 """
 
diff --git a/modules/joex/src/main/scala/docspell/joex/notify/NotifyDueItemsTask.scala b/modules/joex/src/main/scala/docspell/joex/notify/NotifyDueItemsTask.scala
index 42e82884..67ee2745 100644
--- a/modules/joex/src/main/scala/docspell/joex/notify/NotifyDueItemsTask.scala
+++ b/modules/joex/src/main/scala/docspell/joex/notify/NotifyDueItemsTask.scala
@@ -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; }")
+        )
       )
     }
 }