├── itests ├── .gitignore └── src │ ├── META-INF │ └── links │ │ └── org.ops4j.pax.logging.api.link │ └── test │ └── resources │ ├── elasticinbox.ks │ ├── logback.xml │ └── 01-simple-ascii.eml ├── bundles ├── com.ecyrd.speed4j │ ├── .gitignore │ ├── osgi.bnd │ └── pom.xml └── pom.xml ├── modules ├── core │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── .gitignore │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── elasticinbox │ │ │ │ └── core │ │ │ │ ├── account │ │ │ │ ├── validator │ │ │ │ │ ├── IValidator.java │ │ │ │ │ ├── ValidatorFactory.java │ │ │ │ │ └── DummyValidator.java │ │ │ │ └── authenticator │ │ │ │ │ ├── AuthenticationException.java │ │ │ │ │ ├── AuthenticatorFactory.java │ │ │ │ │ ├── IAuthenticator.java │ │ │ │ │ └── AllowAllAuthenticator.java │ │ │ │ ├── message │ │ │ │ ├── MimeParserException.java │ │ │ │ └── id │ │ │ │ │ ├── CurrentTimeMessageIdPolicy.java │ │ │ │ │ ├── AbstractMessageIdPolicy.java │ │ │ │ │ ├── MessageIdBuilder.java │ │ │ │ │ └── SentDateMessageIdPolicy.java │ │ │ │ ├── OverQuotaException.java │ │ │ │ ├── blob │ │ │ │ ├── BlobUtils.java │ │ │ │ ├── naming │ │ │ │ │ ├── UuidBlobNamingPolicy.java │ │ │ │ │ ├── AbstractBlobNamingPolicy.java │ │ │ │ │ └── BlobNameBuilder.java │ │ │ │ ├── compression │ │ │ │ │ ├── CompressionHandler.java │ │ │ │ │ └── DeflateCompressionHandler.java │ │ │ │ ├── encryption │ │ │ │ │ ├── EncryptionHandler.java │ │ │ │ │ └── AESEncryptionHandler.java │ │ │ │ └── store │ │ │ │ │ └── BlobStorage.java │ │ │ │ ├── IllegalLabelException.java │ │ │ │ ├── ExistingLabelException.java │ │ │ │ ├── log │ │ │ │ └── JcloudsSlf4JLoggingModule.java │ │ │ │ ├── model │ │ │ │ ├── LabelConstants.java │ │ │ │ ├── Address.java │ │ │ │ ├── Marker.java │ │ │ │ └── AddressList.java │ │ │ │ ├── cassandra │ │ │ │ ├── utils │ │ │ │ │ ├── BatchConstants.java │ │ │ │ │ ├── ThrottlingMutationResult.java │ │ │ │ │ ├── QuorumConsistencyLevel.java │ │ │ │ │ └── Speed4jOpTimer.java │ │ │ │ └── AbstractMessageDAO.java │ │ │ │ ├── AccountDAO.java │ │ │ │ ├── DAOFactory.java │ │ │ │ └── utils │ │ │ │ └── Base64UUIDUtils.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── elasticinbox │ │ │ └── core │ │ │ ├── cassandra │ │ │ └── persistence │ │ │ │ └── LabelIndexPersistenceTest.java │ │ │ ├── model │ │ │ ├── LabelCountersTest.java │ │ │ └── LabelMapTest.java │ │ │ ├── utils │ │ │ └── Base64UUIDUtilsTest.java │ │ │ └── message │ │ │ ├── id │ │ │ └── MessageIdPolicyTest.java │ │ │ └── MimeParserTest.java │ ├── build.properties │ └── osgi.bnd ├── lmtp │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── .gitignore │ │ │ └── java │ │ │ └── com │ │ │ └── elasticinbox │ │ │ └── lmtp │ │ │ ├── server │ │ │ ├── api │ │ │ │ ├── handler │ │ │ │ │ └── ValidRcptHandler.java │ │ │ │ ├── DeliveryReturnCode.java │ │ │ │ └── DeliveryException.java │ │ │ └── LMTPServerConfig.java │ │ │ ├── filter │ │ │ ├── Filter.java │ │ │ ├── SpamMailFilter.java │ │ │ ├── FilterProcessor.java │ │ │ └── DefaultMailFilter.java │ │ │ ├── delivery │ │ │ ├── DeliveryAction.java │ │ │ ├── DeliveryAgentFactory.java │ │ │ ├── IDeliveryAgent.java │ │ │ └── MulticastDeliveryAgent.java │ │ │ └── utils │ │ │ └── LoggingPeriodicalLog.java │ ├── build.properties │ └── osgi.bnd ├── pop3 │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── .gitignore │ │ │ └── java │ │ │ └── com │ │ │ └── elasticinbox │ │ │ └── pop3 │ │ │ ├── server │ │ │ ├── handler │ │ │ │ └── MailboxHandlerFactory.java │ │ │ └── POP3ServerConfig.java │ │ │ └── POP3ProxyServer.java │ ├── build.properties │ └── osgi.bnd ├── rest │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── .gitignore │ │ │ ├── webapp │ │ │ └── WEB-INF │ │ │ │ └── web.xml │ │ │ └── java │ │ │ └── com │ │ │ └── elasticinbox │ │ │ └── rest │ │ │ ├── JSONResponse.java │ │ │ ├── BadRequestException.java │ │ │ ├── RESTApplicationException.java │ │ │ └── CharsetResponseFilter.java │ ├── build.properties │ └── osgi.bnd ├── common │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── .gitignore │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── elasticinbox │ │ │ │ └── common │ │ │ │ ├── utils │ │ │ │ ├── ThreadLocalByteBuffer.java │ │ │ │ └── Assert.java │ │ │ │ └── Disposable.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── elasticinbox │ │ │ └── common │ │ │ └── utils │ │ │ ├── JSONUtilsTest.java │ │ │ ├── AbstractInputStreamTest.java │ │ │ └── CRLFInputStreamTest.java │ ├── build.properties │ └── osgi.bnd ├── config │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── .gitignore │ │ │ └── java │ │ │ └── com │ │ │ └── elasticinbox │ │ │ └── config │ │ │ ├── crypto │ │ │ └── EncryptionSettings.java │ │ │ ├── ConfigurationException.java │ │ │ ├── DatabaseConstants.java │ │ │ ├── Config.java │ │ │ └── blob │ │ │ └── BlobStoreProfile.java │ ├── build.properties │ └── osgi.bnd └── pom.xml ├── .gitignore ├── assembly └── src │ └── main │ └── etc │ ├── bin │ └── elasticinbox │ └── assembly │ └── assembly.xml ├── README.md ├── CHANGES.md ├── LICENSE ├── config ├── logback.xml └── elasticinbox.cml └── poms ├── wrappers └── pom.xml └── compiled └── pom.xml /itests/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bundles/com.ecyrd.speed4j/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /modules/core/src/main/resources/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /modules/lmtp/src/main/resources/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /modules/pop3/src/main/resources/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /modules/rest/src/main/resources/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /modules/common/src/main/resources/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /modules/config/src/main/resources/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /itests/src/META-INF/links/org.ops4j.pax.logging.api.link: -------------------------------------------------------------------------------- 1 | mvn:org.slf4j/slf4j-api/1.6.1 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /assembly/runner 2 | /runner 3 | target 4 | .settings 5 | .project 6 | .classpath 7 | pom.xml.releaseBackup 8 | -------------------------------------------------------------------------------- /modules/common/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/main/java/,src/main/resources/ 2 | output.. = target/classes/ 3 | bin.includes = . 4 | -------------------------------------------------------------------------------- /modules/config/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/main/java/,src/main/resources/ 2 | output.. = target/classes/ 3 | bin.includes = . 4 | -------------------------------------------------------------------------------- /modules/core/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/main/java/,src/main/resources/ 2 | output.. = target/classes/ 3 | bin.includes = . 4 | -------------------------------------------------------------------------------- /modules/lmtp/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/main/java/,src/main/resources/ 2 | output.. = target/classes/ 3 | bin.includes = . 4 | -------------------------------------------------------------------------------- /modules/pop3/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/main/java/,src/main/resources/ 2 | output.. = target/classes/ 3 | bin.includes = . 4 | -------------------------------------------------------------------------------- /itests/src/test/resources/elasticinbox.ks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/elasticinbox/master/itests/src/test/resources/elasticinbox.ks -------------------------------------------------------------------------------- /modules/rest/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/main/java/,src/main/resources/ 2 | output.. = target/classes/ 3 | bin.includes = .,\ 4 | WEB-INF/ 5 | 6 | -------------------------------------------------------------------------------- /modules/common/osgi.bnd: -------------------------------------------------------------------------------- 1 | #----------------------------------------------------------------- 2 | # Use this file to add customized Bnd instructions for the bundle 3 | #----------------------------------------------------------------- 4 | 5 | 6 | Export-Package: com.elasticinbox.common,\ 7 | com.elasticinbox.common.utils 8 | Private-Package: com.elasticinbox.common.* 9 | Import-Package: *;resolution:=optional -------------------------------------------------------------------------------- /modules/pop3/osgi.bnd: -------------------------------------------------------------------------------- 1 | #----------------------------------------------------------------- 2 | # Use this file to add customized Bnd instructions for the bundle 3 | #----------------------------------------------------------------- 4 | 5 | Bundle-Activator: com.elasticinbox.pop3.Activator 6 | 7 | Import-Package: * 8 | 9 | Private-Package: \ 10 | com.elasticinbox.pop3,\ 11 | com.elasticinbox.pop3.* -------------------------------------------------------------------------------- /modules/lmtp/osgi.bnd: -------------------------------------------------------------------------------- 1 | #----------------------------------------------------------------- 2 | # Use this file to add customized Bnd instructions for the bundle 3 | #----------------------------------------------------------------- 4 | 5 | Bundle-Activator: com.elasticinbox.lmtp.Activator 6 | 7 | Import-Package: * 8 | 9 | Private-Package: \ 10 | com.elasticinbox.lmtp,\ 11 | com.elasticinbox.lmtp.* -------------------------------------------------------------------------------- /itests/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{ISO8601} %-5level [%thread] %C{1} [%M:%L] - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /modules/config/osgi.bnd: -------------------------------------------------------------------------------- 1 | #----------------------------------------------------------------- 2 | # Use this file to add customized Bnd instructions for the bundle 3 | #----------------------------------------------------------------- 4 | 5 | 6 | Export-Package: com.elasticinbox.config,\ 7 | com.elasticinbox.config.blob,\ 8 | com.elasticinbox.config.crypto 9 | 10 | Embed-Dependency: snakeyaml;groupId=org.yaml;inline=false 11 | Embed-Directory: lib -------------------------------------------------------------------------------- /bundles/com.ecyrd.speed4j/osgi.bnd: -------------------------------------------------------------------------------- 1 | #-------------------------------------------------------------------------- 2 | # Use this file to add customized Bnd instructions for the wrapped library 3 | #-------------------------------------------------------------------------- 4 | 5 | # 6 | # this unpacks the contents of the wrapped jar artifact inside the bundle 7 | # to also inline dependencies of this artifact add Embed-Transitive: true 8 | # 9 | Embed-Dependency: *;scope=compile|runtime;type=!pom;inline=true 10 | -------------------------------------------------------------------------------- /modules/common/src/test/java/com/elasticinbox/common/utils/JSONUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.elasticinbox.common.utils; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | import org.junit.Test; 9 | 10 | public class JSONUtilsTest 11 | { 12 | @Test 13 | public void testNullValueSerialization() 14 | { 15 | Map testMap = new HashMap(); 16 | testMap.put("key1", "val1"); 17 | testMap.put("key2", null); 18 | 19 | byte[] bytes = JSONUtils.fromObject(testMap); 20 | String result = new String(bytes); 21 | 22 | assertFalse(result.contains("null")); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /modules/core/src/test/java/com/elasticinbox/core/cassandra/persistence/LabelIndexPersistenceTest.java: -------------------------------------------------------------------------------- 1 | package com.elasticinbox.core.cassandra.persistence; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | public class LabelIndexPersistenceTest { 8 | 9 | @Test 10 | public void testGetLabelKeyStringInt() { 11 | String key = LabelIndexPersistence.getLabelKey("test@elasticinbox.com", 123); 12 | assertEquals("test@elasticinbox.com:123", key); 13 | } 14 | 15 | @Test 16 | public void testGetLabelKeyStringString() { 17 | String key = LabelIndexPersistence.getLabelKey("test@elasticinbox.com", "special"); 18 | assertEquals("test@elasticinbox.com:special", key); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /modules/rest/osgi.bnd: -------------------------------------------------------------------------------- 1 | #----------------------------------------------------------------- 2 | # Use this file to add customized Bnd instructions for the bundle 3 | #----------------------------------------------------------------- 4 | 5 | Private-Package: com.elasticinbox.rest.* 6 | Export-Package: com.elasticinbox.rest 7 | 8 | Import-Package:\ 9 | javax.servlet,\ 10 | javax.servlet.http,\ 11 | # javax.servlet.*,\ 12 | # javax.servlet.jsp.*,\ 13 | # javax.servlet.jsp.jstl.*,\ 14 | * 15 | 16 | DynamicImport-Package: javax.*, org.xml.sax, org.xml.sax.*,org.w3c.* 17 | 18 | Bundle-ClassPath: .,WEB-INF/classes 19 | #Embed-Directory: WEB-INF/lib 20 | #Embed-Dependency: *;scope=compile|runtime 21 | #Embed-Transitive: true 22 | 23 | Web-ContextPath: rest 24 | Webapp-Context: rest 25 | -------------------------------------------------------------------------------- /itests/src/test/resources/01-simple-ascii.eml: -------------------------------------------------------------------------------- 1 | Received: by 10.194.242.74 with HTTP; Sat, 2 Mar 2013 16:48:26 -0800 (PST) 2 | Date: Sun, 3 Mar 2013 00:48:26 +0000 3 | Message-ID: 4 | Subject: Simple email 5 | From: Test User 6 | To: Test User 7 | MIME-Version: 1.0 8 | Content-Type: multipart/alternative; boundary=047d7bb04a0627b11304d6fa9919 9 | 10 | --047d7bb04a0627b11304d6fa9919 11 | Content-Type: text/plain; charset=UTF-8 12 | 13 | Hi, 14 | 15 | This is really simple email. 16 | 17 | That's it. 18 | 19 | -- 20 | EI 21 | 22 | --047d7bb04a0627b11304d6fa9919 23 | Content-Type: text/html; charset=UTF-8 24 | 25 |
Hi,

