From 3700799ce49ee5bfd191e7d8e35843aaff5bd3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Fri, 2 Oct 2020 09:10:02 +0200 Subject: State: add extensions to unnamed attachment downloads --- src/Much/State.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 _ = "" -- cgit v1.2.3