summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKierán Meinhardt <kieran.meinhardt@gmail.com>2020-10-02 09:10:02 +0200
committerKierán Meinhardt <kieran.meinhardt@gmail.com>2020-10-02 09:10:02 +0200
commit3700799ce49ee5bfd191e7d8e35843aaff5bd3e7 (patch)
tree56ef712a151633d2333455cdd68da4889a4eadc0
parent92a67aaa55f5fee4a2b9a7357f1b9956a84cd188 (diff)
State: add extensions to unnamed attachment downloads
-rw-r--r--src/Much/State.hs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/Much/State.hs b/src/Much/State.hs
index 551cdd0..f6f1d89 100644
--- a/src/Much/State.hs
+++ b/src/Much/State.hs
@@ -11,6 +11,7 @@ import GHC.Generics
import Much.TreeView (TreeView(TVSearch))
import Scanner
import System.Posix.Signals
+import qualified Data.CaseInsensitive as CI
import qualified Data.Map as M
import qualified Data.Text as T
import qualified Data.Tree as Tree
@@ -107,5 +108,15 @@ instance Default State where
, attachmentFileName = \message part ->
case Notmuch.partContentFilename part of
Just partFileName -> T.unpack partFileName
- Nothing -> concat [ "much_" , formatTime defaultTimeLocale "%s" (Notmuch.messageTime message) , "_" , show (Notmuch.partID part) ]
+ Nothing ->
+ "much_"
+ <> formatTime defaultTimeLocale "%s" (Notmuch.messageTime message)
+ <> "_"
+ <> show (Notmuch.partID part)
+ <> extension (Notmuch.partContentType part)
}
+
+extension :: CI.CI T.Text -> String
+extension "text/html" = ".html"
+extension "text/plain" = ".txt"
+extension _ = ""