summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Data/MIME/Extended.hs22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/Data/MIME/Extended.hs b/src/Data/MIME/Extended.hs
index 773d0b7..a58b9f5 100644
--- a/src/Data/MIME/Extended.hs
+++ b/src/Data/MIME/Extended.hs
@@ -7,12 +7,14 @@ module Data.MIME.Extended
( module Data.MIME
) where
+import Control.Arrow (left)
import Control.Lens hiding ((.=))
import Data.Aeson
import Data.ByteString (ByteString)
import Data.ByteString.Extended ()
import Data.CaseInsensitive (CI)
import Data.Either (fromRight)
+import Data.Either.Combinators (maybeToRight)
import Data.List.NonEmpty (NonEmpty)
import Data.MIME
import Data.MIME.EncodedWord
@@ -117,12 +119,18 @@ makeMultipart h =
"related" -> Related
<$> ( getRequiredParam "type" ct
>>= \s ->
- maybe
- (Left $ InvalidParameterValue "type" s)
- Right
+ maybeToRight
+ (InvalidParameterValue "type" s)
(preview (parsed parseContentType) s)
+ >>= return . Just . setContentTypeParameters ()
+ )
+ <*> ( getOptionalParam "start" ct
+ >>= traverse
+ (\s ->
+ left
+ (InvalidParameterValue "start" . ((s <> ": ") <>))
+ (makeContentID s))
)
- <*> getOptionalParam "start" ct
<*> getOptionalParam "start-info" ct
unrecognised -> pure $ Unrecognised unrecognised
@@ -134,13 +142,17 @@ makeMultipart h =
getRequiredParam :: HasParameters s =>
CI ByteString -> s -> Either MIMEParseError ByteString
getRequiredParam k =
- maybe (Left $ RequiredParameterMissing k) Right . preview (rawParameter k)
+ maybeToRight (RequiredParameterMissing k) . preview (rawParameter k)
getOptionalParam :: HasParameters s =>
CI ByteString -> s -> Either a (Maybe ByteString)
getOptionalParam k =
Right . preview (rawParameter k)
+ setContentTypeParameters :: b -> ContentTypeWith a -> ContentTypeWith b
+ setContentTypeParameters p (ContentType t st _) =
+ ContentType t st p
+
data MIMEParseError
= RequiredParameterMissing (CI ByteString)
| InvalidParameterValue (CI ByteString) ByteString