diff options
author | tv <tv@shackspace.de> | 2015-03-04 20:17:18 +0100 |
---|---|---|
committer | tv <tv@shackspace.de> | 2015-03-04 20:21:26 +0100 |
commit | a0fc644165cdcedfc430cb84c38f87fc960515a0 (patch) | |
tree | 12590428d6fb8a76d2d0f080a0c420fdfe304940 /Codec/MIME/Utils.hs | |
parent | 432e339ea58761a3a27f71d934fe63b096f2ef01 (diff) |
import mime-0.4.0.1
commit 013ab26ccb84ddec5eed3ba42d8648b32dc79b38
Diffstat (limited to 'Codec/MIME/Utils.hs')
-rw-r--r-- | Codec/MIME/Utils.hs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Codec/MIME/Utils.hs b/Codec/MIME/Utils.hs new file mode 100644 index 0000000..dd54860 --- /dev/null +++ b/Codec/MIME/Utils.hs @@ -0,0 +1,33 @@ +-------------------------------------------------------------------- +-- | +-- Module : Codec.MIME.Utils +-- Copyright : (c) 2006-2009, Galois, Inc. +-- License : BSD3 +-- +-- Maintainer: Sigbjorn Finne <sigbjorn.finne@gmail.com> +-- Stability : provisional +-- Portability: portable +-- +-- Extracting content from MIME values and types. +-- +-------------------------------------------------------------------- +module Codec.MIME.Utils + ( findMultipartNamed -- :: String -> MIMEValue -> Maybe MIMEValue + ) where + +import Codec.MIME.Type +import Data.List ( find ) +import Control.Monad ( msum ) +import Data.Text(Text) + +-- | Given a parameter name, locate it within a MIME value, +-- returning the corresponding (sub) MIME value. +findMultipartNamed :: Text -> MIMEValue -> Maybe MIMEValue +findMultipartNamed nm mv = + case mime_val_content mv of + Multi ms -> msum (map (findMultipartNamed nm) ms) + Single {} -> do cd <- mime_val_disp mv + _ <- find (withDispName nm) (dispParams cd) + return mv + where withDispName a (Name b) = a == b + withDispName _ _ = False |