check-email (empty) → 0.1
raw patch · 6 files changed
+95/−0 lines, 6 filesdep +basedep +email-validatesetup-changed
Dependencies added: base, email-validate
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- cbits/check-mx.c +11/−0
- cbits/check-mx.h +1/−0
- check-email.cabal +26/−0
- src/Network/Email/Check.hsc +25/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2011, Chris Done++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Chris Done nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cbits/check-mx.c view
@@ -0,0 +1,11 @@+#include <stdio.h>+#include <stdlib.h>+#include <unistd.h>+#include <netinet/in.h>+#include <resolv.h>++int check_mx(char *domain)+{+ u_char nsbuf[4096];+ return res_query(domain, ns_c_any, ns_t_mx, nsbuf, sizeof (nsbuf)) > 0;+}
+ cbits/check-mx.h view
@@ -0,0 +1,1 @@+int check_mx(char *domain);
+ check-email.cabal view
@@ -0,0 +1,26 @@+Name: check-email+Category: Network+License-File: LICENSE+Version: 0.1+Cabal-version: >= 1.2+Build-type: Simple+Copyright: 2010 Chris Done+Maintainer: Chris Done <chrisdone@gmail.com>+Author: Chris Done+License: BSD3+Synopsis: Confirm whether an email is valid and probably existant.+Description: Confirm whether an email is valid and probably existant.+Extra-source-files: cbits/check-mx.h++Library+ Build-depends: base >= 4 && < 5, email-validate >= 0.2 && <0.3+ Extensions: ForeignFunctionInterface+ Exposed-Modules: Network.Email.Check+ Ghc-options: -Wall+ Extra-libraries: gd, png, z, jpeg, m, fontconfig, freetype, expat+ Includes: gd.h+ Include-dirs: cbits+ Install-includes: check-mx.h+ C-sources: cbits/check-mx.c+ Extra-libraries: resolv+ Hs-source-dirs: src
+ src/Network/Email/Check.hsc view
@@ -0,0 +1,25 @@+{-# LANGUAGE ForeignFunctionInterface #-}++module Network.Email.Check where++import Foreign.C.Types+import Text.Email.Validate+import Foreign.C++#include "check-mx.h"++foreign import ccall "check-mx.h check_mx" checkMx+ :: CString -> IO CInt++-- | Check to see whether an email is (1) RFC-valid and (2) has an+-- existant MX record.+check :: String -> IO (Either String EmailAddress)+check email = do+ case validate email of+ Left e -> return $ Left $ show e+ Right e -> do exists <- withCString (domainPart e) checkMx + if exists /= 0+ then return $ Right e+ else return $ Left $ "no MX record exists for domain "+ ++ (domainPart e)+