dispose method to release any resources it holds
34 | * when object is destroyed.
35 | *
36 | * @author Rustam Aliyev
37 | */
38 | public interface Disposable
39 | {
40 | /**
41 | * Dispose this object and release all resources it holds.
42 | */
43 | void dispose();
44 | }
45 |
--------------------------------------------------------------------------------
/modules/config/src/main/java/com/elasticinbox/config/DatabaseConstants.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011-2013 Optimax Software Ltd.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names
14 | * of its contributors may be used to endorse or promote products derived
15 | * from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | package com.elasticinbox.config;
30 |
31 | public class DatabaseConstants
32 | {
33 | /** Maximum blob size allowed in database. 128KB */
34 | public static long MAX_BLOB_SIZE = 0x20000;
35 |
36 | /** Maximum blob block size. 128KB */
37 | public static long BLOB_BLOCK_SIZE = 0x20000;
38 |
39 | /** Reserved profile name for internal database storage (e.g. Cassandra) */
40 | public static final String DATABASE_PROFILE = "db";
41 | }
42 |
--------------------------------------------------------------------------------
/modules/rest/src/main/java/com/elasticinbox/rest/BadRequestException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011-2012 Optimax Software Ltd.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names
14 | * of its contributors may be used to endorse or promote products derived
15 | * from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | package com.elasticinbox.rest;
30 |
31 | import javax.ws.rs.core.Response.Status;
32 |
33 | /**
34 | * Throws "400 Bad Request" REST exception
35 | *
36 | * @author Rustam Aliyev
37 | */
38 | public class BadRequestException extends RESTApplicationException
39 | {
40 | private static final long serialVersionUID = 5728319121775424046L;
41 |
42 | public BadRequestException(String message) {
43 | super(Status.BAD_REQUEST, message);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/modules/lmtp/src/main/java/com/elasticinbox/lmtp/filter/Filter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011-2012 Optimax Software Ltd.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names
14 | * of its contributors may be used to endorse or promote products derived
15 | * from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | package com.elasticinbox.lmtp.filter;
30 |
31 | /**
32 | * Filter Interface represents a "Handler" described in Chain of Responsibility
33 | * pattern. Each filter should be processed using {@link FilterProcessor}.
34 | *
35 | * @author Rustam Aliyev
36 | *
37 | * @param Specific {@link #getBlobName()} implementation should generate new Blob name 35 | * based on the provided parameters. Make sure that your implementation produces 36 | * unique Blob name.
37 | * 38 | * @author Rustam Aliyev 39 | */ 40 | public abstract class AbstractBlobNamingPolicy 41 | { 42 | protected AbstractBlobNamingPolicy() { 43 | } 44 | 45 | /** 46 | * Generate new Blob Name 47 | * 48 | * @return 49 | */ 50 | public abstract String getBlobName(BlobNameBuilder builder); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /modules/lmtp/src/main/java/com/elasticinbox/lmtp/delivery/DeliveryAgentFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2012 Optimax Software Ltd. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names 14 | * of its contributors may be used to endorse or promote products derived 15 | * from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | package com.elasticinbox.lmtp.delivery; 30 | 31 | import com.elasticinbox.core.DAOFactory; 32 | import com.elasticinbox.core.MessageDAO; 33 | 34 | /** 35 | * This factory creates delivery agents consuming emails from LMTP and storing 36 | * them. 37 | * 38 | * @author Rustam Aliyev 39 | */ 40 | public class DeliveryAgentFactory 41 | { 42 | private final MessageDAO messageDAO; 43 | 44 | public DeliveryAgentFactory() 45 | { 46 | DAOFactory dao = DAOFactory.getDAOFactory(); 47 | messageDAO = dao.getMessageDAO(); 48 | } 49 | 50 | public IDeliveryAgent getDeliveryAgent() { 51 | return new ElasticInboxDeliveryAgent(messageDAO); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /bundles/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 29 |Specific {@link #getMessageId()} implementation should generate new 37 | * message UUID based on the provided parameters.
38 | * 39 | *IMPORTANT: Make sure that your implementation produces unique 40 | * message ID. If uniqueness is not guaranteed, messages will be overwritten 41 | * and discrepancy between counters and messages will occur.
42 | * 43 | * @author Rustam Aliyev 44 | */ 45 | public abstract class AbstractMessageIdPolicy 46 | { 47 | 48 | protected AbstractMessageIdPolicy() { 49 | } 50 | 51 | /** 52 | * Generate new Blob Name 53 | * 54 | * @return 55 | */ 56 | protected abstract UUID getMessageId(MessageIdBuilder builder); 57 | 58 | } 59 | -------------------------------------------------------------------------------- /modules/lmtp/src/main/java/com/elasticinbox/lmtp/utils/LoggingPeriodicalLog.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2012 Optimax Software Ltd. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names 14 | * of its contributors may be used to endorse or promote products derived 15 | * from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | package com.elasticinbox.lmtp.utils; 30 | 31 | import org.slf4j.Logger; 32 | import org.slf4j.LoggerFactory; 33 | 34 | import com.ecyrd.speed4j.StopWatch; 35 | import com.ecyrd.speed4j.log.PeriodicalLog; 36 | 37 | /** 38 | * A Logging Periodical log has all capabilities of Periodical log, but also 39 | * writes the stopwatch data to the given SLF4J logger. 40 | * 41 | * @author Rustam Aliyev 42 | * @see {@link PeriodicalLog} 43 | */ 44 | public class LoggingPeriodicalLog extends PeriodicalLog 45 | { 46 | private static final Logger logger = LoggerFactory 47 | .getLogger(LoggingPeriodicalLog.class); 48 | 49 | public LoggingPeriodicalLog() 50 | { 51 | super(); 52 | } 53 | 54 | @Override 55 | public void log(StopWatch sw) 56 | { 57 | // use different logger than superclass 58 | logger.info(sw.toString()); 59 | super.log(sw); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/AccountDAO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2012 Optimax Software Ltd. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names 14 | * of its contributors may be used to endorse or promote products derived 15 | * from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | package com.elasticinbox.core; 30 | 31 | import java.io.IOException; 32 | 33 | import com.elasticinbox.core.model.Mailbox; 34 | 35 | /** 36 | * Interface for Account operations 37 | * 38 | * @author Rustam Aliyev 39 | */ 40 | public interface AccountDAO 41 | { 42 | /** 43 | * Add new account and initialize set of predefined labels. 44 | * 45 | * @param mailbox 46 | * @throws IOException 47 | * @throws IllegalArgumentException 48 | */ 49 | public void add(Mailbox mailbox) throws IOException, IllegalArgumentException; 50 | 51 | /** 52 | * Delete account and all messages associated with it. Messages will be 53 | * deleted immediately from blob store and metadata store. All other 54 | * metadata information will also be cleared. 55 | * 56 | * @param mailbox 57 | * @throws IOException 58 | */ 59 | public void delete(Mailbox mailbox) throws IOException; 60 | 61 | } 62 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/cassandra/AbstractMessageDAO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2012 Optimax Software Ltd. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names 14 | * of its contributors may be used to endorse or promote products derived 15 | * from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | package com.elasticinbox.core.cassandra; 30 | 31 | import java.util.UUID; 32 | 33 | import com.elasticinbox.core.IllegalLabelException; 34 | import com.elasticinbox.core.MessageDAO; 35 | import com.elasticinbox.core.MessageModification; 36 | import com.elasticinbox.core.model.Mailbox; 37 | import com.google.common.collect.ImmutableList; 38 | 39 | /** 40 | * A partial implementation of the {@link MessageDAO} interface which translates 41 | * single message operations into multi-message. 42 | * 43 | * @author Rustam Aliyev 44 | */ 45 | public abstract class AbstractMessageDAO implements MessageDAO 46 | { 47 | @Override 48 | public void modify(Mailbox mailbox, UUID messageId, MessageModification modification) throws IllegalLabelException { 49 | modify(mailbox, ImmutableList.of(messageId), modification); 50 | } 51 | 52 | @Override 53 | public void delete(final Mailbox mailbox, final UUID messageId) { 54 | delete(mailbox, ImmutableList.of(messageId)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /modules/rest/src/main/java/com/elasticinbox/rest/RESTApplicationException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2012 Optimax Software Ltd. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names 14 | * of its contributors may be used to endorse or promote products derived 15 | * from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | package com.elasticinbox.rest; 30 | 31 | import javax.ws.rs.WebApplicationException; 32 | import javax.ws.rs.core.MediaType; 33 | import javax.ws.rs.core.Response; 34 | import javax.ws.rs.core.Response.Status; 35 | 36 | import com.elasticinbox.common.utils.JSONUtils; 37 | import com.google.common.collect.ImmutableMap; 38 | 39 | /** 40 | * Throws REST exception with given status code and message. Message will be 41 | * wrapped in JSON object. 42 | * 43 | * @author Rustam Aliyev 44 | */ 45 | public class RESTApplicationException extends WebApplicationException 46 | { 47 | private static final long serialVersionUID = 5728319121775424046L; 48 | 49 | public RESTApplicationException(Status status, String message) 50 | { 51 | super(Response 52 | .status(status) 53 | .entity(JSONUtils 54 | .fromObject(new ImmutableMap.Buildercharset information to the
39 | * HTTP response
40 | *
41 | * @author Rustam Aliyev
42 | */
43 | public class CharsetResponseFilter implements ContainerResponseFilter
44 | {
45 |
46 | public ContainerResponse filter(ContainerRequest request, ContainerResponse response)
47 | {
48 | MediaType contentType = response.getMediaType();
49 |
50 | // For JSON responses use UTF-8 charset
51 | if((contentType != null) && contentType.equals(MediaType.APPLICATION_JSON_TYPE)) {
52 | response.getHttpHeaders().putSingle("Content-Type",
53 | contentType.toString() + ";charset=UTF-8");
54 | }
55 |
56 | return response;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/modules/core/src/main/java/com/elasticinbox/core/DAOFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011-2012 Optimax Software Ltd.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names
14 | * of its contributors may be used to endorse or promote products derived
15 | * from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | package com.elasticinbox.core;
30 |
31 | import com.elasticinbox.core.cassandra.CassandraDAOFactory;
32 |
33 | /**
34 | * Core Data Access Factory
35 | *
36 | * @author Rustam Aliyev
37 | */
38 | public abstract class DAOFactory
39 | {
40 | // List of metadata DAO types supported by ElasticInbox
41 | public static final String CASSANDRA = "cassandra";
42 | public static final String HBASE = "hbase";
43 |
44 | // Data Access decomposed into the following DAOs:
45 | public abstract AccountDAO getAccountDAO();
46 | public abstract MessageDAO getMessageDAO();
47 | public abstract LabelDAO getLabelDAO();
48 |
49 | public static DAOFactory getDAOFactory()
50 | {
51 | // Currently only Cassandra supported, ignore config
52 | return new CassandraDAOFactory();
53 |
54 | /*
55 | String driver = Configurator.getMetadataStorageDriver();
56 |
57 | if (driver.equalsIgnoreCase(CASSANDRA)) {
58 | return new CassandraDAOFactory();
59 | } else {
60 | return null;
61 | }
62 | */
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/modules/lmtp/src/main/java/com/elasticinbox/lmtp/filter/SpamMailFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011-2012 Optimax Software Ltd.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names
14 | * of its contributors may be used to endorse or promote products derived
15 | * from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | package com.elasticinbox.lmtp.filter;
30 |
31 | import org.slf4j.Logger;
32 | import org.slf4j.LoggerFactory;
33 |
34 | import com.elasticinbox.core.message.MimeParser;
35 | import com.elasticinbox.core.model.Message;
36 | import com.elasticinbox.core.model.ReservedLabels;
37 |
38 | /**
39 | * Labels message as Spam if respective header is found.
40 | *
41 | * @author Rustam Aliyev
42 | */
43 | public final class SpamMailFilter implements Filter42 | * Produces a 22 character string which is a URL safe Base64 encoded UUID. 43 | *
44 | * 45 | * @author Rustam Aliyev 46 | */ 47 | public class Base64UUIDUtils 48 | { 49 | public static String encode(UUID uuid) 50 | { 51 | String base64 = DatatypeConverter.printBase64Binary(TimeUUIDUtils.asByteArray(uuid)); 52 | 53 | // remove padding 54 | if (base64.endsWith("==")) { 55 | base64 = base64.substring(0, base64.length() - 2); 56 | } 57 | 58 | return base64; 59 | 60 | // TODO use with Guava 14 (Jclouds 1.6) 61 | // return BaseEncoding.base64Url().omitPadding() 62 | // .encode(TimeUUIDUtils.asByteArray(uuid)); 63 | } 64 | 65 | public static UUID decode(String encoded) 66 | { 67 | // TODO use with Guava 14 (Jclouds 1.6) 68 | // byte[] ba = BaseEncoding.base64Url().decode(encoded); 69 | // return TimeUUIDUtils.toUUID(ba); 70 | 71 | return TimeUUIDUtils.toUUID(DatatypeConverter.parseBase64Binary(encoded + "==")); 72 | } 73 | } -------------------------------------------------------------------------------- /modules/core/src/test/java/com/elasticinbox/core/message/id/MessageIdPolicyTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2012 Optimax Software Ltd. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names 14 | * of its contributors may be used to endorse or promote products derived 15 | * from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | package com.elasticinbox.core.message.id; 30 | 31 | import static org.junit.Assert.*; 32 | import static org.hamcrest.Matchers.*; 33 | 34 | import java.util.Date; 35 | import java.util.UUID; 36 | 37 | import me.prettyprint.cassandra.utils.TimeUUIDUtils; 38 | 39 | import org.junit.Test; 40 | 41 | import com.elasticinbox.core.message.id.MessageIdBuilder; 42 | 43 | public class MessageIdPolicyTest 44 | { 45 | @Test 46 | public void testSentDateMessageIdPolicy() 47 | { 48 | Date date = new Date(); 49 | UUID uuid2; 50 | long ts2; 51 | 52 | for (int i = 0; i < 10000; i++) { 53 | uuid2 = new MessageIdBuilder().setSentDate(date).build(); 54 | ts2 = TimeUUIDUtils.getTimeFromUUID(uuid2); 55 | assertThat(1000L, greaterThan(ts2 - date.getTime())); 56 | } 57 | } 58 | 59 | @Test 60 | public void testCurrentDateMessageIdPolicy() 61 | { 62 | UUID uuid; 63 | UUID prev = new MessageIdBuilder().build(); 64 | long ts; 65 | 66 | for (int i = 0; i < 10000; i++) { 67 | uuid = new MessageIdBuilder().build(); 68 | ts = TimeUUIDUtils.getTimeFromUUID(uuid); 69 | 70 | if(uuid.equals(prev)) 71 | fail("Not unique, same as previous!"); 72 | 73 | prev = uuid; 74 | 75 | assertThat(100L, greaterThan(System.currentTimeMillis() - ts)); 76 | } 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /bundles/com.ecyrd.speed4j/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 29 |38 | * Deflate compression (RFC1951) used in ElasticInbox due to a number of reasons: 39 | *
40 | * 1. It is possible to serve deflated content over HTTP without decompression. 41 | *
42 | * 2. It is possible to serve deflated content over IMAP without decompression. 43 | * IMAP COMPRESS Extension (RFC4978) recognizes only deflate. 44 | *
45 | * 3. Deflate has better performance in comparison to Gzip and provides good trade
46 | * off between size and speed.
47 | *
48 | * @author Rustam Aliyev
49 | */
50 | public class DeflateCompressionHandler implements CompressionHandler
51 | {
52 | public final static String COMPRESSION_TYPE_DEFLATE = "dfl";
53 |
54 | @Override
55 | public InputStream compress(InputStream in) {
56 | return new DeflaterInputStream(in);
57 | }
58 |
59 | @Override
60 | public InputStream uncompress(InputStream in) {
61 | return new InflaterInputStream(in);
62 | }
63 |
64 | @Override
65 | public String getType() {
66 | return COMPRESSION_TYPE_DEFLATE;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/modules/lmtp/src/main/java/com/elasticinbox/lmtp/delivery/MulticastDeliveryAgent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011-2012 Optimax Software Ltd.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names
14 | * of its contributors may be used to endorse or promote products derived
15 | * from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | package com.elasticinbox.lmtp.delivery;
30 |
31 | import java.util.HashMap;
32 | import java.util.Map;
33 |
34 | import org.apache.james.protocols.smtp.MailEnvelope;
35 | import org.apache.james.protocols.smtp.MailAddress;
36 | import org.slf4j.Logger;
37 | import org.slf4j.LoggerFactory;
38 |
39 | import com.elasticinbox.lmtp.server.api.DeliveryReturnCode;
40 |
41 | /**
42 | * Delivery backend implementation
43 | *
44 | * @author Rustam Aliyev
45 | */
46 | public class MulticastDeliveryAgent implements IDeliveryAgent
47 | {
48 | private static final Logger logger = LoggerFactory
49 | .getLogger(MulticastDeliveryAgent.class);
50 | private IDeliveryAgent[] agents;
51 |
52 | public MulticastDeliveryAgent(IDeliveryAgent... agents) {
53 | this.agents = agents;
54 | }
55 |
56 | @Override
57 | public Map Using combination of
40 | * WARNING: This implementation does not guarantee uniqueness.
41 | *
42 | * @author Rustam Aliyev
43 | */
44 | public final class SentDateMessageIdPolicy extends AbstractMessageIdPolicy
45 | {
46 | /** The last time value issued. Used to try to prevent duplicates. */
47 | private static long lastTime = -1;
48 |
49 | @Override
50 | protected UUID getMessageId(MessageIdBuilder builder)
51 | {
52 | Assert.notNull(builder.sentDate, "sent date cannot be null");
53 |
54 | // The following advances mail time by a milliseconds of current time
55 |
56 | // Counter should be checked against current time
57 | long currentUs = System.currentTimeMillis();
58 |
59 | // Message date has granularity of seconds. Delta adds milliseconds of
60 | // current time.
61 | long emailUs = builder.sentDate.getTime();
62 | long delta = 0;
63 |
64 | // Synchronized to guarantee unique time within and across threads.
65 | synchronized (SentDateMessageIdPolicy.class)
66 | {
67 | if (currentUs > lastTime) {
68 | lastTime = currentUs;
69 | } else {
70 | // the time i got from the system is equals or less
71 | // (hope not - clock going backwards)
72 | // One more "millisecond"
73 | ++lastTime;
74 | }
75 |
76 | // Get ms from the static counter
77 | delta = lastTime % 1000L;
78 | }
79 |
80 | // Append ms to the message date
81 | emailUs += delta;
82 | return TimeUUIDUtils.getTimeUUID(emailUs);
83 | }
84 | }
--------------------------------------------------------------------------------
/modules/core/src/test/java/com/elasticinbox/core/message/MimeParserTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011-2013 Optimax Software Ltd.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names
14 | * of its contributors may be used to endorse or promote products derived
15 | * from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | package com.elasticinbox.core.message;
30 |
31 | import static org.junit.Assert.*;
32 |
33 | import java.io.File;
34 | import java.io.FileInputStream;
35 | import java.io.IOException;
36 | import java.io.InputStream;
37 | import java.util.Map;
38 |
39 | import org.apache.commons.codec.digest.DigestUtils;
40 | import org.junit.Test;
41 |
42 | import com.elasticinbox.core.model.Message;
43 | import com.elasticinbox.core.model.MimePart;
44 |
45 | public class MimeParserTest
46 | {
47 | private final static String TEST_INLINE_ATTACH_FILE = "../../itests/src/test/resources/03-inline-attach.eml";
48 |
49 | /**
50 | * Loop through message parts and check if retrieval by PartId is consistent
51 | * with retrieval by ContentId.
52 | *
53 | * @throws IOException
54 | * @throws MimeParserException
55 | */
56 | @Test
57 | public void testGetInputStreamByPartIdAndContentId() throws IOException, MimeParserException
58 | {
59 | File file = new File(TEST_INLINE_ATTACH_FILE);
60 | InputStream in = new FileInputStream(file);
61 |
62 | MimeParser mp = new MimeParser(in);
63 | Message message = mp.getMessage();
64 |
65 | Map
80 | * Suffix no longer used for compression identification. Keep for backward
81 | * compatibility with 0.3.
82 | *
83 | * @param name
84 | */
85 | @Deprecated
86 | private final static void validateBlobName(String name) {
87 | Assert.isFalse(
88 | name.endsWith(BlobStoreConstants.COMPRESS_SUFFIX),
89 | "This suffix is reserved for internal compression. Blob name should not end with "
90 | + BlobStoreConstants.COMPRESS_SUFFIX);
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
date header from email
50 | *
51 | * @param date
52 | * @return
53 | */
54 | public MessageIdBuilder setSentDate(Date date) {
55 | this.sentDate = date;
56 | return this;
57 | }
58 |
59 | /**
60 | * Set message-id header from email
61 | *
62 | * @param messageId
63 | * @return
64 | */
65 | public MessageIdBuilder setMessageIdHeader(String messageId) {
66 | this.messageIdHeader = messageId;
67 | return this;
68 | }
69 |
70 | /**
71 | * Build new message UUID
72 | *
73 | * @return
74 | */
75 | public UUID build()
76 | {
77 | UUID messageId = null;
78 |
79 | if (sentDate != null) {
80 | messageId = sentDatePolicy.getMessageId(this);
81 | } else {
82 | messageId = currentTimePolicy.getMessageId(this);
83 | }
84 |
85 | return messageId;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/modules/core/src/main/java/com/elasticinbox/core/model/Address.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011-2012 Optimax Software Ltd.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names
14 | * of its contributors may be used to endorse or promote products derived
15 | * from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | package com.elasticinbox.core.model;
30 |
31 | import com.fasterxml.jackson.annotation.JsonIgnore;
32 |
33 | /**
34 | * This class represents a single e-mail address.
35 | */
36 | public class Address
37 | {
38 | private final String name;
39 | private final String address;
40 |
41 | /**
42 | * Creates new address
43 | *
44 | * @param name
45 | * The name of the email address. May be null.
46 | * @param address
47 | * Email address localPart@domain.com. May be null.
48 | */
49 | public Address(String name, String address) {
50 | this.name = name;
51 | this.address = address;
52 | }
53 |
54 | /**
55 | * Returns the name of the mailbox or null if it does not
56 | * have a name.
57 | */
58 | public String getName() {
59 | return this.name;
60 | }
61 |
62 | /**
63 | * Returns the e-mail address ("user@example.com").
64 | */
65 | public String getAddress() {
66 | return this.address;
67 | }
68 |
69 | @JsonIgnore
70 | @Override
71 | public String toString() {
72 | boolean includeAngleBrackets = (name != null);
73 |
74 | StringBuilder sb = new StringBuilder();
75 |
76 | if (name != null) {
77 | sb.append(name).append(' ');
78 | }
79 |
80 | if (includeAngleBrackets) {
81 | sb.append('<');
82 | }
83 |
84 | sb.append(address);
85 |
86 | if (includeAngleBrackets) {
87 | sb.append('>');
88 | }
89 |
90 | return sb.toString();
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/modules/core/src/main/java/com/elasticinbox/core/model/Marker.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011-2012 Optimax Software Ltd.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names
14 | * of its contributors may be used to endorse or promote products derived
15 | * from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | package com.elasticinbox.core.model;
30 |
31 | /**
32 | * This is the representation of message markers. Each message can be marked
33 | * with one or more markers.
34 | *
35 | * @author Rustam Aliyev
36 | */
37 | public enum Marker
38 | {
39 | /** Mark message as Seen */
40 | SEEN(1),
41 |
42 | /** Mark message as Replied */
43 | REPLIED(2),
44 |
45 | /** Mark message as Forwarded */
46 | FORWARDED(3);
47 |
48 | private int value;
49 |
50 | Marker(int value) {
51 | this.value = value;
52 | }
53 |
54 | public int toInt() {
55 | return value;
56 | }
57 |
58 | public static Marker fromInt(int value)
59 | {
60 | switch (value) {
61 | case 1:
62 | return SEEN;
63 | case 2:
64 | return REPLIED;
65 | default:
66 | return FORWARDED;
67 | }
68 | }
69 |
70 | public static Marker fromString(String value)
71 | {
72 | if (value == null) {
73 | throw new IllegalArgumentException();
74 | }
75 |
76 | if (value.equals("seen")) {
77 | return Marker.SEEN;
78 | } else if (value.equals("replied")) {
79 | return Marker.REPLIED;
80 | } else if (value.equals("forwarded")) {
81 | return Marker.FORWARDED;
82 | } else {
83 | throw new IllegalArgumentException();
84 | }
85 | }
86 |
87 | public String toString()
88 | {
89 | switch (this) {
90 | case SEEN:
91 | return "seen";
92 | case REPLIED:
93 | return "replied";
94 | case FORWARDED:
95 | return "forwarded";
96 | }
97 |
98 | return null;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/modules/pop3/src/main/java/com/elasticinbox/pop3/POP3ProxyServer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011-2012 Optimax Software Ltd.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names
14 | * of its contributors may be used to endorse or promote products derived
15 | * from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | package com.elasticinbox.pop3;
30 |
31 | import java.net.InetSocketAddress;
32 |
33 | import org.apache.james.protocols.api.logger.Logger;
34 | import org.apache.james.protocols.pop3.POP3Protocol;
35 | import org.apache.james.protocols.pop3.POP3ProtocolHandlerChain;
36 | import org.apache.james.protocols.netty.NettyServer;
37 |
38 | import com.elasticinbox.config.Configurator;
39 | import com.elasticinbox.pop3.server.POP3ServerConfig;
40 | import com.elasticinbox.pop3.server.handler.AuthHandler;
41 | import com.elasticinbox.pop3.server.handler.MailboxHandlerFactory;
42 | import com.elasticinbox.pop3.utils.POP3ProtocolLogger;
43 |
44 | /**
45 | * POP3 proxy main class
46 | *
47 | * @author Rustam Aliyev
48 | */
49 | public class POP3ProxyServer
50 | {
51 | private NettyServer server;
52 | private MailboxHandlerFactory backend;
53 |
54 | protected POP3ProxyServer(final MailboxHandlerFactory backend) {
55 | this.backend = backend;
56 | }
57 |
58 | public void start() throws Exception
59 | {
60 | Logger logger = new POP3ProtocolLogger();
61 |
62 | POP3ProtocolHandlerChain chain = new POP3ProtocolHandlerChain(new AuthHandler(backend));
63 |
64 | server = new NettyServer(new POP3Protocol(chain, new POP3ServerConfig(), logger));
65 | server.setListenAddresses(new InetSocketAddress(Configurator.getPop3Port()));
66 | server.setMaxConcurrentConnections(Configurator.getPop3MaxConnections());
67 | server.setTimeout(POP3ServerConfig.CONNECTION_TIMEOUT);
68 | server.setUseExecutionHandler(true, 16);
69 | server.bind();
70 | }
71 |
72 | public void stop() {
73 | server.unbind();
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/modules/config/src/main/java/com/elasticinbox/config/Config.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011-2012 Optimax Software Ltd.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names
14 | * of its contributors may be used to endorse or promote products derived
15 | * from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | package com.elasticinbox.config;
30 |
31 | import java.util.List;
32 | import java.util.Map;
33 |
34 | import com.elasticinbox.config.blob.BlobStoreProfile;
35 | import com.elasticinbox.config.crypto.EncryptionSettings;
36 |
37 | public class Config
38 | {
39 | // Default quota settings
40 | public Long mailbox_quota_bytes; // maximum mailbox size in bytes
41 | public Long mailbox_quota_count; // maximum message count in mailbox
42 |
43 | // JMX monitoring
44 | public Boolean enable_performance_counters;
45 | public Integer performance_counters_interval;
46 |
47 | // LMTP settings
48 | public Integer lmtp_port;
49 | public Integer lmtp_max_connections;
50 | public boolean lmtp_enable_pop3;
51 |
52 | // POP3 settings
53 | public Integer pop3_port;
54 | public Integer pop3_max_connections;
55 |
56 | // Database settings
57 | public String database_driver;
58 | public Boolean store_html_message;
59 | public Boolean store_plain_message;
60 | public Long database_blob_max_size;
61 |
62 | // Cassandra settings
63 | public ListBlobStoreProfile and blob name (including
35 | * relative path) it is possible to uniquely identify any blob within
36 | * multi-cloud environment.
37 | *
38 | * @author Rustam Aliyev
39 | */
40 | public class BlobStoreProfile
41 | {
42 | private String provider;
43 | private String endpoint;
44 | private String identity;
45 | private String credential;
46 | private String container;
47 | private String apiversion;
48 |
49 | public String getApiversion() {
50 | return apiversion;
51 | }
52 |
53 | public void setApiversion(String apiversion) {
54 | this.apiversion = apiversion;
55 | }
56 |
57 | public String getProvider() {
58 | return provider;
59 | }
60 |
61 | public void setProvider(String provider) {
62 | this.provider = provider;
63 | }
64 |
65 | public String getEndpoint() {
66 | return endpoint;
67 | }
68 |
69 | public void setEndpoint(String endpoint) {
70 | this.endpoint = endpoint;
71 | }
72 |
73 | public String getIdentity() {
74 | return identity;
75 | }
76 |
77 | public void setIdentity(String identity) {
78 | this.identity = identity;
79 | }
80 |
81 | public String getCredential() {
82 | return credential;
83 | }
84 |
85 | public void setCredential(String credential) {
86 | this.credential = credential;
87 | }
88 |
89 | public String getContainer() {
90 | return container;
91 | }
92 |
93 | public void setContainer(String container) {
94 | this.container = container;
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/modules/core/src/main/java/com/elasticinbox/core/blob/encryption/AESEncryptionHandler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011-2012 Optimax Software Ltd.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names
14 | * of its contributors may be used to endorse or promote products derived
15 | * from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | package com.elasticinbox.core.blob.encryption;
30 |
31 | import java.io.InputStream;
32 | import java.security.InvalidAlgorithmParameterException;
33 | import java.security.InvalidKeyException;
34 | import java.security.Key;
35 | import java.security.NoSuchAlgorithmException;
36 | import java.security.NoSuchProviderException;
37 |
38 | import javax.crypto.Cipher;
39 | import javax.crypto.CipherInputStream;
40 | import javax.crypto.NoSuchPaddingException;
41 | import javax.crypto.spec.IvParameterSpec;
42 |
43 | /**
44 | * This class provides AES encryption/decryption methods.
45 | *
46 | * @author Rustam Aliyev
47 | */
48 | public class AESEncryptionHandler implements EncryptionHandler
49 | {
50 | /**
51 | * Use AES-CBC algorithm with PKCS5 padding
52 | */
53 | public static final String CIPHER_TRANSFORMATION = "AES/CBC/PKCS5Padding";
54 |
55 | public InputStream encrypt(InputStream in, Key key, byte[] iv)
56 | throws NoSuchAlgorithmException, NoSuchPaddingException,
57 | InvalidKeyException, InvalidAlgorithmParameterException, NoSuchProviderException
58 | {
59 | Cipher cipher = Cipher.getInstance(CIPHER_TRANSFORMATION);
60 | cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));
61 |
62 | return new CipherInputStream(in, cipher);
63 | }
64 |
65 | public InputStream decrypt(InputStream in, Key key, byte[] iv)
66 | throws NoSuchAlgorithmException, NoSuchPaddingException,
67 | InvalidKeyException, InvalidAlgorithmParameterException, NoSuchProviderException
68 | {
69 | Cipher cipher = Cipher.getInstance(CIPHER_TRANSFORMATION);
70 | cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));
71 |
72 | return new CipherInputStream(in, cipher);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/modules/core/src/main/java/com/elasticinbox/core/message/id/SentDateMessageIdPolicy.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011-2012 Optimax Software Ltd.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | * * Neither the name of Optimax Software, ElasticInbox, nor the names
14 | * of its contributors may be used to endorse or promote products derived
15 | * from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | package com.elasticinbox.core.message.id;
30 |
31 | import java.util.UUID;
32 |
33 | import com.elasticinbox.common.utils.Assert;
34 |
35 | import me.prettyprint.cassandra.utils.TimeUUIDUtils;
36 |
37 | /**
38 | * Generates message ID based on the time when message was sent.
39 | *