Author: rdonkin
Date: Sun Jan 4 10:33:53 2009
New Revision: 731314
URL: http://svn.apache.org/viewvc?rev=731314&view=rev
Log:
Ensure that selected sub mailboxes retain their identity during a rename.
Added:
james/protocols/imap/trunk/seda/src/test/resources/org/apache/james/imap/scripts/ConcurrentRenameSelectedSub.test
Modified:
james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/ConcurrentSessionsTest.java
james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/torque/ConcurrentSessionsTest.java
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
james/protocols/imap/trunk/seda/src/test/java/org/apache/james/imap/functional/suite/ConcurrentSessions.java
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
Modified:
james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/ConcurrentSessionsTest.java
URL:
http://svn.apache.org/viewvc/james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/ConcurrentSessionsTest.java?rev=731314&r1=731313&r2=731314&view=diff
==============================================================================
---
james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/ConcurrentSessionsTest.java
(original)
+++
james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/ConcurrentSessionsTest.java
Sun Jan 4 10:33:53 2009
@@ -27,4 +27,5 @@
public ConcurrentSessionsTest() throws Exception {
super(JPAHostSystem.build());
}
+
}
Modified:
james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/torque/ConcurrentSessionsTest.java
URL:
http://svn.apache.org/viewvc/james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/torque/ConcurrentSessionsTest.java?rev=731314&r1=731313&r2=731314&view=diff
==============================================================================
---
james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/torque/ConcurrentSessionsTest.java
(original)
+++
james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/torque/ConcurrentSessionsTest.java
Sun Jan 4 10:33:53 2009
@@ -22,11 +22,9 @@
import org.apache.james.imap.functional.suite.ConcurrentSessions;
import org.apache.james.mailboxmanager.torque.TorqueHostSystemFactory;
-public class ConcurrentSessionsTest extends
- ConcurrentSessions {
+public class ConcurrentSessionsTest extends ConcurrentSessions {
public ConcurrentSessionsTest() throws Exception {
super(TorqueHostSystemFactory.createStandardImap());
- }
-
+ }
}
Modified:
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
URL:
http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java?rev=731314&r1=731313&r2=731314&view=diff
==============================================================================
---
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
(original)
+++
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
Sun Jan 4 10:33:53 2009
@@ -31,6 +31,7 @@
import javax.persistence.NoResultException;
import javax.persistence.PersistenceException;
+import org.apache.commons.logging.Log;
import org.apache.james.api.imap.AbstractLogEnabled;
import org.apache.james.imap.jpa.mail.MailboxMapper;
import org.apache.james.imap.jpa.mail.map.openjpa.OpenJPAMailboxMapper;
@@ -178,7 +179,8 @@
public void renameMailbox(String from, String to)
throws MailboxException {
- getLog().debug("renameMailbox " + from + " to " + to);
+ final Log log = getLog();
+ if (log.isDebugEnabled()) log.debug("renameMailbox " + from + " to " +
to);
try {
synchronized (mailboxes) {
if (mailboxExists(to)) {
@@ -196,22 +198,19 @@
mailbox.setName(to);
mapper.save(mailbox);
- final JPAMailbox jpaMailbox = mailboxes.remove(from);
- if (jpaMailbox != null) {
- jpaMailbox.reportRenamed(to);
- mailboxes.put(to, jpaMailbox);
- }
+ changeMailboxName(from, to);
// rename submailbox
final List<Mailbox> subMailboxes =
mapper.findMailboxWithNameLike(from + HIERARCHY_DELIMITER + "%");
for (Mailbox sub:subMailboxes) {
- String subOrigName = sub.getName();
- String subNewName = to
- + subOrigName.substring(from.length());
- sub.setName(to + sub.getName().substring(from.length()));
+ final String subOriginalName = sub.getName();
+ final String subNewName = to +
subOriginalName.substring(from.length());
+ sub.setName(subNewName);
mapper.save(sub);
- getLog().info(
- "renameMailbox sub-mailbox " + subOrigName + " to "
+
+ changeMailboxName(subOriginalName, subNewName);
+
+ if (log.isDebugEnabled()) log.debug("Rename mailbox
sub-mailbox " + subOriginalName + " to "
+ subNewName);
}
mapper.commit();
@@ -223,7 +222,18 @@
}
}
-
+ /**
+ * Changes the name of the mailbox instance in the cache.
+ * @param from not null
+ * @param to not null
+ */
+ private void changeMailboxName(String from, String to) {
+ final JPAMailbox jpaMailbox = mailboxes.remove(from);
+ if (jpaMailbox != null) {
+ jpaMailbox.reportRenamed(to);
+ mailboxes.put(to, jpaMailbox);
+ }
+ }
public void copyMessages(MessageRange set, String from, String to,
MailboxSession session) throws MailboxException {
Modified:
james/protocols/imap/trunk/seda/src/test/java/org/apache/james/imap/functional/suite/ConcurrentSessions.java
URL:
http://svn.apache.org/viewvc/james/protocols/imap/trunk/seda/src/test/java/org/apache/james/imap/functional/suite/ConcurrentSessions.java?rev=731314&r1=731313&r2=731314&view=diff
==============================================================================
---
james/protocols/imap/trunk/seda/src/test/java/org/apache/james/imap/functional/suite/ConcurrentSessions.java
(original)
+++
james/protocols/imap/trunk/seda/src/test/java/org/apache/james/imap/functional/suite/ConcurrentSessions.java
Sun Jan 4 10:33:53 2009
@@ -29,6 +29,10 @@
public ConcurrentSessions(HostSystem system) {
super(system);
}
+
+ public void testConcurrentRenameSelectedSubUS() throws Exception {
+ scriptTest("ConcurrentRenameSelectedSub", Locale.US);
+ }
public void testConcurrentExistsResponseUS() throws Exception {
scriptTest("ConcurrentExistsResponse", Locale.US);
@@ -46,6 +50,10 @@
scriptTest("ConcurrentRenameSelected", Locale.US);
}
+ public void testConcurrentRenameSelectedSubKOREA() throws Exception {
+ scriptTest("ConcurrentRenameSelectedSub", Locale.KOREA);
+ }
+
public void testConcurrentExistsResponseKOREA() throws Exception {
scriptTest("ConcurrentExistsResponse", Locale.KOREA);
}
@@ -62,6 +70,10 @@
scriptTest("ConcurrentRenameSelected", Locale.KOREA);
}
+ public void testConcurrentRenameSelectedSubITALY() throws Exception {
+ scriptTest("ConcurrentRenameSelectedSub", Locale.ITALY);
+ }
+
public void testConcurrentExistsResponseITALY() throws Exception {
scriptTest("ConcurrentExistsResponse", Locale.ITALY);
}
Added:
james/protocols/imap/trunk/seda/src/test/resources/org/apache/james/imap/scripts/ConcurrentRenameSelectedSub.test
URL:
http://svn.apache.org/viewvc/james/protocols/imap/trunk/seda/src/test/resources/org/apache/james/imap/scripts/ConcurrentRenameSelectedSub.test?rev=731314&view=auto
==============================================================================
---
james/protocols/imap/trunk/seda/src/test/resources/org/apache/james/imap/scripts/ConcurrentRenameSelectedSub.test
(added)
+++
james/protocols/imap/trunk/seda/src/test/resources/org/apache/james/imap/scripts/ConcurrentRenameSelectedSub.test
Sun Jan 4 10:33:53 2009
@@ -0,0 +1,76 @@
+################################################################
+# 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. #
+################################################################
+#From RFC2180
+#3. Deletion/Renaming of a multi-accessed mailbox
+#3.4. The server MAY allow the RENAME of a multi-accessed mailbox by
+# simply changing the name attribute on the mailbox.
+
+SESSION: 1
+C: 1a CREATE parent
+S: 1a OK CREATE completed.
+C: 1a CREATE parent.child
+S: 1a OK CREATE completed.
+
+C: 1b APPEND parent.child (\Deleted) {254+}
+C: Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)
+C: From: Fred Foobar <[email protected]>
+C: Subject: Test 03
+C: To: [email protected]
+C: Message-Id: <[email protected]>
+C: MIME-Version: 1.0
+C: Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
+C:
+C: Test 03
+C:
+S: 1b OK APPEND completed.
+
+C: 1c SELECT parent.child
+S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
+S: \* 1 EXISTS
+S: \* 1 RECENT
+S: \* OK \[UIDVALIDITY \d+\]
+S: \* OK \[UNSEEN 1\]
+S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)\]
+S: 1c OK \[READ-WRITE\] SELECT completed.
+
+
+# Client #1 has mailbox "parent.child" selected. Client #2 RENAMEs the oarent
mailbox.
+SESSION: 2
+C: 2a RENAME parent renamed
+S: 2a OK RENAME completed.
+
+# Client #1 is still able to do operations that do not reference the mailbox
name.
+SESSION: 1
+C: 1d FETCH 1:* (FLAGS)
+S: \* 1 FETCH \(FLAGS \(\\Recent\)\)
+S: 1d OK FETCH completed.
+
+# Client #1 is not able to do operations that reference the mailbox name.
+C: 1e APPEND parent.child (\Deleted) {254+}
+C: Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)
+C: From: Fred Foobar <[email protected]>
+C: Subject: Test 03
+C: To: [email protected]
+C: Message-Id: <[email protected]>
+C: MIME-Version: 1.0
+C: Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
+C:
+C: Test 03
+C:
+S: 1e NO \[TRYCREATE\] APPEND failed. No such mailbox.
Modified:
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
URL:
http://svn.apache.org/viewvc/james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java?rev=731314&r1=731313&r2=731314&view=diff
==============================================================================
---
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
(original)
+++
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
Sun Jan 4 10:33:53 2009
@@ -196,11 +196,7 @@
mr.setName(to);
mr.save();
- TorqueMailbox torqueMailbox = (TorqueMailbox)
mailboxes.remove(from);
- if (torqueMailbox != null) {
- torqueMailbox.reportRenamed(mr);
- mailboxes.put(to, torqueMailbox);
- }
+ changeMailboxName(from, to, mr);
// rename submailbox
Criteria c = new Criteria();
@@ -211,10 +207,10 @@
for (Iterator iter = l.iterator(); iter.hasNext();) {
MailboxRow sub = (MailboxRow) iter.next();
String subOrigName = sub.getName();
- String subNewName = to
- + subOrigName.substring(from.length());
- sub.setName(to + sub.getName().substring(from.length()));
+ String subNewName = to +
subOrigName.substring(from.length());
+ sub.setName(subNewName);
sub.save();
+ changeMailboxName(subOrigName, subNewName, sub);
getLog().info(
"renameMailbox sub-mailbox " + subOrigName + " to "
+ subNewName);
@@ -225,6 +221,14 @@
}
}
+ private void changeMailboxName(String from, String to, final MailboxRow
mr) {
+ TorqueMailbox torqueMailbox = (TorqueMailbox) mailboxes.remove(from);
+ if (torqueMailbox != null) {
+ torqueMailbox.reportRenamed(mr);
+ mailboxes.put(to, torqueMailbox);
+ }
+ }
+
public void copyMessages(MessageRange set, String from, String to,
MailboxSession session) throws MailboxException {
TorqueMailbox toMailbox = doGetMailbox(to);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]