You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ro...@apache.org on 2020/06/08 13:15:54 UTC

[james-project] branch master updated (0d1d98d -> 36599ea)

This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.


    from 0d1d98d  JAMES-3171 MailboxFactory should take care of mailbox validation, not resolution
     new 106e9af  JAMES-3179 Use a Consumer instead of a Function in TransactionRunner
     new 5f10d70  JAMES-3179 Define MailboxACL.hashCode
     new 5746773  JAMES-3179 Fix QuotaThresholdNoticeTest constant overflow
     new 0f644aa  JAMES-3179 Remove IMAP168JpaMigrateCommand useless substring
     new 2e109d3  JAMES-3179 Fix MailetMatcherDescriptor equals
     new d327f98  JAMES-3179 Fix AbstractMessageRangeRequest hashCode
     new 338a232  JAMES-3179 Fix date formats
     new 6613579  JAMES-3179 Fix wrong regex patterns
     new c3ee324  JAMES-3179 Fix MessageContent hashCode
     new f798f6d  JAMES-3179 Fix RemoteDeliveryConfiguration class configuration
     new bf9c6cd  JAMES-3179 UploadResponse equals
     new ef02ee9  JAMES-3179 Fix SetMessageUpdateProcessorTest assertion definition
     new 022d5ea  JAMES-3179 Enable AttachmentAccessTokenTest tests
     new c3c598f  JAMES-3179 Use a Consumer instead of a Function in FakeSmtp
     new 5f19a09  JAMES-3179 Suppress harmless ErrorProne errors
     new e7a191e  JAMES-3179 Deal with nullity in OsDetector
     new 9537309  JAMES-3179 Fix UrlResource InputStream leaks
     new 2552baa  JAMES-3179 Deal with AbstractMailboxProcessor.getSelectedMailbox nullability
     new ddf638b  JAMES-3179 Fix a ImapRequestFrameDecoder leak
     new 2f3d219  JAMES-3179 Deal with SieveFileRepository nullability
     new a1da25b  JAMES-3179 Deal with ResultUtils nullability
     new e318886  JAMES-3179 Deal with FetchResponseBuilder nullability
     new 9f15eb2  JAMES-3179 Fix MaildirMessage leak
     new 89f364b  JAMES-3179 Migrate ImapFeaturesTest to JUnit 5
     new 7816411  JAMES-3179 Migrate MappingsImplTest to JUnit 5
     new abce10f  JAMES-3179 Remove OsDetector
     new f78e7a2  JAMES-3179 Fix BayesianAnalysis thread safety issue
     new 4c0a8a4  JAMES-3179 Fix ClamAV thread safety issue
     new 6c8d922  JAMES-3179 Fix UpdatableTickingClock thread safety issue
     new 36599ea  JAMES-3179 Drop OSGi

The 30 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../james/backends/jpa/TransactionRunner.java      |   6 +-
 .../org/apache/james/mailbox/model/FetchGroup.java |   2 +-
 .../org/apache/james/mailbox/model/MailboxACL.java |  14 +-
 .../apache/james/mailbox/model/MailboxACLTest.java |  11 +
 .../elasticsearch/query/CriterionConverter.java    |   1 +
 .../mailbox/maildir/mail/model/MaildirMessage.java |   4 +-
 .../apache/james/mailbox/maildir/OsDetector.java   |  37 ---
 .../subscribers/QuotaThresholdNoticeTest.java      |   2 +-
 .../mailbox/quota/model/QuotaThresholdTest.java    |   1 +
 .../apache/james/mailbox/store/ResultUtils.java    |   8 +-
 .../store/MailboxMessageResultImplTest.java        |   1 +
 .../james/mailbox/store/ResultUtilsTest.java       |   7 +-
 .../migrator/command/IMAP168JpaMigrateCommand.java |   2 +-
 .../apache/james/ai/classic/BayesianAnalysis.java  |  13 +-
 .../main/java/org/apache/mailet/Serializer.java    |   1 +
 .../james/mailet/AbstractMailetdocsReport.java     |  12 +-
 .../james/mailet/DefaultDescriptorsExtractor.java  |  37 +--
 .../james/mailet/MailetMatcherDescriptor.java      | 121 ++++++--
 .../mailet/DefaultDescriptorsExtractorTest.java    |  39 +--
 .../james/mailet/MailetMatcherDescriptorTest.java  |   7 +-
 mailet/standard/pom.xml                            |   2 +-
 .../apache/james/transport/mailets/ClamAVScan.java |  15 +-
 .../org/apache/james/mpt/api/ImapFeaturesTest.java |  45 +--
 pom.xml                                            |  41 +--
 .../imap/decode/ImapRequestStreamLineReader.java   |  12 +-
 .../request/AbstractMessageRangeRequest.java       |   2 +-
 .../imap/processor/AbstractMailboxProcessor.java   |  17 +-
 .../imap/processor/AbstractSelectionProcessor.java |   3 +-
 .../james/imap/processor/CloseProcessor.java       |   3 +-
 .../james/imap/processor/ExpungeProcessor.java     |   5 +-
 .../james/imap/processor/SearchProcessor.java      |   3 +-
 .../james/imap/processor/StoreProcessor.java       |  23 +-
 .../james/imap/processor/fetch/FetchProcessor.java |  15 +-
 .../imap/processor/fetch/FetchResponseBuilder.java |  79 +++---
 .../imap/decode/DecoderUtilsLocaleDateTest.java    |   2 +-
 .../apache/james/imap/decode/DecoderUtilsTest.java |   4 +-
 server/app/pom.xml                                 |   8 -
 .../configuration/FileConfigurationProvider.java   |   5 +
 server/container/spring/pom.xml                    |   8 -
 .../AbstractOSGIAnnotationBeanPostProcessor.java   | 312 ---------------------
 .../lifecycle/osgi/OSGIConfigurationProvider.java  |  46 ---
 ...PersistenceUnitAnnotationBeanPostProcessor.java |  44 ---
 .../OSGIResourceAnnotationBeanPostProcessor.java   |  42 ---
 .../spring/osgi/AbstractBundleTracker.java         | 198 -------------
 .../container/spring/osgi/DomainListTracker.java   |  35 ---
 .../spring/osgi/RecipientRewriteTableTracker.java  |  35 ---
 .../spring/osgi/UsersRepositoryTracker.java        |  36 ---
 .../james/util/mime/MessageContentExtractor.java   |   7 +-
 .../org/apache/james/util/FunctionalUtilsTest.java |   2 +
 .../util/mime/MessageContentExtractorTest.java     |   7 +
 .../sieverepository/file/SieveFileRepository.java  |  28 +-
 .../mailrepository/jdbc/JDBCMailRepository.java    |  31 +-
 .../apache/james/sieve/jpa/JPASieveRepository.java |  19 +-
 .../org/apache/james/rrt/lib/MappingsImplTest.java |  27 +-
 .../lib/AbstractSieveRepositoryTest.java           |   2 +-
 .../delivery/RemoteDeliveryConfiguration.java      |   2 +-
 .../james/jmap/draft/crypto/SecurityKeyLoader.java |   8 +-
 .../james/jmap/draft/model/UploadResponse.java     |   6 +-
 .../methods/SetMessagesUpdateProcessorTest.java    |   2 +-
 .../draft/model/AttachmentAccessTokenTest.java     |  13 +-
 .../jmap/draft/model/UploadResponseTest.java}      |   7 +-
 .../imapserver/netty/ImapRequestFrameDecoder.java  |   9 +
 .../netty/NettyStreamImapRequestLineReader.java    |   6 +-
 .../main/java/org/apache/james/utils/FakeSmtp.java |   6 +-
 .../apache/james/utils/UpdatableTickingClock.java  |   3 +
 65 files changed, 418 insertions(+), 1133 deletions(-)
 delete mode 100644 mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/OsDetector.java
 copy server/blob/blob-api/src/test/java/org/apache/james/blob/api/BlobTypeTest.java => mailet/mailetdocs-maven-plugin/src/test/java/org/apache/james/mailet/MailetMatcherDescriptorTest.java (90%)
 delete mode 100644 server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/AbstractOSGIAnnotationBeanPostProcessor.java
 delete mode 100644 server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIConfigurationProvider.java
 delete mode 100644 server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIPersistenceUnitAnnotationBeanPostProcessor.java
 delete mode 100644 server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIResourceAnnotationBeanPostProcessor.java
 delete mode 100644 server/container/spring/src/main/java/org/apache/james/container/spring/osgi/AbstractBundleTracker.java
 delete mode 100644 server/container/spring/src/main/java/org/apache/james/container/spring/osgi/DomainListTracker.java
 delete mode 100644 server/container/spring/src/main/java/org/apache/james/container/spring/osgi/RecipientRewriteTableTracker.java
 delete mode 100644 server/container/spring/src/main/java/org/apache/james/container/spring/osgi/UsersRepositoryTracker.java
 copy server/{blob/blob-api/src/test/java/org/apache/james/blob/api/BlobTypeTest.java => protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/UploadResponseTest.java} (90%)


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 30/30: JAMES-3179 Drop OSGi

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 36599ea9739417d88a7023e4f03d8682218c9c07
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Wed May 27 17:06:09 2020 +0200

    JAMES-3179 Drop OSGi
---
 mailet/standard/pom.xml                            |   2 +-
 pom.xml                                            |  41 +--
 server/app/pom.xml                                 |   8 -
 server/container/spring/pom.xml                    |   8 -
 .../AbstractOSGIAnnotationBeanPostProcessor.java   | 312 ---------------------
 .../lifecycle/osgi/OSGIConfigurationProvider.java  |  46 ---
 ...PersistenceUnitAnnotationBeanPostProcessor.java |  44 ---
 .../OSGIResourceAnnotationBeanPostProcessor.java   |  42 ---
 .../spring/osgi/AbstractBundleTracker.java         | 198 -------------
 .../container/spring/osgi/DomainListTracker.java   |  35 ---
 .../spring/osgi/RecipientRewriteTableTracker.java  |  35 ---
 .../spring/osgi/UsersRepositoryTracker.java        |  36 ---
 12 files changed, 3 insertions(+), 804 deletions(-)

diff --git a/mailet/standard/pom.xml b/mailet/standard/pom.xml
index 03b890d..1fc19d9 100644
--- a/mailet/standard/pom.xml
+++ b/mailet/standard/pom.xml
@@ -100,7 +100,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
-            <artifactId>httpclient-osgi</artifactId>
+            <artifactId>httpclient</artifactId>
         </dependency>
         <dependency>
             <groupId>org.mockito</groupId>
diff --git a/pom.xml b/pom.xml
index b4de1d8..0e87aae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -611,8 +611,6 @@
         <concurrent.version>1.3.4</concurrent.version>
         <xbean-spring.version>4.9</xbean-spring.version>
         <netty.version>3.10.6.Final</netty.version>
-        <spring-osgi-extender.version>1.2.1</spring-osgi-extender.version>
-        <org.osgi.core.version>5.0.0</org.osgi.core.version>
         <cucumber.version>2.4.0</cucumber.version>
 
         <pax-logging-api.version>1.6.4</pax-logging-api.version>
@@ -627,7 +625,6 @@
         <guava.version>25.1-jre</guava.version>
 
         <jutf7.version>1.0.0</jutf7.version>
-        <httpclient-osgi.version>4.5.1</httpclient-osgi.version>
         <apache.httpcomponents.version>4.5.9</apache.httpcomponents.version>
         <!-- maven-mailetdocs-plugin artifacts -->
         <maven-artifact.version>3.0-alpha-1</maven-artifact.version>
@@ -2345,14 +2342,8 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.httpcomponents</groupId>
-                <artifactId>httpclient-osgi</artifactId>
-                <version>${apache.httpcomponents.version}</version>
-                <exclusions>
-                    <exclusion>
-                        <groupId>commons-logging</groupId>
-                        <artifactId>commons-logging</artifactId>
-                    </exclusion>
-                </exclusions>
+                <artifactId>httpclient</artifactId>
+                <version>4.5.10</version>
             </dependency>
             <dependency>
                 <groupId>org.apache.james.jspf</groupId>
@@ -2575,11 +2566,6 @@
                 <version>3.0.0</version>
             </dependency>
             <dependency>
-                <groupId>org.osgi</groupId>
-                <artifactId>org.osgi.core</artifactId>
-                <version>${org.osgi.core.version}</version>
-            </dependency>
-            <dependency>
                 <groupId>org.scala-lang</groupId>
                 <artifactId>scala-library</artifactId>
                 <version>${scala.version}</version>
@@ -2678,29 +2664,6 @@
                 <version>${spring.version}</version>
             </dependency>
             <dependency>
-                <groupId>org.springframework.osgi</groupId>
-                <artifactId>spring-osgi-extender</artifactId>
-                <version>${spring-osgi-extender.version}</version>
-                <exclusions>
-                    <exclusion>
-                        <groupId>org.springframework</groupId>
-                        <artifactId>org.springframework.core</artifactId>
-                    </exclusion>
-                    <exclusion>
-                        <groupId>org.springframework</groupId>
-                        <artifactId>org.springframework.aop</artifactId>
-                    </exclusion>
-                    <exclusion>
-                        <groupId>org.springframework</groupId>
-                        <artifactId>org.springframework.context</artifactId>
-                    </exclusion>
-                    <exclusion>
-                        <groupId>org.springframework</groupId>
-                        <artifactId>org.springframework.beans</artifactId>
-                    </exclusion>
-                </exclusions>
-            </dependency>
-            <dependency>
                 <groupId>org.subethamail</groupId>
                 <artifactId>subethasmtp</artifactId>
                 <version>3.1.7</version>
diff --git a/server/app/pom.xml b/server/app/pom.xml
index 00ab3f0..0be80fd 100644
--- a/server/app/pom.xml
+++ b/server/app/pom.xml
@@ -457,14 +457,6 @@
             <artifactId>james-server-spring</artifactId>
             <exclusions>
                 <exclusion>
-                    <groupId>org.springframework.osgi</groupId>
-                    <artifactId>spring-osgi-extender</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>org.osgi</groupId>
-                    <artifactId>org.osgi.core</artifactId>
-                </exclusion>
-                <exclusion>
                     <groupId>javax.mail</groupId>
                     <artifactId>mail</artifactId>
                 </exclusion>
diff --git a/server/container/spring/pom.xml b/server/container/spring/pom.xml
index 5e7551e..dcb87f5 100644
--- a/server/container/spring/pom.xml
+++ b/server/container/spring/pom.xml
@@ -157,10 +157,6 @@
             <artifactId>log4j-slf4j-impl</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>jcl-over-slf4j</artifactId>
         </dependency>
@@ -208,10 +204,6 @@
             <artifactId>spring-web</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.springframework.osgi</groupId>