This is really simple email.

That's it.

--
EI
26 | 27 | --047d7bb04a0627b11304d6fa9919-- 28 | -------------------------------------------------------------------------------- /assembly/src/main/etc/bin/elasticinbox: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | curdir=`dirname $0` 4 | libdir="${curdir}/../lib" 5 | umask 066 6 | 7 | MEM=512 8 | TMP_DIR="/var/tmp" 9 | CONSOLE="" 10 | 11 | if [ "$1" == "console" ]; then 12 | CONSOLE="-console -consoleLog" 13 | fi 14 | 15 | JVM_OPTS="-Xms${MEM}m -Xmx${MEM}m -Djava.io.tmpdir=${TMP_DIR}" 16 | 17 | # Uncomment to enable remote JMX access 18 | #JMX_OPTS="-Djava.net.preferIPv4Stack=true \ 19 | #-Djava.rmi.server.hostname=10.0.0.1 \ 20 | #-Dcom.sun.management.jmxremote \ 21 | #-Dcom.sun.management.jmxremote.port=9099 \ 22 | #-Dcom.sun.management.jmxremote.authenticate=false \ 23 | #-Dcom.sun.management.jmxremote.ssl=false" 24 | 25 | cd ${libdir} 26 | exec /usr/bin/java ${JVM_OPTS} ${JMX_OPTS} -server -Dosgi.install.area=equinox -cp bundles/org.eclipse.osgi_3.6.2.R36x_v20110210.jar org.eclipse.core.runtime.adaptor.EclipseStarter ${CONSOLE} -configuration equinox 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ElasticInbox is reliable, distributed, scalable email store. 2 | 3 | ## Overview 4 | 5 | ElasticInbox provides highly available email store without a single point of 6 | failure which can run on commodity hardware and scale linearly. ElasticInbox 7 | can easily scale to millions of mailboxes, with hundreds of thousands messages 8 | in each mailbox. 9 | 10 | ## Requirements 11 | 12 | * Java >= 1.6 13 | * Apache Cassandra >= 1.1 (see http://cassandra.apache.org/) 14 | 15 | ## Getting started 16 | 17 | Please visit http://www.elasticinbox.com/ for more information. 18 | 19 | ## Building from Source 20 | 21 | To build and run from source you will need Maven 3 and Git: 22 | 23 | ```bash 24 | % git clone git://github.com/elasticinbox/elasticinbox.git elasticinbox 25 | % cd elasticinbox 26 | % mvn clean install pax:provision -DskipITs 27 | ``` 28 | 29 | ## License 30 | 31 | Licensed under the Modified BSD License. -------------------------------------------------------------------------------- /modules/lmtp/src/main/java/com/elasticinbox/lmtp/server/api/handler/ValidRcptHandler.java: -------------------------------------------------------------------------------- 1 | package com.elasticinbox.lmtp.server.api.handler; 2 | 3 | import org.apache.james.protocols.smtp.MailAddress; 4 | import org.apache.james.protocols.smtp.SMTPSession; 5 | import org.apache.james.protocols.smtp.core.fastfail.AbstractValidRcptHandler; 6 | 7 | import com.elasticinbox.core.account.validator.IValidator; 8 | import com.elasticinbox.core.account.validator.IValidator.AccountStatus; 9 | import com.elasticinbox.core.account.validator.ValidatorFactory; 10 | 11 | public class ValidRcptHandler extends AbstractValidRcptHandler 12 | { 13 | private IValidator validator = ValidatorFactory.getValidator(); 14 | 15 | @Override 16 | protected boolean isValidRecipient(SMTPSession session, MailAddress recipient) 17 | { 18 | AccountStatus status = validator.getAccountStatus(recipient.toString()); 19 | session.getLogger().debug("Validated account (" + recipient + ") status is " + status); 20 | 21 | return status.equals(AccountStatus.ACTIVE) ? true : false; 22 | } 23 | 24 | @Override 25 | protected boolean isLocalDomain(SMTPSession session, String domain) 26 | { 27 | // ignore domain check 28 | return true; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /modules/core/osgi.bnd: -------------------------------------------------------------------------------- 1 | #----------------------------------------------------------------- 2 | # Use this file to add customized Bnd instructions for the bundle 3 | #----------------------------------------------------------------- 4 | 5 | Export-Package: \ 6 | com.elasticinbox.core,\ 7 | com.elasticinbox.core.model,\ 8 | com.elasticinbox.core.utils,\ 9 | com.elasticinbox.core.account.*,\ 10 | com.elasticinbox.core.message,\ 11 | com.elasticinbox.core.message.id,\ 12 | com.elasticinbox.core.blob,\ 13 | com.elasticinbox.core.log 14 | 15 | Private-Package: \ 16 | com.elasticinbox.core.blob.*,\ 17 | com.elasticinbox.core.cassandra,\ 18 | com.elasticinbox.core.cassandra.persistence,\ 19 | com.elasticinbox.core.cassandra.utils 20 | 21 | Import-Package: *;resolution:=optional 22 | 23 | Embed-Dependency: \ 24 | hector-core;groupId=org.hectorclient;inline=false,\ 25 | libthrift;groupId=org.apache.thrift;inline=false,\ 26 | cassandra-thrift;groupId=org.apache.cassandra;inline=false,\ 27 | uuid;groupId=com.github.stephenc.eaio-uuid;inline=false,\ 28 | mail;groupId=javax.mail;inline=false,\ 29 | activation;groupId=javax.activation;inline=false 30 | 31 | Embed-Directory: lib 32 | #Embed-Dependency: *;scope=compile|runtime 33 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | 0.4.0, 2013-09-18 2 | ----------------- 3 | 4 | * Improved batch operation performance and reliability. #46, #47 5 | * Added label index rebuilding feature. #40 6 | * Added support for custom label attributes. #39 7 | * Added hybrid storage support. #32 (see https://github.com/elasticinbox/elasticinbox/wiki/Blob-Storage#hybrid-storage) 8 | * Added POP3 support. #6, #33 (see https://github.com/elasticinbox/elasticinbox/wiki/POP3-and-IMAP) 9 | * Added blob encryption support. #25 (see https://github.com/elasticinbox/elasticinbox/wiki/Encryption) 10 | * API v1 endpoints are removed. 11 | 12 | 0.3.0, 2012-07-22 13 | ----------------- 14 | 15 | * Fixed bug where stale message indexes were not deleted. #23 16 | * Added new "scrub" operation for recalculating counters. #20 17 | * Prevent negative label counters. #19 18 | * Added throttling support for batch operations. #18 19 | * Avoid storing reserved labels. #14 20 | 21 | 0.3.0-RC1, 2012-05-17 22 | --------------------- 23 | 24 | * Make blob names AWS friendly by prefacing UUID 25 | * New structure for Cassandra Counters using composite keys. #15 26 | * Use "unread" messages instead of "new". #11 27 | * New REST API v2 with JSON error messages. #9, #13 28 | * Added support for case insensitive and nested labels #7, #8 29 | * New LMTP implementation using Apache James Protocols and Netty #3, #5 (thanks to @normanmaurer) 30 | * Added Blob compression support #4 31 | 32 | 0.2.0, 2011-12-04 33 | ----------------- 34 | 35 | * Initial Release -------------------------------------------------------------------------------- /assembly/src/main/etc/assembly/assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | bin 7 | 8 | 9 | tar.gz 10 | 11 | 12 | false 13 | 14 | 15 | 16 | ${project.parent.parent.parent.basedir}/target/pax-runner-dir/bundles 17 | /elasticinbox-${project.version}/lib/bundles 18 | 19 | *.jar 20 | 21 | 22 | 23 | ${project.parent.parent.parent.basedir}/target/pax-runner-dir/equinox 24 | /elasticinbox-${project.version}/lib/equinox 25 | 26 | *.ini 27 | 28 | 29 | 30 | ${project.parent.parent.parent.basedir}/config 31 | /elasticinbox-${project.version}/config 32 | 33 | 34 | 35 | 36 | 37 | src/main/etc/bin/elasticinbox 38 | /elasticinbox-${project.version}/bin 39 | 0777 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2012 Optimax Software Ltd. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 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 | 14 | * Neither the name of Optimax Software, ElasticInbox, nor the names 15 | of its contributors may be used to endorse or promote products derived 16 | from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /modules/core/src/test/java/com/elasticinbox/core/model/LabelCountersTest.java: -------------------------------------------------------------------------------- 1 | package com.elasticinbox.core.model; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | public class LabelCountersTest 8 | { 9 | @Test 10 | public void testEqual() 11 | { 12 | LabelCounters c1 = new LabelCounters(); 13 | LabelCounters c2 = new LabelCounters(); 14 | assertEquals(c1, c2); 15 | 16 | c1.setTotalBytes(123L); 17 | c1.setTotalMessages(23L); 18 | c1.setUnreadMessages(335L); 19 | 20 | c2.setTotalBytes(123L); 21 | c2.setTotalMessages(23L); 22 | c2.setUnreadMessages(335L); 23 | 24 | assertEquals(c1, c2); 25 | } 26 | 27 | @Test 28 | public void testInverse() 29 | { 30 | LabelCounters c1 = new LabelCounters(); 31 | LabelCounters c2 = new LabelCounters(); 32 | 33 | c1.setTotalBytes(123L); 34 | c1.setTotalMessages(23L); 35 | c1.setUnreadMessages(335L); 36 | 37 | c2.setTotalBytes(-123L); 38 | c2.setTotalMessages(-23L); 39 | c2.setUnreadMessages(-335L); 40 | 41 | assertEquals(c1.getInverse(), c2); 42 | } 43 | 44 | @Test 45 | public void testAdd() 46 | { 47 | LabelCounters c1 = new LabelCounters(); 48 | LabelCounters c2 = new LabelCounters(); 49 | LabelCounters c3 = new LabelCounters(); 50 | 51 | c1.setTotalBytes(123L); 52 | c1.setTotalMessages(23L); 53 | c1.setUnreadMessages(335L); 54 | 55 | c2.setTotalBytes(223L); 56 | c2.setTotalMessages(223L); 57 | c2.setUnreadMessages(685L); 58 | 59 | c3.setTotalBytes(100L); 60 | c3.setTotalMessages(200L); 61 | c3.setUnreadMessages(350L); 62 | 63 | c1.add(c3); 64 | 65 | assertEquals(c1, c2); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /config/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /var/log/elasticinbox/elasticinbox.log 6 | 7 | /var/log/elasticinbox/elasticinbox.%i.log 8 | 1 9 | 5 10 | 11 | 12 | 10MB 13 | 14 | 15 | %d{ISO8601} %-5level [%thread] %C{1} [%M:%L] - %msg%n 16 | 17 | 18 | 19 | 20 | 21 | %d{ISO8601} %-5level [%thread] %C{1} [%M:%L] - %msg%n 22 | 23 | 24 | 25 | 26 | /dev/null 27 | true 28 | 29 | %msg%n 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /config/elasticinbox.cml: -------------------------------------------------------------------------------- 1 | # ElasticInbox Schema v1.2 2 | # 3 | # To create schema, first you will need to create keyspace: 4 | # 5 | # create keyspace ElasticInbox 6 | # with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' 7 | # and strategy_options = [{replication_factor:3}]; 8 | # 9 | # After keyspace created you can copy paste text below, or simply run: 10 | # 11 | # % cassandra-cli --host 10.0.1.1 < elasticinbox.cml 12 | # 13 | 14 | USE ElasticInbox; 15 | 16 | CREATE COLUMN FAMILY Accounts WITH 17 | key_validation_class = UTF8Type AND 18 | caching = all AND 19 | comment = 'Basic information about accounts'; 20 | 21 | CREATE COLUMN FAMILY MessageMetadata WITH 22 | column_type = Super AND 23 | key_validation_class = UTF8Type AND 24 | comparator = TimeUUIDType AND 25 | subcomparator = BytesType AND 26 | caching = keys_only AND 27 | comment='Message metadata including headers, labels, markers, physical location, etc.'; 28 | 29 | CREATE COLUMN FAMILY MessageBlob WITH 30 | key_validation_class = 'CompositeType(TimeUUIDType, Int32Type)' AND 31 | comparator = Int32Type AND 32 | caching = keys_only AND 33 | comment='Chunked message blobs'; 34 | 35 | CREATE COLUMN FAMILY IndexLabels WITH 36 | key_validation_class = UTF8Type AND 37 | comparator = TimeUUIDType AND 38 | caching = all AND 39 | comment = 'Message ID indexes grouped by labels and ordered by time'; 40 | 41 | CREATE COLUMN FAMILY Counters WITH 42 | comparator = 'CompositeType(UTF8Type,UTF8Type,UTF8Type)' AND 43 | key_validation_class = UTF8Type AND 44 | default_validation_class = CounterColumnType AND 45 | replicate_on_write = true AND 46 | caching = all AND 47 | comment = 'All counters for an account'; -------------------------------------------------------------------------------- /modules/rest/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | com.elasticinbox.rest.WebAppContextListener 5 | 6 | 7 | ElasticInbox REST APIv2 8 | com.sun.jersey.spi.container.servlet.ServletContainer 9 | 10 | com.sun.jersey.config.property.resourceConfigClass 11 | com.sun.jersey.api.core.ClassNamesResourceConfig 12 | 13 | 14 | com.sun.jersey.config.property.classnames 15 | 16 | com.elasticinbox.rest.v2.MailboxResource; 17 | com.elasticinbox.rest.v2.AccountResource; 18 | com.elasticinbox.rest.v2.LabelResource; 19 | com.elasticinbox.rest.v2.MessageResource; 20 | com.elasticinbox.rest.v2.SingleMessageResource; 21 | com.elasticinbox.rest.v2.ScrubResource 22 | 23 | 24 | 25 | com.sun.jersey.spi.container.ContainerResponseFilters 26 | com.elasticinbox.rest.CharsetResponseFilter 27 | 28 | 1 29 | 30 | 31 | ElasticInbox REST APIv2 32 | /v2/* 33 | 34 | -------------------------------------------------------------------------------- /modules/rest/src/main/java/com/elasticinbox/rest/JSONResponse.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 | public final class JSONResponse 32 | { 33 | public final static String OK = "{\"ok\":true}"; 34 | } 35 | -------------------------------------------------------------------------------- /modules/config/src/main/java/com/elasticinbox/config/crypto/EncryptionSettings.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.crypto; 30 | 31 | public class EncryptionSettings 32 | { 33 | public String keystore; 34 | public String keystore_password; 35 | } 36 | -------------------------------------------------------------------------------- /poms/wrappers/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.elasticinbox.parent.build 6 | shared-plugin-settings 7 | 0.5.0-SNAPSHOT 8 | 9 | 10 | 4.0.0 11 | wrapper-bundle-settings 12 | 13 | ElasticInbox Project - Wrapper Instructions 14 | 15 | 18 | 19 | 20 | Simple OSGi wrapper around third-party jar(s) 21 | 22 | 23 | 24 | 25 | 26 | pom 27 | 28 | 29 | 30 | 31 | 34 | org.apache.felix 35 | maven-bundle-plugin 36 | 37 | 38 | ${bundle.symbolicName} 39 | ${wrapped.version} 40 | 43 | <_exportcontents>* 44 | !* 45 | 48 | <_include>-osgi.bnd 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/account/validator/IValidator.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.account.validator; 30 | 31 | public interface IValidator 32 | { 33 | public enum AccountStatus { 34 | ACTIVE, BLOCKED, NOT_FOUND 35 | } 36 | 37 | public AccountStatus getAccountStatus(String username); 38 | } 39 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/message/MimeParserException.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; 30 | 31 | public final class MimeParserException extends Exception 32 | { 33 | private static final long serialVersionUID = 1L; 34 | 35 | public MimeParserException(String message) { 36 | super(message); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/account/authenticator/AuthenticationException.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.account.authenticator; 30 | 31 | public class AuthenticationException extends Exception 32 | { 33 | private static final long serialVersionUID = 1L; 34 | 35 | public AuthenticationException(String message) 36 | { 37 | super(message); 38 | } 39 | } -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/OverQuotaException.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 | /** 32 | * Thrown when mailbox is over the quota 33 | * 34 | * @author Rustam Aliyev 35 | */ 36 | public class OverQuotaException extends Exception 37 | { 38 | private static final long serialVersionUID = 1L; 39 | 40 | public OverQuotaException(String message) { 41 | super(message); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /modules/lmtp/src/main/java/com/elasticinbox/lmtp/server/api/DeliveryReturnCode.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.server.api; 30 | 31 | /** 32 | * Standard and extended LMTP status codes 33 | * 34 | * @author Rustam Aliyev 35 | * @see RFC3463 36 | */ 37 | public enum DeliveryReturnCode 38 | { 39 | OK, 40 | TEMPORARY_FAILURE, 41 | PERMANENT_FAILURE, 42 | NO_SUCH_USER, 43 | OVER_QUOTA 44 | } 45 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/blob/BlobUtils.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; 30 | 31 | public class BlobUtils 32 | { 33 | /** 34 | * Convert absolute path to relative by dropping first forward-slash 35 | * 36 | * @param path 37 | * @return 38 | */ 39 | public static String relativize(String path) { 40 | String relativePath = (path.charAt(0) == '/') ? path.substring(1) : path; 41 | return relativePath; 42 | } 43 | } -------------------------------------------------------------------------------- /modules/config/src/main/java/com/elasticinbox/config/ConfigurationException.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 | public class ConfigurationException extends Exception 32 | { 33 | private static final long serialVersionUID = -6268744249050889188L; 34 | 35 | public ConfigurationException(String message) { 36 | super(message); 37 | } 38 | 39 | public ConfigurationException(String message, Exception e) { 40 | super(message, e); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/IllegalLabelException.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 | /** 32 | * Thrown when operation with the label is not permitted 33 | * 34 | * @author Rustam Aliyev 35 | */ 36 | public class IllegalLabelException extends IllegalArgumentException 37 | { 38 | private static final long serialVersionUID = 1L; 39 | 40 | public IllegalLabelException(String message) { 41 | super(message); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/account/validator/ValidatorFactory.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.account.validator; 30 | 31 | /** 32 | * Creates account validator 33 | * 34 | * @author Rustam Aliyev 35 | */ 36 | public class ValidatorFactory 37 | { 38 | private ValidatorFactory() { 39 | // ensure non-instantiability 40 | } 41 | 42 | public static IValidator getValidator() { 43 | return new DummyValidator(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/ExistingLabelException.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 | /** 32 | * Thrown when operation with the label is not permitted 33 | * 34 | * @author Rustam Aliyev 35 | */ 36 | public class ExistingLabelException extends IllegalArgumentException 37 | { 38 | private static final long serialVersionUID = 1L; 39 | 40 | public ExistingLabelException(String message) { 41 | super(message); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /modules/common/src/main/java/com/elasticinbox/common/utils/ThreadLocalByteBuffer.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.common.utils; 30 | 31 | public class ThreadLocalByteBuffer 32 | { 33 | private static final ThreadLocal BUFFER = new ThreadLocal() 34 | { 35 | @Override 36 | protected byte[] initialValue() { 37 | return new byte[1024 * 4]; 38 | } 39 | }; 40 | 41 | public static byte[] getBuffer() { 42 | return BUFFER.get(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/account/authenticator/AuthenticatorFactory.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.account.authenticator; 30 | 31 | /** 32 | * Creates account authenticator 33 | * 34 | * @author Rustam Aliyev 35 | */ 36 | public class AuthenticatorFactory 37 | { 38 | private AuthenticatorFactory() { 39 | // ensure non-instantiability 40 | } 41 | 42 | public static IAuthenticator getAuthenticator() { 43 | return new AllowAllAuthenticator(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /modules/common/src/main/java/com/elasticinbox/common/Disposable.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.common; 30 | 31 | /** 32 | * Object which implements this interface will be invoked of its 33 | * 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 38 | */ 39 | public interface Filter 40 | { 41 | /** 42 | * Processes input and returns modified version 43 | * 44 | * @param input 45 | * @return 46 | */ 47 | T filter(final T input); 48 | } 49 | -------------------------------------------------------------------------------- /modules/lmtp/src/main/java/com/elasticinbox/lmtp/delivery/DeliveryAction.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 | /** 32 | * Delivery actions 33 | * 34 | * @author Rustam Aliyev 35 | * 36 | */ 37 | public enum DeliveryAction 38 | { 39 | /** 40 | * Accept and deliver 41 | */ 42 | DELIVER, 43 | 44 | /** 45 | * Accept and drop silently 46 | */ 47 | DISCARD, 48 | 49 | /** 50 | * Reject message permanently (permanently unavailable) 51 | */ 52 | REJECT, 53 | 54 | /** 55 | * Defer delivery (temporary unavailable) 56 | */ 57 | DEFER 58 | } 59 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/log/JcloudsSlf4JLoggingModule.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.log; 30 | 31 | import org.jclouds.logging.Logger.LoggerFactory; 32 | import org.jclouds.logging.config.LoggingModule; 33 | 34 | /** 35 | * Configures jclouds logging of type {@link JcloudsSlf4JLogger} 36 | * 37 | * @author Rustam Aliyev 38 | * 39 | */ 40 | public final class JcloudsSlf4JLoggingModule extends LoggingModule 41 | { 42 | @Override 43 | public LoggerFactory createLoggerFactory() { 44 | return new JcloudsSlf4JLogger.JcloudsSlf4JLoggerFactory(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/account/authenticator/IAuthenticator.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.account.authenticator; 30 | 31 | import com.elasticinbox.core.model.Mailbox; 32 | 33 | public interface IAuthenticator 34 | { 35 | public enum AccountStatus { 36 | ACTIVE, BLOCKED, NOT_FOUND 37 | } 38 | 39 | /** 40 | * Authenticate user with provided username/password pair. 41 | * 42 | * @param username 43 | * @param password 44 | * @return 45 | */ 46 | public Mailbox authenticate(String username, String password) throws AuthenticationException; 47 | } 48 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/message/id/CurrentTimeMessageIdPolicy.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 me.prettyprint.cassandra.utils.TimeUUIDUtils; 34 | 35 | /** 36 | * Generates unique message ID based on the current time. 37 | * 38 | * @author Rustam Aliyev 39 | */ 40 | public final class CurrentTimeMessageIdPolicy extends AbstractMessageIdPolicy 41 | { 42 | @Override 43 | protected UUID getMessageId(MessageIdBuilder builder) 44 | { 45 | return TimeUUIDUtils.getUniqueTimeUUIDinMillis(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /poms/compiled/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.elasticinbox.parent.build 6 | shared-plugin-settings 7 | 0.5.0-SNAPSHOT 8 | 9 | 10 | 4.0.0 11 | compiled-bundle-settings 12 | 13 | ElasticInbox Project - Bundle Instructions 14 | 15 | pom 16 | 17 | 18 | 19 | 20 | src/main/resources 21 | 22 | 25 | 26 | . 27 | 28 | plugin.xml 29 | plugin.properties 30 | icons/** 31 | 32 | 33 | 34 | 35 | 36 | 39 | org.apache.felix 40 | maven-bundle-plugin 41 | 42 | 43 | ${bundle.symbolicName} 44 | ${project.version} 45 | 50 | 53 | <_include>-osgi.bnd 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /modules/core/src/test/java/com/elasticinbox/core/utils/Base64UUIDUtilsTest.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.utils; 30 | 31 | import static org.junit.Assert.*; 32 | import static org.hamcrest.Matchers.*; 33 | 34 | import java.util.UUID; 35 | 36 | import org.junit.Test; 37 | 38 | public class Base64UUIDUtilsTest 39 | { 40 | @Test 41 | public void testBase64UUIDEncode() 42 | { 43 | UUID uuid1 = UUID.randomUUID(); 44 | String uuidStr = Base64UUIDUtils.encode(uuid1); 45 | UUID uuid2 = Base64UUIDUtils.decode(uuidStr); 46 | 47 | assertThat(uuidStr, not(endsWith("=="))); 48 | assertThat(22, equalTo(uuidStr.length())); 49 | assertThat(uuid2, equalTo(uuid1)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /modules/common/src/test/java/com/elasticinbox/common/utils/AbstractInputStreamTest.java: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * Licensed to the Apache Software Foundation (ASF) under one * 3 | * or more contributor license agreements. See the NOTICE file * 4 | * distributed with this work for additional information * 5 | * regarding copyright ownership. The ASF licenses this file * 6 | * to you under the Apache License, Version 2.0 (the * 7 | * "License"); you may not use this file except in compliance * 8 | * with the License. You may obtain a copy of the License at * 9 | * * 10 | * http://www.apache.org/licenses/LICENSE-2.0 * 11 | * * 12 | * Unless required by applicable law or agreed to in writing, * 13 | * software distributed under the License is distributed on an * 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 15 | * KIND, either express or implied. See the License for the * 16 | * specific language governing permissions and limitations * 17 | * under the License. * 18 | ****************************************************************/ 19 | package com.elasticinbox.common.utils; 20 | 21 | import java.io.ByteArrayOutputStream; 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | import junit.framework.TestCase; 25 | 26 | public abstract class AbstractInputStreamTest extends TestCase 27 | { 28 | protected void checkRead(InputStream in, String expected) 29 | throws IOException 30 | { 31 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 32 | int i = -1; 33 | while ((i = in.read()) != -1) { 34 | out.write(i); 35 | } 36 | in.close(); 37 | out.close(); 38 | assertEquals(expected, new String(out.toByteArray())); 39 | 40 | } 41 | 42 | protected void checkReadViaArray(InputStream in, String expected) 43 | throws IOException 44 | { 45 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 46 | 47 | byte[] buf = new byte[3]; 48 | int i = 0; 49 | while ((i = in.read(buf)) != -1) { 50 | out.write(buf, 0, i); 51 | } 52 | 53 | in.close(); 54 | out.close(); 55 | assertEquals(expected, new String(out.toByteArray())); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /modules/lmtp/src/main/java/com/elasticinbox/lmtp/server/api/DeliveryException.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.server.api; 30 | 31 | import java.io.IOException; 32 | 33 | /** 34 | * Thrown by delivery backend when delivery failed due to problems with message 35 | * blob 36 | * 37 | * @author Rustam Aliyev 38 | */ 39 | public class DeliveryException extends IOException 40 | { 41 | private static final long serialVersionUID = 5323215105334028562L; 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | public DeliveryException() { 47 | super(); 48 | } 49 | 50 | /** 51 | * {@inheritDoc} 52 | */ 53 | public DeliveryException(String message) { 54 | super(message); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /modules/pop3/src/main/java/com/elasticinbox/pop3/server/handler/MailboxHandlerFactory.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.server.handler; 30 | 31 | import com.elasticinbox.core.DAOFactory; 32 | import com.elasticinbox.core.MessageDAO; 33 | import com.elasticinbox.core.model.Mailbox; 34 | 35 | public class MailboxHandlerFactory 36 | { 37 | private final MessageDAO messageDAO; 38 | 39 | public MailboxHandlerFactory() { 40 | DAOFactory dao = DAOFactory.getDAOFactory(); 41 | messageDAO = dao.getMessageDAO(); 42 | } 43 | 44 | public org.apache.james.protocols.pop3.mailbox.Mailbox getMailboxHander(Mailbox mailbox) { 45 | return new ElasticInboxMailboxHandler(messageDAO, mailbox); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/blob/naming/UuidBlobNamingPolicy.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.naming; 30 | 31 | import com.elasticinbox.common.utils.Assert; 32 | 33 | /** 34 | * Generate unique Blob name based on the mailbox name and message UUID. 35 | * 36 | * @author Rustam Aliyev 37 | */ 38 | public final class UuidBlobNamingPolicy extends AbstractBlobNamingPolicy 39 | { 40 | @Override 41 | public String getBlobName(BlobNameBuilder builder) 42 | { 43 | Assert.notNull(builder.messageId, "message id cannot be null"); 44 | Assert.notNull(builder.mailbox, "mailbox cannot be null"); 45 | 46 | return builder.messageId.toString() + ":" + builder.mailbox.getId(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/blob/naming/AbstractBlobNamingPolicy.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.naming; 30 | 31 | /** 32 | * Abstract policy class for generating Blob name. 33 | * 34 | *

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 | 30 | 31 | 32 | com.elasticinbox 33 | elasticinbox-parent 34 | 0.5.0-SNAPSHOT 35 | 36 | 37 | 4.0.0 38 | com.elasticinbox.bundles 39 | elasticinbox-bundles 40 | 41 | ElasticInbox External Bundles 42 | 43 | pom 44 | 45 | 46 | com.ecyrd.speed4j 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /modules/common/src/test/java/com/elasticinbox/common/utils/CRLFInputStreamTest.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.common.utils; 30 | 31 | import java.io.ByteArrayInputStream; 32 | import java.io.IOException; 33 | 34 | import org.junit.Test; 35 | 36 | public class CRLFInputStreamTest extends AbstractInputStreamTest 37 | { 38 | @Test 39 | public void test() throws IOException 40 | { 41 | String data = "line1\rline2\nline3\r\nline4\n"; 42 | String expected = "line1\r\nline2\r\nline3\r\nline4\r\n"; 43 | 44 | checkRead( 45 | new CRLFInputStream(new ByteArrayInputStream(data.getBytes())), 46 | expected); 47 | 48 | // checkReadViaArray( 49 | // new CRLFInputStream(new ByteArrayInputStream(data.getBytes())), 50 | // expected); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/model/LabelConstants.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 | * Label Constants 33 | * 34 | * @author Rustam Aliyev 35 | */ 36 | public final class LabelConstants 37 | { 38 | /** Maximum label count per mailbox (including reserved labels) */ 39 | public final static int MAX_LABEL_ID = 9999; 40 | 41 | /** Maximum label name length */ 42 | public final static int MAX_LABEL_NAME_LENGTH = 250; 43 | 44 | /** Character used as nested label separator */ 45 | public final static Character NESTED_LABEL_SEPARATOR = '^'; 46 | 47 | /** 48 | * Maximum reserved label ID. I.e. reserved label ID can be between 49 | * 0..MAX_RESERVED_LABEL_ID 50 | */ 51 | public final static int MAX_RESERVED_LABEL_ID = 20; 52 | } 53 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/account/validator/DummyValidator.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.account.validator; 30 | 31 | import org.slf4j.Logger; 32 | import org.slf4j.LoggerFactory; 33 | 34 | import com.elasticinbox.core.model.Mailbox; 35 | 36 | /** 37 | * Dummy validator which will always return ACTIVE status 38 | * 39 | * @author Rustam Aliyev 40 | */ 41 | public final class DummyValidator implements IValidator 42 | { 43 | private static final Logger logger = LoggerFactory 44 | .getLogger(DummyValidator.class); 45 | 46 | @Override 47 | public AccountStatus getAccountStatus(String username) 48 | { 49 | Mailbox mailbox = new Mailbox(username); 50 | logger.debug("Validating " + mailbox.getId()); 51 | return AccountStatus.ACTIVE; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/account/authenticator/AllowAllAuthenticator.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.account.authenticator; 30 | 31 | import org.slf4j.Logger; 32 | import org.slf4j.LoggerFactory; 33 | 34 | import com.elasticinbox.core.model.Mailbox; 35 | 36 | /** 37 | * Authenticator which allows all users without checking password 38 | * 39 | * @author Rustam Aliyev 40 | */ 41 | public final class AllowAllAuthenticator implements IAuthenticator 42 | { 43 | private static final Logger logger = LoggerFactory 44 | .getLogger(AllowAllAuthenticator.class); 45 | 46 | @Override 47 | public Mailbox authenticate(String username, String password) 48 | { 49 | Mailbox mailbox = new Mailbox(username); 50 | logger.debug("Authenticated " + mailbox.getId()); 51 | return mailbox; 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /modules/lmtp/src/main/java/com/elasticinbox/lmtp/delivery/IDeliveryAgent.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.io.IOException; 32 | import java.util.Map; 33 | 34 | import org.apache.james.protocols.smtp.MailEnvelope; 35 | import org.apache.james.protocols.smtp.MailAddress; 36 | 37 | import com.elasticinbox.lmtp.server.api.DeliveryReturnCode; 38 | 39 | /** 40 | * Delivery Agent Interface 41 | * 42 | * @author Rustam Aliyev 43 | */ 44 | public interface IDeliveryAgent 45 | { 46 | /** 47 | * Delivers this message to the list of recipients in the message, and sets 48 | * the delivery status on each recipient address. 49 | * 50 | * @throws IOException 51 | */ 52 | public Map deliver(MailEnvelope env, String sessionId) 53 | throws IOException; 54 | } 55 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/cassandra/utils/BatchConstants.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.utils; 30 | 31 | /** 32 | * Constants for batch operations. 33 | * 34 | * @author Rustam Aliyev 35 | */ 36 | public class BatchConstants 37 | { 38 | /** Maximum number of columns to read at once */ 39 | public final static int BATCH_READS = 250; 40 | 41 | /** 42 | * Maximum number of columns to write within time interval. Used for rate 43 | * limiting where RATE = WRITES / WRITES_INTERVAL 44 | */ 45 | public final static int BATCH_WRITES = 100; 46 | 47 | /** 48 | * Time interval within which maximum number of batch writes should occur. 49 | * In MILLISECONDS. Used for rate limiting where RATE = WRITES / 50 | * WRITES_INTERVAL. 51 | */ 52 | public final static long BATCH_WRITE_INTERVAL = 100L; 53 | } 54 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/cassandra/utils/ThrottlingMutationResult.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.utils; 30 | 31 | import me.prettyprint.cassandra.model.ExecutionResult; 32 | import me.prettyprint.cassandra.service.CassandraHost; 33 | import me.prettyprint.hector.api.mutation.MutationResult; 34 | 35 | public class ThrottlingMutationResult extends ExecutionResult implements MutationResult 36 | { 37 | ThrottlingMutationResult(boolean success, long execTime, CassandraHost cassandraHost) { 38 | super(null, execTime, cassandraHost); 39 | } 40 | 41 | ThrottlingMutationResult(ExecutionResult res) { 42 | super(null, res.getExecutionTimeNano(), res.getHostUsed()); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return formatMessage("ThrottlingMutationResult", "n/a"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/blob/compression/CompressionHandler.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.compression; 30 | 31 | import java.io.InputStream; 32 | 33 | /** 34 | * Handles generic compression/uncompression. Used mainly for dependency injection. 35 | * 36 | * @author Rustam Aliyev 37 | */ 38 | public interface CompressionHandler 39 | { 40 | /** 41 | * Compress input stream 42 | * 43 | * @param in Uncompressed input stream 44 | * @return Compressed input stream 45 | */ 46 | public InputStream compress(InputStream in); 47 | 48 | /** 49 | * Uncompress input stream 50 | * 51 | * @param in Compressed input stream 52 | * @return Uncompressed input stream 53 | */ 54 | public InputStream uncompress(InputStream in); 55 | 56 | /** 57 | * Returns compression type 58 | * 59 | * @return 60 | */ 61 | public String getType(); 62 | } -------------------------------------------------------------------------------- /modules/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 29 | 30 | 31 | 32 | com.elasticinbox 33 | elasticinbox-parent 34 | 0.5.0-SNAPSHOT 35 | 36 | 37 | 4.0.0 38 | com.elasticinbox.modules 39 | elasticinbox-modules 40 | 41 | ElasticInbox Modules 42 | 43 | pom 44 | 45 | 46 | common 47 | config 48 | core 49 | lmtp 50 | pop3 51 | rest 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/message/id/AbstractMessageIdPolicy.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 | /** 34 | * Abstract policy class for generating message UUID. 35 | * 36 | *

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.Builder() 55 | .put("message", message).build())) 56 | .type(MediaType.APPLICATION_JSON).build()); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /modules/rest/src/main/java/com/elasticinbox/rest/CharsetResponseFilter.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 com.sun.jersey.spi.container.ContainerRequest; 32 | import com.sun.jersey.spi.container.ContainerResponse; 33 | import com.sun.jersey.spi.container.ContainerResponseFilter; 34 | 35 | import javax.ws.rs.core.MediaType; 36 | 37 | /** 38 | * This response filter adds missing charset 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 Filter 44 | { 45 | private static final Logger logger = LoggerFactory 46 | .getLogger(SpamMailFilter.class); 47 | 48 | private final static String MIME_HEADER_SPAM_VALUE = "YES"; 49 | 50 | @Override 51 | public Message filter(Message message) 52 | { 53 | if (message.getMinorHeader(MimeParser.MIME_HEADER_SPAM) != null 54 | && message.getMinorHeader(MimeParser.MIME_HEADER_SPAM).equalsIgnoreCase(MIME_HEADER_SPAM_VALUE)) 55 | { 56 | logger.debug("Applying filter for SPAM"); 57 | message.addLabel(ReservedLabels.SPAM.getId()); 58 | } 59 | 60 | return message; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /modules/lmtp/src/main/java/com/elasticinbox/lmtp/filter/FilterProcessor.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 java.util.LinkedList; 32 | import java.util.List; 33 | 34 | /** 35 | * This processor is modified implementation of Chain of Responsibility pattern. 36 | * Filters are applied in the given order. Each filter (handler) processes input 37 | * and passes output to the next one. Final result returned by processor. 38 | * 39 | * @author rustam 40 | * 41 | * @param 42 | */ 43 | public class FilterProcessor 44 | { 45 | private List> filters; 46 | 47 | public FilterProcessor() { 48 | filters = new LinkedList>(); 49 | } 50 | 51 | /** 52 | * Add filter to the bottom of the chain 53 | * 54 | * @param filter 55 | */ 56 | public void add(Filter filter) { 57 | filters.add(filter); 58 | } 59 | 60 | /** 61 | * Perform filtering process 62 | * 63 | * @param input 64 | * @return 65 | */ 66 | public T doFilter(final T input) 67 | { 68 | T output = input; 69 | for (Filter filter : filters) { 70 | output = filter.filter(output); 71 | } 72 | 73 | return output; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /modules/core/src/test/java/com/elasticinbox/core/model/LabelMapTest.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.model; 30 | 31 | import static org.junit.Assert.*; 32 | 33 | import org.junit.Test; 34 | 35 | public class LabelMapTest 36 | { 37 | @Test 38 | public void testIncrementCounters() 39 | { 40 | LabelMap labels = new LabelMap(); 41 | 42 | LabelCounters lc = new LabelCounters(); 43 | lc.setTotalMessages(120L); 44 | lc.setTotalBytes(1024000L); 45 | lc.setUnreadMessages(32L); 46 | 47 | LabelCounters diff = new LabelCounters(); 48 | diff.setTotalMessages(19L); 49 | diff.setTotalBytes(24000L); 50 | diff.setUnreadMessages(5L); 51 | 52 | // increment initialized label 53 | labels.put(ReservedLabels.INBOX); 54 | 55 | int labelId = ReservedLabels.INBOX.getId(); 56 | labels.get(labelId).setCounters(lc); 57 | labels.get(labelId).incrementCounters(diff); 58 | 59 | assertEquals(labels.get(labelId).getCounters().getTotalMessages().intValue(), 120+19); 60 | assertEquals(labels.get(labelId).getCounters().getTotalBytes().intValue(), 1024000+24000); 61 | assertEquals(labels.get(labelId).getCounters().getUnreadMessages().intValue(), 32+5); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /modules/pop3/src/main/java/com/elasticinbox/pop3/server/POP3ServerConfig.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.server; 30 | 31 | import java.net.InetAddress; 32 | import java.net.UnknownHostException; 33 | 34 | import org.apache.james.protocols.pop3.POP3Configuration; 35 | 36 | /** 37 | * This class holds the configuration options of the {@link LMTPServer}. 38 | * 39 | * @author Rustam Aliyev 40 | */ 41 | public class POP3ServerConfig extends POP3Configuration 42 | { 43 | /** 44 | * Server name. 45 | */ 46 | private static final String SERVER_NAME = "ElasticInbox"; 47 | 48 | /** 49 | * The server host name. Defaults to a lookup of the local address. 50 | */ 51 | private String hostName = "localhost"; 52 | 53 | /** 54 | * The timeout for waiting for data on a connection is one minute: 60 sec 55 | */ 56 | public final static int CONNECTION_TIMEOUT = 60; 57 | 58 | public POP3ServerConfig() 59 | { 60 | try { 61 | this.hostName = InetAddress.getLocalHost().getCanonicalHostName(); 62 | } catch (UnknownHostException e) { 63 | this.hostName = "localhost"; 64 | } 65 | 66 | setHelloName(hostName); 67 | setSoftwareName(SERVER_NAME); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /modules/lmtp/src/main/java/com/elasticinbox/lmtp/filter/DefaultMailFilter.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.config.Configurator; 35 | import com.elasticinbox.core.model.Message; 36 | import com.elasticinbox.core.model.ReservedLabels; 37 | 38 | /** 39 | * Default filter which adds Inbox label if no other label assigned by previous 40 | * labels. Should appear at the bottom of the filter chain. 41 | * 42 | * @author Rustam Aliyev 43 | */ 44 | public final class DefaultMailFilter implements Filter 45 | { 46 | private static final Logger logger = LoggerFactory.getLogger(DefaultMailFilter.class); 47 | 48 | @Override 49 | public Message filter(Message message) 50 | { 51 | // by default store in Inbox 52 | if(message.getLabels().isEmpty()) 53 | { 54 | message.addLabel(ReservedLabels.INBOX.getId()); 55 | 56 | // add to POP3 if enabled 57 | if (Configurator.isLmtpPop3Enabled()) 58 | { 59 | logger.debug("Adding message received via LMTP to POP3"); 60 | message.addLabel(ReservedLabels.POP3.getId()); 61 | } 62 | } 63 | 64 | return message; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/blob/encryption/EncryptionHandler.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.GeneralSecurityException; 33 | import java.security.Key; 34 | 35 | /** 36 | * Handles generic encryption/decryption tasks. Used mainly for dependency injection. 37 | * 38 | * @author Rustam Aliyev 39 | */ 40 | public interface EncryptionHandler 41 | { 42 | /** 43 | * Encrypt input stream 44 | * 45 | * @param in Clear input stream 46 | * @param key AES key used for encryption 47 | * @param iv Initialisation vector 48 | * @return Encrypted input stream 49 | * @throws GeneralSecurityException 50 | */ 51 | public InputStream encrypt(InputStream in, Key key, byte[] iv) throws GeneralSecurityException; 52 | 53 | /** 54 | * Decrypt input stream 55 | * 56 | * @param in Encrypted input stream 57 | * @param key AES key used for encryption 58 | * @param iv Initialisation vector used for encryption 59 | * @return Decrypted input stream 60 | * @throws GeneralSecurityException 61 | */ 62 | public InputStream decrypt(InputStream in, Key key, byte[] iv) throws GeneralSecurityException; 63 | } 64 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/cassandra/utils/QuorumConsistencyLevel.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.utils; 30 | 31 | import me.prettyprint.cassandra.service.OperationType; 32 | import me.prettyprint.hector.api.ConsistencyLevelPolicy; 33 | import me.prettyprint.hector.api.HConsistencyLevel; 34 | 35 | /** 36 | * Set Cassandra operations' consistency level to QUORUM for both - read and 37 | * write operations. 38 | * 39 | * @author Rustam Aliyev 40 | */ 41 | public final class QuorumConsistencyLevel implements ConsistencyLevelPolicy 42 | { 43 | @Override 44 | public HConsistencyLevel get(OperationType op) 45 | { 46 | switch (op) { 47 | case READ: 48 | return HConsistencyLevel.QUORUM; 49 | case WRITE: 50 | return HConsistencyLevel.QUORUM; 51 | default: 52 | return HConsistencyLevel.QUORUM; // just in Case 53 | } 54 | } 55 | 56 | @Override 57 | public HConsistencyLevel get(OperationType op, String cfName) 58 | { 59 | switch (op) { 60 | case READ: 61 | return HConsistencyLevel.QUORUM; 62 | case WRITE: 63 | return HConsistencyLevel.QUORUM; 64 | default: 65 | return HConsistencyLevel.QUORUM; // just in Case 66 | } 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /modules/lmtp/src/main/java/com/elasticinbox/lmtp/server/LMTPServerConfig.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.server; 30 | 31 | import java.net.InetAddress; 32 | import java.net.UnknownHostException; 33 | 34 | import org.apache.james.protocols.lmtp.LMTPConfigurationImpl; 35 | 36 | /** 37 | * This class holds the configuration options of the {@link LMTPServer}. 38 | * 39 | * @author Rustam Aliyev 40 | */ 41 | public class LMTPServerConfig extends LMTPConfigurationImpl 42 | { 43 | /** 44 | * Server name. 45 | */ 46 | private static final String SERVER_NAME = "ElasticInbox"; 47 | 48 | /** 49 | * The server host name. Defaults to a lookup of the local address. 50 | */ 51 | private String hostName = "localhost"; 52 | 53 | /** 54 | * The timeout for waiting for data on a connection is one minute: 60 sec 55 | */ 56 | public final static int CONNECTION_TIMEOUT = 60; 57 | 58 | public LMTPServerConfig() 59 | { 60 | try { 61 | this.hostName = InetAddress.getLocalHost().getCanonicalHostName(); 62 | } catch (UnknownHostException e) { 63 | this.hostName = "localhost"; 64 | } 65 | 66 | setHelloName(hostName); 67 | setSoftwareName(SERVER_NAME); 68 | 69 | // TODO: make msg size configurable 70 | //setMaxMessageSize(0); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /modules/common/src/main/java/com/elasticinbox/common/utils/Assert.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.common.utils; 30 | 31 | /** 32 | * A generic low weight assert utility 33 | * 34 | */ 35 | public class Assert 36 | { 37 | 38 | public static void notNull(Object object, String message) 39 | { 40 | if (object == null) { 41 | throw new IllegalArgumentException(message); 42 | } 43 | } 44 | 45 | public static void noneNull(Object ... object) 46 | { 47 | for (int i = 0; i < object.length; ++i) { 48 | if (object[i] == null) { 49 | throw new NullPointerException("Null not allowed, number " 50 | + (i + 1)); 51 | } 52 | } 53 | } 54 | 55 | /** 56 | * Will throw {@link IllegalArgumentException} if expression is false. 57 | * 58 | * @param b Boolean expression 59 | * @param message Exception message 60 | */ 61 | public static void isTrue(boolean b, String message) 62 | { 63 | if (!b) { 64 | throw new IllegalArgumentException(message); 65 | } 66 | } 67 | 68 | /** 69 | * Will throw {@link IllegalArgumentException} if expression is true. 70 | * 71 | * @param b Boolean expression 72 | * @param message Exception message 73 | */ 74 | public static void isFalse(boolean b, String message) 75 | { 76 | if (b) { 77 | throw new IllegalArgumentException(message); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/utils/Base64UUIDUtils.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.utils; 30 | 31 | import java.util.UUID; 32 | 33 | import me.prettyprint.cassandra.utils.TimeUUIDUtils; 34 | 35 | //import com.google.common.io.BaseEncoding; 36 | 37 | import javax.xml.bind.DatatypeConverter; 38 | 39 | /** 40 | * URL safe Base64 encoding/decoding of UUID 41 | *

42 | * 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 | 30 | 31 | 32 | ../../poms/wrappers/ 33 | com.elasticinbox.parent.build 34 | wrapper-bundle-settings 35 | 0.5.0-SNAPSHOT 36 | 37 | 38 | 39 | com.ecyrd.speed4j 40 | com.ecyrd.speed4j 41 | speed4j 42 | ${bundle.speed4j.version} 43 | 44 | 45 | 4.0.0 46 | com.elasticinbox.bundles 47 | com.ecyrd.speed4j 48 | 0.13-1 49 | 50 | ElasticInbox Bundles :: ${wrapped.artifactId} 51 | 52 | bundle 53 | 54 | 55 | 56 | ${wrapped.groupId} 57 | ${wrapped.artifactId} 58 | ${wrapped.version} 59 | true 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/blob/compression/DeflateCompressionHandler.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.compression; 30 | 31 | import java.io.InputStream; 32 | import java.util.zip.DeflaterInputStream; 33 | import java.util.zip.InflaterInputStream; 34 | 35 | /** 36 | * This class provides compression/decompression using Deflate algorithm. 37 | *

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 deliver(MailEnvelope env, final String sessionId) 58 | { 59 | Map map = new HashMap(); 60 | 61 | for (IDeliveryAgent agent : agents) { 62 | try { 63 | map.putAll(agent.deliver(env, sessionId)); 64 | } catch (Exception e) { 65 | logger.warn(agent.getClass().getName() 66 | + " delivery deferred: mail delivery failed: ", e); 67 | for (MailAddress address : env.getRecipients()) { 68 | map.put(address, DeliveryReturnCode.TEMPORARY_FAILURE); 69 | } 70 | } 71 | } 72 | return map; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/blob/store/BlobStorage.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.blob.store; 30 | 31 | import java.io.IOException; 32 | import java.io.InputStream; 33 | import java.net.URI; 34 | import java.security.GeneralSecurityException; 35 | import java.util.UUID; 36 | 37 | import com.elasticinbox.core.blob.BlobDataSource; 38 | import com.elasticinbox.core.blob.BlobURI; 39 | import com.elasticinbox.core.model.Mailbox; 40 | 41 | public interface BlobStorage 42 | { 43 | /** 44 | * Store blob contents, optionally compress and encrypt. 45 | * 46 | * @param messageId 47 | * Unique message ID 48 | * @param mailbox 49 | * Message owner's Mailbox 50 | * @param profileName 51 | * Blob store profile name 52 | * @param in 53 | * Payload 54 | * @param size 55 | * Payload size in bytes 56 | * @return 57 | * @throws IOException 58 | * @throws GeneralSecurityException 59 | */ 60 | public BlobURI write(final UUID messageId, final Mailbox mailbox, final String profileName, final InputStream in, final Long size) 61 | throws IOException, GeneralSecurityException; 62 | 63 | /** 64 | * Read blob contents and decrypt 65 | * 66 | * @param uri Blob URI 67 | * @return 68 | * @throws IOException 69 | */ 70 | public BlobDataSource read(final URI uri) throws IOException; 71 | 72 | /** 73 | * Delete blob 74 | * 75 | * @param uri 76 | * @throws IOException 77 | */ 78 | public void delete(final URI uri) throws IOException; 79 | 80 | } 81 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/cassandra/utils/Speed4jOpTimer.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.utils; 30 | 31 | import me.prettyprint.cassandra.connection.HOpTimer; 32 | 33 | import com.ecyrd.speed4j.StopWatch; 34 | import com.ecyrd.speed4j.StopWatchFactory; 35 | import com.ecyrd.speed4j.log.PeriodicalLog; 36 | import com.elasticinbox.config.Configurator; 37 | 38 | /** 39 | * Implementation of {@link HOpTimer} for JMX performance counters without 40 | * speed4j.properties file. 41 | * 42 | * @author Rustam Aliyev 43 | */ 44 | public final class Speed4jOpTimer implements HOpTimer 45 | { 46 | private final StopWatchFactory stopWatchFactory; 47 | 48 | public Speed4jOpTimer() 49 | { 50 | // Instantiate a new Periodical logger 51 | PeriodicalLog pLog = new PeriodicalLog(); 52 | pLog.setName("ElasticInbox-Hector"); 53 | pLog.setPeriod(Configurator.getPerformanceCountersInterval()); 54 | pLog.setMode(PeriodicalLog.Mode.JMX_ONLY); 55 | pLog.setMaxQueueSize(250000); 56 | pLog.setJmx("READ.success,WRITE.success,READ.fail,WRITE.fail,META_READ.success,META_READ.fail"); 57 | pLog.setSlf4jLogname("com.elasticinbox.speed4j.cassandra.HectorPeriodicalLogger"); 58 | stopWatchFactory = StopWatchFactory.getInstance(pLog); 59 | } 60 | 61 | @Override 62 | public Object start(String tagName) { 63 | return stopWatchFactory.getStopWatch(tagName); 64 | } 65 | 66 | @Override 67 | public void stop(Object token, String tagName, boolean success) { 68 | ((StopWatch) token).stop(tagName.concat(success ? ".success" : ".fail")); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/message/id/MessageIdBuilder.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.Date; 32 | import java.util.UUID; 33 | 34 | /** 35 | * This builder generates new message UUID based on the provided parameters and 36 | * specific {@link AbstractMessageIdPolicy} implementation. 37 | * 38 | * @author Rustam Aliyev 39 | */ 40 | public final class MessageIdBuilder 41 | { 42 | protected String messageIdHeader; // message-id header 43 | protected Date sentDate; 44 | 45 | private static AbstractMessageIdPolicy sentDatePolicy = new SentDateMessageIdPolicy(); 46 | private static AbstractMessageIdPolicy currentTimePolicy = new CurrentTimeMessageIdPolicy(); 47 | 48 | /** 49 | * Set 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 List cassandra_hosts; 64 | public Boolean cassandra_autodiscovery; 65 | public String cassandra_cluster_name; 66 | public String cassandra_keyspace; 67 | 68 | // Blob store settings 69 | public Map blobstore_profiles; 70 | public String blobstore_write_profile; 71 | public Boolean blobstore_enable_compression; 72 | 73 | // Blob store encryption 74 | public Boolean blobstore_enable_encryption = false; 75 | public String blobstore_default_encryption_key = null; 76 | 77 | // Encryption options 78 | public EncryptionSettings encryption = new EncryptionSettings(); 79 | } 80 | -------------------------------------------------------------------------------- /modules/config/src/main/java/com/elasticinbox/config/blob/BlobStoreProfile.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.blob; 30 | 31 | /** 32 | * This class stores access information of the specific blob store. 33 | * 34 | *

Using combination of BlobStoreProfile 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 | *

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 parts = message.getParts(); 66 | 67 | for (String partId : parts.keySet()) 68 | { 69 | MimePart part = parts.get(partId); 70 | InputStream attachmentContentByPartId = mp.getInputStreamByPartId(partId); 71 | String attachmentHashByPartId = DigestUtils.md5Hex(attachmentContentByPartId); 72 | 73 | InputStream attachmentContentByContentId = mp.getInputStreamByContentId(part.getContentId()); 74 | String attachmentHashByContentId = DigestUtils.md5Hex(attachmentContentByContentId); 75 | 76 | assertEquals(attachmentHashByPartId, attachmentHashByContentId); 77 | } 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/model/AddressList.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 java.util.AbstractList; 32 | import java.util.ArrayList; 33 | import java.util.Collections; 34 | import java.util.List; 35 | 36 | /** 37 | * This class represents a list of {@link Address} objects 38 | * 39 | * @author Rustam Aliyev 40 | * @see {@link Address} 41 | */ 42 | public class AddressList extends AbstractList

43 | { 44 | private final List
addresses; 45 | 46 | /** 47 | * Create new address list 48 | * 49 | * @param addresses 50 | * A List that contains only Address objects. 51 | */ 52 | public AddressList(List
addresses) 53 | { 54 | if (addresses != null) { 55 | this.addresses = new ArrayList
(addresses); 56 | } else { 57 | this.addresses = Collections.emptyList(); 58 | } 59 | } 60 | 61 | /** 62 | * Create new address list 63 | * 64 | * @param address 65 | */ 66 | public AddressList(Address address) 67 | { 68 | if (address != null) { 69 | this.addresses = new ArrayList
(1); 70 | this.addresses.add(address); 71 | } else { 72 | this.addresses = Collections.emptyList(); 73 | } 74 | } 75 | 76 | public String getDisplayString() 77 | { 78 | try { 79 | String s = this.addresses.toString(); 80 | return s.substring(1, s.length() - 1); 81 | } catch (Exception e) { 82 | return null; 83 | } 84 | } 85 | 86 | /** 87 | * Gets an address. 88 | */ 89 | @Override 90 | public Address get(int index) { 91 | return addresses.get(index); 92 | } 93 | 94 | /** 95 | * The number of elements in this list. 96 | */ 97 | @Override 98 | public int size() { 99 | return addresses.size(); 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /modules/core/src/main/java/com/elasticinbox/core/blob/naming/BlobNameBuilder.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.naming; 30 | 31 | import java.util.UUID; 32 | 33 | import com.elasticinbox.common.utils.Assert; 34 | import com.elasticinbox.core.blob.store.BlobStoreConstants; 35 | import com.elasticinbox.core.model.Mailbox; 36 | 37 | /** 38 | * This builder generates new Blob name based on the provided parameters and 39 | * specific {@link AbstractBlobNamingPolicy} implementation. 40 | * 41 | * @author Rustam Aliyev 42 | */ 43 | public final class BlobNameBuilder 44 | { 45 | protected Mailbox mailbox; 46 | protected UUID messageId; 47 | protected Long messageSize; 48 | 49 | private static AbstractBlobNamingPolicy uuidPolicy = new UuidBlobNamingPolicy(); 50 | 51 | public BlobNameBuilder setMailbox(Mailbox mailbox) { 52 | this.mailbox = mailbox; 53 | return this; 54 | } 55 | 56 | public BlobNameBuilder setMessageId(UUID messageId) { 57 | this.messageId = messageId; 58 | return this; 59 | } 60 | 61 | public BlobNameBuilder setMessageSize(Long size) { 62 | this.messageSize = size; 63 | return this; 64 | } 65 | 66 | /** 67 | * Generate new Blob name 68 | * 69 | * @return 70 | */ 71 | public String build() { 72 | String name = uuidPolicy.getBlobName(this); 73 | validateBlobName(name); 74 | return name; 75 | } 76 | 77 | /** 78 | * Validate generated Blob name. 79 | *

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 | --------------------------------------------------------------------------------