I'm successfully reading outlook email from JAVAX mail. But when i try to get the "Link" available in email body it's not giving the exact URL, instead it gives the URL with some extra characters like "=3D?*/". I tried to use below code but it didn't help me.
public List<String> getUrlsFromMessage(Message message, String linkText) throws Exception {
String html = getMessageContent(message);
List<String> allMatches = new ArrayList<String>();
// (<a [^>]+>)
Matcher matcher = Pattern.compile(" (<a [^>]+>)" + linkText + "</a>").matcher(html);
while (matcher.find()) {
String aTag = matcher.group(1);
allMatches.add(aTag.substring(aTag.indexOf("http"), aTag.indexOf("\">")));
}
return allMatches;
}
Also I changed the pattern to
Pattern linkPattern = Pattern.compile(" <a\\b[^>]*href=\"([^\"]*)[^>]*>(.*?)</a>",
Pattern.CASE_INSENSITIVE | Pattern.DOTALL);`
But still it gives me the wrong URL.