2012-05-03 23:41:00 +00:00
|
|
|
ReParse = require('../src/reparse').ReParse
|
|
|
|
util = require("util")
|
|
|
|
|
|
|
|
class EmailAddress extends ReParse
|
|
|
|
|
|
|
|
addressList: => @sepEndBy @address, /^\s*,\s*/
|
|
|
|
address: => @choice @namedAddress, @bareAddress
|
2013-05-11 04:04:24 +00:00
|
|
|
namedAddress: => @seq(@phrase, /^\s*</m, @bareAddress, '>')[2]
|
|
|
|
bareAddress: => @seq(@word, '@', @word).join ""
|
2012-05-03 23:41:00 +00:00
|
|
|
phrase: => @many @word
|
|
|
|
word: => @skip(/^\s+/).choice @quoted, @dottedAtom
|
2013-05-11 04:04:24 +00:00
|
|
|
quoted: => @m /^"(?:\\.|[^"\r\n])+"/m
|
|
|
|
dottedAtom: => @m /^[!#\$%&'\*\+\-\/\w=\?\^`\{\|\}~]+(?:\.[!#\$%&'\*\+\-\/\w=\?\^`\{\|\}~]+)*/m
|
2012-05-03 23:41:00 +00:00
|
|
|
|
|
|
|
parse: =>
|
|
|
|
super
|
|
|
|
@start(@addressList)
|
|
|
|
|
|
|
|
unless process.argv.length is 3
|
|
|
|
util.puts "Usage: node " + process.argv[1] + " list-of-addresses"
|
|
|
|
process.exit 1
|
|
|
|
|
|
|
|
console.log util.inspect (new EmailAddress).parse(process.argv[2])
|