JavaMail issue

E

EdUarDo

Hello, I'm using JavaMail, and when I get address' messages they are
in an incorret format:

=?ISO-8859-1?Q?Eduardo_Ya=F1ez_Parareda?= <[email protected]>

when it might be:

Eduardo Yañez Parareda <[email protected]>

I know it is at ISO-8859-1 charset, so when I print the address I'm doing:

Address[] addresses = msg.getFrom();
for (int j = 0; j < addresses.length; j++) {
Address address = addresses[j];
System.out.println(new String(address.toString().getBytes("ISO-8859-1")));
}

but doesn't work.

Some suggestions?
 
I

Igor N. Kolomiyets

Try this:

Address[] addresses = msg.getFrom();
for (int j = 0; j < addresses.length; j++)
{
if(addresses[j] instanceof InternetAddress)
{
InternetAddress address = addresses[j];
String szPersonal = address.getPersonal();
System.out.println(szPersonal != null ? szPersonal + " " +
address.getAddress() : address.getAddress());
}
}

Best regards,
Igor
 
E

EdUarDo

Igor said:
Try this:

Address[] addresses = msg.getFrom();
for (int j = 0; j < addresses.length; j++)
{
if(addresses[j] instanceof InternetAddress)
{
InternetAddress address = addresses[j];
String szPersonal = address.getPersonal();
System.out.println(szPersonal != null ? szPersonal + " " +
address.getAddress() : address.getAddress());
}
}

It works fine, thank you!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top