diff options
author | evuez <julien@mulga.net> | 2024-04-01 15:17:30 +0200 |
---|---|---|
committer | evuez <julien@mulga.net> | 2024-04-03 22:45:36 +0200 |
commit | 985974c264804ff788b3b5242fef707d4b7fa9a6 (patch) | |
tree | d80f83db178c3fd1b83b3b749793d47236dde35d /src/Common | |
download | webmaild-985974c264804ff788b3b5242fef707d4b7fa9a6.tar.gz |
Initial commit
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/Mime.hs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Common/Mime.hs b/src/Common/Mime.hs new file mode 100644 index 0000000..5356312 --- /dev/null +++ b/src/Common/Mime.hs @@ -0,0 +1,23 @@ +module Common.Mime (getType, getSubtype, MimeType (..)) where + +import Common (split2, trim) +import Intro + +data MimeType = Text String | Image String | Application String + +getType :: String -> Maybe MimeType +getType mime = case type_ of + "text" -> Just (Text subtype) + "image" -> Just (Image subtype) + "application" -> Just (Application subtype) + _ -> Nothing + where + (type_, subtype) = split2 (== '/') $ trim mime + +getSubtype :: String -> String +getSubtype = trim . snd . split2 (== '/') + +instance Show MimeType where + show (Text sub) = "text/" ++ sub + show (Image sub) = "image/" ++ sub + show (Application sub) = "application/" ++ sub |