[JIRA-Opensymphony] Commented: (CORE-51) MailUtils in Oscore method verifyEmail

[email protected]
Newsgroups gmane.comp.java.open-symphony.cvs
Message-ID <[email protected]>
The following comment has been added to this issue:

     Author: Scott Farquhar
    Created: Wed, 13 Aug 2003 8:36 AM
       Body:
I don't see the problem?

RFC822 (6.1) states that subdomains do not need a '.' in them to be valid.
---------------------------------------------------------------------
View the issue:

  http://jira.opensymphony.com/secure/ViewIssue.jspa?key=CORE-51


Here is an overview of the issue:
---------------------------------------------------------------------
        Key: CORE-51
    Summary: MailUtils in Oscore method verifyEmail
       Type: Improvement

     Status: Assigned
   Priority: Minor

    Project: OSCore
   Versions:
             2.2.1

   Assignee: Patrick Lightbody
   Reporter: Adeyemi E  Adegbile

    Created: Thu, 31 Jul 2003 2:18 AM
    Updated: Thu, 31 Jul 2003 2:18 AM
Environment: Not Applicable

Description:
     I downloaded oscore for a inhouse project. I discover there might be a problem in the implementation of the method
 public final static boolean verifyEmail(String email) when it verifes
emails
 I believe the problem will here,which is
     if (email.indexOf('@') < 1)

 in my test I have change the code.

 I have included the old and the new code

public class Tester {

   public static void main(String[] ars){
        System.out.println(Tester.verifyEmail("[email protected]"));
   }
 
> *
>     * Verify that the given string is a valid email address.
>    * "Validity" in this context only means that the address conforms
>    * to the correct syntax (not if the address actually exists).
>     *
>     * @param email The email address to verify.
>    * @return a boolean indicating whether the email address is correctly
formatted.
>
>    public final static boolean verifyEmail(String email) {
>        if (email == null) {
>            return false;
>        }
>
>        if (email.indexOf('@') < 1) {
>            return false;
>        }
>
>        try {
>            new InternetAddress(email);
>
>            return true;
>        } catch (AddressException e) {
>            return false;
>        }
>    }
> */
>      public final static boolean verifyEmail(String email) {
>          if (email == null) {
>              return false;
>          }
>
>          if (email.indexOf('@') < 1) {
>              return false;
>          }
>          //lastIndexOf(String str)
>        if (email.indexOf('.') < email.indexOf('@'))
>            return false;
>
>          return true;
>    }
> }
>

 This is the new updated Class file if it is acceptable

 /*
 * Copyright (c) 2002-2003 by OpenSymphony
  * All rights reserved.
  */
 package com.opensymphony.util;

 import java.io.*;

 import javax.mail.MessagingException;
 import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeUtility;


 /**
  * Utility methods once in TextUtils that require the mail.jar library.
  *
  * @author $Author: plightbo $
  * @version $Revision: 1.1 $
  */
 public class MailUtils {
     //~ Methods
////////////////////////////////////////////////////////////////

     /**
     * Decode binary data from String using base64.
     *
     * @see #encodeBytes(byte[])
     */
     public final static byte[] decodeBytes(String str) throws IOException
{
         try {
             ByteArrayInputStream encodedStringStream = new
ByteArrayInputStream(str.getBytes());
             InputStream decoder = MimeUtility.decode(encodedStringStream,
"base64");
             ByteArrayOutputStream decodedByteStream = new
ByteArrayOutputStream();
             byte[] buffer = new byte[256];

             while (true) {
                 int read = decoder.read(buffer);

                 if (read == -1) {
                     break;
                 }

                 decodedByteStream.write(buffer, 0, read);
             }

             decodedByteStream.flush();

             return decodedByteStream.toByteArray();
         } catch (MessagingException me) {
             throw new IOException("Cannot decode data.");
         }
     }

     /**
      * Encode binary data into String using base64.
      *
      * @see #decodeBytes(java.lang.String)
      */
     public final static String encodeBytes(byte[] data) throws IOException
{
         try {
             ByteArrayOutputStream encodedByteStream = new
ByteArrayOutputStream();
             OutputStream encoder = MimeUtility.encode(encodedByteStream,
"base64");
             encoder.write(data);
             encoder.flush();

             return new String(encodedByteStream.toByteArray());
         } catch (MessagingException me) {
             throw new IOException("Cannot encode data.");
         }
     }

     /**
      * Verify that the given string is a valid email address.
     * "Validity" in this context only means that the address conforms
     * to the correct syntax (not if the address actually exists).
      *
      * @param email The email address to verify.
     * @return a boolean indicating whether the email address is correctly
formatted.
      */
     public final static boolean verifyEmail(String email) {
         if (email == null) {
             return false;
         }

         // (email.indexOf('@') < 1) {
         //    return false;

      // Changes applied to validation
      if (email.lastIndexOf('.') < email.indexOf('@')) {
            return false;
         }

         try {
             new InternetAddress(email);

             return true;
         } catch (AddressException e) {
             return false;
         }
     }
 }



> Regards
> Adeyemi E Adegbile



---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.

If you think it was sent incorrectly contact one of the administrators:
   http://jira.opensymphony.com/secure/Administrators.jspa

If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira



-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.