From fe7398249152bff2f4052417e001393e4099999b Mon Sep 17 00:00:00 2001 From: mguessan Date: Fri, 24 Sep 2010 08:43:20 +0000 Subject: [PATCH] SMTP: rewrite getAllRecipients to disable strict header check git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1473 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/ExchangeSession.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index e3293449..bc885808 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -35,7 +35,6 @@ import org.htmlcleaner.CommentToken; import org.htmlcleaner.HtmlCleaner; import org.htmlcleaner.TagNode; -import javax.mail.Address; import javax.mail.MessagingException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; @@ -633,6 +632,11 @@ public abstract class ExchangeSession { */ public abstract MessageList searchMessages(String folderName, Set attributes, Condition condition) throws IOException; + /** + * Get server version (Exchange2003, Exchange2007 or Exchange2010) + * + * @return server version + */ public String getServerVersion() { return serverVersion; } @@ -1074,11 +1078,9 @@ public abstract class ExchangeSession { // remove visible recipients from list Set visibleRecipients = new HashSet(); - Address[] recipients = mimeMessage.getAllRecipients(); - if (recipients != null) { - for (Address address : recipients) { - visibleRecipients.add(((InternetAddress) address).getAddress().toLowerCase()); - } + List recipients = getAllRecipients(mimeMessage); + for (InternetAddress address : recipients) { + visibleRecipients.add((address.getAddress().toLowerCase())); } for (String recipient : rcptToRecipients) { if (!visibleRecipients.contains(recipient.toLowerCase())) { @@ -1089,6 +1091,21 @@ public abstract class ExchangeSession { } + protected static final String[] RECIPIENT_HEADERS = {"to", "cc", "bcc"}; + + protected List getAllRecipients(MimeMessage mimeMessage) throws MessagingException { + List recipientList = new ArrayList(); + for (String recipientHeader : RECIPIENT_HEADERS) { + final String recipientHeaderValue = mimeMessage.getHeader(recipientHeader, ","); + if (recipientHeaderValue != null) { + // parse headers in non strict mode + recipientList.addAll(Arrays.asList(InternetAddress.parseHeader(recipientHeaderValue, false))); + } + + } + return recipientList; + } + /** * Send Mime message. * @@ -1208,6 +1225,7 @@ public abstract class ExchangeSession { /** * Move item from source path to target path. + * * @param sourcePath item source path * @param targetPath item target path * @throws IOException on error