|
@@ -1,28 +1,24 @@
|
|
|
module Data.SMTP.Types.Resource where
|
|
|
|
|
|
-import Data.SMTP.Types.Seal
|
|
|
-import Data.SMTP.Types.URI
|
|
|
---import Data.SMTP.Account (Account)
|
|
|
+import qualified Data.SMTP.URI as URI
|
|
|
import qualified Data.SMTP.Types.Mime as Mime
|
|
|
+import qualified Data.SMTP.Parser.Mime as PMime
|
|
|
+import qualified Data.Attoparsec.ByteString as BA
|
|
|
|
|
|
---import qualified System.IO.Uniform as UIO
|
|
|
import qualified Data.ByteString.Lazy as LBS
|
|
|
+import qualified Text.StringConvert as SC
|
|
|
|
|
|
import Data.Char
|
|
|
|
|
|
data Header = Header (String, String) deriving (Read, Show, Eq, Ord)
|
|
|
|
|
|
-data RevisionInfo = RevisionInfo {
|
|
|
- current :: Revision,
|
|
|
- bases :: [Revision]
|
|
|
- } deriving (Eq, Ord, Read, Show)
|
|
|
-
|
|
|
-data Resource = Resource {
|
|
|
+data ResourceInfo = ResourceInfo {
|
|
|
mimeType :: Mime.ContentType,
|
|
|
- publicHeaders :: [Header],
|
|
|
- seal :: Maybe Seal,
|
|
|
- revision :: Maybe RevisionInfo,
|
|
|
- bodyData :: ResourceData}
|
|
|
+ mimeParameters :: Mime.ContentTypeParameters,
|
|
|
+ revision :: URI.Revision,
|
|
|
+ bases :: [URI.Revision],
|
|
|
+ address :: [URI.URI]
|
|
|
+ } deriving (Eq, Ord, Show)
|
|
|
|
|
|
type ResourceData = LBS.ByteString
|
|
|
|
|
@@ -44,13 +40,23 @@ getMultipleValue :: [Header] -> String -> [String]
|
|
|
getMultipleValue hh = map (\(Header (_, v)) -> v) . getMultiple hh
|
|
|
|
|
|
revisionHeader :: String
|
|
|
-revisionHeader = "FCMTP-Revision"
|
|
|
+revisionHeader = "fCMTP-Revision"
|
|
|
|
|
|
baseHeader :: String
|
|
|
-baseHeader = "FCMTP-Revision-Base"
|
|
|
-
|
|
|
-headersRevision :: [Header] -> Maybe RevisionInfo
|
|
|
-headersRevision hh = do
|
|
|
- curr <- Revision <$> getHeaderValue hh revisionHeader
|
|
|
- let bb = map Revision $ getMultipleValue hh baseHeader
|
|
|
- return $ RevisionInfo curr bb
|
|
|
+baseHeader = "fCMTP-Revision-Base"
|
|
|
+
|
|
|
+addressHeader :: String
|
|
|
+addressHeader = "fCMTP-Address"
|
|
|
+
|
|
|
+resourceInfo :: [Header] -> Maybe ResourceInfo
|
|
|
+resourceInfo hh = do
|
|
|
+ (mimet, mimep) <- getHeaderValue hh Mime.contentTypeHeaderName >>= bparse PMime.parseContentType
|
|
|
+ curr <- URI.Revision <$> getHeaderValue hh revisionHeader
|
|
|
+ let bb = map URI.Revision $ getMultipleValue hh baseHeader
|
|
|
+ uu <- mapM (bparse URI.parseURI) $ getMultipleValue hh addressHeader
|
|
|
+ return $ ResourceInfo mimet mimep curr bb uu
|
|
|
+ where
|
|
|
+ bparse :: BA.Parser a -> String -> Maybe a
|
|
|
+ bparse p v = eitherToMaybe . BA.parseOnly p $ SC.s v
|
|
|
+ eitherToMaybe (Left _) = Nothing
|
|
|
+ eitherToMaybe (Right v) = Just v
|