From c3498b63e241d9880f32862c9b92498f7ec9c936 Mon Sep 17 00:00:00 2001 From: ray Date: Fri, 28 Apr 2006 22:00:23 +0000 Subject: [PATCH] Added a static method to normalize an email address. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1835 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/net/MailUtil.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/java/com/samskivert/net/MailUtil.java b/src/java/com/samskivert/net/MailUtil.java index ed8014f9..18e572ea 100644 --- a/src/java/com/samskivert/net/MailUtil.java +++ b/src/java/com/samskivert/net/MailUtil.java @@ -52,6 +52,19 @@ public class MailUtil return _emailre.matcher(address).matches(); } + /** + * @return a normalized form of the specified email address + * (everything after the @ sign is lowercased). + */ + public static String normalizeAddress (String address) + { + // this algorithm is tolerant of bogus input: if address has no + // @ symbol it will cope. + int afterAt = address.indexOf('@') + 1; + return address.substring(0, afterAt) + + address.substring(afterAt).toLowerCase(); + } + /** * Delivers the supplied mail message using the machine's local mail * SMTP server which must be listening on port 25.