ismtp 2.0.0 → 2.0.1
raw patch · 4 files changed
+32/−79 lines, 4 filesdep +netlinesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: netlines
API changes (from Hackage documentation)
- Network.Smtp.Types: Extension :: Extension
+ Network.Smtp.Types: AuthExt :: (Set AuthMethod) -> Extension
+ Network.Smtp.Types: AuthMethod :: AuthMethod
+ Network.Smtp.Types: data AuthMethod
+ Network.Smtp.Types: instance Eq AuthMethod
+ Network.Smtp.Types: instance Ord AuthMethod
+ Network.Smtp.Types: instance Read AuthMethod
+ Network.Smtp.Types: instance Read Extension
+ Network.Smtp.Types: instance Show AuthMethod
+ Network.Smtp.Types: instance Show Extension
Files
- Network/Smtp/Session.hs +3/−2
- Network/Smtp/Tools.hs +14/−73
- Network/Smtp/Types.hs +13/−3
- ismtp.cabal +2/−1
Network/Smtp/Session.hs view
@@ -40,11 +40,12 @@ hello domain = do mailPutLn ["EHLO ", domain] SmtpResponse code msgs <- nextResponse- let exts = S.fromList . catMaybes .- L.map stringToExtension . V.toList $ msgs+ let exts = S.fromList . catMaybes . L.map stringToExtension .+ L.drop 1 . V.toList $ msgs case code of 250 -> lift $ modify (\cfg -> cfg { mailExtensions = exts })+ >> liftIO (print exts) 500 -> tryHelo 502 -> tryHelo 554 -> tryHelo
Network/Smtp/Tools.hs view
@@ -7,7 +7,7 @@ -- -- Helper functions and types. -{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-} module Network.Smtp.Tools ( enumHandleTimeout,@@ -23,45 +23,19 @@ import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC+import qualified Data.Set as S import qualified Data.Vector as V import Control.ContStuff as Cont import Data.Enumerator as E-import Data.Enumerator.Binary as EB import Data.Enumerator.List as EL import Data.ByteString (ByteString) import Data.List as L+import Data.Maybe import Data.Vector (Vector)-import Data.Word+import Network.NetLines import Network.Smtp.Types-import System.IO-import System.IO.Error as IOErr --- | Enumerate from a handle with the given buffer size (first argument)--- and timeout in milliseconds (second argument). If the timeout is--- exceeded an exception is thrown via 'throwError'.--enumHandleTimeout :: forall b m. MonadIO m =>- Int -> Int -> Handle -> Enumerator ByteString m b-enumHandleTimeout bufSize timeout h = loop- where- loop :: Enumerator ByteString m b- loop (Continue k) = do- mHaveInput <- liftIO $ IOErr.try (hWaitForInput h timeout)- case mHaveInput of- Left err- | isEOFError err -> continue k- | otherwise -> throwError err- Right False -> throwError $ userError "Handle timed out"- Right True -> do- mStr <- liftIO $ IOErr.try (B.hGetNonBlocking h bufSize)- str <- either throwError return mStr- if B.null str- then continue k- else k (Chunks [str]) >>== loop- loop step = returnI step-- -- | Format a 'Vector' of 'ByteString' messages from an 'SmtpResponse' -- for output. @@ -69,48 +43,6 @@ formatMsgs = BC.unpack . BC.unwords . V.toList --- | Savely read a line with the given maximum length. If a longer line--- is enumerated, the excess data is dropped in constant space. Returns--- 'Nothing' on EOF.--netLine :: forall m r. Monad m => Int -> MaybeT r (Iteratee ByteString m) ByteString-netLine n =- lift (EB.dropWhile isEol) >> netLine' n-- where- isEol :: Word8 -> Bool- isEol 10 = True- isEol 13 = True- isEol _ = False-- isNotEol :: Word8 -> Bool- isNotEol = not . isEol-- netLine' :: Int -> MaybeT r (Iteratee ByteString m) ByteString- netLine' 0 = B.empty <$ lift (EB.dropWhile isNotEol)- netLine' n = do- c <- liftF EB.head- if isNotEol c- then B.cons c <$> netLine' (n-1)- else return B.empty----- | Convert a stream of bytes to a stream of lines with the given--- maximum length. Longer lines are silently truncated in constant--- space.--netLines :: forall b m. Monad m => Int -> Enumeratee ByteString ByteString m b-netLines maxLen = loop- where- loop :: Enumeratee ByteString ByteString m b- loop (Continue k) = do- mLine <- evalMaybeT $ netLine maxLen- case mLine of- Just line -> k (Chunks [line]) >>== loop- Nothing -> k EOF >>== loop- loop step = return step-- -- | Read a three digit SMTP response code. readRespCode :: ByteString -> Maybe Integer@@ -217,4 +149,13 @@ -- extension is known. stringToExtension :: ByteString -> Maybe Extension-stringToExtension _ = Nothing+stringToExtension str =+ case BC.words str of+ "AUTH" : methods ->+ Just . AuthExt . S.fromList . catMaybes . L.map authMethod $ methods++ _ -> Nothing++ where+ authMethod :: ByteString -> Maybe AuthMethod+ authMethod _ = Nothing
Network/Smtp/Types.hs view
@@ -15,8 +15,11 @@ MailT, StringMailT, - -- * Other types+ -- * SMTP service extensions Extension(..),+ AuthMethod(..),++ -- * Other types MailConfig(..), SmtpCommand(..), SmtpException(..),@@ -35,11 +38,18 @@ import Text.Printf +-- | Authentication methods for the SMTP authentication extension.++data AuthMethod+ = AuthMethod -- ^ We don't know any authentication methods yet.+ deriving (Eq, Ord, Read, Show)++ -- | SMTP service extension. data Extension- = Extension -- ^ We don't support any extensions yet.- deriving (Eq, Ord)+ = AuthExt (Set AuthMethod) -- ^ Authentication extension.+ deriving (Eq, Ord, Read, Show) -- | The 'MailT' monad transformer encapsulates an SMTP session.
ismtp.cabal view
@@ -1,5 +1,5 @@ Name: ismtp-Version: 2.0.0+Version: 2.0.1 Category: Network Synopsis: Advanced ESMTP library Maintainer: Ertugrul Söylemez <es@ertes.de>@@ -24,6 +24,7 @@ dnscache >= 1.0.1, enumerator >= 0.4.7, monad-peel >= 0.1,+ netlines >= 0.1.0, network >= 2.2.1.7, unix >= 2.4.0.2, vector >= 0.7.0.1