-- | This function retrieve the MX Server which are reponsible for the given
-- email address
lookupMXs :: Domain -> SMTP [MXServer]
lookupMXs domain = do
    seed <- smtpLiftIO "get the DNS Resolver information" $ DNS.makeResolvSeed resolvconf
    eres <- smtpLiftIO "send the DNS MXs Query" $ DNS.withResolver seed $ \r -> DNS.lookupMX r (toBytes domain)
    case eres of
        Left err -> fail $ "unable to collect the MX Domains for " ++ BC.unpack (toBytes domain) ++ " error is: " ++ show err
        Right v  -> do
            let mxs = sort $ map (\(d, p) -> MXServer p (Domain d)) v
            smtpReportInfo $ ("collecting MX for " ++ BC.unpack (toBytes domain)) ++ ": " ++ (intercalate " " $ map showMXServer mxs)
            return mxs
  where
    resolvconf :: DNS.ResolvConf
    resolvconf = DNS.defaultResolvConf
lookupMXs :: Domain -> SMTP [MXServer]
lookupMXs domain = do
    seed <- smtpLiftIO "get the DNS Resolver information" $ DNS.makeResolvSeed resolvconf
    eres <- smtpLiftIO "send the DNS MXs Query" $ DNS.withResolver seed $ \r -> DNS.lookupMX r (toBytes domain)
    case eres of
        Left err -> fail $ "unable to collect the MX Domains for " ++ BC.unpack (toBytes domain) ++ " error is: " ++ show err
        Right v  -> do
            let mxs = sort $ map (\(d, p) -> MXServer p (Domain d)) v
            smtpReportInfo $ ("collecting MX for " ++ BC.unpack (toBytes domain)) ++ ": " ++ (intercalate " " $ map showMXServer mxs)
            return mxs
  where
    resolvconf :: DNS.ResolvConf
    resolvconf = DNS.defaultResolvConf
lookupMXs domain = do
    seed <- smtpLiftIO "get the DNS Resolver information" $ DNS.makeResolvSeed resolvconf
    eres <- smtpLiftIO "send the DNS MXs Query" $ DNS.withResolver seed $ \r -> DNS.lookupMX r (toBytes domain)
    case eres of
        Left err -> fail $ "unable to collect the MX Domains for " ++ BC.unpack (toBytes domain) ++ " error is: " ++ show err
        Right v  -> do
            let mxs = sort $ map (\(d, p) -> MXServer p (Domain d)) v
            smtpReportInfo $ ("collecting MX for " ++ BC.unpack (toBytes domain)) ++ ": " ++ (intercalate " " $ map showMXServer mxs)
            return mxs
  where
    resolvconf :: DNS.ResolvConf
    resolvconf = DNS.defaultResolvConf