Added: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/providers/LogProvider.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/providers/LogProvider.java?rev=1333089&view=auto ============================================================================== --- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/providers/LogProvider.java (added) +++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/providers/LogProvider.java Wed May 2 16:05:26 2012 @@ -0,0 +1,36 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + + +package org.apache.hupa.server.guice.providers; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.impl.Log4JLogger; + +import com.google.inject.Provider; +import com.google.inject.Singleton; + +@Singleton +public class LogProvider implements Provider<Log>{ + + public Log get() { + return new Log4JLogger("HupaLogger"); + } + +}
Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java (original) +++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java Wed May 2 16:05:26 2012 @@ -25,7 +25,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import javax.activation.DataSource; import javax.mail.Address; @@ -53,7 +52,6 @@ import org.apache.commons.fileupload.Fil import org.apache.commons.logging.Log; import org.apache.hupa.server.FileItemRegistry; import org.apache.hupa.server.IMAPStoreCache; -import org.apache.hupa.server.mock.MockSMTPTransport; import org.apache.hupa.server.preferences.UserPreferencesStorage; import org.apache.hupa.server.utils.MessageUtils; import org.apache.hupa.server.utils.RegexPatterns; @@ -76,13 +74,12 @@ import com.sun.mail.imap.IMAPStore; */ public abstract class AbstractSendMessageHandler<A extends SendMessage> extends AbstractSessionHandler<A,GenericResult> { - private final Properties props = new Properties(); private final boolean auth; private final String address; private final int port; private boolean useSSL = false; - private Provider<HttpSession> httpSessionProvider; UserPreferencesStorage userPreferences; + Session session; @Inject public AbstractSendMessageHandler(Log logger, IMAPStoreCache store, Provider<HttpSession> provider, UserPreferencesStorage preferences, @Named("SMTPServerAddress") String address, @Named("SMTPServerPort") int port, @Named("SMTPAuth") boolean auth, @Named("SMTPS") boolean useSSL) { @@ -91,9 +88,9 @@ public abstract class AbstractSendMessag this.address = address; this.port = port; this.useSSL = useSSL; - this.httpSessionProvider = provider; - props.put("mail.smtp.auth", auth); this.userPreferences = preferences; + this.session = store.getMailSession(); + session.getProperties().put("mail.smtp.auth", auth); } @Override @@ -101,13 +98,12 @@ public abstract class AbstractSendMessag throws ActionException { GenericResult result = new GenericResult(); try { - Session session = Session.getDefaultInstance(props); Message message = createMessage(session, action); message = fillBody(message,action); - sendMessage(session, getUser(), message); - saveSentMessage(session, getUser(), message); + sendMessage(getUser(), message); + saveSentMessage(getUser(), message); resetAttachments(action); @@ -174,7 +170,7 @@ public abstract class AbstractSendMessag // it is easier to handle html in the browser. String text = htmlToText(html); - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") List items = getAttachments(action); return composeMessage(message, text, html, items); @@ -201,7 +197,7 @@ public abstract class AbstractSendMessag * @param action * @return A list of stored attachments */ - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") protected List getAttachments(A action) throws MessagingException, ActionException { FileItemRegistry registry = SessionUtils.getSessionRegistry(logger, httpSessionProvider.get()); List<MessageAttachment> attachments = action.getMessage().getMessageAttachments(); @@ -243,17 +239,10 @@ public abstract class AbstractSendMessag * @param message * @throws MessagingException */ - protected void sendMessage(Session session, User user, Message message) throws MessagingException { - Transport transport; + protected void sendMessage(User user, Message message) throws MessagingException { + + Transport transport = cache.getMailTransport(useSSL); - if (MockSMTPTransport.MOCK_HOST.equals(address)) { - transport = new MockSMTPTransport(session); - } else if (useSSL) { - transport = session.getTransport("smtps"); - } else { - transport = session.getTransport("smtp"); - } - if (auth) { logger.debug("Use auth for smtp connection"); transport.connect(address,port,user.getName(), user.getPassword()); @@ -281,7 +270,7 @@ public abstract class AbstractSendMessag * @throws MessagingException * @throws IOException */ - protected void saveSentMessage(Session session, User user, Message message) throws MessagingException, IOException { + protected void saveSentMessage(User user, Message message) throws MessagingException, IOException { IMAPStore iStore = cache.get(user); IMAPFolder folder = (IMAPFolder) iStore.getFolder(user.getSettings().getSentFolderName()); @@ -320,7 +309,7 @@ public abstract class AbstractSendMessag * @throws MessagingException * @throws IOException */ - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") public static Message composeMessage (Message message, String text, String html, List parts) throws MessagingException, IOException { MimeBodyPart txtPart = null; Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractSessionHandler.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractSessionHandler.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractSessionHandler.java (original) +++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractSessionHandler.java Wed May 2 16:05:26 2012 @@ -43,13 +43,13 @@ import com.google.inject.Provider; */ public abstract class AbstractSessionHandler<A extends Action<R>,R extends Result> implements ActionHandler<A, R> { - protected final Provider<HttpSession> sessionProvider; + protected final Provider<HttpSession> httpSessionProvider; protected final IMAPStoreCache cache; protected final Log logger; @Inject - public AbstractSessionHandler(IMAPStoreCache cache, Log logger, Provider<HttpSession> sessionProvider) { - this.sessionProvider = sessionProvider; + public AbstractSessionHandler(IMAPStoreCache cache, Log logger, Provider<HttpSession> httpSessionProvider) { + this.httpSessionProvider = httpSessionProvider; this.cache = cache; this.logger = logger; } @@ -82,9 +82,9 @@ public abstract class AbstractSessionHan * @throws ActionException */ protected User getUser() throws ActionException{ - User user = (User) sessionProvider.get().getAttribute(SConsts.USER_SESS_ATTR); + User user = (User) httpSessionProvider.get().getAttribute(SConsts.USER_SESS_ATTR); if (user == null) { - throw new InvalidSessionException("User not found in session with id " + sessionProvider.get().getId()); + throw new InvalidSessionException("User not found in session with id " + httpSessionProvider.get().getId()); } else { return user; } Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ForwardMessageHandler.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ForwardMessageHandler.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ForwardMessageHandler.java (original) +++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ForwardMessageHandler.java Wed May 2 16:05:26 2012 @@ -23,7 +23,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import javax.mail.BodyPart; import javax.mail.Folder; import javax.mail.Message; import javax.mail.MessagingException; @@ -56,9 +55,9 @@ public class ForwardMessageHandler exten } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings({ "rawtypes", "unchecked" }) protected List getAttachments(ForwardMessage action) throws MessagingException, ActionException { - List<BodyPart> items = new ArrayList<BodyPart>(); + List<?> items = new ArrayList(); IMAPStore store = cache.get(getUser()); IMAPFolder folder = (IMAPFolder) store.getFolder(action.getFolder().getFullName()); Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/GetMessageDetailsHandler.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/GetMessageDetailsHandler.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/GetMessageDetailsHandler.java (original) +++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/GetMessageDetailsHandler.java Wed May 2 16:05:26 2012 @@ -102,7 +102,7 @@ public class GetMessageDetailsHandler ex mDetails.setUid(uid); f.setFlags(new Message[] { message }, new Flags(Flag.SEEN), true); - + return mDetails; } catch (Exception e) { logger.error("Unable to expose msg for user " + user @@ -133,7 +133,7 @@ public class GetMessageDetailsHandler ex ArrayList<MessageAttachment> attachmentList = new ArrayList<MessageAttachment>(); boolean isHTML = handleParts(message, con, sbPlain, attachmentList); - + if (isHTML) { mDetails.setText(filterHtmlDocument(sbPlain.toString(), folderName, uid)); } else { @@ -185,14 +185,16 @@ public class GetMessageDetailsHandler ex Part part = mp.getBodyPart(i); String contentType = part.getContentType().toLowerCase(); + + Boolean bodyRead = sbPlain.length() > 0; - if (text == null && contentType.startsWith("text/plain") ) { + if (!bodyRead && contentType.startsWith("text/plain") ) { isHTML = false; text = (String)part.getContent(); - } else if (contentType.startsWith("text/html")) { + } else if (!bodyRead && contentType.startsWith("text/html")) { isHTML = true; text = (String)part.getContent(); - } else if (contentType.startsWith("message/rfc822")) { + } else if (!bodyRead && contentType.startsWith("message/rfc822")) { // Extract the message and pass it MimeMessage msg = (MimeMessage) part.getDataHandler().getContent(); isHTML = handleParts(msg, msg.getContent(), sbPlain, attachmentList); Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/IdleHandler.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/IdleHandler.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/IdleHandler.java (original) +++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/IdleHandler.java Wed May 2 16:05:26 2012 @@ -26,7 +26,6 @@ import net.customware.gwt.dispatch.share import org.apache.commons.logging.Log; import org.apache.hupa.server.IMAPStoreCache; -import org.apache.hupa.server.mock.MockSMTPTransport; import org.apache.hupa.shared.rpc.Idle; import org.apache.hupa.shared.rpc.IdleResult; @@ -56,9 +55,7 @@ public class IdleHandler extends Abstrac try { IMAPStore store = cache.get(getUser()); - if (store.getURLName() != null && - !MockSMTPTransport.MOCK_HOST.equals(store.getURLName().getHost()) ) { - + if (store.getURLName() != null ) { // check if the store supports the IDLE command if (store.hasCapability("IDLE")) { // just send a noop to keep the connection alive @@ -66,7 +63,6 @@ public class IdleHandler extends Abstrac } else { return new IdleResult(false); } - } return new IdleResult(true); } catch (Exception e) { Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/LogoutUserHandler.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/LogoutUserHandler.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/LogoutUserHandler.java (original) +++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/LogoutUserHandler.java Wed May 2 16:05:26 2012 @@ -61,7 +61,7 @@ public class LogoutUserHandler extends A cache.delete(user); // remove user attributes from session - SessionUtils.cleanSessionAttributes(sessionProvider.get()); + SessionUtils.cleanSessionAttributes(httpSessionProvider.get()); return new LogoutUserResult(user); } Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/PrepareNewMessageHandler.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/PrepareNewMessageHandler.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/PrepareNewMessageHandler.java (original) +++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/PrepareNewMessageHandler.java Wed May 2 16:05:26 2012 @@ -26,7 +26,6 @@ import net.customware.gwt.dispatch.share import org.apache.commons.logging.Log; import org.apache.hupa.server.IMAPStoreCache; -import org.apache.hupa.server.mock.MockSMTPTransport; import org.apache.hupa.shared.rpc.Idle; import org.apache.hupa.shared.rpc.IdleResult; @@ -55,8 +54,7 @@ public class PrepareNewMessageHandler ex throws ActionException { try { IMAPStore store = cache.get(getUser()); - if (store.getURLName() != null && - !MockSMTPTransport.MOCK_HOST.equals(store.getURLName().getHost()) ) { + if (store.getURLName() != null) { // just send a noop to keep the connection alive store.idle(); } Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java (original) +++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java Wed May 2 16:05:26 2012 @@ -23,7 +23,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import javax.mail.BodyPart; import javax.mail.Folder; import javax.mail.Message; import javax.mail.MessagingException; @@ -57,9 +56,9 @@ public class ReplyMessageHandler extends } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings({ "rawtypes", "unchecked" }) protected List getAttachments(ReplyMessage action) throws MessagingException, ActionException { - List<BodyPart> items = new ArrayList<BodyPart>(); + List<?> items = new ArrayList(); IMAPStore store = cache.get(getUser()); IMAPFolder folder = (IMAPFolder) store.getFolder(action.getFolder().getFullName()); Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/preferences/InImapUserPreferencesStorage.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/preferences/InImapUserPreferencesStorage.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/preferences/InImapUserPreferencesStorage.java (original) +++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/preferences/InImapUserPreferencesStorage.java Wed May 2 16:05:26 2012 @@ -19,24 +19,8 @@ package org.apache.hupa.server.preferences; -import com.google.inject.Inject; -import com.google.inject.Provider; - -import com.sun.mail.imap.IMAPFolder; -import com.sun.mail.imap.IMAPStore; - import gwtupload.server.UploadServlet; -import org.apache.commons.fileupload.FileItem; -import org.apache.commons.fileupload.FileItemFactory; -import org.apache.commons.fileupload.disk.DiskFileItemFactory; -import org.apache.commons.io.output.ByteArrayOutputStream; -import org.apache.commons.logging.Log; -import org.apache.hupa.server.IMAPStoreCache; -import org.apache.hupa.server.utils.MessageUtils; -import org.apache.hupa.shared.data.User; -import org.apache.hupa.shared.rpc.ContactsResult.Contact; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -44,20 +28,34 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.HashMap; import java.util.Hashtable; -import java.util.Properties; import javax.mail.BodyPart; +import javax.mail.Flags.Flag; import javax.mail.Folder; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Multipart; import javax.mail.Session; -import javax.mail.Flags.Flag; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; import javax.servlet.http.HttpSession; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.FileItemFactory; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.commons.logging.Log; +import org.apache.hupa.server.IMAPStoreCache; +import org.apache.hupa.server.utils.MessageUtils; +import org.apache.hupa.shared.data.User; +import org.apache.hupa.shared.rpc.ContactsResult.Contact; + +import com.google.inject.Inject; +import com.google.inject.Provider; +import com.sun.mail.imap.IMAPFolder; +import com.sun.mail.imap.IMAPStore; + /** * A user preferences storage which uses IMAP as repository data * @@ -184,7 +182,7 @@ public class InImapUserPreferencesStorag private Log logger; - private Session session = Session.getDefaultInstance(new Properties()); + private Session session; private final IMAPStoreCache cache; @@ -198,6 +196,7 @@ public class InImapUserPreferencesStorag this.sessionProvider = sessionProvider; this.cache = cache; this.logger = logger; + this.session = cache.getMailSession(); } /* (non-Javadoc) Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/servlet/DownloadAttachmentServlet.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/servlet/DownloadAttachmentServlet.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/servlet/DownloadAttachmentServlet.java (original) +++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/servlet/DownloadAttachmentServlet.java Wed May 2 16:05:26 2012 @@ -35,7 +35,7 @@ import javax.servlet.http.HttpServletRes import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; -import org.apache.hupa.server.InMemoryIMAPStoreCache; +import org.apache.hupa.server.IMAPStoreCache; import org.apache.hupa.server.utils.MessageUtils; import org.apache.hupa.shared.SConsts; import org.apache.hupa.shared.data.User; @@ -44,21 +44,17 @@ import com.google.inject.Inject; import com.sun.mail.imap.IMAPFolder; /** - * Handle download of attachments - * - * + * Handle to download attachments in messages */ public class DownloadAttachmentServlet extends HttpServlet { - /** - * - */ private static final long serialVersionUID = 1245563204035792963L; - private InMemoryIMAPStoreCache cache; + + private IMAPStoreCache cache; private Log logger; @Inject - public DownloadAttachmentServlet(InMemoryIMAPStoreCache cache, Log logger) { + public DownloadAttachmentServlet(IMAPStoreCache cache, Log logger) { this.cache = cache; this.logger = logger; } Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/ConfigurationProperties.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/ConfigurationProperties.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/ConfigurationProperties.java (original) +++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/ConfigurationProperties.java Wed May 2 16:05:26 2012 @@ -19,6 +19,13 @@ package org.apache.hupa.server.utils; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + /** * Enumeration of valid configuration properties */ @@ -26,8 +33,8 @@ public enum ConfigurationProperties { // Mandatory configuration properties IMAP_SERVER_ADDRESS("IMAPServerAddress", true, null), SMTP_SERVER_ADDRESS("SMTPServerAddress", true, null), - IMAP_SERVER_PORT("IMAPServerPort", true, null), - SMTP_SERVER_PORT("SMTPServerPort", true, null), + IMAP_SERVER_PORT("IMAPServerPort", false, "143"), + SMTP_SERVER_PORT("SMTPServerPort", false, "25"), // Optional configuration properties IMAP_CONNECTION_POOL_SIZE("IMAPConnectionPoolSize", false, "4"), @@ -42,7 +49,12 @@ public enum ConfigurationProperties { POST_FETCH_MESSAGE_COUNT("PostFetchMessageCount", false, "0"), SESSION_DEBUG("SessionDebug", false, "false"), SMTP_AUTH("SMTPAuth", false, "true"), - SMTPS("SMTPS", false, "false"); + SMTPS("SMTPS", false, "false"), + + // Used only in demo mode + USERNAME("Username", false, null), + PASSWORD("Password", false, null), + SESSIONID("DefaultUserSessionId", false, null); private String property; private boolean mandatory; @@ -97,4 +109,78 @@ public enum ConfigurationProperties { public String getPropValue() { return this.propValue; } + + /** + * Test for mandatory properties, complete with default values when + * missing, and avoid unknown properties. + */ + public static void validateProperties(Properties properties) { + + List<String> errors = new ArrayList<String>(); + + // Test for mandatory and complete properties with default values when + // missing + for (ConfigurationProperties confProps : ConfigurationProperties + .values()) { + String propName = confProps.getProperty(); + String propValue = confProps.getPropValue(); + Object value = properties.get(propName); + if (confProps.isMandatory()) { + if (value == null) { + errors.add("The mandatory Property '" + + confProps.getProperty() + "' is not set."); + } + } else if (value == null && propValue != null) { + properties.setProperty(propName, propValue); + } + } + + // Test for unknown properties set in configuration + for (Object key : properties.keySet()) { + if (ConfigurationProperties.lookup((String) key) == null) { + errors.add("The Property '" + key + + "' is unknown"); + } + } + if (!errors.isEmpty()) { + throw new IllegalArgumentException("Error validating configuration: \n" + properties + "\n" + errors.toString()); + } + } + + /** + * Loads and validate a properties file. + * + * @param configDir + * @param name + * @return + */ + public static Properties loadProperties(String name) { + if (name == null) + return null; + + Properties properties = null; + File file = new File(name); + + if (file.exists()) { + FileInputStream fis = null; + try { + properties = new Properties(); + fis = new FileInputStream(file); + properties.load(fis); + } catch (Exception e) { + properties = null; + e.printStackTrace(); + } finally { + if (fis != null) { + try { + fis.close(); + } catch (IOException e) { + // Empty on purpose + } + } + } + } + + return properties; + } } \ No newline at end of file Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/SessionUtils.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/SessionUtils.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/SessionUtils.java (original) +++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/SessionUtils.java Wed May 2 16:05:26 2012 @@ -47,7 +47,7 @@ public class SessionUtils { * @param session */ public static void cleanSessionAttributes(HttpSession session) { - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") Enumeration en = session.getAttributeNames(); ArrayList<String> toRemove = new ArrayList<String>(); while (en.hasMoreElements()) { Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/GuiceServerTestModule.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/GuiceServerTestModule.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/GuiceServerTestModule.java (original) +++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/GuiceServerTestModule.java Wed May 2 16:05:26 2012 @@ -19,12 +19,16 @@ package org.apache.hupa.server.guice; +import java.util.Properties; + import javax.mail.Session; import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.hupa.server.IMAPStoreCache; -import org.apache.hupa.server.InMemoryIMAPStoreCache; +import org.apache.hupa.server.guice.demo.DemoGuiceServerModule.DemoIMAPStoreCache; +import org.apache.hupa.server.guice.providers.DefaultUserSettingsProvider; +import org.apache.hupa.server.guice.providers.JavaMailSessionProvider; import org.apache.hupa.server.handler.AbstractSendMessageHandler; import org.apache.hupa.server.handler.ContactsHandler; import org.apache.hupa.server.handler.CreateFolderHandler; @@ -39,11 +43,13 @@ import org.apache.hupa.server.handler.Lo import org.apache.hupa.server.handler.LogoutUserHandler; import org.apache.hupa.server.handler.ReplyMessageHandler; import org.apache.hupa.server.handler.SendMessageHandler; +import org.apache.hupa.server.mock.MockConstants; import org.apache.hupa.server.mock.MockHttpSessionProvider; import org.apache.hupa.server.mock.MockIMAPStore; import org.apache.hupa.server.mock.MockLogProvider; import org.apache.hupa.server.preferences.InSessionUserPreferencesStorage; import org.apache.hupa.server.preferences.UserPreferencesStorage; +import org.apache.hupa.server.utils.ConfigurationProperties; import org.apache.hupa.shared.data.Settings; import org.apache.hupa.shared.data.User; import org.apache.hupa.shared.rpc.Contacts; @@ -60,7 +66,10 @@ public class GuiceServerTestModule exten @Override protected void configureHandlers() { - Names.bindProperties(binder(), DemoModeConstants.demoProperties); + Properties properties = MockConstants.mockProperties; + ConfigurationProperties.validateProperties(properties); + + Names.bindProperties(binder(), properties); bind(Session.class).toProvider(JavaMailSessionProvider.class); bind(HttpSession.class).toProvider(MockHttpSessionProvider.class); @@ -68,7 +77,7 @@ public class GuiceServerTestModule exten bind(Log.class).toProvider(MockLogProvider.class).in(Singleton.class); bind(IMAPStore.class).to(MockIMAPStore.class); - bind(IMAPStoreCache.class).to(InMemoryIMAPStoreCache.class).in(Singleton.class); + bind(IMAPStoreCache.class).to(DemoIMAPStoreCache.class).in(Singleton.class); bind(LoginUserHandler.class); bind(LogoutUserHandler.class); @@ -91,6 +100,8 @@ public class GuiceServerTestModule exten bind(UserPreferencesStorage.class).to(InSessionUserPreferencesStorage.class); bind(User.class).to(TestUser.class).in(Singleton.class); + bind(Properties.class).toInstance(properties); + } } \ No newline at end of file Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/ServerModulTest.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/ServerModulTest.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/ServerModulTest.java (original) +++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/ServerModulTest.java Wed May 2 16:05:26 2012 @@ -21,24 +21,28 @@ package org.apache.hupa.server.guice; import java.io.File; import java.util.ArrayList; import java.util.Collection; +import java.util.Map.Entry; import java.util.Properties; import junit.framework.Assert; import org.apache.commons.io.FileUtils; -import org.apache.hupa.server.mock.MockIMAPStore; -import org.apache.hupa.server.mock.MockSMTPTransport; +import org.apache.hupa.server.mock.MockConstants; +import org.apache.hupa.server.utils.ConfigurationProperties; import org.junit.Before; import org.junit.Test; public class ServerModulTest { private String tmpDir = System.getProperty("java.io.tmpdir"); - private GuiceServerModule module = new GuiceServerModule(tmpDir); +// private GuiceServerModule module = new GuiceServerModule(tmpDir); + + private String configDir = GuiceServletConfig.CONFIG_DIR_IN_WAR; + @Before public void setUp() { // create config directory - File f = new File(tmpDir + File.separator + GuiceServerModule.CONF_DIR); + File f = new File(tmpDir + File.separator + configDir); f.delete(); f.deleteOnExit(); f.mkdirs(); @@ -46,20 +50,10 @@ public class ServerModulTest { @Test public void testLoadProperties() throws Exception { - String fileName = tmpDir + File.separator +"foo.properties"; File file = new File(fileName); file.createNewFile(); - Properties p = module.loadProperties(fileName); - Assert.assertNotNull(p); - Assert.assertNull(p.get("IMAPServerAddress")); - file.delete(); - - // load file from not absolute file - fileName = tmpDir + File.separator + GuiceServerModule.CONF_DIR + File.separator + "foo2.properties"; - file = new File(fileName); - file.createNewFile(); - p = module.loadProperties(file.getName()); + Properties p = ConfigurationProperties.loadProperties(fileName); Assert.assertNotNull(p); Assert.assertNull(p.get("IMAPServerAddress")); file.delete(); @@ -67,53 +61,48 @@ public class ServerModulTest { @Test public void testLoadPropertiesWithEmptyFile() throws Exception { + GuiceServletConfig sconfig = new GuiceServletConfig(); + File tmp = File.createTempFile("foo", ".properties"); tmp.deleteOnExit(); try { - module.loadProperties(tmp.toString()); + ConfigurationProperties.loadProperties(tmp.toString()); } catch (IllegalArgumentException e) { // This must be thrown because of missing mandatory configuration properties } catch (Exception e) { Assert.fail("IllegalArgumentException must be thrown because of missing mandatory configuration properties"); } - System.setProperty(GuiceServerModule.SYS_PROP_CONFIG_FILE, tmp.toString()); + System.setProperty(GuiceServletConfig.SYS_PROP_CONFIG_FILE, tmp.toString()); try { - module.loadProperties(); + sconfig.loadProperties(); } catch (IllegalArgumentException e) { // This must be thrown because of missing mandatory configuration properties } catch (Exception e) { Assert.fail("IllegalArgumentException must be thrown because of missing mandatory configuration properties"); } - System.clearProperty(GuiceServerModule.SYS_PROP_CONFIG_FILE); - + System.clearProperty(GuiceServletConfig.SYS_PROP_CONFIG_FILE); } @Test public void testLoadDemoProperties() throws Exception { File tmp = File.createTempFile("foo", ".properties"); tmp.deleteOnExit(); + Properties p = MockConstants.mockProperties; Collection<String> lines = new ArrayList<String>(); - lines.add("IMAPServerAddress = " + MockSMTPTransport.MOCK_HOST); - lines.add("IMAPServerPort = 143"); - lines.add("SMTPServerAddress = " + MockSMTPTransport.MOCK_HOST); - lines.add("SMTPServerPort = 25"); - lines.add("DefaultInboxFolder = " + MockIMAPStore.MOCK_INBOX_FOLDER); - lines.add("DefaultTrashFolder = " + MockIMAPStore.MOCK_TRASH_FOLDER); - lines.add("DefaultSentFolder = " + MockIMAPStore.MOCK_SENT_FOLDER); - lines.add("DefaultDraftsFolder = " + MockIMAPStore.MOCK_DRAFTS_FOLDER); + for (Entry<Object, Object> e : p.entrySet()) { + lines.add(e.getKey() + " = " + e.getValue()); + } FileUtils.writeLines(tmp, lines); - - System.setProperty(GuiceServerModule.SYS_PROP_CONFIG_FILE, tmp.getAbsolutePath()); - Properties p = module.loadProperties(); - Assert.assertNotNull(p); - Assert.assertEquals(DemoModeConstants.mockSettings.getInboxFolderName(), p.get("DefaultInboxFolder")); - Assert.assertEquals(DemoModeConstants.mockSettings.getTrashFolderName(), p.get("DefaultTrashFolder")); - Assert.assertEquals(DemoModeConstants.mockSettings.getSentFolderName(), p.get("DefaultSentFolder")); - System.clearProperty(GuiceServerModule.SYS_PROP_CONFIG_FILE); - + System.setProperty(GuiceServletConfig.SYS_PROP_CONFIG_FILE, tmp.getAbsolutePath()); + p = new GuiceServletConfig().loadProperties(); + Assert.assertNotNull(p); + Assert.assertEquals(MockConstants.mockSettings.getInboxFolderName(), p.get("DefaultInboxFolder")); + Assert.assertEquals(MockConstants.mockSettings.getTrashFolderName(), p.get("DefaultTrashFolder")); + Assert.assertEquals(MockConstants.mockSettings.getSentFolderName(), p.get("DefaultSentFolder")); + System.clearProperty(GuiceServletConfig.SYS_PROP_CONFIG_FILE); } } Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/AbtractSendMessageHandlerTest.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/AbtractSendMessageHandlerTest.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/AbtractSendMessageHandlerTest.java (original) +++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/AbtractSendMessageHandlerTest.java Wed May 2 16:05:26 2012 @@ -107,14 +107,14 @@ public class AbtractSendMessageHandlerTe assertEquals(contentTwoAttach, TestUtils.summaryzeContent(message).toString()); - sendMessageHandler.sendMessage(session, testUser, message); + sendMessageHandler.sendMessage(testUser, message); // The reported size is wrong before the message has been saved Part part = MessageUtils.handleMultiPart(logger, message.getContent(), "uploadedFile_1.bin"); assertTrue(part.getSize() < 0); assertTrue(sentbox.getMessages().length == 0); - sendMessageHandler.saveSentMessage(session, testUser, message); + sendMessageHandler.saveSentMessage(testUser, message); assertTrue(sentbox.getMessages().length == 1); message = sentbox.getMessage(0); Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/GetMessageDetailsHandlerTest.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/GetMessageDetailsHandlerTest.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/GetMessageDetailsHandlerTest.java (original) +++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/GetMessageDetailsHandlerTest.java Wed May 2 16:05:26 2012 @@ -124,7 +124,7 @@ public class GetMessageDetailsHandlerTes long end = System.currentTimeMillis(); assertTrue("Large message bodies should be filtered fast", (end - start) < 1000); } - + private MessageDetails loadMessageDetails(String msgFile) throws Exception { return getDetailsHandler.mimeToDetails(TestUtils.loadMessageFromFile(session,msgFile), "theFolder", 9999l); } @@ -145,6 +145,13 @@ public class GetMessageDetailsHandlerTes assertEquals(0, details.getMessageAttachments().size()); assertTrue(details.getText().length() > 0); } + + public void testMessageDetails_AlternativeInsideMultiparMixed() throws Exception { + MessageDetails details = loadMessageDetails("10.msg"); + assertEquals(1, details.getMessageAttachments().size()); + System.out.println(details.getText()); + assertTrue(details.getText().contains("<span>")); + } public void testMessageDetails_charsetIso() throws Exception { MimeMessage message = TestUtils.loadMessageFromFile(session,"3.msg"); Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/integration/StoreBugTest.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/integration/StoreBugTest.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/integration/StoreBugTest.java (original) +++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/integration/StoreBugTest.java Wed May 2 16:05:26 2012 @@ -19,26 +19,26 @@ package org.apache.hupa.server.integration; -import com.sun.mail.imap.IMAPFolder; -import com.sun.mail.imap.IMAPStore; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Properties; + +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.Session; import junit.framework.Assert; import org.apache.hupa.server.InMemoryIMAPStoreCache; -import org.apache.hupa.server.guice.JavaMailSessionProvider; +import org.apache.hupa.server.guice.providers.JavaMailSessionProvider; import org.apache.hupa.server.mock.MockIMAPStore; import org.apache.hupa.server.mock.MockLog; import org.apache.hupa.shared.data.User; import org.junit.Ignore; import org.junit.Test; -import java.io.IOException; -import java.io.OutputStream; -import java.util.Properties; - -import javax.mail.Message; -import javax.mail.MessagingException; -import javax.mail.Session; +import com.sun.mail.imap.IMAPFolder; +import com.sun.mail.imap.IMAPStore; public class StoreBugTest { Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/preferences/InImapUserPreferencesStorageTest.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/preferences/InImapUserPreferencesStorageTest.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/preferences/InImapUserPreferencesStorageTest.java (original) +++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/preferences/InImapUserPreferencesStorageTest.java Wed May 2 16:05:26 2012 @@ -19,20 +19,22 @@ package org.apache.hupa.server.preferences; -import com.google.inject.Module; -import com.google.inject.Singleton; -import com.google.inject.name.Names; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Properties; -import com.sun.mail.imap.IMAPStore; +import javax.mail.Flags; +import javax.mail.Folder; +import javax.mail.Session; +import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.hupa.server.HupaGuiceTestCase; import org.apache.hupa.server.IMAPStoreCache; -import org.apache.hupa.server.InMemoryIMAPStoreCache; -import org.apache.hupa.server.guice.DefaultUserSettingsProvider; -import org.apache.hupa.server.guice.DemoModeConstants; import org.apache.hupa.server.guice.GuiceServerTestModule; -import org.apache.hupa.server.guice.JavaMailSessionProvider; +import org.apache.hupa.server.guice.demo.DemoGuiceServerModule.DemoIMAPStoreCache; +import org.apache.hupa.server.guice.providers.DefaultUserSettingsProvider; +import org.apache.hupa.server.guice.providers.JavaMailSessionProvider; import org.apache.hupa.server.handler.AbstractSendMessageHandler; import org.apache.hupa.server.handler.ContactsHandler; import org.apache.hupa.server.handler.CreateFolderHandler; @@ -47,9 +49,11 @@ import org.apache.hupa.server.handler.Lo import org.apache.hupa.server.handler.LogoutUserHandler; import org.apache.hupa.server.handler.ReplyMessageHandler; import org.apache.hupa.server.handler.SendMessageHandler; +import org.apache.hupa.server.mock.MockConstants; import org.apache.hupa.server.mock.MockHttpSessionProvider; import org.apache.hupa.server.mock.MockIMAPStore; import org.apache.hupa.server.mock.MockLogProvider; +import org.apache.hupa.server.utils.ConfigurationProperties; import org.apache.hupa.server.utils.SessionUtils; import org.apache.hupa.server.utils.TestUtils; import org.apache.hupa.shared.data.IMAPFolder; @@ -61,13 +65,10 @@ import org.apache.hupa.shared.rpc.FetchM import org.apache.hupa.shared.rpc.FetchMessagesResult; import org.apache.hupa.shared.rpc.SendMessage; -import java.util.ArrayList; -import java.util.Arrays; - -import javax.mail.Flags; -import javax.mail.Folder; -import javax.mail.Session; -import javax.servlet.http.HttpSession; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.name.Names; +import com.sun.mail.imap.IMAPStore; public class InImapUserPreferencesStorageTest extends HupaGuiceTestCase { @@ -94,7 +95,9 @@ public class InImapUserPreferencesStorag @Override protected void configureHandlers() { - Names.bindProperties(binder(), DemoModeConstants.demoProperties); + Properties p = MockConstants.mockProperties; + ConfigurationProperties.validateProperties(p); + Names.bindProperties(binder(), p); bind(Session.class).toProvider(JavaMailSessionProvider.class); bind(HttpSession.class).toProvider(MockHttpSessionProvider.class); @@ -102,7 +105,7 @@ public class InImapUserPreferencesStorag bind(Log.class).toProvider(MockLogProvider.class).in(Singleton.class); bind(IMAPStore.class).to(MockIMAPStore.class); - bind(IMAPStoreCache.class).to(InMemoryIMAPStoreCache.class).in(Singleton.class); + bind(IMAPStoreCache.class).to(DemoIMAPStoreCache.class).in(Singleton.class); bind(LoginUserHandler.class); bind(LogoutUserHandler.class); Modified: james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/SConsts.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/SConsts.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/SConsts.java (original) +++ james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/SConsts.java Wed May 2 16:05:26 2012 @@ -33,6 +33,4 @@ public class SConsts { public static final String USER_SESS_ATTR = "user"; public static final String CONTACTS_SESS_ATTR = "contacts"; - - } \ No newline at end of file Modified: james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/Util.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/Util.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/Util.java (original) +++ james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/Util.java Wed May 2 16:05:26 2012 @@ -19,6 +19,7 @@ package org.apache.hupa.shared; +import java.util.ArrayList; import java.util.List; public class Util { @@ -30,7 +31,7 @@ public class Util { public final static String HTML_CR = "<br>"; public final static String STRING_CR = "\n"; - public static String toString(String string) { + public static String unEscapeHtmlTags(String string) { if (string != null) { string = string.replaceAll(HTML_LT, STRING_LT); string = string.replaceAll(HTML_GT, STRING_GT); @@ -47,16 +48,7 @@ public class Util { return string; } - public static String listToString(List<String> list) { - if (list == null) - return ""; - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < list.size(); i++) { - sb.append(list.get(i)); - if (i < list.size()-1) { - sb.append(", "); - } - } - return sb.toString(); + public static <T> String listToString(List<T> list) { + return list == null ? "" : new ArrayList<T>(list).toString().replaceFirst("^\\[(.*)\\]$", "$1"); } } Modified: james/hupa/trunk/widgets/src/main/java/org/apache/hupa/widgets/editor/Editor.java URL: http://svn.apache.org/viewvc/james/hupa/trunk/widgets/src/main/java/org/apache/hupa/widgets/editor/Editor.java?rev=1333089&r1=1333088&r2=1333089&view=diff ============================================================================== --- james/hupa/trunk/widgets/src/main/java/org/apache/hupa/widgets/editor/Editor.java (original) +++ james/hupa/trunk/widgets/src/main/java/org/apache/hupa/widgets/editor/Editor.java Wed May 2 16:05:26 2012 @@ -101,7 +101,7 @@ public class Editor extends VerticalPane public void setHTML(String html) { isNewMessage = html.trim().length() > 0; - area.setHTML("<font size=2 style='font-family: arial'><br/>" + html + "</font>"); +// area.setHTML("<font size=2 style='font-family: arial'><br/>" + html + "</font>"); } public String getText() { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
