You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by er...@apache.org on 2012/11/24 15:48:17 UTC
svn commit: r1413195 - in /james/protocols/trunk/pop3/src:
main/java/org/apache/james/protocols/pop3/core/
main/java/org/apache/james/protocols/pop3/mailbox/
test/java/org/apache/james/protocols/pop3/utils/
Author: eric
Date: Sat Nov 24 14:48:13 2012
New Revision: 1413195
URL: http://svn.apache.org/viewvc?rev=1413195&view=rev
Log:
Decouple POP3 UID forming logic from protocol implementation (PROTOCOLS-98) - patch contributed by Rustam Aliyev
Added:
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMailbox.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMessageMetaData.java
Modified:
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ExtraDotInputStream.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/MessageMetaDataUtils.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/QuitCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RetrCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RsetCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/StatCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/TopCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UidlCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/WelcomeMessageHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/AbstractMailbox.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/Mailbox.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/MessageMetaData.java
james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/utils/MockMailbox.java
Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java?rev=1413195&r1=1413194&r2=1413195&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java Sat Nov 24 14:48:13 2012
@@ -60,9 +60,9 @@ public class DeleCmdHandler implements C
StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
return new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
}
- List<Long> deletedUidList = (List<Long>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);
+ List<String> deletedUidList = (List<String>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);
- Long uid = meta.getUid();
+ String uid = meta.getUid();
if (deletedUidList.contains(uid)) {
StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") already deleted.");
Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ExtraDotInputStream.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ExtraDotInputStream.java?rev=1413195&r1=1413194&r2=1413195&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ExtraDotInputStream.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ExtraDotInputStream.java Sat Nov 24 14:48:13 2012
@@ -38,7 +38,6 @@ public class ExtraDotInputStream extends
this.in = new PushbackInputStream(in, 2);
startLine = true;
}
-
@Override
public int read() throws IOException {
Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java?rev=1413195&r1=1413194&r2=1413195&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java Sat Nov 24 14:48:13 2012
@@ -54,7 +54,7 @@ public class ListCmdHandler implements C
public Response onCommand(POP3Session session, Request request) {
String parameters = request.getArgument();
List<MessageMetaData> uidList = (List<MessageMetaData>) session.getAttachment(POP3Session.UID_LIST, State.Transaction);
- List<Long> deletedUidList = (List<Long>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);
+ List<String> deletedUidList = (List<String>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);
if (session.getHandlerState() == POP3Session.TRANSACTION) {
POP3Response response = null;
@@ -95,7 +95,6 @@ public class ListCmdHandler implements C
}
if (deletedUidList.contains(data.getUid()) == false) {
-
StringBuilder responseBuffer = new StringBuilder(64).append(num).append(" ").append(data.getSize());
response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
} else {
Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/MessageMetaDataUtils.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/MessageMetaDataUtils.java?rev=1413195&r1=1413194&r2=1413195&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/MessageMetaDataUtils.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/MessageMetaDataUtils.java Sat Nov 24 14:48:13 2012
@@ -44,4 +44,24 @@ public class MessageMetaDataUtils {
return uidList.get(number -1);
}
}
+
+ /**
+ * Check whether POP3 UID is compatible with RFC1939
+ *
+ * @param uid
+ * @return
+ */
+ public static boolean isRFC1939Compatible(String uid) {
+ if (uid == null) {
+ return false;
+ }
+
+ for (int i = 0; i < uid.length(); i++) {
+ if ((uid.charAt(i) >= 0x21 && uid.charAt(i) < 0x7E) == false) {
+ return false;
+ }
+ }
+
+ return true;
+ }
}
Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/QuitCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/QuitCmdHandler.java?rev=1413195&r1=1413194&r2=1413195&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/QuitCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/QuitCmdHandler.java Sat Nov 24 14:48:13 2012
@@ -59,20 +59,16 @@ public class QuitCmdHandler implements C
if (session.getHandlerState() == POP3Session.AUTHENTICATION_READY || session.getHandlerState() == POP3Session.AUTHENTICATION_USERSET) {
return SIGN_OFF;
}
- List<Long> toBeRemoved = (List<Long>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);
+ List<String> toBeRemoved = (List<String>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);
Mailbox mailbox = session.getUserMailbox();
try {
- ;
- long uids[] = new long[toBeRemoved.size()];
- for (int i = 0;i < toBeRemoved.size(); i++) {
- uids[i] = toBeRemoved.get(i);
- }
+ String[] uids = toBeRemoved.toArray(new String[toBeRemoved.size()]);
mailbox.remove(uids);
response = SIGN_OFF;
} catch (Exception ex) {
response = SIGN_OFF_NOT_CLEAN;
session.getLogger().error("Some deleted messages were not removed", ex);
- }
+ }
try {
mailbox.close();
} catch (IOException e) {
Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RetrCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RetrCmdHandler.java?rev=1413195&r1=1413194&r2=1413195&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RetrCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RetrCmdHandler.java Sat Nov 24 14:48:13 2012
@@ -67,9 +67,9 @@ public class RetrCmdHandler implements C
response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
return response;
}
- List<Long> deletedUidList = (List<Long>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);
+ List<String> deletedUidList = (List<String>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);
- Long uid = data.getUid();
+ String uid = data.getUid();
if (deletedUidList.contains(uid) == false) {
InputStream content = session.getUserMailbox().getMessage(uid);
Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RsetCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RsetCmdHandler.java?rev=1413195&r1=1413194&r2=1413195&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RsetCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RsetCmdHandler.java Sat Nov 24 14:48:13 2012
@@ -66,7 +66,7 @@ public class RsetCmdHandler implements C
List<MessageMetaData> messages = session.getUserMailbox().getMessages();
session.setAttachment(POP3Session.UID_LIST, messages, State.Transaction);
- session.setAttachment(POP3Session.DELETED_UID_LIST, new ArrayList<Long>(), State.Transaction);
+ session.setAttachment(POP3Session.DELETED_UID_LIST, new ArrayList<String>(), State.Transaction);
} catch (IOException e) {
// In the event of an exception being thrown there may or may not be
// anything in userMailbox
Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/StatCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/StatCmdHandler.java?rev=1413195&r1=1413194&r2=1413195&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/StatCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/StatCmdHandler.java Sat Nov 24 14:48:13 2012
@@ -48,7 +48,7 @@ public class StatCmdHandler implements C
if (session.getHandlerState() == POP3Session.TRANSACTION) {
List<MessageMetaData> uidList = (List<MessageMetaData>) session.getAttachment(POP3Session.UID_LIST, State.Transaction);
- List<Long> deletedUidList = (List<Long>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);
+ List<String> deletedUidList = (List<String>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);
long size = 0;
int count = 0;
if (uidList.isEmpty() == false) {
Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/TopCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/TopCmdHandler.java?rev=1413195&r1=1413194&r2=1413195&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/TopCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/TopCmdHandler.java Sat Nov 24 14:48:13 2012
@@ -88,9 +88,9 @@ public class TopCmdHandler extends RetrC
return new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
}
- List<Long> deletedUidList = (List<Long>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);
+ List<String> deletedUidList = (List<String>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);
- Long uid = data.getUid();
+ String uid = data.getUid();
if (deletedUidList.contains(uid) == false) {
InputStream body = new CountingBodyInputStream(new ExtraDotInputStream(new CRLFTerminatedInputStream(session.getUserMailbox().getMessageBody(uid))), lines);
Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UidlCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UidlCmdHandler.java?rev=1413195&r1=1413194&r2=1413195&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UidlCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UidlCmdHandler.java Sat Nov 24 14:48:13 2012
@@ -53,16 +53,16 @@ public class UidlCmdHandler implements C
String parameters = request.getArgument();
if (session.getHandlerState() == POP3Session.TRANSACTION) {
List<MessageMetaData> uidList = (List<MessageMetaData>) session.getAttachment(POP3Session.UID_LIST, State.Transaction);
- List<Long> deletedUidList = (List<Long>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);
+ List<String> deletedUidList = (List<String>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);
try {
String identifier = session.getUserMailbox().getIdentifier();
if (parameters == null) {
response = new POP3Response(POP3Response.OK_RESPONSE, "unique-id listing follows");
+
for (int i = 0; i < uidList.size(); i++) {
- Long uid = uidList.get(i).getUid();
- if (deletedUidList.contains(uid) == false) {
- // construct unique UIDL. See JAMES-1264
- StringBuilder responseBuffer = new StringBuilder(64).append(i + 1).append(" ").append(identifier).append("-").append(uid);
+ MessageMetaData metadata = uidList.get(i);
+ if (deletedUidList.contains(metadata.getUid()) == false) {
+ StringBuilder responseBuffer = new StringBuilder().append(i + 1).append(" ").append(metadata.getUid(identifier));
response.appendLine(responseBuffer.toString());
}
}
@@ -73,18 +73,16 @@ public class UidlCmdHandler implements C
try {
num = Integer.parseInt(parameters);
- MessageMetaData data = MessageMetaDataUtils.getMetaData(session, num);
- if (data == null) {
+ MessageMetaData metadata = MessageMetaDataUtils.getMetaData(session, num);
+
+ if (metadata == null) {
StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
return new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
}
- long uid = data.getUid();
-
- if (deletedUidList.contains(uid) == false) {
- // construct unique UIDL. See JAMES-1264
- StringBuilder responseBuffer = new StringBuilder(64).append(num).append(" ").append(identifier).append("-").append(uid);
- response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
+ if (deletedUidList.contains(metadata.getUid()) == false) {
+ StringBuilder responseBuffer = new StringBuilder(64).append(num).append(" ").append(metadata.getUid(identifier));
+ response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
} else {
StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") already deleted.");
response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/WelcomeMessageHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/WelcomeMessageHandler.java?rev=1413195&r1=1413194&r2=1413195&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/WelcomeMessageHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/WelcomeMessageHandler.java Sat Nov 24 14:48:13 2012
@@ -45,7 +45,5 @@ public class WelcomeMessageHandler imple
POP3Response response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
return response;
}
-
-
-
-}
+
+}
\ No newline at end of file
Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/AbstractMailbox.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/AbstractMailbox.java?rev=1413195&r1=1413194&r2=1413195&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/AbstractMailbox.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/AbstractMailbox.java Sat Nov 24 14:48:13 2012
@@ -34,13 +34,12 @@ public abstract class AbstractMailbox im
/*
* (non-Javadoc)
*
- * @see org.apache.james.protocols.pop3.mailbox.Mailbox#getMessage(long)
+ * @see org.apache.james.protocols.pop3.mailbox.Mailbox#getMessage(String)
*/
- public InputStream getMessage(long uid) throws IOException {
+ public InputStream getMessage(String uid) throws IOException {
return new CombinedInputStream(getMessageHeaders(uid), getMessageBody(uid));
}
-
/**
* Does nothing
*/
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMailbox.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMailbox.java?rev=1413195&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMailbox.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMailbox.java Sat Nov 24 14:48:13 2012
@@ -0,0 +1,90 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.protocols.pop3.mailbox;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * An IMAP Mailbox adapter which is used in POP3 to retrieve messages
+ *
+ *
+ */
+@Deprecated
+public abstract class ImapMailbox implements Mailbox {
+
+ /**
+ * Returns the message body as {@link InputStream} or <code>null</code> if
+ * no message can be found for the given <code>uid</code>
+ *
+ * @param uid
+ * @return body
+ * @throws IOException
+ */
+ public abstract InputStream getMessageBody(long uid) throws IOException;
+
+ public InputStream getMessageBody(String uid) throws NumberFormatException, IOException {
+ return this.getMessageBody(Long.parseLong(uid));
+ }
+
+ /**
+ * Returns the message headers as {@link InputStream} or <code>null</code>
+ * if no message can be found for the given <code>uid</code>
+ *
+ * @param uid
+ * @return headers
+ * @throws IOException
+ */
+ public abstract InputStream getMessageHeaders(long uid) throws IOException;
+
+ public InputStream getMessageHeaders(String uid) throws NumberFormatException, IOException {
+ return this.getMessageHeaders(Long.parseLong(uid));
+ }
+
+ /**
+ * Return the full message (headers + body) as {@link InputStream} or
+ * <code>null</code> if no message can be found for the given
+ * <code>uid</code>
+ *
+ * @param uid
+ * @return message
+ * @throws IOException
+ */
+ public abstract InputStream getMessage(long uid) throws IOException;
+
+ public InputStream getMessage(String uid) throws NumberFormatException, IOException {
+ return this.getMessage(Long.parseLong(uid));
+ }
+
+ /**
+ * Remove the messages with the given uids
+ *
+ * @param uids
+ */
+ public abstract void remove(long... uids) throws IOException;
+
+ public void remove(String... uids) throws NumberFormatException, IOException {
+ long imapUids[] = new long[uids.length];
+ for (int i = 0; i < uids.length; i++) {
+ imapUids[i] = Long.parseLong(uids[i]);
+ }
+ this.remove(imapUids);
+ }
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMessageMetaData.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMessageMetaData.java?rev=1413195&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMessageMetaData.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMessageMetaData.java Sat Nov 24 14:48:13 2012
@@ -0,0 +1,36 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.protocols.pop3.mailbox;
+
+/**
+ * Hold meta data for a IMAP message. Construct unique POP3 UIDL from IMAP UID.
+ * See JAMES-1264.
+ */
+public final class ImapMessageMetaData extends MessageMetaData {
+
+ public ImapMessageMetaData(Long uid, long size) {
+ super(uid.toString(), size);
+ }
+
+ @Override
+ public String getUid(String mailboxId) {
+ return mailboxId + "-" + super.getUid();
+ }
+
+}
Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/Mailbox.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/Mailbox.java?rev=1413195&r1=1413194&r2=1413195&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/Mailbox.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/Mailbox.java Sat Nov 24 14:48:13 2012
@@ -37,7 +37,7 @@ public interface Mailbox {
* @return body
* @throws IOException
*/
- InputStream getMessageBody(long uid) throws IOException;
+ InputStream getMessageBody(String uid) throws IOException;
/**
* Returns the message headers as {@link InputStream} or <code>null</code>
@@ -47,7 +47,7 @@ public interface Mailbox {
* @return headers
* @throws IOException
*/
- InputStream getMessageHeaders(long uid) throws IOException;
+ InputStream getMessageHeaders(String uid) throws IOException;
/**
* Return the full message (headers + body) as {@link InputStream} or
@@ -58,7 +58,7 @@ public interface Mailbox {
* @return message
* @throws IOException
*/
- InputStream getMessage(long uid) throws IOException;
+ InputStream getMessage(String uid) throws IOException;
/**
* Return a immutable {@link List} which holds the {@link MessageMetaData}
@@ -67,14 +67,14 @@ public interface Mailbox {
* @return messages
* @throws IOException
*/
- List<MessageMetaData> getMessages() throws IOException;;
+ List<MessageMetaData> getMessages() throws IOException;
/**
* Remove the messages with the given uids
*
* @param uids
*/
- void remove(long... uids) throws IOException;
+ void remove(String... uids) throws IOException;
/**
* Return the identifier for the mailbox. This MUST not change
Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/MessageMetaData.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/MessageMetaData.java?rev=1413195&r1=1413194&r2=1413195&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/MessageMetaData.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/MessageMetaData.java Sat Nov 24 14:48:13 2012
@@ -18,25 +18,43 @@
****************************************************************/
package org.apache.james.protocols.pop3.mailbox;
+import org.apache.james.protocols.pop3.core.MessageMetaDataUtils;
+
/**
* Hold meta data for a message
*/
-public final class MessageMetaData {
+public class MessageMetaData {
- private final long uid;
+ private final String uid;
private final long size;
- public MessageMetaData(long uid, long size) {
+ public MessageMetaData(String uid, long size) {
this.uid = uid;
this.size = size;
- }
- /**
+ if(!MessageMetaDataUtils.isRFC1939Compatible(uid)) {
+ throw new IllegalArgumentException("UID is not RFC1939 compatible");
+ }
+ }
+
+ /**
* Return the uid of the message
*
* @return uid
*/
- public long getUid() {
+ public String getUid() {
+ return uid;
+ }
+
+ /**
+ * Return the uid of the message. This method uses extra Mailbox ID argument to make
+ * UID unique when it is not globally unique. By default assuming UID globally unique.
+ *
+ * @param mailboxId
+ * Mailbox ID
+ * @return
+ */
+ public String getUid(String mailboxId) {
return uid;
}
@@ -48,4 +66,5 @@ public final class MessageMetaData {
public long getSize() {
return size;
}
+
}
Modified: james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/utils/MockMailbox.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/utils/MockMailbox.java?rev=1413195&r1=1413194&r2=1413195&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/utils/MockMailbox.java (original)
+++ james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/utils/MockMailbox.java Sat Nov 24 14:48:13 2012
@@ -28,10 +28,11 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
-import org.apache.james.protocols.pop3.mailbox.Mailbox;
+import org.apache.james.protocols.pop3.mailbox.ImapMailbox;
+import org.apache.james.protocols.pop3.mailbox.ImapMessageMetaData;
import org.apache.james.protocols.pop3.mailbox.MessageMetaData;
-public class MockMailbox implements Mailbox {
+public class MockMailbox extends ImapMailbox {
private final Map<Long, Message> messages = new HashMap<Long, Message>();
private final String identifier;
@@ -39,13 +40,14 @@ public class MockMailbox implements Mail
public MockMailbox(String identifier, Message... messages) {
this.identifier = identifier;
for (Message m: messages) {
- this.messages.put(m.meta.getUid(), m);
+ this.messages.put(Long.parseLong(m.meta.getUid()), m);
}
}
public MockMailbox(String identifier) {
this(identifier, new Message[0]);
}
+
public InputStream getMessageBody(long uid) throws IOException {
Message m = messages.get(uid);
if (m == null) {
@@ -102,7 +104,7 @@ public class MockMailbox implements Mail
public Message(String headers, String body) {
this.headers = headers;
this.body = body;
- this.meta = new MessageMetaData(UIDS.incrementAndGet(), headers.length() + body.length() + 2);
+ this.meta = new ImapMessageMetaData(UIDS.incrementAndGet(), headers.length() + body.length() + 2);
}
public String toString() {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org