Przemek Nowak
Przemek Nowak

Reputation: 7703

How to get simply email address after MimeUtility.decodeText()?

How can I simply get the email address after use MimeUtility.decodeText() from javax.mail.internet ?

After that operation I have following String: Foo Bar <[email protected]>

I can do that by methods from String class but I'm interested in existed predefinied method for this ?

Upvotes: 0

Views: 308

Answers (2)

dkarp
dkarp

Reputation: 14763

Just call new InternetAddress(addr).getAddress(). In fact, you don't even need to call MimeUtility.decodeText() first.

Upvotes: 0

dragostis
dragostis

Reputation: 2662

It's very easy to define your method. To get the String you only need one line of code:

String email = stringToDecode.split("<")[1].substring(0, stringToDecode.split("<")[1].length() - 1);

Upvotes: 1

Related Questions