dev@javamail.java.net

Re: Username and host can't be parsed when username contains _at_

From: Bill Shannon <bill.shannon_at_sun.com>
Date: Mon, 25 Oct 2010 12:25:31 -0700

If the username or password contain special characters, they need to be
encoded. If you use the URLName constructor that takes separate parameters
for the fields, the encoding is done for you. If you use the constructor
that takes a single string, it assumes it's a valid URL and that the encoding
has already been done.

emeratius_at_gmail.com wrote on 10/25/10 02:54 AM:
> Hi,
>
> I got the wrong host when the username contains @.
>
> In URLName.parseString the fulluserpass and fullhost is collected by
> indexOf('@').
>
> I should be lastIndexOf('@')
>
> // examine the fullhost, for username password etc.
> int i = fullhost.lastIndexOf('@');
> if (i != -1) {
> String fulluserpass = fullhost.substring(0, i);
> fullhost = fullhost.substring(i + 1);