[darcs-users] Re: push mail error?

Peter Simons simons at cryp.to
Mon May 19 22:30:26 UTC 2003


David Roundy writes:

 > Just a convention.  Although if I use it for the from address, it had
 > better be an email...

Using RFC2822.hs, you can (a) verify it's an address and (b) make sure
you get the canonical form! For instance:

    import Text.ParserCombinators.Parsec
    import RFC2822

    check           :: String -> String
    check input     = case (parse addr_spec "" input) of
                          Left _  -> error "nice try"
                          Right r -> r

Which works like this:

 | Main> check "simons at cryp.to"
 | "simons at cryp.to"
 | Main> check "simons  @ (foo\r\n bar) \r\n\tcryp.to"
 | "simons at cryp.to"
 | Main> check "foo.bar"
 | Program error: nice try

The parser will even return (mostly) meaningful error messages, which
you can actually show the user. :-)

Peter





More information about the darcs-users mailing list