Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 0456ca6

Browse files
author
Rustam Aliyev
committed
added initial version of the POP3 module
1 parent 1394978 commit 0456ca6

File tree

14 files changed

+753
-0
lines changed

14 files changed

+753
-0
lines changed

modules/core/src/main/java/com/elasticinbox/core/model/ReservedLabels.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public final class ReservedLabels
5050
public final static Label IMPORTANT = new Label(7, "important");
5151
public final static Label NOTIFICATIONS = new Label(8, "notifications");
5252
public final static Label ATTACHMENTS = new Label(9, "attachments");
53+
public final static Label POP3 = new Label(10, "pop3");
5354

5455
private final static ImmutableMap<Integer, Label> labels =
5556
new ImmutableMap.Builder<Integer, Label>()
@@ -63,6 +64,7 @@ public final class ReservedLabels
6364
.put(IMPORTANT.getId(), IMPORTANT)
6465
.put(NOTIFICATIONS.getId(), NOTIFICATIONS)
6566
.put(ATTACHMENTS.getId(), ATTACHMENTS)
67+
.put(POP3.getId(), POP3)
6668
.build();
6769

6870
public static Label get(final int labelId) {

modules/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<module>config</module>
4848
<module>core</module>
4949
<module>lmtp</module>
50+
<module>pop3</module>
5051
<module>rest</module>
5152
</modules>
5253

modules/pop3/build.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source.. = src/main/java/,src/main/resources/
2+
output.. = target/classes/
3+
bin.includes = .

modules/pop3/osgi.bnd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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/pop3/pom.xml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (c) 2011-2012 Optimax Software Ltd.
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice,
10+
this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
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.
28+
-->
29+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
30+
31+
<parent>
32+
<relativePath>../../poms/compiled/</relativePath>
33+
<groupId>com.elasticinbox.parent.build</groupId>
34+
<artifactId>compiled-bundle-settings</artifactId>
35+
<version>0.4.0-SNAPSHOT</version>
36+
</parent>
37+
38+
<properties>
39+
<bundle.symbolicName>com.elasticinbox.pop3</bundle.symbolicName>
40+
<bundle.namespace>com.elasticinbox</bundle.namespace>
41+
</properties>
42+
43+
<modelVersion>4.0.0</modelVersion>
44+
<groupId>com.elasticinbox</groupId>
45+
<artifactId>elasticinbox-pop3</artifactId>
46+
47+
<name>ElasticInbox POP3 Module</name>
48+
49+
<packaging>bundle</packaging>
50+
51+
<build>
52+
<plugins>
53+
<plugin>
54+
<groupId>org.apache.maven.plugins</groupId>
55+
<artifactId>maven-compiler-plugin</artifactId>
56+
<version>2.3.2</version>
57+
<configuration>
58+
<source>1.6</source>
59+
<target>1.6</target>
60+
</configuration>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
65+
<dependencies>
66+
<!--
67+
| uncomment to add all imported (non-local) bundles to your compilation classpath
68+
<dependency>
69+
<type>pom</type>
70+
<groupId>${parent.groupId}</groupId>
71+
<artifactId>provision</artifactId>
72+
<optional>true</optional>
73+
</dependency>
74+
-->
75+
<dependency>
76+
<groupId>org.osgi</groupId>
77+
<artifactId>osgi_R4_core</artifactId>
78+
<optional>true</optional>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.osgi</groupId>
82+
<artifactId>osgi_R4_compendium</artifactId>
83+
<optional>true</optional>
84+
</dependency>
85+
<dependency>
86+
<groupId>org.apache.james.protocols</groupId>
87+
<artifactId>protocols-netty</artifactId>
88+
<version>${bundle.james-protocols.version}</version>
89+
<type>bundle</type>
90+
<scope>provided</scope>
91+
</dependency>
92+
<dependency>
93+
<groupId>org.apache.james.protocols</groupId>
94+
<artifactId>protocols-api</artifactId>
95+
<version>${bundle.james-protocols.version}</version>
96+
<type>bundle</type>
97+
<scope>provided</scope>
98+
</dependency>
99+
<dependency>
100+
<groupId>org.apache.james.protocols</groupId>
101+
<artifactId>protocols-pop3</artifactId>
102+
<version>${bundle.james-protocols.version}</version>
103+
<type>bundle</type>
104+
<scope>provided</scope>
105+
</dependency>
106+
<dependency>
107+
<groupId>io.netty</groupId>
108+
<artifactId>netty</artifactId>
109+
<version>${bundle.netty.version}</version>
110+
<type>bundle</type>
111+
<scope>provided</scope>
112+
</dependency>
113+
<dependency>
114+
<groupId>javax.mail</groupId>
115+
<artifactId>mail</artifactId>
116+
<version>${bundle.javamail.version}</version>
117+
<type>bundle</type>
118+
<scope>provided</scope>
119+
</dependency>
120+
<dependency>
121+
<groupId>org.slf4j</groupId>
122+
<artifactId>slf4j-api</artifactId>
123+
<version>${bundle.slf4j.version}</version>
124+
<scope>provided</scope>
125+
</dependency>
126+
<dependency>
127+
<groupId>com.elasticinbox.bundles</groupId>
128+
<artifactId>com.ecyrd.speed4j</artifactId>
129+
<version>${bundle.speed4j.version}-1</version>
130+
<type>bundle</type>
131+
<scope>provided</scope>
132+
</dependency>
133+
<dependency>
134+
<groupId>com.elasticinbox</groupId>
135+
<artifactId>elasticinbox-common</artifactId>
136+
<version>${project.version}</version>
137+
<type>bundle</type>
138+
<scope>provided</scope>
139+
</dependency>
140+
<dependency>
141+
<groupId>com.elasticinbox</groupId>
142+
<artifactId>elasticinbox-config</artifactId>
143+
<version>${project.version}</version>
144+
<type>bundle</type>
145+
<scope>provided</scope>
146+
</dependency>
147+
<dependency>
148+
<groupId>com.elasticinbox</groupId>
149+
<artifactId>elasticinbox-core</artifactId>
150+
<version>${project.version}</version>
151+
<type>bundle</type>
152+
<scope>provided</scope>
153+
</dependency>
154+
</dependencies>
155+
156+
</project>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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 org.osgi.framework.BundleActivator;
32+
import org.osgi.framework.BundleContext;
33+
import org.slf4j.Logger;
34+
import org.slf4j.LoggerFactory;
35+
36+
import com.ecyrd.speed4j.StopWatch;
37+
import com.ecyrd.speed4j.StopWatchFactory;
38+
import com.ecyrd.speed4j.log.PeriodicalLog;
39+
import com.ecyrd.speed4j.log.Slf4jLog;
40+
import com.elasticinbox.config.Configurator;
41+
import com.elasticinbox.pop3.server.handler.MailboxHandlerFactory;
42+
import com.elasticinbox.pop3.utils.LoggingPeriodicalLog;
43+
44+
public class Activator implements BundleActivator
45+
{
46+
private static final Logger logger =
47+
LoggerFactory.getLogger(Activator.class);
48+
49+
private static final String SPEED4J_LOG_NAME = "ElasticInbox-POP3";
50+
private StopWatchFactory stopWatchFactory;
51+
private MailboxHandlerFactory backend;
52+
private POP3ProxyServer server;
53+
54+
// The shared instance
55+
private static Activator plugin;
56+
private static BundleContext bundleContext;
57+
58+
public void start(BundleContext context) throws Exception
59+
{
60+
plugin = this;
61+
bundleContext = context;
62+
63+
// Setup performance logger for POP3
64+
if(Configurator.isPerformanceCountersEnabled()) {
65+
LoggingPeriodicalLog pLog = new LoggingPeriodicalLog();
66+
pLog.setName(SPEED4J_LOG_NAME);
67+
pLog.setMode(PeriodicalLog.Mode.JMX_ONLY);
68+
pLog.setMaxQueueSize(250000);
69+
pLog.setPeriod(Configurator.getPerformanceCountersInterval());
70+
pLog.setJmx("DELIVERY.success,DELIVERY.discard,DELIVERY.defer,DELIVERY.defer_failure,DELIVERY.reject_overQuota,DELIVERY.reject_nonExistent");
71+
pLog.setSlf4jLogname("com.elasticinbox.speed4j.pop3.PeriodicalLogger");
72+
stopWatchFactory = StopWatchFactory.getInstance(pLog);
73+
} else {
74+
Slf4jLog pLog = new Slf4jLog();
75+
pLog.setName(SPEED4J_LOG_NAME);
76+
pLog.setSlf4jLogname("com.elasticinbox.speed4j.pop3.PeriodicalLogger");
77+
stopWatchFactory = StopWatchFactory.getInstance(pLog);
78+
}
79+
80+
backend = new MailboxHandlerFactory();
81+
82+
logger.debug("Starting POP3 daemon...");
83+
server = new POP3ProxyServer(backend);
84+
server.start();
85+
logger.info("POP3 daemon started.");
86+
}
87+
88+
public void stop(BundleContext context) throws Exception
89+
{
90+
logger.debug("Stopping POP3 daemon...");
91+
server.stop();
92+
server = null;
93+
//StopWatchFactory.getInstance(SPEED4J_LOG_NAME).shutdown();
94+
logger.info("POP3 daemon stopped.");
95+
}
96+
97+
public static Activator getDefault() {
98+
return plugin;
99+
}
100+
101+
public MailboxHandlerFactory getBackend() {
102+
return backend;
103+
}
104+
105+
public static BundleContext getContext() {
106+
return bundleContext;
107+
}
108+
109+
public StopWatch getStopWatch() {
110+
return stopWatchFactory.getStopWatch();
111+
}
112+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.pop3.server.POP3ServerConfig;
39+
import com.elasticinbox.pop3.server.handler.AuthHandler;
40+
import com.elasticinbox.pop3.server.handler.MailboxHandlerFactory;
41+
import com.elasticinbox.pop3.utils.POP3ProtocolLogger;
42+
43+
/**
44+
* POP3 proxy main class which sends traffic to multiple registered handlers
45+
*
46+
* @author Rustam Aliyev
47+
*/
48+
public class POP3ProxyServer
49+
{
50+
private NettyServer server;
51+
private MailboxHandlerFactory backend;
52+
53+
protected POP3ProxyServer(final MailboxHandlerFactory backend) {
54+
this.backend = backend;
55+
}
56+
57+
public void start() throws Exception
58+
{
59+
Logger logger = new POP3ProtocolLogger();
60+
61+
// POP3ProtocolHandlerChain chain = new POP3ProtocolHandlerChain();
62+
// chain.add(0, new PassCmdHandler(backend));
63+
// chain.wireExtensibleHandlers();
64+
65+
POP3ProtocolHandlerChain chain = new POP3ProtocolHandlerChain(new AuthHandler(backend));
66+
67+
server = new NettyServer(new POP3Protocol(chain, new POP3ServerConfig(), logger));
68+
//TODO: add Configurator.getPop3Port()
69+
server.setListenAddresses(new InetSocketAddress(2110));
70+
//TODO: Configurator.getPop3MaxConnections()
71+
server.setMaxConcurrentConnections(10);
72+
server.setTimeout(POP3ServerConfig.CONNECTION_TIMEOUT);
73+
server.setUseExecutionHandler(true, 16);
74+
server.bind();
75+
}
76+
77+
public void stop() {
78+
server.unbind();
79+
}
80+
}

0 commit comments

Comments
 (0)