From b99baac33e68d5603d0aa9ef699460a7e6a15c1d Mon Sep 17 00:00:00 2001 From: "Iavor S. Diatchki" Date: Fri, 21 Dec 2007 11:39:47 -0800 Subject: Initial import. --- MIME/Utils.hs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 MIME/Utils.hs (limited to 'MIME/Utils.hs') diff --git a/MIME/Utils.hs b/MIME/Utils.hs new file mode 100644 index 0000000..a5db2d9 --- /dev/null +++ b/MIME/Utils.hs @@ -0,0 +1,30 @@ +{- | + Module : MIME.Utils + Copyright : (c) 2007 + + Maintainer : tse-dev-team@galois.com + Stability : unstable + Portability : GHC + + Extracting content from MIME values and types. +-} +module MIME.Utils + ( findMultipartNamed -- :: String -> MIMEValue -> Maybe MIMEValue + ) where + +import MIME.Type +import Data.List ( find ) +import Control.Monad ( msum ) + +-- | Given a parameter name, locate it within a MIME value, +-- returning the corresponding (sub) MIME value. +findMultipartNamed :: String -> 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 + -- cgit v1.2.3