Index: store/src/main/java/org/apache/james/imap/store/mail/MailboxMapper.java
===================================================================
--- store/src/main/java/org/apache/james/imap/store/mail/MailboxMapper.java	(Revision 952201)
+++ store/src/main/java/org/apache/james/imap/store/mail/MailboxMapper.java	(Arbeitskopie)
@@ -39,60 +39,51 @@
      * @throws StorageException
      */
     public abstract void save(Mailbox<Id> mailbox) throws StorageException;
-
+    
     /**
-     * Return the {@link Mailbox} for the given name
+     * Delete the given {@link Mailbox} from the underlying storage
      * 
-     * @param name 
-     * @return mailbox
+     * @param mailbox
      * @throws StorageException
-     * @throws MailboxNotFoundException
      */
-    public abstract Mailbox<Id> findMailboxByName(String name)
-            throws StorageException, MailboxNotFoundException;
+    public abstract void delete(Mailbox<Id> mailbox) throws StorageException;
 
     /**
-     * Return if the given {@link Mailbox} has children
+     * Delete all {@link Mailbox} objects from the underlying storage
      * 
-     * @param mailboxName not null
-     * @return true when the mailbox has children, false otherwise
      * @throws StorageException
      */
-    public abstract boolean existsMailboxStartingWith(String mailboxName) throws StorageException;
-    
-    /**
-     * Delete the given {@link Mailbox} from the underlying storage
-     * 
-     * @param mailbox
-     * @throws StorageException
-     */
-    public abstract void delete(Mailbox<Id> mailbox) throws StorageException;
+    public abstract void deleteAll() throws StorageException;
 
     /**
-     * Return a List of {@link Mailbox} which name is like the given name
+     * Return the count of {@link Mailbox} objects with the given name
      * 
      * @param name
-     * @return mailboxList
+     * @return count
      * @throws StorageException
      */
-    public abstract List<Mailbox<Id>> findMailboxWithNameLike(String name)
+    public abstract long countMailboxesWithName(String name)
             throws StorageException;
 
     /**
-     * Delete all {@link Mailbox} objects from the underlying storage
+     * Return the {@link Mailbox} for the given name
      * 
+     * @param name 
+     * @return mailbox
      * @throws StorageException
+     * @throws MailboxNotFoundException
      */
-    public abstract void deleteAll() throws StorageException;
+    public abstract Mailbox<Id> findMailboxByName(String mailboxName)
+            throws StorageException, MailboxNotFoundException;
 
     /**
-     * Return the count of {@link Mailbox} objects with the given name
+     * Return a List of {@link Mailbox} which name is like the given name
      * 
      * @param name
-     * @return count
+     * @return mailboxList
      * @throws StorageException
      */
-    public abstract long countMailboxesWithName(String name)
+    public abstract List<Mailbox<Id>> findMailboxWithNameLike(String mailboxName)
             throws StorageException;
 
     /**
@@ -105,4 +96,15 @@
      */
     public abstract Mailbox<Id> findMailboxById(Id mailboxId)
             throws StorageException, MailboxNotFoundException;
+
+    /**
+     * Return if the given {@link Mailbox} has children
+     * 
+     * @param mailbox not null
+     * @return true when the mailbox has children, false otherwise
+     * @throws StorageException
+     * @throws MailboxNotFoundException
+     */
+    public abstract boolean hasChildren(Mailbox<Id> mailbox)
+            throws StorageException, MailboxNotFoundException;
 }
\ No newline at end of file
Index: store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
===================================================================
--- store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java	(Revision 952201)
+++ store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java	(Arbeitskopie)
@@ -40,7 +40,6 @@
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.MessageRange;
 import org.apache.james.imap.mailbox.StandardMailboxMetaDataComparator;
-import org.apache.james.imap.mailbox.StorageException;
 import org.apache.james.imap.mailbox.SubscriptionException;
 import org.apache.james.imap.mailbox.MailboxMetaData.Selectability;
 import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
