aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Sacchi2013-05-03 15:43:41 (EDT)
committerGerrit Code Review @ Eclipse.org2013-05-06 12:02:42 (EDT)
commita83e910c73f70d81b02c68e143f49defc873e459 (patch)
tree343e31b722daab4b52ffc0545f204a74ee496a51
parent3fb0357f07ff265d08d38d8e9d05bc709b3b0238 (diff)
downloadorg.eclipse.scout.rt-a83e910c73f70d81b02c68e143f49defc873e459.zip
org.eclipse.scout.rt-a83e910c73f70d81b02c68e143f49defc873e459.tar.gz
org.eclipse.scout.rt-a83e910c73f70d81b02c68e143f49defc873e459.tar.bz2
bug 406813: ImapAdapter: 6 Issuesrefs/changes/06/12506/5
https://bugs.eclipse.org/bugs/show_bug.cgi?id=406813 these Issues fixed: - hardcoded ssl-port - isConnected() implementation based on cached flag is bad - cachedFolders should be cleared on (re-)connect - deleteMessagesPermanently(Message[] messages) should call Folder.expunge() - username should be added to logging when authentication fails Change-Id: I62d81b55a3add42392af61c797e1a32994a8b798
-rw-r--r--org.eclipse.scout.rt.server/src/org/eclipse/scout/rt/server/services/common/imap/ImapAdapter.java49
1 files changed, 33 insertions, 16 deletions
diff --git a/org.eclipse.scout.rt.server/src/org/eclipse/scout/rt/server/services/common/imap/ImapAdapter.java b/org.eclipse.scout.rt.server/src/org/eclipse/scout/rt/server/services/common/imap/ImapAdapter.java
index 34d4625..03f7458 100644
--- a/org.eclipse.scout.rt.server/src/org/eclipse/scout/rt/server/services/common/imap/ImapAdapter.java
+++ b/org.eclipse.scout.rt.server/src/org/eclipse/scout/rt/server/services/common/imap/ImapAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 BSI Business Systems Integration AG.
+ * Copyright (c) 2010,2013 BSI Business Systems Integration AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,14 +7,19 @@
*
* Contributors:
* BSI Business Systems Integration AG - initial API and implementation
+ * Adrian Sacchi <adrian.sacchi@bsiag.com> - Bug 406813 - ImapAdapter: 6 Issues
******************************************************************************/
package org.eclipse.scout.rt.server.services.common.imap;
import java.lang.reflect.Array;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import javax.mail.AuthenticationFailedException;
import javax.mail.Flags;
@@ -32,16 +37,17 @@ import org.eclipse.scout.commons.exception.ProcessingException;
public class ImapAdapter {
public static final String TRASH_FOLDER_NAME = "Trash";
+ public static final int DEFAULT_IMAP_PORT = 143;
+
private boolean m_useSSL;
private String[] m_sslProtocols;
private String m_host;
- private int m_port = 143;
+ private int m_port = DEFAULT_IMAP_PORT;
private String m_username;
private String m_password;
private String m_defaultFolderName;
private Store m_store;
- private HashMap<String, Folder> m_cachedFolders;
- private boolean m_connected = false;
+ private Map<String, Folder> m_cachedFolders;
public ImapAdapter() {
m_cachedFolders = new HashMap<String, Folder>();
@@ -138,16 +144,29 @@ public class ImapAdapter {
}
}
+ /**
+ * messages are flagged as DELETED and their folder is closed in order to delete them on the server
+ *
+ * @param messages
+ * @throws ProcessingException
+ */
public void deleteMessagesPermanently(Message[] messages) throws ProcessingException {
connect();
- for (Message msg : messages) {
- try {
+ Set<Folder> folders = new HashSet<Folder>();
+ try {
+ for (Message msg : messages) {
+ folders.add(msg.getFolder());
msg.setFlag(Flags.Flag.DELETED, true);
}
- catch (MessagingException e) {
- throw new ProcessingException(e.getMessage(), e);
+ for (Folder f : folders) {
+ if (f.isOpen()) {
+ f.expunge();
+ }
}
}
+ catch (MessagingException e) {
+ throw new ProcessingException(e.getMessage(), e);
+ }
}
public void createFolder(String folderName) throws ProcessingException {
@@ -172,7 +191,7 @@ public class ImapAdapter {
public void connect() throws ProcessingException {
if (!isConnected()) {
- // try{
+ m_cachedFolders.clear();
Properties props = new Properties();
props.put("mail.transport.protocol", "imap");
if (getHost() != null) {
@@ -187,7 +206,7 @@ public class ImapAdapter {
if (isUseSSL()) {
props.setProperty("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.imap.socketFactory.fallback", "false");
- props.setProperty("mail.imap.socketFactory.port", "993");
+ props.setProperty("mail.imap.socketFactory.port", "" + getPort());
if (ListUtility.length(getSSLProtocols()) > 0) {
props.setProperty("mail.imap.ssl.protocols", StringUtility.join(" ", getSSLProtocols()));
@@ -207,12 +226,11 @@ public class ImapAdapter {
}
}
catch (AuthenticationFailedException e) {
- throw new ProcessingException("IMAP-Authentication failed on " + (m_host == null ? "?" : m_host) + ":" + m_port);
+ throw new ProcessingException("IMAP-Authentication failed on " + (m_host == null ? "?" : m_host) + ":" + m_port + ":" + m_username);
}
catch (Exception e) {
throw new ProcessingException(e.getMessage(), e);
}
- m_connected = true;
}
}
@@ -293,7 +311,6 @@ public class ImapAdapter {
exceptions.add(e);
}
m_cachedFolders.clear();
- m_connected = false;
if (!exceptions.isEmpty()) {
throw new ProcessingException(exceptions.get(0).getMessage());
}
@@ -301,7 +318,7 @@ public class ImapAdapter {
}
public boolean isConnected() {
- return m_connected;
+ return m_store != null && m_store.isConnected();
}
public Store getStore() throws ProcessingException {
@@ -358,10 +375,10 @@ public class ImapAdapter {
}
public String[] getSSLProtocols() {
- return m_sslProtocols;
+ return Arrays.copyOf(m_sslProtocols, m_sslProtocols.length);
}
public void setSSLProtocols(String[] sslProtocols) {
- m_sslProtocols = sslProtocols;
+ m_sslProtocols = Arrays.copyOf(sslProtocols, sslProtocols.length);
}
}