-            <artifactId>spring-osgi-extender</artifactId>
-        </dependency>
-        <dependency>
             <groupId>pl.pragmatists</groupId>
             <artifactId>JUnitParams</artifactId>
             <scope>test</scope>
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/AbstractOSGIAnnotationBeanPostProcessor.java b/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/AbstractOSGIAnnotationBeanPostProcessor.java
deleted file mode 100644
index 4bad5f5..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/AbstractOSGIAnnotationBeanPostProcessor.java
+++ /dev/null
@@ -1,312 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.lifecycle.osgi;
-
-import java.beans.PropertyDescriptor;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-
-import org.osgi.framework.BundleContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.FatalBeanException;
-import org.springframework.beans.MutablePropertyValues;
-import org.springframework.beans.PropertyValues;
-import org.springframework.beans.factory.BeanClassLoaderAware;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.BeanFactoryAware;
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-import org.springframework.beans.factory.config.BeanPostProcessor;
-import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
-import org.springframework.core.annotation.AnnotationUtils;
-import org.springframework.osgi.context.BundleContextAware;
-import org.springframework.osgi.service.importer.support.Cardinality;
-import org.springframework.osgi.service.importer.support.OsgiServiceCollectionProxyFactoryBean;
-import org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean;
-import org.springframework.util.ReflectionUtils;
-
-/**
- * Abstract base class for {@link BeanPostProcessor} implementations which need to wire stuff via annotations and need to be functional via OSGI.
- * 
- * Many of this code is borrowed from the spring-dm's class <code>org.springframework.osgi.extensions.annotation.ServiceReferenceInjectionBeanPostProcessor.</code>
- *  * 
- * 
- *
- * @param <A>
- */
-public abstract class AbstractOSGIAnnotationBeanPostProcessor<A extends Annotation> extends InstantiationAwareBeanPostProcessorAdapter implements BundleContextAware, BeanClassLoaderAware, BeanFactoryAware {
-
-    public static final long DEFAULT_TIMEOUT = 60 * 1000 * 5;
-    private BundleContext bundleContext;
-
-    private static final Logger logger = LoggerFactory.getLogger(AbstractOSGIAnnotationBeanPostProcessor.class);
-
-    protected BeanFactory beanFactory;
-
-    private ClassLoader classLoader;
-
-    private boolean lookupBeanFactory = true;
-
-    private long timeout = DEFAULT_TIMEOUT;
-
-
-    /**
-     * Set the timeout in milliseconds. The default is 5 minutes
-     * 
-     * @param timeout
-     */
-    public void setTimeout(long timeout) {
-        this.timeout = timeout;
-    }
-    
-    public void setLookupBeanFactory(boolean lookupBeanFactory) {
-        this.lookupBeanFactory = lookupBeanFactory;
-    }
-    
-    private abstract static class ImporterCallAdapter {
-
-        @SuppressWarnings("rawtypes")
-        static void setInterfaces(Object importer, Class[] classes) {
-            if (importer instanceof OsgiServiceProxyFactoryBean) {
-                ((OsgiServiceProxyFactoryBean) importer).setInterfaces(classes);
-            } else {
-                ((OsgiServiceCollectionProxyFactoryBean) importer).setInterfaces(classes);
-            }
-        }
-
-        static void setBundleContext(Object importer, BundleContext context) {
-            ((BundleContextAware) importer).setBundleContext(context);
-        }
-
-        static void setBeanClassLoader(Object importer, ClassLoader cl) {
-            ((BeanClassLoaderAware) importer).setBeanClassLoader(cl);
-        }
-
-        static void setCardinality(Object importer, Cardinality cardinality) {
-            if (importer instanceof OsgiServiceProxyFactoryBean) {
-                ((OsgiServiceProxyFactoryBean) importer).setCardinality(cardinality);
-            } else {
-                ((OsgiServiceCollectionProxyFactoryBean) importer).setCardinality(cardinality);
-            }
-        }
-
-
-        static void afterPropertiesSet(Object importer) throws Exception {
-            ((InitializingBean) importer).afterPropertiesSet();
-        }
-
-        static void setFilter(Object importer, String filter) {
-            if (importer instanceof OsgiServiceProxyFactoryBean) {
-                ((OsgiServiceProxyFactoryBean) importer).setFilter(filter);
-            } else {
-                ((OsgiServiceCollectionProxyFactoryBean) importer).setFilter(filter);
-            }
-        }
-
-
-        @SuppressWarnings("unused")
-        static void setServiceBean(Object importer, String name) {
-            if (importer instanceof OsgiServiceProxyFactoryBean) {
-                ((OsgiServiceProxyFactoryBean) importer).setServiceBeanName(name);
-            } else {
-                ((OsgiServiceCollectionProxyFactoryBean) importer).setServiceBeanName(name);
-            }
-        }
-    }
-
-    @Override
-    public void setBeanClassLoader(ClassLoader classLoader) {
-        this.classLoader = classLoader;
-    }
-
-    /**
-     * process FactoryBean created objects, since these will not have had
-     * services injected.
-     * 
-     * @param bean
-     * @param beanName
-     */
-    @Override
-    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
-        logger.debug("processing [{}, {}]", bean.getClass().getName(), beanName);
-        // Catch FactoryBean created instances.
-        if (!(bean instanceof FactoryBean) && beanFactory.containsBean(BeanFactory.FACTORY_BEAN_PREFIX + beanName)) {
-            injectServices(bean, beanName);
-        }
-        return bean;
-    }
-
-    /* private version of the injector can use */
-    private void injectServices(final Object bean, final String beanName) {
-        ReflectionUtils.doWithMethods(bean.getClass(),
-            method -> {
-                A s = AnnotationUtils.getAnnotation(method, getAnnotation());
-                if (s != null && method.getParameterTypes().length == 1) {
-                    try {
-                        logger.debug("Processing annotation [{}] for [{}.{}()] on bean [{}]", s, bean.getClass().getName(), method.getName(), beanName);
-                        method.invoke(bean, getServiceImporter(s, method, beanName).getObject());
-                    } catch (Exception e) {
-                        throw new IllegalArgumentException("Error processing annotation " + s, e);
-                    }
-                }
-            });
-    }
-
-    @Override
-    @SuppressWarnings("rawtypes")
-    public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean,
-            String beanName) throws BeansException {
-
-        MutablePropertyValues newprops = new MutablePropertyValues(pvs);
-        for (PropertyDescriptor pd : pds) {
-            A s = findAnnotatedProperty(pd);
-            if (s != null && !pvs.contains(pd.getName())) {
-                try {
-                    logger.debug("Processing annotation [{}] for [{}.{}]", s, beanName, pd.getName());
-                    FactoryBean importer = getServiceImporter(s, pd.getWriteMethod(), beanName);
-                    // BPPs are created in stageOne(), even though they are run in stageTwo(). This check means that
-                    // the call to getObject() will not fail with ServiceUnavailable. This is safe to do because
-                    // ServiceReferenceDependencyBeanFactoryPostProcessor will ensure that mandatory services are
-                    // satisfied before stageTwo() is run.
-                    if (bean instanceof BeanPostProcessor) {
-                        ImporterCallAdapter.setCardinality(importer, Cardinality.C_0__1);
-                    }
-                    newprops.addPropertyValue(pd.getName(), importer.getObject());
-                } catch (Exception e) {
-                    throw new FatalBeanException("Could not create service reference", e);
-                }
-            }
-        }
-        return newprops;
-    }
-
-    @SuppressWarnings("rawtypes")
-    private FactoryBean getServiceImporter(A s, Method writeMethod, String beanName) throws Exception {
-        // Invocations will block here, so although the ApplicationContext is
-        // created nothing will
-        // proceed until all the dependencies are satisfied.
-        Class<?>[] params = writeMethod.getParameterTypes();
-        if (params.length != 1) {
-            throw new IllegalArgumentException("Setter for [" + beanName + "] must have only one argument");
-        }
-
-        if (lookupBeanFactory) {
-            logger.debug("Lookup the bean via the BeanFactory");
-
-            final Class<?> clazz = writeMethod.getParameterTypes()[0];
-            Object bean;
-            try {
-                bean = getBeanFromFactory(s, clazz);
-            } catch (NoSuchBeanDefinitionException e) {
-                // We was not able to find the bean in the factory so fallback to the osgi registry
-                bean = null;
-            }
-            
-            if (bean != null) {
-                final Object fBean = bean;
-                
-                // Create a new FactoryBean which just return the found beab
-                return new FactoryBean() {
-
-                    @Override
-                    public Object getObject() throws Exception {
-                        return fBean;
-                    }
-
-                    @Override
-                    public Class getObjectType() {
-                        return fBean.getClass();
-                    }
-
-                    @Override
-                    public boolean isSingleton() {
-                        return true;
-                    }
-                };
-            }
-        }
-        // The bean was not found in the BeanFactory. Its time to lookup it via the OSGI-Registry
-        return getResourceProperty(new OsgiServiceProxyFactoryBean(), getFilter(s), writeMethod, beanName);
-    }
-
-    
-
-    @SuppressWarnings("rawtypes")
-    private FactoryBean getResourceProperty(OsgiServiceProxyFactoryBean pfb,  String filter, Method writeMethod, String beanName) throws Exception {
-        pfb.setTimeout(timeout);
-        
-        // check if the we have a name for the requested bean. If so we set the filter for it
-        if (filter != null) {
-            ImporterCallAdapter.setFilter(pfb, filter);
-        }
-        ImporterCallAdapter.setInterfaces(pfb, writeMethod.getParameterTypes());
-        
-        ImporterCallAdapter.setBundleContext(pfb, bundleContext);
-        ImporterCallAdapter.setBeanClassLoader(pfb, classLoader);
-        ImporterCallAdapter.afterPropertiesSet(pfb);
-        return pfb;
-    }
-
-
-    private A findAnnotatedProperty(PropertyDescriptor propertyDescriptor) {
-        Method setter = propertyDescriptor.getWriteMethod();
-        return setter != null ? AnnotationUtils.getAnnotation(setter, getAnnotation()) : null;
-    }
-
-    @Override
-    public void setBundleContext(BundleContext context) {
-        this.bundleContext = context;
-    }
-
-    @Override
-    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
-        this.beanFactory = beanFactory;
-    }
-    
-
-    /**
-     * Return the class of the {@link Annotation}
-     * 
-     * @return clazz
-     */
-    protected abstract Class<A> getAnnotation();
-    
-    /**
-     * Return the filter which should get used to lookup the service in the osgi registry.
-     * If no special filter should be used, just return null
-     * 
-     * @param annotation
-     * @return filter
-     */
-    protected abstract String getFilter(A annotation);
-    
-    /**
-     * Return the Bean lookup-ed from the {@link BeanFactory}. If non can be found just return null
-     * 
-     * @param a
-     * @param clazz
-     * @return bean
-     */
-    protected abstract Object getBeanFromFactory(A a, Class<?> clazz);
-    
-}
-
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIConfigurationProvider.java b/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIConfigurationProvider.java
deleted file mode 100644
index 426e37d..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIConfigurationProvider.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.lifecycle.osgi;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-
-import org.apache.commons.configuration2.HierarchicalConfiguration;
-import org.apache.commons.configuration2.ex.ConfigurationException;
-import org.apache.commons.configuration2.tree.ImmutableNode;
-import org.apache.james.server.core.configuration.FileConfigurationProvider;
-
-public class OSGIConfigurationProvider implements org.apache.james.container.spring.lifecycle.ConfigurationProvider {
-
-    @Override
-    public void registerConfiguration(String beanName, HierarchicalConfiguration<ImmutableNode> conf) {
-        
-    }
-
-    @Override
-    public HierarchicalConfiguration<ImmutableNode> getConfiguration(String beanName) throws ConfigurationException {
-        try (FileInputStream fis = new FileInputStream("/tmp/" + beanName + ".xml")) {
-            return FileConfigurationProvider.getConfig(fis);
-        } catch (IOException e) {
-            throw new ConfigurationException("Bean " + beanName);
-        }
-        // Left empty on purpose
-    }
-
-}
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIPersistenceUnitAnnotationBeanPostProcessor.java b/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIPersistenceUnitAnnotationBeanPostProcessor.java
deleted file mode 100644
index 56ca90c..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIPersistenceUnitAnnotationBeanPostProcessor.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.lifecycle.osgi;
-
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceUnit;
-
-/**
- * Inject the {@link EntityManagerFactory} if an method is marked with the {@link PersistenceUnit} annotation
- */
-public class OSGIPersistenceUnitAnnotationBeanPostProcessor extends AbstractOSGIAnnotationBeanPostProcessor<PersistenceUnit> {
-
-    @Override
-    protected Class<PersistenceUnit> getAnnotation() {
-        return PersistenceUnit.class;
-    }
-
-    @Override
-    protected String getFilter(PersistenceUnit a) {
-        return null;
-    }
-
-    @Override
-    protected Object getBeanFromFactory(PersistenceUnit a, Class<?> clazz) {
-        return beanFactory.getBean(clazz);
-    }
-
-}
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIResourceAnnotationBeanPostProcessor.java b/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIResourceAnnotationBeanPostProcessor.java
deleted file mode 100644
index cd8b485..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIResourceAnnotationBeanPostProcessor.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.lifecycle.osgi;
-
-import javax.annotation.Resource;
-
-import org.springframework.osgi.service.exporter.OsgiServicePropertiesResolver;
-
-public class OSGIResourceAnnotationBeanPostProcessor extends AbstractOSGIAnnotationBeanPostProcessor<Resource> {
-
-    @Override
-    protected Class<Resource> getAnnotation() {
-        return Resource.class;
-    }
-
-    @Override
-    protected String getFilter(Resource a) {
-        return  "(" + OsgiServicePropertiesResolver.BEAN_NAME_PROPERTY_KEY + "=" + a.name() + ")";
-    }
-    
-    @Override
-    protected Object getBeanFromFactory(Resource a, Class<?> clazz) {
-        return beanFactory.getBean(a.name(), clazz);
-    }
-    
-}
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/AbstractBundleTracker.java b/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/AbstractBundleTracker.java
deleted file mode 100644
index 637aeb0..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/AbstractBundleTracker.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.osgi;
-
-import java.net.URL;
-import java.util.Enumeration;
-
-import org.apache.commons.configuration2.HierarchicalConfiguration;
-import org.apache.commons.configuration2.tree.ImmutableNode;
-import org.apache.james.container.spring.lifecycle.ConfigurationProvider;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleListener;
-import org.osgi.framework.ServiceReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.BeanFactoryAware;
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.context.ApplicationContext;
-import org.springframework.osgi.context.BundleContextAware;
-import org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext;
-import org.springframework.osgi.service.exporter.OsgiServicePropertiesResolver;
-import org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean;
-
-/**
- * This {@link BundleListener} use the extender pattern to scan all loaded
- * bundles if a class name with a given name is present. If so it register in
- * the {@link BeanDefinitionRegistry} and also register it to the OSG-Registry via an {@link OsgiServiceFactoryBean}
- * 
- */
-public abstract class AbstractBundleTracker implements BeanFactoryAware, BundleListener, BundleContextAware, InitializingBean, DisposableBean {
-
-    private BundleContext context;
-    private String configuredClass;
-    private volatile OsgiServiceFactoryBean osgiFactoryBean;
-    private BeanFactory factory;
-    private final Logger logger = LoggerFactory.getLogger(AbstractBundleTracker.class);
-    
-    @Override
-    public void setBeanFactory(BeanFactory factory) throws BeansException {
-        this.factory = factory;
-    }
-
-    @Override
-    public void setBundleContext(BundleContext context) {
-        this.context = context;
-    }
-
-    @Override
-    public void bundleChanged(BundleEvent event) {
-        Bundle b = event.getBundle();
-
-        // Check if the event was fired for this class
-        if (b.equals(this.context.getBundle())) {
-            return;
-        }
-
-        switch (event.getType()) {
-        case BundleEvent.STARTED:
-            Enumeration<?> entrs = b.findEntries("/", "*.class", true);
-            if (entrs != null) {
-
-                // Loop over all the classes
-                while (entrs.hasMoreElements()) {
-                    URL e = (URL) entrs.nextElement();
-                    String file = e.getFile();
-
-                    String className = file.replaceAll("/", ".").replaceAll("\\.class", "").replaceFirst("\\.", "");
-                    if (className.equals(configuredClass)) {
-                        try {
-
-                            BeanFactory bFactory = getBeanFactory(b.getBundleContext());
-                            Class<?> clazz = getServiceClass();
-
-                            // Create the definition and register it
-                            BeanDefinitionRegistry registry = (BeanDefinitionRegistry) bFactory;
-                            BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(className).getBeanDefinition();
-                            registry.registerBeanDefinition(getComponentName(), def);
-
-                            // register the bean as service in the OSGI-Registry
-                            osgiFactoryBean = new OsgiServiceFactoryBean();
-                            osgiFactoryBean.setTargetBeanName(getComponentName());
-                            osgiFactoryBean.setBeanFactory(bFactory);
-                            osgiFactoryBean.setBundleContext(b.getBundleContext());
-                            osgiFactoryBean.setInterfaces(new Class[] { clazz });
-                            osgiFactoryBean.afterPropertiesSet();
-                            logger.debug("Registered {} in the OSGI-Registry with interface {}", configuredClass, clazz.getName());
-                        } catch (Exception e1) {
-                            logger.error("Unable to register {} in the OSGI-Registry", configuredClass, e1);
-                        }
-                    }
-                }
-            }
-            break;
-        case BundleEvent.STOPPED:
-            // check if we need to destroy the OsgiFactoryBean. This also include the unregister from the OSGI-Registry
-            if (osgiFactoryBean != null) {
-                osgiFactoryBean.destroy();
-                osgiFactoryBean = null;
-                logger.debug("Unregistered {} in the OSGI-Registry with interface {}", configuredClass, getServiceClass().getName());
-
-            }
-            break;
-        default:
-            break;
-        }
-
-    }
-
-    
-    /**
-     * Return the {@link BeanFactory} for the given {@link BundleContext}. If none can be found we just create a new {@link AbstractDelegatedExecutionApplicationContext} and return the {@link BeanFactory} of it
-     * 
-     * 
-     * @param bundleContext
-     * @return factory
-     * @throws Exception
-     */
-    private BeanFactory getBeanFactory(BundleContext bundleContext) throws Exception {
-        final String filter = "(" + OsgiServicePropertiesResolver.BEAN_NAME_PROPERTY_KEY + "=" + bundleContext.getBundle().getSymbolicName() + ")";
-        final ServiceReference<?>[] applicationContextRefs = bundleContext.getServiceReferences(ApplicationContext.class.getName(), filter);
-        
-        // Check if we found an ApplicationContext. If not create one
-        if (applicationContextRefs == null || applicationContextRefs.length != 1) {
-            
-            // Create a new context which just serve as registry later
-            AbstractDelegatedExecutionApplicationContext context = new AbstractDelegatedExecutionApplicationContext() {
-            };
-            context.setBundleContext(bundleContext);
-            context.setPublishContextAsService(true);
-            context.refresh();
-            return context.getBeanFactory();
-        } else {
-            return ((ApplicationContext) bundleContext.getService(applicationContextRefs[0])).getAutowireCapableBeanFactory();
-        }
-       
-       
-    }
-
-    @Override
-    public void afterPropertiesSet() throws Exception {
-        ConfigurationProvider confProvider = factory.getBean(ConfigurationProvider.class);
-        HierarchicalConfiguration<ImmutableNode> config = confProvider.getConfiguration(getComponentName());
-
-        // Get the configuration for the class
-        configuredClass = config.getString("[@class]");
-        if (context != null) {
-            context.addBundleListener(this);
-        }
-    }
-
-    @Override
-    public void destroy() throws Exception {
-        // Its time to unregister the listener so we are sure resources are released
-        if (context != null) {
-            context.removeBundleListener(this);
-        }
-    }
-
-    /**
-     * Return the name of the component
-     * 
-     * @return name
-     */
-    protected abstract String getComponentName();
-
-    /**
-     * Return the class which will be used to expose the service in the OSGI
-     * registry
-     * 
-     * @return sClass
-     */
-    protected abstract Class<?> getServiceClass();
-
-}
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/DomainListTracker.java b/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/DomainListTracker.java
deleted file mode 100644
index 9d94886..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/DomainListTracker.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.osgi;
-
-import org.apache.james.domainlist.api.DomainList;
-
-public class DomainListTracker extends AbstractBundleTracker {
-
-    @Override
-    protected String getComponentName() {
-        return "domainlist";
-    }
-
-    @Override
-    protected Class<?> getServiceClass() {
-        return DomainList.class;
-    }
-
-}
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/RecipientRewriteTableTracker.java b/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/RecipientRewriteTableTracker.java
deleted file mode 100644
index 3126604..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/RecipientRewriteTableTracker.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.osgi;
-
-import org.apache.james.rrt.api.RecipientRewriteTable;
-
-public class RecipientRewriteTableTracker extends AbstractBundleTracker {
-
-    @Override
-    protected String getComponentName() {
-        return "recipientrewritetable";
-    }
-
-    @Override
-    protected Class<?> getServiceClass() {
-        return RecipientRewriteTable.class;
-    }
-
-}
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/UsersRepositoryTracker.java b/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/UsersRepositoryTracker.java
deleted file mode 100644
index e956e47..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/UsersRepositoryTracker.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.osgi;
-
-import org.apache.james.user.api.UsersRepository;
-
-public class UsersRepositoryTracker extends AbstractBundleTracker {
-
-    
-    @Override
-    protected String getComponentName() {
-        return "usersrepository";
-    }
-    
-    @Override
-    protected Class<?> getServiceClass() {
-        return UsersRepository.class;
-    }
-
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 08/30: JAMES-3179 Fix wrong regex patterns

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 6613579a5a993ff1b68d0fb4bb7fe540377a1372
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 15:33:22 2020 +0200

    JAMES-3179 Fix wrong regex patterns
---
 .../org/apache/james/container/spring/osgi/AbstractBundleTracker.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/AbstractBundleTracker.java b/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/AbstractBundleTracker.java
index d2879bd..637aeb0 100644
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/AbstractBundleTracker.java
+++ b/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/AbstractBundleTracker.java
@@ -88,7 +88,7 @@ public abstract class AbstractBundleTracker implements BeanFactoryAware, BundleL
                     URL e = (URL) entrs.nextElement();
                     String file = e.getFile();
 
-                    String className = file.replaceAll("/", ".").replaceAll(".class", "").replaceFirst(".", "");
+                    String className = file.replaceAll("/", ".").replaceAll("\\.class", "").replaceFirst("\\.", "");
                     if (className.equals(configuredClass)) {
                         try {
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 14/30: JAMES-3179 Use a Consumer instead of a Function in FakeSmtp

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit c3c598ff8d2091283f78d3a25bf26038a6e3e0e7
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 15:42:09 2020 +0200

    JAMES-3179 Use a Consumer instead of a Function in FakeSmtp
---
 server/testing/src/main/java/org/apache/james/utils/FakeSmtp.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/server/testing/src/main/java/org/apache/james/utils/FakeSmtp.java b/server/testing/src/main/java/org/apache/james/utils/FakeSmtp.java
index d6a2d1c..89c15d1 100644
--- a/server/testing/src/main/java/org/apache/james/utils/FakeSmtp.java
+++ b/server/testing/src/main/java/org/apache/james/utils/FakeSmtp.java
@@ -25,7 +25,7 @@ import static io.restassured.config.RestAssuredConfig.newConfig;
 
 import java.nio.charset.StandardCharsets;
 import java.time.Duration;
-import java.util.function.Function;
+import java.util.function.Consumer;
 
 import org.apache.james.util.docker.DockerContainer;
 import org.apache.james.util.docker.Images;
@@ -89,8 +89,8 @@ public class FakeSmtp implements TestRule {
         return container.apply(statement, description);
     }
 
-    public void assertEmailReceived(Function<ValidatableResponse, ValidatableResponse> expectations) {
-        expectations.apply(
+    public void assertEmailReceived(Consumer<ValidatableResponse> expectations) {
+        expectations.accept(
             given(requestSpecification(), RESPONSE_SPECIFICATION)
                 .get("/api/email")
             .then()


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 27/30: JAMES-3179 Fix BayesianAnalysis thread safety issue

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit f78e7a23a9dd90ddd4a75a40a4f493dcf3e4d972
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Thu May 14 11:45:40 2020 +0200

    JAMES-3179 Fix BayesianAnalysis thread safety issue
---
 .../java/org/apache/james/ai/classic/BayesianAnalysis.java  | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/mailet/ai/src/main/java/org/apache/james/ai/classic/BayesianAnalysis.java b/mailet/ai/src/main/java/org/apache/james/ai/classic/BayesianAnalysis.java
index 865f6d9..48f87c4 100644
--- a/mailet/ai/src/main/java/org/apache/james/ai/classic/BayesianAnalysis.java
+++ b/mailet/ai/src/main/java/org/apache/james/ai/classic/BayesianAnalysis.java
@@ -180,17 +180,6 @@ public class BayesianAnalysis extends GenericMailet {
     }
 
     /**
-     * Setter for property maxSize.
-     * 
-     * @param maxSize
-     *            New value of property maxSize.
-     */
-    public void setMaxSize(int maxSize) {
-
-        this.maxSize = maxSize;
-    }
-
-    /**
      * Getter for property lastCorpusLoadTime.
      * 
      * @return Value of property lastCorpusLoadTime.
@@ -244,7 +233,7 @@ public class BayesianAnalysis extends GenericMailet {
 
         String maxSizeParam = getInitParameter("maxSize");
         if (maxSizeParam != null) {
-            setMaxSize(Integer.parseInt(maxSizeParam));
+            this.maxSize = Integer.parseInt(maxSizeParam);
         }
         LOGGER.debug("maxSize: {}", getMaxSize());
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 06/30: JAMES-3179 Fix AbstractMessageRangeRequest hashCode

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit d327f9856e7a983d78af93044bee2c47788bd114
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 15:30:58 2020 +0200

    JAMES-3179 Fix AbstractMessageRangeRequest hashCode
---
 .../apache/james/imap/message/request/AbstractMessageRangeRequest.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java b/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java
index 8632240..59571e5 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java
@@ -74,6 +74,6 @@ public abstract class AbstractMessageRangeRequest extends AbstractImapRequest {
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(idSet, mailboxName, useUids);
+        return Objects.hashCode(Arrays.hashCode(idSet), mailboxName, useUids);
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 17/30: JAMES-3179 Fix UrlResource InputStream leaks

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 95373094887123570f0b209882055ba26de3d319
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 15:56:31 2020 +0200

    JAMES-3179 Fix UrlResource InputStream leaks
---
 .../configuration/FileConfigurationProvider.java   |  5 ++++
 .../mailrepository/jdbc/JDBCMailRepository.java    | 31 ++++++++++------------
 .../james/jmap/draft/crypto/SecurityKeyLoader.java |  8 +++---
 3 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/server/container/core/src/main/java/org/apache/james/server/core/configuration/FileConfigurationProvider.java b/server/container/core/src/main/java/org/apache/james/server/core/configuration/FileConfigurationProvider.java
index 48b965b..0297774 100644
--- a/server/container/core/src/main/java/org/apache/james/server/core/configuration/FileConfigurationProvider.java
+++ b/server/container/core/src/main/java/org/apache/james/server/core/configuration/FileConfigurationProvider.java
@@ -57,6 +57,11 @@ public class FileConfigurationProvider implements ConfigurationProvider {
         XMLConfiguration xmlConfiguration = builder.getConfiguration();
         FileHandler fileHandler = new FileHandler(xmlConfiguration);
         fileHandler.load(configStream);
+        try {
+            configStream.close();
+        } catch (IOException ignored) {
+            // Ignored
+        }
 
         return xmlConfiguration;
     }
diff --git a/server/data/data-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/JDBCMailRepository.java b/server/data/data-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/JDBCMailRepository.java
index ac64737..344c4c3 100644
--- a/server/data/data-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/JDBCMailRepository.java
+++ b/server/data/data-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/JDBCMailRepository.java
@@ -263,28 +263,25 @@ public class JDBCMailRepository implements MailRepository, Configurable, Initial
 
         try (Connection conn = datasource.getConnection()) {
             // Initialise the sql strings.
-            InputStream sqlFile;
-            try {
-                sqlFile = fileSystem.getResource(sqlFileName);
+            try (InputStream sqlFile = fileSystem.getResource(sqlFileName)) {
+                LOGGER.debug("Reading SQL resources from file: {}, section {}.", sqlFileName, getClass().getName());
+
+                // Build the statement parameters
+                Map<String, String> sqlParameters = new HashMap<>();
+                if (tableName != null) {
+                    sqlParameters.put("table", tableName);
+                }
+                if (repositoryName != null) {
+                    sqlParameters.put("repository", repositoryName);
+                }
+
+                sqlQueries = new SqlResources();
+                sqlQueries.init(sqlFile, this.getClass().getName(), conn, sqlParameters);
             } catch (Exception e) {
                 LOGGER.error(e.getMessage(), e);
                 throw e;
             }
 
-            LOGGER.debug("Reading SQL resources from file: {}, section {}.", sqlFileName, getClass().getName());
-
-            // Build the statement parameters
-            Map<String, String> sqlParameters = new HashMap<>();
-            if (tableName != null) {
-                sqlParameters.put("table", tableName);
-            }
-            if (repositoryName != null) {
-                sqlParameters.put("repository", repositoryName);
-            }
-
-            sqlQueries = new SqlResources();
-            sqlQueries.init(sqlFile, this.getClass().getName(), conn, sqlParameters);
-
             // Check if the required table exists. If not, create it.
             DatabaseMetaData dbMetaData = conn.getMetaData();
             // Need to ask in the case that identifiers are stored, ask the
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/crypto/SecurityKeyLoader.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/crypto/SecurityKeyLoader.java
index 38da9c4..6b208ca 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/crypto/SecurityKeyLoader.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/crypto/SecurityKeyLoader.java
@@ -55,9 +55,11 @@ public class SecurityKeyLoader {
         Preconditions.checkState(jmapDraftConfiguration.isEnabled(), "JMAP is not enabled");
 
         KeyStore keystore = KeyStore.getInstance(JKS);
-        InputStream fis = fileSystem.getResource(jmapDraftConfiguration.getKeystore());
-        char[] secret = jmapDraftConfiguration.getSecret().toCharArray();
-        keystore.load(fis, secret);
+        char[] secret;
+        try (InputStream fis = fileSystem.getResource(jmapDraftConfiguration.getKeystore())) {
+            secret = jmapDraftConfiguration.getSecret().toCharArray();
+            keystore.load(fis, secret);
+        }
         Certificate aliasCertificate = Optional
                 .ofNullable(keystore.getCertificate(ALIAS))
                 .orElseThrow(() -> new KeyStoreException("Alias '" + ALIAS + "' keystore can't be found"));


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 10/30: JAMES-3179 Fix RemoteDeliveryConfiguration class configuration

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit f798f6d01b579926952bbfa412e8e4da9b2092db
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 15:35:37 2020 +0200

    JAMES-3179 Fix RemoteDeliveryConfiguration class configuration
---
 .../transport/mailets/remote/delivery/RemoteDeliveryConfiguration.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/RemoteDeliveryConfiguration.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/RemoteDeliveryConfiguration.java
index 68ef607..0cbee09 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/RemoteDeliveryConfiguration.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/RemoteDeliveryConfiguration.java
@@ -225,7 +225,7 @@ public class RemoteDeliveryConfiguration {
         if (isBindUsed()) {
             // undocumented JavaMail 1.2 feature, smtp transport will use
             // our socket factory, which will also set the local address
-            props.put("mail.smtp.socketFactory.class", RemoteDeliverySocketFactory.class.getClass());
+            props.put("mail.smtp.socketFactory.class", RemoteDeliverySocketFactory.class);
             // Don't fallback to the standard socket factory on error, do throw an exception
             props.put("mail.smtp.socketFactory.fallback", "false");
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 21/30: JAMES-3179 Deal with ResultUtils nullability

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit a1da25b65264c05b4209d8decd13a12a0cf46622
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 17:20:46 2020 +0200

    JAMES-3179 Deal with ResultUtils nullability
---
 .../src/main/java/org/apache/james/mailbox/model/FetchGroup.java  | 2 +-
 .../src/main/java/org/apache/james/mailbox/store/ResultUtils.java | 8 +++++---
 .../test/java/org/apache/james/mailbox/store/ResultUtilsTest.java | 7 ++++++-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java
index 37913bd..395821a 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java
@@ -60,7 +60,7 @@ public class FetchGroup extends Profiles<FetchGroup> {
     }
 
     @VisibleForTesting
-    FetchGroup(Collection<Profile> content, ImmutableSet<PartContentDescriptor> partContentDescriptors) {
+    public FetchGroup(Collection<Profile> content, ImmutableSet<PartContentDescriptor> partContentDescriptors) {
         super(content);
         this.partContentDescriptors = partContentDescriptors;
     }
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java
index 31efbfe..1c00394 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java
@@ -216,9 +216,11 @@ public class ResultUtils {
     private static void addMimeBodyContent(MailboxMessage message, MessageResultImpl messageResult, MimePath mimePath)
             throws IOException, MimeException {
         int[] path = path(mimePath);
-        PartContentBuilder builder = build(path, message);
-        Content content = builder.getMimeBodyContent();
-        messageResult.setMimeBodyContent(mimePath, content);
+        if (path != null) {
+            PartContentBuilder builder = build(path, message);
+            Content content = builder.getMimeBodyContent();
+            messageResult.setMimeBodyContent(mimePath, content);
+        }
     }
 
     private static void addFullContent(MailboxMessage message, MessageResultImpl messageResult, MimePath mimePath)
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/ResultUtilsTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/ResultUtilsTest.java
index d122cbd..5ffeaed 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/ResultUtilsTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/ResultUtilsTest.java
@@ -21,14 +21,18 @@ package org.apache.james.mailbox.store;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.util.EnumSet;
 import java.util.stream.Stream;
 
 import org.apache.james.mailbox.model.FetchGroup;
 import org.apache.james.mailbox.model.FetchGroup.Profile;
+import org.apache.james.mailbox.model.PartContentDescriptor;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
 
+import com.google.common.collect.ImmutableSet;
+
 class ResultUtilsTest {
     static Stream<Arguments> haveValidContent() {
         return Stream.of(
@@ -37,7 +41,8 @@ class ResultUtilsTest {
             Arguments.of(FetchGroup.FULL_CONTENT),
             Arguments.of(FetchGroup.HEADERS),
             Arguments.of(FetchGroup.BODY_CONTENT),
-            Arguments.of(FetchGroup.BODY_CONTENT.with(Profile.HEADERS)));
+            Arguments.of(FetchGroup.BODY_CONTENT.with(Profile.HEADERS)),
+            Arguments.of(new FetchGroup(EnumSet.of(Profile.BODY_CONTENT), ImmutableSet.of(new PartContentDescriptor(null)))));
     }
 
     @ParameterizedTest


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 29/30: JAMES-3179 Fix UpdatableTickingClock thread safety issue

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 6c8d92204875de71dbc1f9dee4f3702b9e8622d6
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Thu May 14 13:17:20 2020 +0200

    JAMES-3179 Fix UpdatableTickingClock thread safety issue
---
 .../src/main/java/org/apache/james/utils/UpdatableTickingClock.java    | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/server/testing/src/main/java/org/apache/james/utils/UpdatableTickingClock.java b/server/testing/src/main/java/org/apache/james/utils/UpdatableTickingClock.java
index e7f6a86..017db2d 100644
--- a/server/testing/src/main/java/org/apache/james/utils/UpdatableTickingClock.java
+++ b/server/testing/src/main/java/org/apache/james/utils/UpdatableTickingClock.java
@@ -25,6 +25,8 @@ import java.time.ZoneId;
 
 import org.apache.commons.lang3.NotImplementedException;
 
+import com.google.common.annotations.VisibleForTesting;
+
 public class UpdatableTickingClock extends Clock {
     private Instant currentInstant;
 
@@ -32,6 +34,7 @@ public class UpdatableTickingClock extends Clock {
         this.currentInstant = currentInstant;
     }
 
+    @VisibleForTesting
     public void setInstant(Instant instant) {
         currentInstant = instant;
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 19/30: JAMES-3179 Fix a ImapRequestFrameDecoder leak

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit ddf638b56ef30ab2bd859556fd8d1c0a07b3dc6e
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 16:38:26 2020 +0200

    JAMES-3179 Fix a ImapRequestFrameDecoder leak
---
 .../james/imap/decode/ImapRequestStreamLineReader.java       | 12 ++++++++++--
 .../james/imapserver/netty/ImapRequestFrameDecoder.java      |  9 +++++++++
 .../imapserver/netty/NettyStreamImapRequestLineReader.java   |  6 ++++--
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestStreamLineReader.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestStreamLineReader.java
index bbc7445..11c277b 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestStreamLineReader.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestStreamLineReader.java
@@ -19,6 +19,7 @@
 
 package org.apache.james.imap.decode;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -31,9 +32,8 @@ import com.google.common.io.ByteStreams;
 /**
  * {@link ImapRequestLineReader} which use normal IO Streaming
  */
-public class ImapRequestStreamLineReader extends ImapRequestLineReader {
+public class ImapRequestStreamLineReader extends ImapRequestLineReader implements Closeable {
     private final InputStream input;
-
     private final OutputStream output;
 
     public ImapRequestStreamLineReader(InputStream input, OutputStream output) {
@@ -102,4 +102,12 @@ public class ImapRequestStreamLineReader extends ImapRequestLineReader {
         }
     }
 
+    @Override
+    public void close() throws IOException {
+        try {
+            input.close();
+        } finally {
+            output.close();
+        }
+    }
 }
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
index c8e35de..bebc259 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
@@ -19,6 +19,7 @@
 
 package org.apache.james.imapserver.netty;
 
+import java.io.Closeable;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -211,6 +212,14 @@ public class ImapRequestFrameDecoder extends FrameDecoder implements NettyConsta
                 
                 buffer.resetReaderIndex();
                 return null;
+            } finally {
+                if (reader instanceof Closeable) {
+                    try {
+                        ((Closeable) reader).close();
+                    } catch (IOException ignored) {
+                        // Nothing to do
+                    }
+                }
             }
         } else {
             // The session was null so may be the case because the channel was already closed but there were still bytes in the buffer.
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyStreamImapRequestLineReader.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyStreamImapRequestLineReader.java
index d6b2f61..562f271 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyStreamImapRequestLineReader.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyStreamImapRequestLineReader.java
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.imapserver.netty;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -28,7 +29,7 @@ import org.jboss.netty.channel.Channel;
 
 import com.google.common.io.ByteStreams;
 
-public class NettyStreamImapRequestLineReader extends AbstractNettyImapRequestLineReader {
+public class NettyStreamImapRequestLineReader extends AbstractNettyImapRequestLineReader implements Closeable {
 
     private final InputStream in;
 
@@ -96,7 +97,8 @@ public class NettyStreamImapRequestLineReader extends AbstractNettyImapRequestLi
         
     }
 
-    public void dispose() throws IOException {
+    @Override
+    public void close() throws IOException {
         in.close();
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 07/30: JAMES-3179 Fix date formats

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 338a23241c2bbb6fbf6d53eb440c73f2ff8ef0c9
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 15:32:41 2020 +0200

    JAMES-3179 Fix date formats
---
 .../java/org/apache/james/imap/decode/DecoderUtilsLocaleDateTest.java | 2 +-
 .../src/test/java/org/apache/james/imap/decode/DecoderUtilsTest.java  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsLocaleDateTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsLocaleDateTest.java
index 64a4475..ad1c5e8 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsLocaleDateTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsLocaleDateTest.java
@@ -175,7 +175,7 @@ public class DecoderUtilsLocaleDateTest {
         LocalDateTime localDateTime = DecoderUtils.decodeDateTime(input);
         assertThat(ZonedDateTime.of(localDateTime, ZoneId.systemDefault())
             .withZoneSameInstant(ZoneId.of("GMT"))
-            .format(DateTimeFormatter.ofPattern("dd MMM YYYY HH:mm:ss VV", Locale.US)))
+            .format(DateTimeFormatter.ofPattern("dd MMM yyyy HH:mm:ss VV", Locale.US)))
             .isEqualTo(expected);
     }
 }
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsTest.java
index 19ad193..a0bf1f7 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsTest.java
@@ -159,7 +159,7 @@ class DecoderUtilsTest {
         LocalDateTime localDateTime = DecoderUtils.decodeDateTime(input);
         assertThat(ZonedDateTime.of(localDateTime, ZoneId.systemDefault())
                 .withZoneSameInstant(ZoneId.of("GMT"))
-                .format(DateTimeFormatter.ofPattern("dd MMM YYYY HH:mm:ss VV", Locale.US)))
+                .format(DateTimeFormatter.ofPattern("dd MMM yyyy HH:mm:ss VV", Locale.US)))
             .isEqualTo(parsed);
     }
 
@@ -168,7 +168,7 @@ class DecoderUtilsTest {
         LocalDateTime localDateTime = DecoderUtils.decodeDateTime("09-Apr-2008 15:17:51 +0200");
         assertThat(ZonedDateTime.of(localDateTime, ZoneId.systemDefault())
                 .withZoneSameInstant(ZoneId.of("GMT"))
-                .format(DateTimeFormatter.ofPattern("dd MMM YYYY HH:mm:ss VV", Locale.US)))
+                .format(DateTimeFormatter.ofPattern("dd MMM yyyy HH:mm:ss VV", Locale.US)))
             .isEqualTo("09 Apr 2008 13:17:51 GMT");
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 26/30: JAMES-3179 Remove OsDetector

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit abce10f0a930308a417678b5e1bd8e36983c296e
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Wed May 13 14:11:47 2020 +0200

    JAMES-3179 Remove OsDetector
---
 .../apache/james/mailbox/maildir/OsDetector.java   | 40 ----------------------
 1 file changed, 40 deletions(-)

diff --git a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/OsDetector.java b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/OsDetector.java
deleted file mode 100644
index 7e0fcd1..0000000
--- a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/OsDetector.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/****************************************************************
- * 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.james.mailbox.maildir;
-
-import java.util.Locale;
-import java.util.Optional;
-
-public class OsDetector {
-
-    /**
-     * Return if the Test is run on windows
-     * 
-     * @return windows
-     */
-    public static boolean isWindows() {
-        return Optional.ofNullable(System.getProperty("os.name"))
-            .orElse("")
-            .toLowerCase(Locale.US)
-            .contains("win");
-    }
-    
-    
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 23/30: JAMES-3179 Fix MaildirMessage leak

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 9f15eb226abffa8db30a993410beb4a7c4b15b71
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 17:51:36 2020 +0200

    JAMES-3179 Fix MaildirMessage leak
---
 .../org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java
index 0195b58..d094699 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java
@@ -275,9 +275,9 @@ public class MaildirMessage implements Message {
 
     @Override
     public List<MessageAttachmentMetadata> getAttachments() {
-        try {
+        try (InputStream fullContent = getFullContent()) {
             AtomicInteger counter = new AtomicInteger(0);
-            return new MessageParser().retrieveAttachments(getFullContent())
+            return new MessageParser().retrieveAttachments(fullContent)
                 .stream()
                 .map(Throwing.<ParsedAttachment, MessageAttachmentMetadata>function(
                     attachmentMetadata -> attachmentMetadata.asMessageAttachment(generateFixedAttachmentId(counter.incrementAndGet())))


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 22/30: JAMES-3179 Deal with FetchResponseBuilder nullability

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit e318886c8ce5a730cbe8bc7866fc3c9d884841e6
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 17:48:34 2020 +0200

    JAMES-3179 Deal with FetchResponseBuilder nullability
---
 .../imap/processor/fetch/FetchResponseBuilder.java | 79 +++++++++++-----------
 1 file changed, 38 insertions(+), 41 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
index 4229b5e..bc978b7 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
@@ -29,6 +29,7 @@ import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Objects;
+import java.util.Optional;
 
 import javax.mail.Flags;
 
@@ -221,28 +222,29 @@ public final class FetchResponseBuilder {
         final Long numberOfOctets = fetchElement.getNumberOfOctets();
         final String name = fetchElement.getResponseName();
         final SectionType specifier = fetchElement.getSectionType();
-        final int[] path = fetchElement.getPath();
+        final Optional<MimePath> path = Optional.ofNullable(fetchElement.getPath())
+                .filter(paths -> paths.length > 0)
+                .map(MimePath::new);
         final Collection<String> names = fetchElement.getFieldNames();
-        final boolean isBase = (path == null || path.length == 0);
-        final FetchResponse.BodyElement fullResult = bodyContent(messageResult, name, specifier, path, names, isBase);
+        final FetchResponse.BodyElement fullResult = bodyContent(messageResult, name, specifier, path, names);
         return wrapIfPartialFetch(firstOctet, numberOfOctets, fullResult);
 
     }
 
-    private FetchResponse.BodyElement bodyContent(MessageResult messageResult, String name, SectionType specifier, int[] path, Collection<String> names, boolean isBase) throws MailboxException {
+    private FetchResponse.BodyElement bodyContent(MessageResult messageResult, String name, SectionType specifier, Optional<MimePath> path, Collection<String> names) throws MailboxException {
         switch (specifier) {
             case CONTENT:
-                return content(messageResult, name, path, isBase);
+                return content(messageResult, name, path);
             case HEADER_FIELDS:
-                return fields(messageResult, name, path, names, isBase);
+                return fields(messageResult, name, path, names);
             case HEADER_NOT_FIELDS:
-                return fieldsNot(messageResult, name, path, names, isBase);
+                return fieldsNot(messageResult, name, path, names);
             case MIME:
-                return mimeHeaders(messageResult, name, path, isBase);
+                return mimeHeaders(messageResult, name, path);
             case HEADER:
-                return headers(messageResult, name, path, isBase);
+                return headers(messageResult, name, path);
             case TEXT:
-                return text(messageResult, name, path, isBase);
+                return text(messageResult, name, path);
             default:
                 return null;
         }
@@ -263,18 +265,17 @@ public final class FetchResponseBuilder {
         return result;
     }
 
-    private FetchResponse.BodyElement text(MessageResult messageResult, String name, int[] path, boolean isBase) throws MailboxException {
+    private FetchResponse.BodyElement text(MessageResult messageResult, String name, Optional<MimePath> path) throws MailboxException {
         final FetchResponse.BodyElement result;
         Content body;
-        if (isBase) {
+        if (!path.isPresent()) {
             try {
                 body = messageResult.getBody();
             } catch (IOException e) {
                 throw new MailboxException("Unable to get TEXT of body", e);
             }
         } else {
-            MimePath mimePath = new MimePath(path);
-            body = messageResult.getBody(mimePath);
+            body = messageResult.getBody(path.get());
         }
         if (body == null) {
             body = new EmptyContent();
@@ -283,15 +284,15 @@ public final class FetchResponseBuilder {
         return result;
     }
 
-    private FetchResponse.BodyElement mimeHeaders(MessageResult messageResult, String name, int[] path, boolean isBase) throws MailboxException {
+    private FetchResponse.BodyElement mimeHeaders(MessageResult messageResult, String name, Optional<MimePath> path) throws MailboxException {
         final FetchResponse.BodyElement result;
-        final Iterator<Header> headers = getMimeHeaders(messageResult, path, isBase);
+        final Iterator<Header> headers = getMimeHeaders(messageResult, path);
         List<Header> lines = MessageResultUtils.getAll(headers);
         result = new MimeBodyElement(name, lines);
         return result;
     }
 
-    private HeaderBodyElement headerBodyElement(MessageResult messageResult, String name, List<Header> lines, int[] path, boolean isBase) throws MailboxException {
+    private HeaderBodyElement headerBodyElement(MessageResult messageResult, String name, List<Header> lines, Optional<MimePath> path) throws MailboxException {
         final HeaderBodyElement result = new HeaderBodyElement(name, lines);
         // if the size is 2 we had found not header and just want to write the empty line with CLRF terminated
         // so check if there is a content for it. If not we MUST NOT write the empty line in any case
@@ -300,15 +301,14 @@ public final class FetchResponseBuilder {
             // Check if its base as this can give use a more  correctly working check
             // to see if we need to write the newline out to the client. 
             // This is related to IMAP-298
-            if (isBase) {
+            if (!path.isPresent()) {
                 if (messageResult.getSize() - result.size() <= 0) {
                     // Seems like this mail has no body 
                     result.noBody();
                 }
-              
             } else {
                 try {
-                    if (content(messageResult, name, path, isBase).size() <= 0) {
+                    if (content(messageResult, name, path).size() <= 0) {
                         // Seems like this mail has no body
                         result.noBody();
                     }
@@ -320,8 +320,8 @@ public final class FetchResponseBuilder {
         return result;
     }
     
-    private FetchResponse.BodyElement headers(MessageResult messageResult, String name, int[] path, boolean isBase) throws MailboxException {      
-        if (isBase) {
+    private FetchResponse.BodyElement headers(MessageResult messageResult, String name, Optional<MimePath> path) throws MailboxException {
+        if (!path.isPresent()) {
             // if its base we can just return the raw headers without parsing
             // them. See MAILBOX-311 and IMAP-?
             HeadersBodyElement element = new HeadersBodyElement(name, messageResult.getHeaders());
@@ -337,45 +337,43 @@ public final class FetchResponseBuilder {
             }
             return element;
         } else {
-            final Iterator<Header> headers = getHeaders(messageResult, path, isBase);
+            final Iterator<Header> headers = getHeaders(messageResult, path);
             List<Header> lines = MessageResultUtils.getAll(headers);
-            return headerBodyElement(messageResult, name, lines, path, isBase);
+            return headerBodyElement(messageResult, name, lines, path);
         }
     }
 
-    private FetchResponse.BodyElement fieldsNot(MessageResult messageResult, String name, int[] path, Collection<String> names, boolean isBase) throws MailboxException {
-        final Iterator<Header> headers = getHeaders(messageResult, path, isBase);
+    private FetchResponse.BodyElement fieldsNot(MessageResult messageResult, String name, Optional<MimePath> path, Collection<String> names) throws MailboxException {
+        final Iterator<Header> headers = getHeaders(messageResult, path);
         List<Header> lines = MessageResultUtils.getNotMatching(names, headers);
         
-        return headerBodyElement(messageResult, name, lines, path, isBase);
+        return headerBodyElement(messageResult, name, lines, path);
     }
 
-    private FetchResponse.BodyElement fields(MessageResult messageResult, String name, int[] path, Collection<String> names, boolean isBase) throws MailboxException {
-        final Iterator<Header> headers = getHeaders(messageResult, path, isBase);
+    private FetchResponse.BodyElement fields(MessageResult messageResult, String name, Optional<MimePath> path, Collection<String> names) throws MailboxException {
+        final Iterator<Header> headers = getHeaders(messageResult, path);
         List<Header> lines = MessageResultUtils.getMatching(names, headers);
-        return headerBodyElement(messageResult, name, lines, path, isBase);
+        return headerBodyElement(messageResult, name, lines, path);
     }
 
-    private Iterator<Header> getHeaders(MessageResult messageResult, int[] path, boolean isBase) throws MailboxException {
+    private Iterator<Header> getHeaders(MessageResult messageResult, Optional<MimePath> path) throws MailboxException {
         final Iterator<Header> headers;
-        if (isBase) {
+        if (!path.isPresent()) {
             headers = messageResult.getHeaders().headers();
         } else {
-            MimePath mimePath = new MimePath(path);
-            headers = messageResult.iterateHeaders(mimePath);
+            headers = messageResult.iterateHeaders(path.get());
         }
         return headers;
     }
 
-    private Iterator<Header> getMimeHeaders(MessageResult messageResult, int[] path, boolean isBase) throws MailboxException {
-        MimePath mimePath = new MimePath(path);
-        return messageResult.iterateMimeHeaders(mimePath);
+    private Iterator<Header> getMimeHeaders(MessageResult messageResult, Optional<MimePath> path) throws MailboxException {
+        return messageResult.iterateMimeHeaders(path.get());
     }
 
-    private FetchResponse.BodyElement content(MessageResult messageResult, String name, int[] path, boolean isBase) throws MailboxException {
+    private FetchResponse.BodyElement content(MessageResult messageResult, String name, Optional<MimePath> path) throws MailboxException {
         final FetchResponse.BodyElement result;
         Content full;
-        if (isBase) {
+        if (!path.isPresent()) {
             try {
                 full = messageResult.getFullContent();
 
@@ -383,8 +381,7 @@ public final class FetchResponseBuilder {
                 throw new MailboxException("Unable to get content", e);
             }
         } else {
-            MimePath mimePath = new MimePath(path);
-            full = messageResult.getMimeBody(mimePath);
+            full = messageResult.getMimeBody(path.get());
         }
 
         if (full == null) {


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 03/30: JAMES-3179 Fix QuotaThresholdNoticeTest constant overflow

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 574677337fe3ec66c6772d0972b2dec0eb03bdf8
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 14:07:36 2020 +0200

    JAMES-3179 Fix QuotaThresholdNoticeTest constant overflow
---
 .../mailbox/quota/mailing/subscribers/QuotaThresholdNoticeTest.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdNoticeTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdNoticeTest.java
index 325b111..3a55cdf 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdNoticeTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdNoticeTest.java
@@ -232,7 +232,7 @@ class QuotaThresholdNoticeTest {
             .withConfiguration(DEFAULT_CONFIGURATION)
             .sizeQuota(Quota.<QuotaSizeLimit, QuotaSizeUsage>builder()
                 .used(QuotaSizeUsage.size(801 * 1024 * 1024))
-                .computedLimit(QuotaSizeLimit.size((2 * 1024 * 1024 * 1024) - 1))
+                .computedLimit(QuotaSizeLimit.size((2L * 1024 * 1024 * 1024) - 1))
                 .build())
             .countQuota(Counts._72_PERCENT)
             .sizeThreshold(HistoryEvolution.higherThresholdReached(sizeThresholdChange, NotAlreadyReachedDuringGracePeriod))


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 15/30: JAMES-3179 Suppress harmless ErrorProne errors

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 5f19a090171b8b666a084984beaf6651ef992202
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 15:42:54 2020 +0200

    JAMES-3179 Suppress harmless ErrorProne errors
---
 .../james/mailbox/elasticsearch/query/CriterionConverter.java    | 1 +
 .../org/apache/james/mailbox/quota/model/QuotaThresholdTest.java | 1 +
 .../apache/james/mailbox/store/MailboxMessageResultImplTest.java | 1 +
 mailet/api/src/main/java/org/apache/mailet/Serializer.java       | 1 +
 .../src/test/java/org/apache/james/mpt/api/ImapFeaturesTest.java | 6 ++++--
 .../src/test/java/org/apache/james/util/FunctionalUtilsTest.java | 2 ++
 .../src/test/java/org/apache/james/rrt/lib/MappingsImplTest.java | 9 ++++++---
 7 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
index 0d6c24a..0f99287 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
@@ -215,6 +215,7 @@ public class CriterionConverter {
         }
     }
 
+    @SuppressWarnings("ReturnValueIgnored")
     private BoolQueryBuilder convertToBoolQuery(Stream<QueryBuilder> stream, BiFunction<BoolQueryBuilder, QueryBuilder, BoolQueryBuilder> addCriterionToBoolQuery) {
         return stream.collect(Collector.of(QueryBuilders::boolQuery,
                 addCriterionToBoolQuery::apply,
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdTest.java
index 15a47e8..f53658e 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdTest.java
@@ -133,6 +133,7 @@ public class QuotaThresholdTest {
     }
 
     @Test
+    @SuppressWarnings("SelfComparison")
     public void compareToShouldReturnZeroWhenEquals() {
         assertThat(_75.compareTo(_75))
             .isEqualTo(0);
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxMessageResultImplTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxMessageResultImplTest.java
index af19971..cef27ba 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxMessageResultImplTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxMessageResultImplTest.java
@@ -72,6 +72,7 @@ class MailboxMessageResultImplTest {
 
 
     @Test
+    @SuppressWarnings("SelfComparison")
     void testCompareToReflexive() {
         assertThat(msgResultA.compareTo(msgResultA)).isEqualTo(0);
     }
diff --git a/mailet/api/src/main/java/org/apache/mailet/Serializer.java b/mailet/api/src/main/java/org/apache/mailet/Serializer.java
index 17855e4..cc3f787 100644
--- a/mailet/api/src/main/java/org/apache/mailet/Serializer.java
+++ b/mailet/api/src/main/java/org/apache/mailet/Serializer.java
@@ -59,6 +59,7 @@ import com.google.common.collect.ImmutableMap;
  * 
  * @since Mailet API v3.2
  */
+@SuppressWarnings("EqualsHashCode")
 public interface Serializer<T> {
     JsonNode serialize(T object);
 
diff --git a/mpt/core/src/test/java/org/apache/james/mpt/api/ImapFeaturesTest.java b/mpt/core/src/test/java/org/apache/james/mpt/api/ImapFeaturesTest.java
index d6790ba..8411f84 100644
--- a/mpt/core/src/test/java/org/apache/james/mpt/api/ImapFeaturesTest.java
+++ b/mpt/core/src/test/java/org/apache/james/mpt/api/ImapFeaturesTest.java
@@ -62,13 +62,15 @@ public class ImapFeaturesTest {
     }
 
     @Test(expected = NullPointerException.class)
+    @SuppressWarnings("CheckReturnValue")
     public void supportsShouldThrowOnNullFeature() {
-        assertThat(ImapFeatures.of().supports((Feature)null));
+        ImapFeatures.of().supports((Feature)null);
     }
 
     @Test(expected = NullPointerException.class)
+    @SuppressWarnings("CheckReturnValue")
     public void supportsShouldThrowOnNullFeatureArray() {
-        assertThat(ImapFeatures.of().supports((Feature[])null));
+        ImapFeatures.of().supports((Feature[])null);
     }
 
     
diff --git a/server/container/util/src/test/java/org/apache/james/util/FunctionalUtilsTest.java b/server/container/util/src/test/java/org/apache/james/util/FunctionalUtilsTest.java
index c62653f..9b603be 100644
--- a/server/container/util/src/test/java/org/apache/james/util/FunctionalUtilsTest.java
+++ b/server/container/util/src/test/java/org/apache/james/util/FunctionalUtilsTest.java
@@ -40,6 +40,7 @@ class FunctionalUtilsTest {
         }
 
         @Test
+        @SuppressWarnings("ReturnValueIgnored")
         void toFunctionShouldCallConsumer() {
             Counter counter = new Counter(26);
             Consumer<Integer> consumer = counter::increment;
@@ -58,6 +59,7 @@ class FunctionalUtilsTest {
         }
 
         @Test
+        @SuppressWarnings("ReturnValueIgnored")
         void identityWithSideEffectShouldCallRunnable() {
             Counter counter = new Counter(26);
             Runnable runnable = () -> counter.increment(1);
diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingsImplTest.java b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingsImplTest.java
index 82bbe19..41d428c 100644
--- a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingsImplTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingsImplTest.java
@@ -158,9 +158,10 @@ public class MappingsImplTest {
 
     
     @Test(expected = NullPointerException.class)
+    @SuppressWarnings("CheckReturnValue")
     public void containsShouldThrowWhenNull() {
         MappingsImpl mappings = MappingsImpl.builder().add(Mapping.regex("toto")).build();
-        assertThat(mappings.contains((Mapping.Type)null));
+        mappings.contains((Mapping.Type)null);
     }
     
     @Test
@@ -190,9 +191,10 @@ public class MappingsImplTest {
 
     
     @Test(expected = NullPointerException.class)
+    @SuppressWarnings("CheckReturnValue")
     public void selectShouldThrowWhenNull() {
         MappingsImpl mappings = MappingsImpl.builder().add(Mapping.regex("toto")).build();
-        assertThat(mappings.select((Mapping.Type)null));
+        mappings.select((Mapping.Type)null);
     }
 
     @Test
@@ -221,9 +223,10 @@ public class MappingsImplTest {
 
     
     @Test(expected = NullPointerException.class)
+    @SuppressWarnings("CheckReturnValue")
     public void excludeShouldThrowWhenNull() {
         MappingsImpl mappings = MappingsImpl.builder().add(Mapping.regex("toto")).build();
-        assertThat(mappings.exclude((Mapping.Type)null));
+        mappings.exclude((Mapping.Type)null);
     }
 
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 16/30: JAMES-3179 Deal with nullity in OsDetector

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit e7a191e9dfd4cd985d7cbe9400d719687e4c11b4
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 15:47:17 2020 +0200

    JAMES-3179 Deal with nullity in OsDetector
---
 .../src/test/java/org/apache/james/mailbox/maildir/OsDetector.java | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/OsDetector.java b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/OsDetector.java
index 75fe97b..7e0fcd1 100644
--- a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/OsDetector.java
+++ b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/OsDetector.java
@@ -20,6 +20,7 @@
 package org.apache.james.mailbox.maildir;
 
 import java.util.Locale;
+import java.util.Optional;
 
 public class OsDetector {
 
@@ -29,8 +30,10 @@ public class OsDetector {
      * @return windows
      */
     public static boolean isWindows() {
-        String os = System.getProperty("os.name").toLowerCase(Locale.US);
-        return (os.contains("win"));
+        return Optional.ofNullable(System.getProperty("os.name"))
+            .orElse("")
+            .toLowerCase(Locale.US)
+            .contains("win");
     }
     
     


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 02/30: JAMES-3179 Define MailboxACL.hashCode

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 5f10d7039a23f16e7daf435a3d1b3ceaa1b5042c
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 14:06:31 2020 +0200

    JAMES-3179 Define MailboxACL.hashCode
---
 .../java/org/apache/james/mailbox/model/MailboxACL.java    | 14 ++++++++++----
 .../org/apache/james/mailbox/model/MailboxACLTest.java     | 11 +++++++++++
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
index 8a7d692..e0d58ae 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
@@ -241,10 +241,16 @@ public class MailboxACL {
             return value.containsAll(Arrays.asList(rights));
         }
 
-        public boolean equals(Object o) {
+        @Override
+        public final int hashCode() {
+            return Objects.hash(value);
+        }
+
+        @Override
+        public final boolean equals(Object o) {
             if (o instanceof Rfc4314Rights) {
                 Rfc4314Rights that = (Rfc4314Rights) o;
-                return this.value.equals(that.value);
+                return Objects.equals(this.value, that.value);
             }
             return false;
         }
@@ -717,7 +723,7 @@ public class MailboxACL {
         this(toMap(props));
     }
 
-    public boolean equals(Object o) {
+    public final boolean equals(Object o) {
         if (o instanceof MailboxACL) {
             MailboxACL acl = (MailboxACL) o;
             return Objects.equals(this.getEntries(), acl.getEntries());
@@ -725,7 +731,7 @@ public class MailboxACL {
         return false;
     }
 
-    public int hashCode() {
+    public final int hashCode() {
         return Objects.hash(entries);
     }
 
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java
index f299efa..f53fad2 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java
@@ -37,6 +37,7 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableMap;
+import nl.jqno.equalsverifier.EqualsVerifier;
 
 class MailboxACLTest {
 
@@ -71,6 +72,16 @@ class MailboxACLTest {
     }
 
     @Test
+    void shouldRespectBeanContract() {
+        EqualsVerifier.forClass(MailboxACL.class).verify();
+    }
+
+    @Test
+    void rfc4314RightsShouldRespectBeanContract() {
+        EqualsVerifier.forClass(MailboxACL.Rfc4314Rights.class).verify();
+    }
+
+    @Test
     void testUnionACLNew() throws UnsupportedRightException {
 
         Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries());


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 24/30: JAMES-3179 Migrate ImapFeaturesTest to JUnit 5

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 89f364b1f7191d3dabd343c53372e4a013c50754
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Wed May 13 10:35:37 2020 +0200

    JAMES-3179 Migrate ImapFeaturesTest to JUnit 5
---
 .../org/apache/james/mpt/api/ImapFeaturesTest.java | 47 ++++++++++++----------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/mpt/core/src/test/java/org/apache/james/mpt/api/ImapFeaturesTest.java b/mpt/core/src/test/java/org/apache/james/mpt/api/ImapFeaturesTest.java
index 8411f84..fb43eb9 100644
--- a/mpt/core/src/test/java/org/apache/james/mpt/api/ImapFeaturesTest.java
+++ b/mpt/core/src/test/java/org/apache/james/mpt/api/ImapFeaturesTest.java
@@ -19,68 +19,71 @@
 package org.apache.james.mpt.api;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.apache.james.mpt.api.ImapFeatures.Feature;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class ImapFeaturesTest {
 
     @Test
-    public void supportedFeaturesShouldReturnEmptySetWhenNoFeatures() {
+    void supportedFeaturesShouldReturnEmptySetWhenNoFeatures() {
         assertThat(ImapFeatures.of().supportedFeatures()).isEmpty();
     }
 
     @Test
-    public void supportedFeaturesShouldReturnNamespaceInSetWhenNamespaceSupported() {
+    void supportedFeaturesShouldReturnNamespaceInSetWhenNamespaceSupported() {
         assertThat(ImapFeatures.of(Feature.NAMESPACE_SUPPORT).supportedFeatures()).containsExactly(Feature.NAMESPACE_SUPPORT);
     }
 
     @Test
-    public void supportsShouldReturnFalseOnNamespaceWhenNamespaceIsNotSupported() {
+    void supportsShouldReturnFalseOnNamespaceWhenNamespaceIsNotSupported() {
         assertThat(ImapFeatures.of().supports(Feature.NAMESPACE_SUPPORT)).isFalse();
     }
 
     @Test
-    public void supportsShouldReturnTrueOnNamespaceWhenNamespaceIsSupported() {
+    void supportsShouldReturnTrueOnNamespaceWhenNamespaceIsSupported() {
         assertThat(ImapFeatures.of(Feature.NAMESPACE_SUPPORT).supports(Feature.NAMESPACE_SUPPORT)).isTrue();
     }
 
     @Test
-    public void supportsShouldReturnTrueOnDuplicateNamespaceEntryWhenNamespaceIsSupported() {
+    void supportsShouldReturnTrueOnDuplicateNamespaceEntryWhenNamespaceIsSupported() {
         assertThat(ImapFeatures.of(Feature.NAMESPACE_SUPPORT).supports(Feature.NAMESPACE_SUPPORT, Feature.NAMESPACE_SUPPORT)).isTrue();
     }
 
     
     @Test
-    public void supportsShouldReturnTrueOnEmptyListWhenNamespaceIsSupported() {
+    void supportsShouldReturnTrueOnEmptyListWhenNamespaceIsSupported() {
         assertThat(ImapFeatures.of(Feature.NAMESPACE_SUPPORT).supports()).isTrue();
     }
 
     @Test
-    public void supportsShouldReturnTrueOnEmptyListWhenNoFeatures() {
+    void supportsShouldReturnTrueOnEmptyListWhenNoFeatures() {
         assertThat(ImapFeatures.of().supports()).isTrue();
     }
 
-    @Test(expected = NullPointerException.class)
-    @SuppressWarnings("CheckReturnValue")
-    public void supportsShouldThrowOnNullFeature() {
-        ImapFeatures.of().supports((Feature)null);
+    @Test
+    void supportsShouldThrowOnNullFeature() {
+        assertThatThrownBy(() -> ImapFeatures.of().supports((Feature)null))
+            .isInstanceOf(NullPointerException.class);
     }
 
-    @Test(expected = NullPointerException.class)
-    @SuppressWarnings("CheckReturnValue")
-    public void supportsShouldThrowOnNullFeatureArray() {
-        ImapFeatures.of().supports((Feature[])null);
+    @Test
+    void supportsShouldThrowOnNullFeatureArray() {
+        assertThatThrownBy(() -> ImapFeatures.of().supports((Feature[])null))
+            .isInstanceOf(NullPointerException.class);
     }
 
     
-    @Test(expected = NullPointerException.class)
-    public void ofShouldThrowOnNullFeature() {
-        ImapFeatures.of((Feature)null);
+    @Test
+    void ofShouldThrowOnNullFeature() {
+        assertThatThrownBy(() -> ImapFeatures.of((Feature)null))
+            .isInstanceOf(NullPointerException.class);
     }
 
-    @Test(expected = NullPointerException.class)
-    public void ofShouldThrowOnNullFeatureArray() {
-        ImapFeatures.of((Feature[])null);
+    @Test
+    void ofShouldThrowOnNullFeatureArray() {
+        assertThatThrownBy(() -> ImapFeatures.of((Feature[])null))
+            .isInstanceOf(NullPointerException.class);
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 12/30: JAMES-3179 Fix SetMessageUpdateProcessorTest assertion definition

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit ef02ee9ff1dbc40d6ec90bb82649970597d2efb1
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 15:40:05 2020 +0200

    JAMES-3179 Fix SetMessageUpdateProcessorTest assertion definition
---
 .../apache/james/jmap/draft/methods/SetMessagesUpdateProcessorTest.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessorTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessorTest.java
index b9c11cf..4741acb 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessorTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessorTest.java
@@ -257,7 +257,7 @@ public class SetMessagesUpdateProcessorTest {
         SetMessagesResponse result = sut.process(requestWithInvalidUpdate, null);
 
         // Then
-        assertThat(result.getNotUpdated()).isNotEmpty().describedAs("NotUpdated should not be empty");
+        assertThat(result.getNotUpdated()).describedAs("NotUpdated should not be empty").isNotEmpty();
         assertThat(result.getNotUpdated()).containsKey(requestMessageId);
         assertThat(result.getNotUpdated().get(requestMessageId).getProperties()).isPresent();
         assertThat(result.getNotUpdated().get(requestMessageId).getProperties().get()).contains(invalidProperty);


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 20/30: JAMES-3179 Deal with SieveFileRepository nullability

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 2f3d2197a0a9d4072968d04acb01e8a98b27cf15
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 17:18:35 2020 +0200

    JAMES-3179 Deal with SieveFileRepository nullability
---
 .../sieverepository/file/SieveFileRepository.java  | 28 ++++++++++++----------
 .../lib/AbstractSieveRepositoryTest.java           |  2 +-
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java b/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java
index b774270..ebb50ea 100644
--- a/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java
+++ b/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java
@@ -32,11 +32,13 @@ import java.io.Writer;
 import java.time.Instant;
 import java.time.ZoneOffset;
 import java.time.ZonedDateTime;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.NoSuchElementException;
+import java.util.Optional;
 import java.util.Scanner;
+import java.util.function.Predicate;
+import java.util.stream.Stream;
 
 import javax.inject.Inject;
 
@@ -55,6 +57,8 @@ import org.apache.james.sieverepository.api.exception.QuotaNotFoundException;
 import org.apache.james.sieverepository.api.exception.ScriptNotFoundException;
 import org.apache.james.sieverepository.api.exception.StorageException;
 
+import com.github.steveash.guavate.Guavate;
+
 /**
  * <code>SieveFileRepository</code> manages sieve scripts stored on the file system.
  * <p>The sieve root directory is a sub-directory of the application base directory named "sieve".
@@ -199,25 +203,25 @@ public class SieveFileRepository implements SieveRepository {
 
     @Override
     public List<ScriptSummary> listScripts(Username username) throws StorageException {
-        File[] files = getUserDirectory(username).listFiles();
-        List<ScriptSummary> summaries = new ArrayList<>(files.length);
         File activeFile = null;
         try {
             activeFile = getActiveFile(username);
         } catch (ScriptNotFoundException ex) {
             // no op
         }
-        for (File file : files) {
-            if (!SYSTEM_FILES.contains(file.getName())) {
-                summaries.add(new ScriptSummary(new ScriptName(file.getName()), isActive(file, activeFile)));
-            }
-        }
-        return summaries;
+
+        Predicate<File> isActive = isActiveValidator(activeFile);
+        return Stream.of(Optional.ofNullable(getUserDirectory(username).listFiles()).orElse(new File[]{}))
+            .filter(file -> !SYSTEM_FILES.contains(file.getName()))
+            .map(file -> new ScriptSummary(new ScriptName(file.getName()), isActive.test(file)))
+            .collect(Guavate.toImmutableList());
     }
 
-    private boolean isActive(File file, File activeFile) {
-        return null != activeFile
-            && activeFile.equals(file);
+    private Predicate<File> isActiveValidator(File activeFile) {
+        if (activeFile != null) {
+            return activeFile::equals;
+        }
+        return file -> false;
     }
 
     @Override
diff --git a/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/AbstractSieveRepositoryTest.java b/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/AbstractSieveRepositoryTest.java
index 3f76b5a..4482d97 100644
--- a/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/AbstractSieveRepositoryTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/AbstractSieveRepositoryTest.java
@@ -130,7 +130,7 @@ public abstract class AbstractSieveRepositoryTest {
     }
 
     @Test
-    public void listScriptsShouldThrowIfUserNotFound() throws Exception {
+    public void listScriptsShouldReturnAnEmptyListIfUserNotFound() throws Exception {
         assertThat(sieveRepository.listScripts(USERNAME)).isEmpty();
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 09/30: JAMES-3179 Fix MessageContent hashCode

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit c3ee324cdada5efaad20bf4de0980b60c90283a8
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 15:34:13 2020 +0200

    JAMES-3179 Fix MessageContent hashCode
---
 .../java/org/apache/james/util/mime/MessageContentExtractor.java   | 7 ++++++-
 .../org/apache/james/util/mime/MessageContentExtractorTest.java    | 7 +++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/server/container/util/src/main/java/org/apache/james/util/mime/MessageContentExtractor.java b/server/container/util/src/main/java/org/apache/james/util/mime/MessageContentExtractor.java
index 454d3d0..5a3292a 100644
--- a/server/container/util/src/main/java/org/apache/james/util/mime/MessageContentExtractor.java
+++ b/server/container/util/src/main/java/org/apache/james/util/mime/MessageContentExtractor.java
@@ -179,7 +179,7 @@ public class MessageContentExtractor {
             && part.getHeader().getField(CONTENT_ID) == null;
     }
 
-    public static class MessageContent {
+    public static final class MessageContent {
         private final Optional<String> textBody;
         private final Optional<String> htmlBody;
 
@@ -230,6 +230,11 @@ public class MessageContentExtractor {
         }
 
         @Override
+        public int hashCode() {
+            return Objects.hash(textBody, htmlBody);
+        }
+
+        @Override
         public boolean equals(Object other) {
             if (!(other instanceof MessageContent)) {
                 return false;
diff --git a/server/container/util/src/test/java/org/apache/james/util/mime/MessageContentExtractorTest.java b/server/container/util/src/test/java/org/apache/james/util/mime/MessageContentExtractorTest.java
index e622d80..65ab84d 100644
--- a/server/container/util/src/test/java/org/apache/james/util/mime/MessageContentExtractorTest.java
+++ b/server/container/util/src/test/java/org/apache/james/util/mime/MessageContentExtractorTest.java
@@ -41,6 +41,8 @@ import org.apache.james.util.mime.MessageContentExtractor.MessageContent;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import nl.jqno.equalsverifier.EqualsVerifier;
+
 class MessageContentExtractorTest {
     private static final String BINARY_CONTENT = "binary";
     private static final String TEXT_CONTENT = "text content";
@@ -91,6 +93,11 @@ class MessageContentExtractorTest {
     }
 
     @Test
+    void shouldRespectBeanContract() {
+        EqualsVerifier.forClass(MessageContent.class).verify();
+    }
+
+    @Test
     void extractShouldReturnEmptyWhenBinaryContentOnly() throws IOException {
         Message message = Message.Builder.of()
                 .setBody(BasicBodyFactory.INSTANCE.binaryBody(BINARY_CONTENT, StandardCharsets.UTF_8))


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 05/30: JAMES-3179 Fix MailetMatcherDescriptor equals

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 2e109d3922b68f08969cf4b0b8ff78923a6e19f5
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 15:24:53 2020 +0200

    JAMES-3179 Fix MailetMatcherDescriptor equals
---
 .../james/mailet/AbstractMailetdocsReport.java     |  12 +-
 .../james/mailet/DefaultDescriptorsExtractor.java  |  37 ++++---
 .../james/mailet/MailetMatcherDescriptor.java      | 121 +++++++++++++++------
 .../mailet/DefaultDescriptorsExtractorTest.java    |  39 ++++---
 .../james/mailet/MailetMatcherDescriptorTest.java  |  31 ++++++
 5 files changed, 166 insertions(+), 74 deletions(-)

diff --git a/mailet/mailetdocs-maven-plugin/src/main/java/org/apache/james/mailet/AbstractMailetdocsReport.java b/mailet/mailetdocs-maven-plugin/src/main/java/org/apache/james/mailet/AbstractMailetdocsReport.java
index 44b6ce2..9035413 100644
--- a/mailet/mailetdocs-maven-plugin/src/main/java/org/apache/james/mailet/AbstractMailetdocsReport.java
+++ b/mailet/mailetdocs-maven-plugin/src/main/java/org/apache/james/mailet/AbstractMailetdocsReport.java
@@ -31,7 +31,6 @@ import org.apache.maven.reporting.AbstractMavenReport;
 import org.apache.maven.reporting.MavenReportException;
 
 import com.github.steveash.guavate.Guavate;
-import com.google.common.base.Strings;
 
 /**
  * <p>
@@ -189,7 +188,7 @@ public abstract class AbstractMailetdocsReport extends AbstractMavenReport {
             getSink().anchor_();
             getSink().sectionTitle2_();
 
-            if (descriptor.getInfo() != null) {
+            descriptor.getInfo().ifPresent(info -> {
                 getSink().paragraph();
                 if (descriptor.getType() == MailetMatcherDescriptor.Type.MAILET) {
                     getSink().text("Mailet Info: ");
@@ -199,17 +198,14 @@ public abstract class AbstractMailetdocsReport extends AbstractMavenReport {
                     getSink().text("Info: ");
                 }
                 getSink().bold();
-                getSink().text(descriptor.getInfo());
+                getSink().text(descriptor.getInfo().orElse(""));
                 getSink().bold_();
                 getSink().lineBreak();
                 getSink().paragraph_();
-            }
+            });
 
             getSink().paragraph();
-            String classDocs = descriptor.getClassDocs();
-            if (!Strings.isNullOrEmpty(classDocs)) {
-                getSink().rawText(classDocs);
-            }
+            descriptor.getClassDocs().ifPresent(classDocs -> getSink().rawText(classDocs));
             getSink().paragraph_();
 
             getSink().section2_();
diff --git a/mailet/mailetdocs-maven-plugin/src/main/java/org/apache/james/mailet/DefaultDescriptorsExtractor.java b/mailet/mailetdocs-maven-plugin/src/main/java/org/apache/james/mailet/DefaultDescriptorsExtractor.java
index eaba5f0..c927e7b 100644
--- a/mailet/mailetdocs-maven-plugin/src/main/java/org/apache/james/mailet/DefaultDescriptorsExtractor.java
+++ b/mailet/mailetdocs-maven-plugin/src/main/java/org/apache/james/mailet/DefaultDescriptorsExtractor.java
@@ -28,6 +28,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Optional;
 import java.util.Set;
 
 import org.apache.james.mailet.MailetMatcherDescriptor.Type;
@@ -154,36 +155,33 @@ public class DefaultDescriptorsExtractor {
     private MailetMatcherDescriptor describeMatcher(Log log,
             final JavaClass nextClass, String nameOfNextClass,
             final Class<?> klass) {
-        
-        final MailetMatcherDescriptor result = buildDescriptor(log, nextClass,
-                nameOfNextClass, klass, "getMatcherInfo", MailetMatcherDescriptor.Type.MATCHER);
+
+        MailetMatcherDescriptor result = MailetMatcherDescriptor.builder()
+                .name(nextClass.getName())
+                .fullyQualifiedClassName(nameOfNextClass)
+                .type(Type.MATCHER)
+                .info(fetchInfo(log, nameOfNextClass, klass, "getMatcherInfo", Type.MATCHER))
+                .classDocs(nextClass.getComment())
+                .experimental(isExperimental(nextClass));
         
         log.info("Found a Matcher: " + klass.getName());
         return result;
     }
 
 
-    private MailetMatcherDescriptor buildDescriptor(Log log, JavaClass nextClass,
-            final String nameOfClass, Class<?> klass,
-            final String infoMethodName, Type type) {
-        final MailetMatcherDescriptor result = new MailetMatcherDescriptor();
-        result.setName(nextClass.getName());
-        result.setFullyQualifiedName(nameOfClass);
-        result.setClassDocs(nextClass.getComment());
-        result.setType(type);
-        result.setExperimental(isExperimental(nextClass));
-
+    private Optional<String> fetchInfo(Log log, String nameOfClass, Class<?> klass, String infoMethodName, Type type) {
         try {
             final Object instance = klass.newInstance();
             final String info = (String) klass.getMethod(infoMethodName).invoke(instance);
             if (info != null && info.length() > 0) {
-                result.setInfo(info);
+                return Optional.of(info);
             }
         } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
                 | InvocationTargetException | SecurityException | NoSuchMethodException e) {
             handleInfoLoadFailure(log, nameOfClass, type, e);
         }
-        return result;
+
+        return Optional.empty();
     }
 
 
@@ -212,8 +210,13 @@ public class DefaultDescriptorsExtractor {
             final JavaClass nextClass, String nameOfNextClass,
             final Class<?> klass) {
 
-        final MailetMatcherDescriptor result = buildDescriptor(log, nextClass,
-                nameOfNextClass, klass, "getMailetInfo", MailetMatcherDescriptor.Type.MAILET);
+        final MailetMatcherDescriptor result = MailetMatcherDescriptor.builder()
+                .name(nextClass.getName())
+                .fullyQualifiedClassName(nameOfNextClass)
+                .type(Type.MAILET)
+                .info(fetchInfo(log, nameOfNextClass, klass, "getMailetInfo", Type.MAILET))
+                .classDocs(nextClass.getComment())
+                .experimental(isExperimental(nextClass));
         
         log.info("Found a Mailet: " + klass.getName());
         return result;
diff --git a/mailet/mailetdocs-maven-plugin/src/main/java/org/apache/james/mailet/MailetMatcherDescriptor.java b/mailet/mailetdocs-maven-plugin/src/main/java/org/apache/james/mailet/MailetMatcherDescriptor.java
index 5a368f6..c14e603 100644
--- a/mailet/mailetdocs-maven-plugin/src/main/java/org/apache/james/mailet/MailetMatcherDescriptor.java
+++ b/mailet/mailetdocs-maven-plugin/src/main/java/org/apache/james/mailet/MailetMatcherDescriptor.java
@@ -19,8 +19,11 @@
 
 package org.apache.james.mailet;
 
+import java.util.Optional;
+
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
+import com.google.common.base.Strings;
 
 /**
  * Simple bean to describe a mailet or a matcher
@@ -56,66 +59,116 @@ public class MailetMatcherDescriptor {
         }
     }
 
-    private String fullyQualifiedClassName;
+    public interface Builder {
+        @FunctionalInterface
+        interface RequiresName {
+            RequiresFullyQualifiedClassName name(String name);
+        }
 
-    private String name;
+        @FunctionalInterface
+        interface RequiresFullyQualifiedClassName {
+            RequiresType fullyQualifiedClassName(String fullyQualifiedClassName);
+        }
 
-    private String info;
+        @FunctionalInterface
+        interface RequiresType {
+            RequiresInfo type(Type type);
+        }
 
-    private String classDocs;
+        @FunctionalInterface
+        interface RequiresInfo {
+            default RequiresClassDocs info(String info) {
+                if (Strings.isNullOrEmpty(info)) {
+                    return noInfo();
+                }
 
-    private Type type;
+                return info(Optional.of(info));
+            }
 
-    private boolean experimental;
+            default RequiresClassDocs noInfo() {
+                return info(Optional.empty());
+            }
 
-    public String getFullyQualifiedName() {
-        return fullyQualifiedClassName;
-    }
+            RequiresClassDocs info(Optional<String> info);
+        }
+
+        @FunctionalInterface
+        interface RequiresClassDocs {
+            default RequiresExperimental classDocs(String classDocs) {
+                if (Strings.isNullOrEmpty(classDocs)) {
+                    return noClassDocs();
+                }
+
+                return classDocs(Optional.of(classDocs));
+            }
+
+            default RequiresExperimental noClassDocs() {
+                return classDocs(Optional.empty());
+            }
+
+            RequiresExperimental classDocs(Optional<String> classDocs);
+        }
+
+        @FunctionalInterface
+        interface RequiresExperimental {
+            default MailetMatcherDescriptor isExperimental() {
+                return experimental(true);
+            }
+
+            default MailetMatcherDescriptor isNotExperimental() {
+                return experimental(false);
+            }
+
+            MailetMatcherDescriptor experimental(boolean experimental);
+        }
 
-    public void setFullyQualifiedName(String fqName) {
-        this.fullyQualifiedClassName = fqName;
     }
 
-    public String getName() {
-        return name;
+    public static Builder.RequiresName builder() {
+        return name -> fullyQualifiedClassName -> type -> info -> classDocs -> experimental ->
+            new MailetMatcherDescriptor(name, fullyQualifiedClassName, type, info, classDocs, experimental);
     }
 
-    public void setName(String name) {
+    private final String name;
+    private final String fullyQualifiedClassName;
+    private final Type type;
+    private final Optional<String> info;
+    private final Optional<String> classDocs;
+    private final boolean experimental;
+
+    private MailetMatcherDescriptor(String name, String fullyQualifiedClassName, Type type, Optional<String> info, Optional<String> classDocs, boolean experimental) {
         this.name = name;
+        this.fullyQualifiedClassName = fullyQualifiedClassName;
+        this.type = type;
+        this.info = info;
+        this.classDocs = classDocs;
+        this.experimental = experimental;
     }
 
-    public String getInfo() {
-        return info;
+    public String getFullyQualifiedName() {
+        return fullyQualifiedClassName;
     }
 
-    public void setInfo(String info) {
-        this.info = info;
+    public String getName() {
+        return name;
     }
 
-    public String getClassDocs() {
-        return classDocs;
+    public Optional<String> getInfo() {
+        return info;
     }
 
-    public void setClassDocs(String classDocs) {
-        this.classDocs = classDocs;
+    public Optional<String> getClassDocs() {
+        return classDocs;
     }
 
     public Type getType() {
         return type;
     }
 
-    public void setType(Type type) {
-        this.type = type;
-    }
-
     public boolean isExperimental() {
         return experimental;
     }
 
-    public void setExperimental(boolean experimental) {
-        this.experimental = experimental;
-    }
-
     @Override
     public String toString() {
         return MoreObjects.toStringHelper(MailetMatcherDescriptor.class)
@@ -128,11 +181,17 @@ public class MailetMatcherDescriptor {
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public final int hashCode() {
+        return Objects.hashCode(fullyQualifiedClassName, name, info, classDocs, type, experimental);
+    }
+
+    @Override
+    public final boolean equals(Object obj) {
         if (obj instanceof MailetMatcherDescriptor) {
             MailetMatcherDescriptor other = (MailetMatcherDescriptor) obj;
             return Objects.equal(this.fullyQualifiedClassName, other.fullyQualifiedClassName)
                 && Objects.equal(this.name, other.name)
+                && Objects.equal(this.classDocs, other.classDocs)
                 && Objects.equal(this.info, other.info)
                 && Objects.equal(this.type, other.type)
                 && Objects.equal(this.experimental, other.experimental);
diff --git a/mailet/mailetdocs-maven-plugin/src/test/java/org/apache/james/mailet/DefaultDescriptorsExtractorTest.java b/mailet/mailetdocs-maven-plugin/src/test/java/org/apache/james/mailet/DefaultDescriptorsExtractorTest.java
index 35fa063..e9058d7 100644
--- a/mailet/mailetdocs-maven-plugin/src/test/java/org/apache/james/mailet/DefaultDescriptorsExtractorTest.java
+++ b/mailet/mailetdocs-maven-plugin/src/test/java/org/apache/james/mailet/DefaultDescriptorsExtractorTest.java
@@ -54,18 +54,20 @@ public class DefaultDescriptorsExtractorTest {
         List<MailetMatcherDescriptor> descriptors = testee.extract(mavenProject, log)
             .descriptors();
 
-        MailetMatcherDescriptor experimentalMailet = new MailetMatcherDescriptor();
-        experimentalMailet.setFullyQualifiedName("org.apache.james.mailet.experimental.ExperimentalMailet");
-        experimentalMailet.setName("ExperimentalMailet");
-        experimentalMailet.setInfo(null);
-        experimentalMailet.setType(Type.MAILET);
-        experimentalMailet.setExperimental(true);
-        MailetMatcherDescriptor nonExperimentalMailet = new MailetMatcherDescriptor();
-        nonExperimentalMailet.setFullyQualifiedName("org.apache.james.mailet.experimental.NonExperimentalMailet");
-        nonExperimentalMailet.setName("NonExperimentalMailet");
-        nonExperimentalMailet.setInfo(null);
-        nonExperimentalMailet.setType(Type.MAILET);
-        nonExperimentalMailet.setExperimental(false);
+        MailetMatcherDescriptor experimentalMailet = MailetMatcherDescriptor.builder()
+            .name("ExperimentalMailet")
+            .fullyQualifiedClassName("org.apache.james.mailet.experimental.ExperimentalMailet")
+            .type(Type.MAILET)
+            .noInfo()
+            .noClassDocs()
+            .isExperimental();
+        MailetMatcherDescriptor nonExperimentalMailet = MailetMatcherDescriptor.builder()
+            .name("NonExperimentalMailet")
+            .fullyQualifiedClassName("org.apache.james.mailet.experimental.NonExperimentalMailet")
+            .type(Type.MAILET)
+            .noInfo()
+            .noClassDocs()
+            .isNotExperimental();
 
         assertThat(descriptors).containsOnly(experimentalMailet, nonExperimentalMailet);
     }
@@ -78,12 +80,13 @@ public class DefaultDescriptorsExtractorTest {
         List<MailetMatcherDescriptor> descriptors = testee.extract(mavenProject, log)
             .descriptors();
 
-        MailetMatcherDescriptor notExcludedMailet = new MailetMatcherDescriptor();
-        notExcludedMailet.setFullyQualifiedName("org.apache.james.mailet.excluded.NotExcludedFromDocumentationMailet");
-        notExcludedMailet.setName("NotExcludedFromDocumentationMailet");
-        notExcludedMailet.setInfo(null);
-        notExcludedMailet.setType(Type.MAILET);
-        notExcludedMailet.setExperimental(false);
+        MailetMatcherDescriptor notExcludedMailet = MailetMatcherDescriptor.builder()
+            .name("NotExcludedFromDocumentationMailet")
+            .fullyQualifiedClassName("org.apache.james.mailet.excluded.NotExcludedFromDocumentationMailet")
+            .type(Type.MAILET)
+            .noInfo()
+            .noClassDocs()
+            .isNotExperimental();
 
         assertThat(descriptors).containsOnly(notExcludedMailet);
     }
diff --git a/mailet/mailetdocs-maven-plugin/src/test/java/org/apache/james/mailet/MailetMatcherDescriptorTest.java b/mailet/mailetdocs-maven-plugin/src/test/java/org/apache/james/mailet/MailetMatcherDescriptorTest.java
new file mode 100644
index 0000000..4759bcb
--- /dev/null
+++ b/mailet/mailetdocs-maven-plugin/src/test/java/org/apache/james/mailet/MailetMatcherDescriptorTest.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.james.mailet;
+
+import org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class MailetMatcherDescriptorTest {
+    @Test
+    void shouldRespectBeanContract() {
+        EqualsVerifier.forClass(MailetMatcherDescriptor.class).verify();
+    }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 13/30: JAMES-3179 Enable AttachmentAccessTokenTest tests

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 022d5eae54f661791b2231394b9dcebb21d8d5d5
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 15:41:17 2020 +0200

    JAMES-3179 Enable AttachmentAccessTokenTest tests
---
 .../james/jmap/draft/model/AttachmentAccessTokenTest.java   | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/AttachmentAccessTokenTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/AttachmentAccessTokenTest.java
index ed1d92f..fdc69b4 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/AttachmentAccessTokenTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/AttachmentAccessTokenTest.java
@@ -35,23 +35,24 @@ public class AttachmentAccessTokenTest {
     private static final String SIGNATURE = "signature";
 
     @Test
-    public void getAsStringShouldNotContainBlobId() throws Exception {
+    public void getAsStringShouldNotContainBlobId() {
         assertThat(new AttachmentAccessToken(USERNAME, BLOB_ID, EXPIRATION_DATE, SIGNATURE).serialize())
             .isEqualTo(USERNAME + AttachmentAccessToken.SEPARATOR + EXPIRATION_DATE_STRING + AttachmentAccessToken.SEPARATOR + SIGNATURE);
     }
 
     @Test
-    public void getPayloadShouldNotContainBlobId() throws Exception {
+    public void getPayloadShouldNotContainBlobId() {
         assertThat(new AttachmentAccessToken(USERNAME, BLOB_ID, EXPIRATION_DATE, SIGNATURE).getPayload())
             .isEqualTo(USERNAME + AttachmentAccessToken.SEPARATOR + EXPIRATION_DATE_STRING);
     }
 
     @Test
-    public void getSignedContentShouldContainBlobId() throws Exception {
+    public void getSignedContentShouldContainBlobId() {
         assertThat(new AttachmentAccessToken(USERNAME, BLOB_ID, EXPIRATION_DATE, SIGNATURE).getSignedContent())
             .isEqualTo(BLOB_ID + AttachmentAccessToken.SEPARATOR + USERNAME + AttachmentAccessToken.SEPARATOR + EXPIRATION_DATE_STRING);
     }
-    
+
+    @Test
     public void buildWithNullUsernameShouldThrow() {
         assertThatThrownBy(() -> AttachmentAccessToken.builder()
             .username(null)
@@ -59,6 +60,7 @@ public class AttachmentAccessTokenTest {
         ).isInstanceOf(NullPointerException.class);
     }
 
+    @Test
     public void buildWithNullBlobIdShouldThrow() {
         assertThatThrownBy(() -> AttachmentAccessToken.builder()
             .username(USERNAME)
@@ -67,6 +69,7 @@ public class AttachmentAccessTokenTest {
         ).isInstanceOf(NullPointerException.class);
     }
 
+    @Test
     public void buildWithNullExpirationDateShouldThrow() {
         assertThatThrownBy(() -> AttachmentAccessToken.builder()
             .username(USERNAME)
@@ -76,6 +79,7 @@ public class AttachmentAccessTokenTest {
         ).isInstanceOf(NullPointerException.class);
     }
 
+    @Test
     public void buildWithNullSignatureShouldThrow() {
         assertThatThrownBy(() -> AttachmentAccessToken.builder()
             .username(USERNAME)
@@ -86,6 +90,7 @@ public class AttachmentAccessTokenTest {
         ).isInstanceOf(NullPointerException.class);
     }
 
+    @Test
     public void buildWithValidArgumentsShouldBuild() {
         AttachmentAccessToken expected = new AttachmentAccessToken(USERNAME, BLOB_ID, EXPIRATION_DATE, SIGNATURE);
         AttachmentAccessToken actual = AttachmentAccessToken.builder()


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 04/30: JAMES-3179 Remove IMAP168JpaMigrateCommand useless substring

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 0f644aa7de779f0f875b092165625a8e30a17394
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 14:08:48 2020 +0200

    JAMES-3179 Remove IMAP168JpaMigrateCommand useless substring
---
 .../mailbox/tools/jpa/migrator/command/IMAP168JpaMigrateCommand.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP168JpaMigrateCommand.java b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP168JpaMigrateCommand.java
index 68ea248..3423910 100644
--- a/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP168JpaMigrateCommand.java
+++ b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP168JpaMigrateCommand.java
@@ -103,7 +103,7 @@ public class IMAP168JpaMigrateCommand implements JpaMigrateCommand {
                 mailboxName = name.substring(userName.length() + 1);
             } else {
                 // We don't have a mailbox name...
-                userName = name.substring(0);
+                userName = name;
                 mailboxName = "";
             }
             


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 11/30: JAMES-3179 UploadResponse equals

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit bf9c6cd30a6655c186510402f2f7aa656a933be7
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 15:37:14 2020 +0200

    JAMES-3179 UploadResponse equals
---
 .../james/jmap/draft/model/UploadResponse.java     |  6 ++---
 .../james/jmap/draft/model/UploadResponseTest.java | 31 ++++++++++++++++++++++
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/UploadResponse.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/UploadResponse.java
index 9443ed9..6a674e8 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/UploadResponse.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/UploadResponse.java
@@ -113,10 +113,10 @@ public class UploadResponse {
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public final boolean equals(Object obj) {
         if (obj instanceof UploadResponse) {
             UploadResponse other = (UploadResponse) obj;
-            return Objects.equal(accountId, accountId)
+            return Objects.equal(accountId, other.accountId)
                 && Objects.equal(blobId, other.blobId)
                 && Objects.equal(type, other.type)
                 && Objects.equal(size, other.size)
@@ -126,7 +126,7 @@ public class UploadResponse {
     }
 
     @Override
-    public int hashCode() {
+    public final int hashCode() {
         return Objects.hashCode(accountId, blobId, type, size, expires);
     }
 
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/UploadResponseTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/UploadResponseTest.java
new file mode 100644
index 0000000..904f363
--- /dev/null
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/UploadResponseTest.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.james.jmap.draft.model;
+
+import org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class UploadResponseTest {
+    @Test
+    void shouldRespectBeanContract() {
+        EqualsVerifier.forClass(UploadResponse.class).verify();
+    }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 28/30: JAMES-3179 Fix ClamAV thread safety issue

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 4c0a8a44d0ab8db6b1ec9b4572f4eeef5a33f659
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Thu May 14 11:50:37 2020 +0200

    JAMES-3179 Fix ClamAV thread safety issue
---
 .../org/apache/james/transport/mailets/ClamAVScan.java    | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java b/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java
index 9ad2565..7410e30 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java
@@ -272,7 +272,7 @@ public class ClamAVScan extends GenericMailet {
      */
     protected void initDebug() {
         String debugParam = getInitParameter("debug");
-        setDebug((debugParam == null) ? false : Boolean.parseBoolean(debugParam));
+        this.debug = (debugParam != null) && Boolean.parseBoolean(debugParam);
     }
 
     /**
@@ -285,15 +285,6 @@ public class ClamAVScan extends GenericMailet {
     }
 
     /**
-     * Setter for property debug.
-     *
-     * @param debug New value of property debug.
-     */
-    public void setDebug(boolean debug) {
-        this.debug = debug;
-    }
-
-    /**
      * Initializer for property host.
      *
      * @throws UnknownHostException if unable to resolve the host name, or if invalid
@@ -311,7 +302,6 @@ public class ClamAVScan extends GenericMailet {
      * @return Value of property host.
      */
     public String getHost() {
-
         return this.host;
     }
 
@@ -324,8 +314,7 @@ public class ClamAVScan extends GenericMailet {
      * @param host New value of property host.
      * @throws UnknownHostException if unable to resolve the host name, or if invalid
      */
-    public void setHost(String host) throws UnknownHostException {
-
+    private void setHost(String host) throws UnknownHostException {
         this.host = host;
 
         setAddresses(InetAddress.getAllByName(host));


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 25/30: JAMES-3179 Migrate MappingsImplTest to JUnit 5

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 781641160d50ff1474be29c13d856d0864eb65ae
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Wed May 13 10:52:14 2020 +0200

    JAMES-3179 Migrate MappingsImplTest to JUnit 5
---
 .../org/apache/james/rrt/lib/MappingsImplTest.java | 30 ++++++++++++----------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingsImplTest.java b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingsImplTest.java
index 41d428c..cd2cfe8 100644
--- a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingsImplTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingsImplTest.java
@@ -26,14 +26,15 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import java.util.Optional;
 
 import org.apache.james.core.Domain;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 
 public class MappingsImplTest {
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void fromRawStringShouldThrowWhenNull() {
-        MappingsImpl.fromRawString(null);
+        assertThatThrownBy(() -> MappingsImpl.fromRawString(null))
+            .isInstanceOf(NullPointerException.class);
     }
 
     @Test
@@ -157,11 +158,11 @@ public class MappingsImplTest {
     }
 
     
-    @Test(expected = NullPointerException.class)
-    @SuppressWarnings("CheckReturnValue")
+    @Test
     public void containsShouldThrowWhenNull() {
         MappingsImpl mappings = MappingsImpl.builder().add(Mapping.regex("toto")).build();
-        mappings.contains((Mapping.Type)null);
+        assertThatThrownBy(() -> mappings.contains((Mapping.Type)null))
+            .isInstanceOf(NullPointerException.class);
     }
     
     @Test
@@ -190,11 +191,11 @@ public class MappingsImplTest {
     }
 
     
-    @Test(expected = NullPointerException.class)
-    @SuppressWarnings("CheckReturnValue")
+    @Test
     public void selectShouldThrowWhenNull() {
         MappingsImpl mappings = MappingsImpl.builder().add(Mapping.regex("toto")).build();
-        mappings.select((Mapping.Type)null);
+        assertThatThrownBy(() -> mappings.select((Mapping.Type)null))
+            .isInstanceOf(NullPointerException.class);
     }
 
     @Test
@@ -222,11 +223,11 @@ public class MappingsImplTest {
     }
 
     
-    @Test(expected = NullPointerException.class)
-    @SuppressWarnings("CheckReturnValue")
+    @Test
     public void excludeShouldThrowWhenNull() {
         MappingsImpl mappings = MappingsImpl.builder().add(Mapping.regex("toto")).build();
-        mappings.exclude((Mapping.Type)null);
+        assertThatThrownBy(() -> mappings.exclude((Mapping.Type)null))
+            .isInstanceOf(NullPointerException.class);
     }
 
     @Test
@@ -245,9 +246,10 @@ public class MappingsImplTest {
         assertThat(optional.isPresent()).isFalse();
     }
 
-    @Test(expected = IllegalStateException.class)
+    @Test
     public void unionShouldThrowWhenMappingsNull() {
-        MappingsImpl.empty().union(null);
+        assertThatThrownBy(() -> MappingsImpl.empty().union(null))
+            .isInstanceOf(IllegalStateException.class);
     }
 
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 01/30: JAMES-3179 Use a Consumer instead of a Function in TransactionRunner

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 106e9af7197e6ef41ab1990b3497a8e52808e327
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 14:05:05 2020 +0200

    JAMES-3179 Use a Consumer instead of a Function in TransactionRunner
---
 .../apache/james/backends/jpa/TransactionRunner.java  |  6 +++---
 .../apache/james/sieve/jpa/JPASieveRepository.java    | 19 +++++++++++++------
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/backends-common/jpa/src/main/java/org/apache/james/backends/jpa/TransactionRunner.java b/backends-common/jpa/src/main/java/org/apache/james/backends/jpa/TransactionRunner.java
index e3575a1..d75473a 100644
--- a/backends-common/jpa/src/main/java/org/apache/james/backends/jpa/TransactionRunner.java
+++ b/backends-common/jpa/src/main/java/org/apache/james/backends/jpa/TransactionRunner.java
@@ -76,8 +76,8 @@ public class TransactionRunner {
         }
     }
 
-    public <T> void runAndHandleException(Consumer<EntityManager> runnable,
-                                          Function<PersistenceException, T> errorHandler) {
+    public void runAndHandleException(Consumer<EntityManager> runnable,
+                                      Consumer<PersistenceException> errorHandler) {
         EntityManager entityManager = entityManagerFactory.createEntityManager();
         EntityTransaction transaction = entityManager.getTransaction();
         try {
@@ -89,7 +89,7 @@ public class TransactionRunner {
             if (transaction.isActive()) {
                 transaction.rollback();
             }
-            errorHandler.apply(e);
+            errorHandler.accept(e);
         } finally {
             EntityManagerUtils.safelyClose(entityManager);
         }
diff --git a/server/data/data-jpa/src/main/java/org/apache/james/sieve/jpa/JPASieveRepository.java b/server/data/data-jpa/src/main/java/org/apache/james/sieve/jpa/JPASieveRepository.java
index c82213b..adf74d2 100644
--- a/server/data/data-jpa/src/main/java/org/apache/james/sieve/jpa/JPASieveRepository.java
+++ b/server/data/data-jpa/src/main/java/org/apache/james/sieve/jpa/JPASieveRepository.java
@@ -24,6 +24,7 @@ import java.nio.charset.StandardCharsets;
 import java.time.ZonedDateTime;
 import java.util.List;
 import java.util.Optional;
+import java.util.function.Consumer;
 import java.util.function.Function;
 
 import javax.inject.Inject;
@@ -109,7 +110,7 @@ public class JPASieveRepository implements SieveRepository {
                 rollbackTransactionIfActive(entityManager.getTransaction());
                 throw e;
             }
-        }).sneakyThrow(), throwStorageException("Unable to put script for user " + username.asString()));
+        }).sneakyThrow(), throwStorageExceptionConsumer("Unable to put script for user " + username.asString()));
     }
 
     @Override
@@ -171,7 +172,7 @@ public class JPASieveRepository implements SieveRepository {
                 rollbackTransactionIfActive(entityManager.getTransaction());
                 throw e;
             }
-        }).sneakyThrow(), throwStorageException("Unable to set active script " + name.getValue() + " for user " + username.asString()));
+        }).sneakyThrow(), throwStorageExceptionConsumer("Unable to set active script " + name.getValue() + " for user " + username.asString()));
     }
 
     private void switchOffActiveScript(Username username, EntityManager entityManager) throws StorageException {
@@ -224,7 +225,7 @@ public class JPASieveRepository implements SieveRepository {
                 throw new IsActiveException("Unable to delete active script " + name.getValue() + " for user " + username.asString());
             }
             entityManager.remove(sieveScriptToRemove);
-        }).sneakyThrow(), throwStorageException("Unable to delete script " + name.getValue() + " for user " + username.asString()));
+        }).sneakyThrow(), throwStorageExceptionConsumer("Unable to delete script " + name.getValue() + " for user " + username.asString()));
     }
 
     @Override
@@ -244,7 +245,7 @@ public class JPASieveRepository implements SieveRepository {
 
             JPASieveScript sieveScriptToRename = sieveScript.get();
             sieveScriptToRename.renameTo(newName);
-        }).sneakyThrow(), throwStorageException("Unable to rename script " + oldName.getValue() + " for user " + username.asString()));
+        }).sneakyThrow(), throwStorageExceptionConsumer("Unable to rename script " + oldName.getValue() + " for user " + username.asString()));
     }
 
     private void rollbackTransactionIfActive(EntityTransaction transaction) {
@@ -310,6 +311,12 @@ public class JPASieveRepository implements SieveRepository {
         }).sneakyThrow();
     }
 
+    private Consumer<PersistenceException> throwStorageExceptionConsumer(String message) {
+        return Throwing.<PersistenceException>consumer(e -> {
+            throw new StorageException(message, e);
+        }).sneakyThrow();
+    }
+
     private Optional<JPASieveQuota> findQuotaForUser(String username, EntityManager entityManager) {
         try {
             JPASieveQuota sieveQuota = entityManager.createNamedQuery("findByUsername", JPASieveQuota.class)
@@ -331,13 +338,13 @@ public class JPASieveRepository implements SieveRepository {
                 JPASieveQuota jpaSieveQuota = new JPASieveQuota(username, quota.asLong());
                 entityManager.persist(jpaSieveQuota);
             }
-        }), throwStorageException("Unable to set quota for user " + username));
+        }), throwStorageExceptionConsumer("Unable to set quota for user " + username));
     }
 
     private void removeQuotaForUser(String username) throws StorageException {
         transactionRunner.runAndHandleException(Throwing.consumer(entityManager -> {
             Optional<JPASieveQuota> quotaForUser = findQuotaForUser(username, entityManager);
             quotaForUser.ifPresent(entityManager::remove);
-        }), throwStorageException("Unable to remove quota for user " + username));
+        }), throwStorageExceptionConsumer("Unable to remove quota for user " + username));
     }
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 18/30: JAMES-3179 Deal with AbstractMailboxProcessor.getSelectedMailbox nullability

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 2552baa371888b3adf90cabefddcabda2d476ecf
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue May 12 16:18:24 2020 +0200

    JAMES-3179 Deal with AbstractMailboxProcessor.getSelectedMailbox nullability
---
 .../imap/processor/AbstractMailboxProcessor.java   | 17 +++++++---------
 .../imap/processor/AbstractSelectionProcessor.java |  3 ++-
 .../james/imap/processor/CloseProcessor.java       |  3 ++-
 .../james/imap/processor/ExpungeProcessor.java     |  5 +++--
 .../james/imap/processor/SearchProcessor.java      |  3 ++-
 .../james/imap/processor/StoreProcessor.java       | 23 ++++++++++------------
 .../james/imap/processor/fetch/FetchProcessor.java | 15 ++++++--------
 7 files changed, 32 insertions(+), 37 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
index a5f2b4a..2675934 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
@@ -72,6 +72,8 @@ import org.apache.james.metrics.api.TimeMetric;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.fge.lambdas.Throwing;
+
 public abstract class AbstractMailboxProcessor<R extends ImapRequest> extends AbstractChainedProcessor<R> {
     private static final Logger LOGGER = LoggerFactory.getLogger(AbstractMailboxProcessor.class);
 
@@ -397,16 +399,11 @@ public abstract class AbstractMailboxProcessor<R extends ImapRequest> extends Ab
         return factory;
     }
 
-    protected MessageManager getSelectedMailbox(ImapSession session) throws MailboxException {
-        MessageManager result;
-        final SelectedMailbox selectedMailbox = session.getSelected();
-        if (selectedMailbox == null) {
-            result = null;
-        } else {
-            final MailboxManager mailboxManager = getMailboxManager();
-            result = mailboxManager.getMailbox(selectedMailbox.getMailboxId(), session.getMailboxSession());
-        }
-        return result;
+    protected Optional<MessageManager> getSelectedMailbox(ImapSession session) throws MailboxException {
+        return Optional.ofNullable(session.getSelected())
+            .map(Throwing.<SelectedMailbox, MessageManager>function(selectedMailbox ->
+                getMailboxManager().getMailbox(selectedMailbox.getMailboxId(), session.getMailboxSession()))
+                .sneakyThrow());
     }
 
     /**
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
index 3905387..0a676fa 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
@@ -444,7 +444,8 @@ abstract class AbstractSelectionProcessor<R extends AbstractMailboxSelectionRequ
                     MailboxMetaData metaData  = null;
                     boolean send = false;
                     if (sm != null) {
-                        MessageManager mailbox = getSelectedMailbox(session);
+                        MessageManager mailbox = getSelectedMailbox(session)
+                            .orElseThrow(() -> new MailboxException("Session not in SELECTED state"));
                         metaData = mailbox.getMetaData(false, session.getMailboxSession(), FetchGroup.NO_COUNT);
                         send = true;
                     }
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/CloseProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/CloseProcessor.java
index e92891d..60d6e17 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/CloseProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/CloseProcessor.java
@@ -48,7 +48,8 @@ public class CloseProcessor extends AbstractMailboxProcessor<CloseRequest> {
     @Override
     protected void processRequest(CloseRequest request, ImapSession session, Responder responder) {
         try {
-            MessageManager mailbox = getSelectedMailbox(session);
+            MessageManager mailbox = getSelectedMailbox(session)
+                .orElseThrow(() -> new MailboxException("Session not in SELECTED state"));
             final MailboxSession mailboxSession = session.getMailboxSession();
             if (mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT).isWriteable()) {
                 mailbox.expunge(MessageRange.all(), mailboxSession);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java
index c72b385..dc6094d 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java
@@ -64,8 +64,9 @@ public class ExpungeProcessor extends AbstractMailboxProcessor<ExpungeRequest> i
     @Override
     protected void processRequest(ExpungeRequest request, ImapSession session, Responder responder) {
         try {
-            final MessageManager mailbox = getSelectedMailbox(session);
-            final MailboxSession mailboxSession = session.getMailboxSession();
+            MessageManager mailbox = getSelectedMailbox(session)
+                .orElseThrow(() -> new MailboxException("Session not in SELECTED state"));
+            MailboxSession mailboxSession = session.getMailboxSession();
 
             int expunged = 0;
             MailboxMetaData mdata = mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
index 9ed93cf..c2ccf61 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
@@ -91,7 +91,8 @@ public class SearchProcessor extends AbstractMailboxProcessor<SearchRequest> imp
 
         try {
 
-            final MessageManager mailbox = getSelectedMailbox(session);
+            MessageManager mailbox = getSelectedMailbox(session)
+                .orElseThrow(() -> new MailboxException("Session not in SELECTED state"));
 
             final SearchQuery query = toQuery(searchKey, session);
             MailboxSession msession = session.getMailboxSession();
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java
index cbc579f..f14fac2 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java
@@ -77,19 +77,19 @@ public class StoreProcessor extends AbstractMailboxProcessor<StoreRequest> {
 
     @Override
     protected void processRequest(StoreRequest request, ImapSession session, Responder responder) {
-        final IdRange[] idSet = request.getIdSet();
-        final boolean useUids = request.isUseUids();
-        final long unchangedSince = request.getUnchangedSince();
-        ImapCommand imapCommand = request.getCommand();
-        
+        IdRange[] idSet = request.getIdSet();
+        boolean useUids = request.isUseUids();
+        long unchangedSince = request.getUnchangedSince();
+
         try {
-            final MessageManager mailbox = getSelectedMailbox(session);
-            final MailboxSession mailboxSession = session.getMailboxSession();
-            final Flags flags = request.getFlags();
-            
+            MessageManager mailbox = getSelectedMailbox(session)
+                .orElseThrow(() -> new MailboxException("Session not in SELECTED state"));
+            MailboxSession mailboxSession = session.getMailboxSession();
+            Flags flags = request.getFlags();
+
             if (unchangedSince != -1) {
                 MailboxMetaData metaData = mailbox.getMetaData(false, mailboxSession, MailboxMetaData.FetchGroup.NO_COUNT);
-                if (metaData.isModSeqPermanent() == false) {
+                if (!metaData.isModSeqPermanent()) {
                     // Check if the mailbox did not support modsequences. If so return a tagged bad response.
                     // See RFC4551 3.1.2. NOMODSEQ Response Code 
                     taggedBad(request, responder, HumanReadableText.NO_MOD_SEQ);
@@ -120,9 +120,6 @@ public class StoreProcessor extends AbstractMailboxProcessor<StoreRequest> {
                 if (messageSet != null) {
 
                     if (unchangedSince != -1) {
-                        // Ok we have a CONDSTORE option so use the CONDSTORE_COMMAND
-                        imapCommand = CONDSTORE_COMMAND;
-
                         List<MessageUid> uids = new ArrayList<>();
 
                         MessageResultIterator results = mailbox.getMessages(messageSet, FetchGroup.MINIMAL, mailboxSession);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
index b1ef8f8..4fe3a81 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
@@ -60,20 +60,17 @@ public class FetchProcessor extends AbstractMailboxProcessor<FetchRequest> {
 
     @Override
     protected void processRequest(FetchRequest request, ImapSession session, Responder responder) {
-        final boolean useUids = request.isUseUids();
-        final IdRange[] idSet = request.getIdSet();
-        final FetchData fetch = computeFetchData(request, session);
+        boolean useUids = request.isUseUids();
+        IdRange[] idSet = request.getIdSet();
+        FetchData fetch = computeFetchData(request, session);
 
         try {
             final long changedSince = fetch.getChangedSince();
 
-            final MessageManager mailbox = getSelectedMailbox(session);
+            MessageManager mailbox = getSelectedMailbox(session)
+                .orElseThrow(() -> new MailboxException("Session not in SELECTED state"));
 
-            if (mailbox == null) {
-                throw new MailboxException("Session not in SELECTED state");
-            }
-
-            final boolean vanished = fetch.getVanished();
+            boolean vanished = fetch.getVanished();
             if (vanished && !EnableProcessor.getEnabledCapabilities(session).contains(ImapConstants.SUPPORTS_QRESYNC)) {
                 taggedBad(request, responder, HumanReadableText.QRESYNC_NOT_ENABLED);
                 return;


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org