|
@@ -6,10 +6,10 @@ module Walrus.Backend.Metadata where
|
|
import Data.ByteString (ByteString)
|
|
import Data.ByteString (ByteString)
|
|
import Data.Time.Clock (UTCTime)
|
|
import Data.Time.Clock (UTCTime)
|
|
|
|
|
|
-import Data.SMTP.Address (Address)
|
|
|
|
-import qualified Data.SMTP.Address as Add
|
|
|
|
-import Data.SMTP.Account
|
|
|
|
---import qualified Data.SMTP.URI as URI
|
|
|
|
|
|
+import Data.SMTP.Account (Account)
|
|
|
|
+import qualified Data.SMTP.Account as Ac
|
|
|
|
+import Data.SMTP.URI (URI)
|
|
|
|
+import qualified Data.SMTP.URI as URI
|
|
import qualified Data.SMTP.Mime as Mime
|
|
import qualified Data.SMTP.Mime as Mime
|
|
import Data.SMTP.Response
|
|
import Data.SMTP.Response
|
|
import qualified Text.StringConvert as SC
|
|
import qualified Text.StringConvert as SC
|
|
@@ -51,7 +51,7 @@ data MaybeMetadata = MaybeMetadata {_mclientId :: Maybe ClientIdentity, _mclient
|
|
_mmailFrom :: Maybe Account, _mrcptTo :: [Account], _mrcptFailed :: [(Account, Response)],
|
|
_mmailFrom :: Maybe Account, _mrcptTo :: [Account], _mrcptFailed :: [(Account, Response)],
|
|
_mauth :: Maybe ByteString, _mrecvDate :: Maybe UTCTime, _mbodyEnc :: Mime.BodyEncoding,
|
|
_mauth :: Maybe ByteString, _mrecvDate :: Maybe UTCTime, _mbodyEnc :: Mime.BodyEncoding,
|
|
_msmtpUtf8 :: Bool, _maction :: Maybe BackendAction, _munrecognized :: [ByteString],
|
|
_msmtpUtf8 :: Bool, _maction :: Maybe BackendAction, _munrecognized :: [ByteString],
|
|
- _mdataSize :: Maybe Int, _mtargetResc :: Maybe Address, _mtargetFailure :: Maybe Response,
|
|
|
|
|
|
+ _mdataSize :: Maybe Int, _mtargetResc :: Maybe URI.URI, _mtargetFailure :: Maybe Response,
|
|
_mftchRecursive :: Bool, _mftchHeaders :: Bool, _mftchQuery :: FtchQuery,
|
|
_mftchRecursive :: Bool, _mftchHeaders :: Bool, _mftchQuery :: FtchQuery,
|
|
_mftchOffset :: Int, _mftchSize :: Maybe Int
|
|
_mftchOffset :: Int, _mftchSize :: Maybe Int
|
|
} deriving (Show, Ord, Eq)
|
|
} deriving (Show, Ord, Eq)
|
|
@@ -113,7 +113,7 @@ data FetchRescData =
|
|
-- Size
|
|
-- Size
|
|
Int
|
|
Int
|
|
-- Target
|
|
-- Target
|
|
- Address
|
|
|
|
|
|
+ URI
|
|
-- Fetch result
|
|
-- Fetch result
|
|
(Maybe Response)
|
|
(Maybe Response)
|
|
deriving (Show, Ord, Eq)
|
|
deriving (Show, Ord, Eq)
|
|
@@ -135,7 +135,7 @@ data FetchHdrData =
|
|
-- Query
|
|
-- Query
|
|
FtchQuery
|
|
FtchQuery
|
|
-- Target
|
|
-- Target
|
|
- Address
|
|
|
|
|
|
+ URI
|
|
-- Fetch result
|
|
-- Fetch result
|
|
(Maybe Response)
|
|
(Maybe Response)
|
|
deriving (Show, Ord, Eq)
|
|
deriving (Show, Ord, Eq)
|
|
@@ -247,21 +247,21 @@ renderMetadata m = BS.concat $ serializeDt ++ serializeMain ++ ["\r\n"]
|
|
rfail = rcptFailed d
|
|
rfail = rcptFailed d
|
|
enc = bodyEnc d
|
|
enc = bodyEnc d
|
|
utf = smtpUtf8 d
|
|
utf = smtpUtf8 d
|
|
- toStr = List.concatMap (\x -> ["To: ", fullAccount x, "\r\n"]) rto
|
|
|
|
- failStr = List.concatMap (\(a, r) -> ["Failed: ", fullAccount a, "; ", renderLineResponse r, "\r\n"]) rfail
|
|
|
|
|
|
+ toStr = List.concatMap (\x -> ["To: ", SC.s . Ac.fullAccount $ x, "\r\n"]) rto
|
|
|
|
+ failStr = List.concatMap (\(a, r) -> ["Failed: ", SC.s . Ac.fullAccount $ a, "; ", renderLineResponse r, "\r\n"]) rfail
|
|
h = [
|
|
h = [
|
|
"Client-Name: ", SC.s cnm, "\r\n",
|
|
"Client-Name: ", SC.s cnm, "\r\n",
|
|
- "Return-Path: ", SC.s . normalize $ rfm, "\r\n",
|
|
|
|
|
|
+ "Return-Path: ", SC.s . Ac.normalize $ rfm, "\r\n",
|
|
"Body-Encoding: ", show enc, "\r\n",
|
|
"Body-Encoding: ", show enc, "\r\n",
|
|
"SMTP-UTF8: ", serialBool utf, "\r\n"
|
|
"SMTP-UTF8: ", serialBool utf, "\r\n"
|
|
] :: [String]
|
|
] :: [String]
|
|
in map SC.s h ++ toStr ++ failStr
|
|
in map SC.s h ++ toStr ++ failStr
|
|
- serializeHandle (AccountRequest a) = ["To: ", SC.s . fullAccount $ a, "\r\n"]
|
|
|
|
- serializeHandle (AccountResponse (a, r)) = ["Failed: ", fullAccount a, "; ", renderLineResponse r, "\r\n"]
|
|
|
|
|
|
+ serializeHandle (AccountRequest a) = ["To: ", SC.s . Ac.fullAccount $ a, "\r\n"]
|
|
|
|
+ serializeHandle (AccountResponse (a, r)) = ["Failed: ", Ac.fullAccount a, "; ", renderLineResponse r, "\r\n"]
|
|
serializeHandle AccountOk = []
|
|
serializeHandle AccountOk = []
|
|
serializeFetchResc (FetchRescData cnm rfm ofst sz trg resp) =
|
|
serializeFetchResc (FetchRescData cnm rfm ofst sz trg resp) =
|
|
["Client-Name: ", SC.s cnm, "\r\n",
|
|
["Client-Name: ", SC.s cnm, "\r\n",
|
|
- "Return-Path: ", SC.s . normalize $ rfm, "\r\n",
|
|
|
|
|
|
+ "Return-Path: ", SC.s . Ac.normalize $ rfm, "\r\n",
|
|
"Headers: No\r\n",
|
|
"Headers: No\r\n",
|
|
"Offset: ", SC.s . show $ ofst, "\r\n",
|
|
"Offset: ", SC.s . show $ ofst, "\r\n",
|
|
"Block-Size: ", SC.s . show $ sz, "\r\n",
|
|
"Block-Size: ", SC.s . show $ sz, "\r\n",
|
|
@@ -271,7 +271,7 @@ renderMetadata m = BS.concat $ serializeDt ++ serializeMain ++ ["\r\n"]
|
|
Just r -> ["Failure: ", renderLineResponse r, "\r\n"]
|
|
Just r -> ["Failure: ", renderLineResponse r, "\r\n"]
|
|
serializeFetchHdr (FetchHdrData cnm rfm r q trg resp) =
|
|
serializeFetchHdr (FetchHdrData cnm rfm r q trg resp) =
|
|
["Client-Name: ", SC.s cnm, "\r\n",
|
|
["Client-Name: ", SC.s cnm, "\r\n",
|
|
- "Return-Path: ", SC.s . normalize $ rfm, "\r\n",
|
|
|
|
|
|
+ "Return-Path: ", SC.s . Ac.normalize $ rfm, "\r\n",
|
|
"Headers: Yes\r\n",
|
|
"Headers: Yes\r\n",
|
|
"Recursive: ", serialBool r, "\r\n",
|
|
"Recursive: ", serialBool r, "\r\n",
|
|
"Query: ", serializeFtchQuery q, "\r\n",
|
|
"Query: ", serializeFtchQuery q, "\r\n",
|
|
@@ -316,15 +316,15 @@ parseMetadata = do
|
|
nm <- hdr "Client-Name" (A.takeTill A.isSpace)
|
|
nm <- hdr "Client-Name" (A.takeTill A.isSpace)
|
|
return $ \(m, ip, p) -> (set mclientName (Just nm) m, ip, p),
|
|
return $ \(m, ip, p) -> (set mclientName (Just nm) m, ip, p),
|
|
do
|
|
do
|
|
- frm <- hdr "Return-Path" parseAccount
|
|
|
|
|
|
+ frm <- hdr "Return-Path" Ac.parseAccount
|
|
return $ \(m, ip, p) -> (set mmailFrom (Just frm) m, ip, p),
|
|
return $ \(m, ip, p) -> (set mmailFrom (Just frm) m, ip, p),
|
|
do
|
|
do
|
|
- rtp <- hdr "To" parseAccount
|
|
|
|
|
|
+ rtp <- hdr "To" Ac.parseAccount
|
|
return $ \(m, ip, p) -> let
|
|
return $ \(m, ip, p) -> let
|
|
crtp = m^.mrcptTo
|
|
crtp = m^.mrcptTo
|
|
in (set mrcptTo (rtp:crtp) m, ip, p),
|
|
in (set mrcptTo (rtp:crtp) m, ip, p),
|
|
do
|
|
do
|
|
- resc <- hdr "Target" Add.parseAddress
|
|
|
|
|
|
+ resc <- hdr "Target" URI.parseURI
|
|
return $ \(m, ip, p) -> (set mtargetResc (Just resc) m, ip, p),
|
|
return $ \(m, ip, p) -> (set mtargetResc (Just resc) m, ip, p),
|
|
do
|
|
do
|
|
rfl <- hdr "Failed" parseAccountReason
|
|
rfl <- hdr "Failed" parseAccountReason
|
|
@@ -425,7 +425,7 @@ parseMetadata = do
|
|
]
|
|
]
|
|
parseAccountReason :: Parser (Account, Response)
|
|
parseAccountReason :: Parser (Account, Response)
|
|
parseAccountReason = do
|
|
parseAccountReason = do
|
|
- a <- parseAccount
|
|
|
|
|
|
+ a <- Ac.parseAccount
|
|
skipHorizontalSpace
|
|
skipHorizontalSpace
|
|
A.char ';'
|
|
A.char ';'
|
|
skipHorizontalSpace
|
|
skipHorizontalSpace
|
|
@@ -442,8 +442,8 @@ getTo Metadata{_actionData=act} = case act of
|
|
Deliver dt -> rcptTo dt
|
|
Deliver dt -> rcptTo dt
|
|
WillHandle dt -> hdl dt
|
|
WillHandle dt -> hdl dt
|
|
Verify dt -> hdl dt
|
|
Verify dt -> hdl dt
|
|
- FetchResc (FetchRescData _ _ _ _ dt _) -> [Add.account dt]
|
|
|
|
- FetchHdr (FetchHdrData _ _ _ _ dt _) -> [Add.account dt]
|
|
|
|
|
|
+ FetchResc (FetchRescData _ _ _ _ dt _) -> [URI.account dt]
|
|
|
|
+ FetchHdr (FetchHdrData _ _ _ _ dt _) -> [URI.account dt]
|
|
where
|
|
where
|
|
hdl (AccountRequest a) = [a]
|
|
hdl (AccountRequest a) = [a]
|
|
hdl _ = []
|
|
hdl _ = []
|