@@ -316,7 +315,7 @@
                 final String match = name.substring(baseLength);
                 if (mailboxExpression.isExpressionMatch(match, delimiter)) {
                     final MailboxMetaData.Children inferiors; 
-                    if (hasChildren(name, mapper)) {
+                    if (mapper.hasChildren(mailbox)) {
                         inferiors = MailboxMetaData.Children.HAS_CHILDREN;
                     } else {
                         inferiors = MailboxMetaData.Children.HAS_NO_CHILDREN;
@@ -330,17 +329,6 @@
 
     }
 
-    /**
-     * Does the mailbox with the given name have inferior child mailboxes?
-     * @param name not null
-     * @return true when the mailbox has children, false otherwise
-     * @throws StorageException 
-     * @throws TorqueException
-     */
-    private boolean hasChildren(String name, final MailboxMapper<Id> mapper) throws StorageException {
-        return mapper.existsMailboxStartingWith(name + delimiter);
-    }
-
     /*
      * (non-Javadoc)
      * @see org.apache.james.imap.mailbox.MailboxManager#mailboxExists(java.lang.String, org.apache.james.imap.mailbox.MailboxSession)
Index: memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMailboxMapper.java
===================================================================
--- memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMailboxMapper.java	(Revision 952201)
+++ memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMailboxMapper.java	(Arbeitskopie)
@@ -34,6 +34,7 @@
     
     private static final int INITIAL_SIZE = 128;
     private Map<Long, InMemoryMailbox> mailboxesById;
+    private static final char DELIMITER = '.';
 
     public InMemoryMailboxMapper() {
         mailboxesById = new ConcurrentHashMap<Long, InMemoryMailbox>(INITIAL_SIZE);
@@ -110,21 +111,6 @@
 
     /*
      * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MailboxMapper#existsMailboxStartingWith(java.lang.String)
-     */
-    public boolean existsMailboxStartingWith(String mailboxName) throws StorageException {
-        boolean result = false;
-        for (final InMemoryMailbox mailbox:mailboxesById.values()) {
-            if (mailbox.getName().startsWith(mailboxName)) {
-                result = true;
-                break;
-            }
-        }
-        return result;
-    }
-
-    /*
-     * (non-Javadoc)
      * @see org.apache.james.imap.store.mail.MailboxMapper#save(org.apache.james.imap.store.mail.model.Mailbox)
      */
     public void save(Mailbox<Long> mailbox) throws StorageException {
@@ -143,5 +129,20 @@
         // TODO Auto-generated method stub
         
     }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MailboxMapper#hasChildren(org.apache.james.imap.store.mail.model.Mailbox)
+     */
+    public boolean hasChildren(Mailbox<Long> mailbox) throws StorageException,
+            MailboxNotFoundException {
+        String mailboxName = mailbox.getName() + DELIMITER;
+        for (final InMemoryMailbox box:mailboxesById.values()) {
+            if (box.getName().startsWith(mailboxName)) {
+                return true;
+            }
+        }
+        return false;
+    }
     
 }
Index: jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMailboxMapper.java
===================================================================
--- jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMailboxMapper.java	(Revision 952201)
+++ jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMailboxMapper.java	(Arbeitskopie)
@@ -39,22 +39,13 @@
 public class JPAMailboxMapper extends JPATransactionalMapper implements MailboxMapper<Long> {
 
     private static final char SQL_WILDCARD_CHAR = '%';
+    private static final char DELIMITER = '.';
     
     public JPAMailboxMapper(EntityManagerFactory entityManagerFactory) {
         super(entityManagerFactory);
     }
 
     /**
-     * @see org.apache.james.imap.store.mail.MailboxMapper#hasChildren
-     */
-    public boolean existsMailboxStartingWith(String mailboxName) throws StorageException {
-        
-        final String name = mailboxName + SQL_WILDCARD_CHAR; 
-        final Long numberOfChildMailboxes = (Long) getEntityManager().createNamedQuery("countMailboxesWithNameLike").setParameter("nameParam", name).getSingleResult();
-        return numberOfChildMailboxes != null && numberOfChildMailboxes > 0;
-    }
-
-    /**
      * @see org.apache.james.imap.store.mail.MailboxMapper#save(Mailbox)
      */
     public void save(Mailbox<Long> mailbox) throws StorageException {
@@ -136,4 +127,14 @@
             throw new StorageException(HumanReadableText.SEARCH_FAILED, e);
         } 
     }
+
+    /**
+     * @see org.apache.james.imap.store.mail.MailboxMapper#hasChildren(java.lang.String)
+     */
+    public boolean hasChildren(Mailbox<Long> mailbox) throws StorageException,
+            MailboxNotFoundException {
+        final String name = mailbox.getName() + DELIMITER + SQL_WILDCARD_CHAR; 
+        final Long numberOfChildMailboxes = (Long) getEntityManager().createNamedQuery("countMailboxesWithNameLike").setParameter("nameParam", name).getSingleResult();
+        return numberOfChildMailboxes != null && numberOfChildMailboxes > 0;
+    }
 }
Index: jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
===================================================================
--- jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java	(Revision 952201)
+++ jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java	(Arbeitskopie)
@@ -127,31 +127,7 @@
     }
 
     /*
-     * 
      * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.james.imap.store.mail.MailboxMapper#existsMailboxStartingWith
-     * (java.lang.String)
-     */
-    public boolean existsMailboxStartingWith(String mailboxName) throws StorageException {
-        try {
-            QueryManager manager = getSession().getWorkspace()
-                    .getQueryManager();
-            String queryString = "//" + MAILBOXES_PATH
-                    + "//element(*,jamesMailbox:mailbox)[jcr:like(@"
-                    + JCRMailbox.NAME_PROPERTY + ",'" + mailboxName + "%')]";
-            QueryResult result = manager.createQuery(queryString, Query.XPATH)
-                    .execute();
-            NodeIterator it = result.getNodes();
-            return it.hasNext();
-        } catch (RepositoryException e) {
-            throw new StorageException(HumanReadableText.SEARCH_FAILED, e);
-        }
-    }
-
-    /*
-     * (non-Javadoc)
      * @see org.apache.james.imap.store.mail.MailboxMapper#findMailboxById(java.lang.Object)
      */
     public Mailbox<String> findMailboxById(String mailboxId) throws StorageException, MailboxNotFoundException {
@@ -283,5 +259,28 @@
             throw new StorageException(HumanReadableText.SAVE_FAILED, e);
         }
     }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.james.imap.store.mail.MailboxMapper#hasChildren(org.apache.james.
+     * imap.store.mail.model.Mailbox)
+     */
+    public boolean hasChildren(Mailbox<String> mailbox)
+            throws StorageException, MailboxNotFoundException {
+        try {
+            QueryManager manager = getSession().getWorkspace()
+                    .getQueryManager();
+            String queryString = "//" + MAILBOXES_PATH
+                    + "//element(*,jamesMailbox:mailbox)[jcr:like(@"
+                    + JCRMailbox.NAME_PROPERTY + ",'" + mailbox.getName() + "%')]";
+            QueryResult result = manager.createQuery(queryString, Query.XPATH)
+                    .execute();
+            NodeIterator it = result.getNodes();
+            return it.hasNext();
+        } catch (RepositoryException e) {
+            throw new StorageException(HumanReadableText.SEARCH_FAILED, e);
+        }
+    }
  
 }
