-- |Run the given computation with an initialized global
-- environment for 'Smtpd'. The environment is destroyed
-- when this function returns.

withGlobalEnv :: HostName           -- ^ 'myHeloName'
              -> Resolver
              -> EventT
              -> (GlobalEnv -> IO a)
              -> IO a
withGlobalEnv myHelo dns eventT f = do
  let eventH  = eventT (mkEvent myHelo "/tmp/test-spool")
      initEnv = do setDNSResolver dns
                   setEventHandler eventH
  newMVar (execState initEnv emptyEnv) >>= f


-- * ESMTP Network Daemon
withGlobalEnv :: HostName           -- ^ 'myHeloName'
              -> Resolver
              -> EventT
              -> (GlobalEnv -> IO a)
              -> IO a
withGlobalEnv myHelo dns eventT f = do
  let eventH  = eventT (mkEvent myHelo "/tmp/test-spool")
      initEnv = do setDNSResolver dns
                   setEventHandler eventH
  newMVar (execState initEnv emptyEnv) >>= f


-- * ESMTP Network Daemon
withGlobalEnv myHelo dns eventT f = do
  let eventH  = eventT (mkEvent myHelo "/tmp/test-spool")
      initEnv = do setDNSResolver dns
                   setEventHandler eventH
  newMVar (execState initEnv emptyEnv) >>= f


-- * ESMTP Network Daemon