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

Commit 84796ae

Browse files
author
Rustam Aliyev
committed
Update James Protocols POP3 with string based UIDL support. Added Base64
encoding for POP3 UIDL of UUID.
1 parent 0456ca6 commit 84796ae

File tree

5 files changed

+127
-8
lines changed

5 files changed

+127
-8
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
/**
38+
* URL safe Base64 encoding/decoding of UUID
39+
* <p>
40+
* Produces a 22 character string which is a URL safe Base64 encoded UUID.
41+
* </p>
42+
*
43+
* @author Rustam Aliyev
44+
*/
45+
public class Base64UUIDUtils
46+
{
47+
public static String encode(UUID uuid)
48+
{
49+
return BaseEncoding.base64Url().omitPadding()
50+
.encode(TimeUUIDUtils.asByteArray(uuid));
51+
}
52+
53+
public static UUID decode(String encoded64)
54+
{
55+
byte[] ba = BaseEncoding.base64Url().decode(encoded64);
56+
return TimeUUIDUtils.toUUID(ba);
57+
}
58+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

modules/pop3/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,4 @@
152152
<scope>provided</scope>
153153
</dependency>
154154
</dependencies>
155-
156155
</project>

modules/pop3/src/main/java/com/elasticinbox/pop3/server/handler/ElasticInboxMailboxHandler.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.elasticinbox.core.model.Mailbox;
1616
import com.elasticinbox.core.model.Message;
1717
import com.elasticinbox.core.model.ReservedLabels;
18+
import com.elasticinbox.core.utils.Base64UUIDUtils;
1819

1920
public class ElasticInboxMailboxHandler implements org.apache.james.protocols.pop3.mailbox.Mailbox
2021
{
@@ -37,18 +38,18 @@ public ElasticInboxMailboxHandler(final MessageDAO dao, final String username)
3738
}
3839

3940
@Override
40-
public InputStream getMessageBody(long uid) throws IOException {
41+
public InputStream getMessageBody(String uid) throws IOException {
4142
return null;
4243
}
4344

4445
@Override
45-
public InputStream getMessageHeaders(long uid) throws IOException {
46+
public InputStream getMessageHeaders(String uid) throws IOException {
4647
// TODO Auto-generated method stub
4748
return null;
4849
}
4950

5051
@Override
51-
public InputStream getMessage(long uid) throws IOException {
52+
public InputStream getMessage(String uid) throws IOException {
5253
// TODO Auto-generated method stub
5354
return null;
5455
}
@@ -63,15 +64,15 @@ public List<MessageMetaData> getMessages() throws IOException
6364
// convert to James Protocols list
6465
for (Map.Entry<UUID, Message> entry : messages.entrySet()) {
6566
MessageMetaData md = new MessageMetaData(
66-
entry.getKey().timestamp(), entry.getValue().getSize());
67+
Base64UUIDUtils.encode(entry.getKey()), entry.getValue().getSize());
6768
list.add(md);
6869
}
6970

7071
return list;
7172
}
7273

7374
@Override
74-
public void remove(long... uids) throws IOException {
75+
public void remove(String... uids) throws IOException {
7576
logger.debug("POP3: Remove messages");
7677
}
7778

pom.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
<bundle.javax-inject.version>1_1</bundle.javax-inject.version>
7474
<bundle.guice.version>3.0</bundle.guice.version>
7575
<bundle.gson.version>2.2.2</bundle.gson.version>
76-
<bundle.guava.version>13.0.1</bundle.guava.version>
76+
<bundle.guava.version>14.0-rc2</bundle.guava.version>
7777
<bundle.aopalliance.version>1.0_5</bundle.aopalliance.version>
7878
<bundle.net.oauth.version>20100527_1</bundle.net.oauth.version>
7979
<bundle.jersey.version>1.16</bundle.jersey.version>
@@ -85,7 +85,7 @@
8585
<bundle.commons-lang.version>2.6</bundle.commons-lang.version>
8686
<bundle.servlet-api.version>2.5.20110712</bundle.servlet-api.version>
8787
<bundle.netty.version>3.5.11.Final</bundle.netty.version>
88-
<bundle.james-protocols.version>1.6.2</bundle.james-protocols.version>
88+
<bundle.james-protocols.version>1.6.3-SNAPSHOT</bundle.james-protocols.version>
8989
<bundle.snakeyaml.version>1.11</bundle.snakeyaml.version>
9090

9191
<!-- Profiling Configs -->
@@ -221,5 +221,15 @@
221221
<id>sonatype</id>
222222
<url>https://oss.sonatype.org/content/repositories/releases/</url>
223223
</repository>
224+
<repository>
225+
<id>apache-snapshot</id>
226+
<releases>
227+
<enabled>false</enabled>
228+
</releases>
229+
<snapshots>
230+
<enabled>true</enabled>
231+
</snapshots>
232+
<url>http://repository.apache.org/snapshots/</url>
233+
</repository>
224234
</repositories>
225235
</project>

0 commit comments

Comments
 (0)