A fast, RFC-compliant email address validator and parser.
Email address validation is deceptively hard.
What is a valid email address? You'll find many different answers for this online, and multiple RFCs that sometimes conflict. RFC 5321 is the authoritative document.
This library complies with RFC 5321 and includes a comprehensive test suite. It provides validation and parsing that's much more robust than most regex-based solutions.
And it's fast.
Email Parse is available on Ultralisp and is easy to install using Quicklisp.
The system makes heavy use of inline functions to achieve performance. Consequently, compiling it can be memory-hungry. Starting your Lisp implementation with a fair amount of dynamic space is recommended, e.g:
$ sbcl --dynamic-space-size 16384
Add the Ultralisp repository:
CL-USER> (ql-dist:install-dist "http://dist.ultralisp.org/")
Install Email Parse:
CL-USER> (ql:quickload :email-parse)
You can parse email address strings:
CL-USER> (require :email-parse)
NIL
CL-USER> (email-parse:parse "simple@example.com")
"simple"
"example.com"
CL-USER> (email-parse:parse "simple@example.com" :plist t)
(:LOCAL-PART "simple" :DOMAIN "example.com")
Or octet sequences:
CL-USER> (require :email-parse)
NIL
CL-USER> (email-parse:parse-octets
(trivial-us-ascii:ascii-string-code
'(simple-array (unsigned-byte 8) (*))
"simple@example.com")
0
(length "simple@example.com"))
"simple"
"example.com"
CL-USER> (email-parse:parse-octets
(trivial-us-ascii:ascii-string-code
'(simple-array (unsigned-byte 8) (*))
"simple@example.com")
0
(length "simple@example.com")
:plist t)
(:LOCAL-PART "simple" :DOMAIN "example.com")
Parsing is fairly quick, and runs in linear time, though the parser does cons:
CL-USER> (time (dotimes (c 100000)
(email-parse:parse "simple@example.com")))
Evaluation took:
0.152 seconds of real time
0.151840 seconds of total run time (0.147935 user, 0.003905 system)
100.00% CPU
516,269,668 processor cycles
113,608,576 bytes consed
NIL
CL-USER> (time (dotimes (c 100000)
(email-parse:parse-octets
(trivial-us-ascii:ascii-string-code
'(simple-array (unsigned-byte 8) (*))
"simple@example.com")
0
(length "simple@example.com"))))
Evaluation took:
0.152 seconds of real time
0.148390 seconds of total run time (0.144645 user, 0.003745 system)
97.37% CPU
504,555,988 processor cycles
113,608,592 bytes consed
NIL
Patches are welcome.
Email Parse is licensed under the two-clause BSD license.
See LICENSE.