module Network.Parser.Rfc2046 where
import Control.Applicative as A hiding (many)
import Control.Monad (join)
import Data.Attoparsec
import qualified Data.Attoparsec.Char8 as AC
import Data.ByteString as W
import Data.ByteString.Char8 as C
import Data.ByteString.Internal (c2w, w2c)
import qualified Data.Map as M
import Data.Word (Word8)
import Prelude hiding (take, takeWhile)
import Prelude hiding (id)
import Network.Parser.Rfc2045
import Network.Parser.Rfc2234
import Network.Parser.Rfc2822
import Network.Parser.RfcCommon hiding (text)
bcharsnospacePred :: Word8 -> Bool
bcharsnospacePred w = digitPred w
|| alphaPred w
|| inClass "'()+_,-./:=?" w
bcharsnospace :: Parser Word8
bcharsnospace = satisfy bcharsnospacePred
bchars = bcharsnospace <|> satisfy (== 32)
boundary = many1 bchars
dashBoundary = word8 45 *> word8 45 *> boundary
encapsulation = ret <$> delimiter <* transportPadding
<*> crlf *> bodyPart
where ret d b = (d,b)
delimiter = crlf *> dashBoundary
bodyPart = ret <$> mimePartHeaders
<*> option [] (crlf *> many' octet)
where ret hs d = (hs,d)