diff --git a/src/commands.py b/src/commands.py index 5615d02b3..2da9ba308 100644 --- a/src/commands.py +++ b/src/commands.py @@ -475,6 +475,12 @@ def getUrl(irc, msg, args, state): else: irc.errorInvalid('url', args[0]) +def getEmail(irc, msg, args, state): + if utils.net.emailRe.match(args[0]): + state.args.append(args.pop(0)) + else: + irc.errorInvalid('email', args[0]) + def getHttpUrl(irc, msg, args, state): if utils.web.httpUrlRe.match(args[0]): state.args.append(args.pop(0)) @@ -557,6 +563,7 @@ wrappers = ircutils.IrcDict({ 'color': getIrcColor, 'now': getNow, 'url': getUrl, + 'email': getEmail, 'httpUrl': getHttpUrl, 'long': getLong, 'float': getFloat, diff --git a/test/test_commands.py b/test/test_commands.py index cd216b691..aef09f3ee 100644 --- a/test/test_commands.py +++ b/test/test_commands.py @@ -142,5 +142,12 @@ class ConverterTestCase(CommandsTestCase): self.assertState(['url'], [url], [url]) self.assertState(['httpUrl'], [url], [url]) + def testEmail(self): + email = 'jemfinch@supybot.com' + self.assertState(['email'], [email], [email]) + self.assertError(['email'], ['foo']) + self.assertError(['email'], ['foo@']) + self.assertError(['email'], ['@foo']) + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: