james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1147690 - in /james/mailbox/trunk: api/src/main/java/org/apache/james/mailbox/ReadOnlyException.java store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
Date Sun, 17 Jul 2011 18:13:03 GMT
Author: norman
Date: Sun Jul 17 18:13:02 2011
New Revision: 1147690

URL: http://svn.apache.org/viewvc?rev=1147690&view=rev
Log:
Throw exception when try to modify a READ-ONLY mailbox. See MAILBOX-106

Added:
    james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/ReadOnlyException.java
Modified:
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java

Added: james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/ReadOnlyException.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/ReadOnlyException.java?rev=1147690&view=auto
==============================================================================
--- james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/ReadOnlyException.java
(added)
+++ james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/ReadOnlyException.java
Sun Jul 17 18:13:02 2011
@@ -0,0 +1,46 @@
+/****************************************************************
+ * 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.mailbox;
+
+/**
+ * {@link MailboxException} which should get thrown if someone tries to modify a READ-ONLY
Mailbox
+ * 
+ *
+ */
+public class ReadOnlyException extends MailboxException{
+
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 5016914557908202113L;
+
+
+
+    public ReadOnlyException(MailboxPath path, char delimiter) {
+        super(path.getFullName(delimiter));
+    }
+
+
+    public ReadOnlyException(MailboxPath path, char delimiter, Exception e) {
+        super(path.getFullName(delimiter), e);
+    }
+}
+

Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java?rev=1147690&r1=1147689&r2=1147690&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
(original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
Sun Jul 17 18:13:02 2011
@@ -46,6 +46,7 @@ import org.apache.james.mailbox.MessageM
 import org.apache.james.mailbox.MessageMetaData;
 import org.apache.james.mailbox.MessageRange;
 import org.apache.james.mailbox.MessageResult;
+import org.apache.james.mailbox.ReadOnlyException;
 import org.apache.james.mailbox.SearchQuery;
 import org.apache.james.mailbox.UpdatedFlags;
 import org.apache.james.mailbox.MessageResult.FetchGroup;
@@ -170,6 +171,9 @@ public class StoreMessageManager<Id> imp
      * @see org.apache.james.mailbox.Mailbox#expunge(org.apache.james.mailbox.MessageRange,
org.apache.james.mailbox.MailboxSession)
      */
     public Iterator<Long> expunge(final MessageRange set, MailboxSession mailboxSession)
throws MailboxException {
+        if (!isWriteable(mailboxSession)) {
+            throw new ReadOnlyException(new StoreMailboxPath<Id>(getMailboxEntity()),mailboxSession.getPathDelimiter());
+        }
         Map<Long, MessageMetaData> uids = deleteMarkedInMailbox(set, mailboxSession);
      
         dispatcher.expunged(mailboxSession, uids, getMailboxEntity());
@@ -189,6 +193,10 @@ public class StoreMessageManager<Id> imp
         FileOutputStream out = null;
         SharedFileInputStream contentIn = null;
         
+        if (!isWriteable(mailboxSession)) {
+            throw new ReadOnlyException(new StoreMailboxPath<Id>(getMailboxEntity()),mailboxSession.getPathDelimiter());
+        }
+        
         try {
             // Create a temporary file and copy the message to it. We will work with the
file as
             // source for the InputStream
@@ -442,6 +450,9 @@ public class StoreMessageManager<Id> imp
     public Map<Long, Flags> setFlags(final Flags flags, final boolean value, final
boolean replace,
             final MessageRange set, MailboxSession mailboxSession) throws MailboxException
{
        
+        if (!isWriteable(mailboxSession)) {
+            throw new ReadOnlyException(new StoreMailboxPath<Id>(getMailboxEntity()),mailboxSession.getPathDelimiter());
+        }
         final SortedMap<Long, Flags> newFlagsByUid = new TreeMap<Long, Flags>();
 
         trimFlags(flags, mailboxSession);
@@ -479,6 +490,10 @@ public class StoreMessageManager<Id> imp
      * @throws MailboxException
      */
     public List<MessageRange> copyTo(MessageRange set, StoreMessageManager<Id>
toMailbox, MailboxSession session) throws MailboxException {
+        if (!toMailbox.isWriteable(session)) {
+            throw new ReadOnlyException(new StoreMailboxPath<Id>(getMailboxEntity()),session.getPathDelimiter());
+        }
+        
         try {
             Map<Long, MessageMetaData> copiedUids = copy(set, toMailbox, session);
             dispatcher.added(session, copiedUids, toMailbox.getMailboxEntity());
@@ -609,6 +624,11 @@ public class StoreMessageManager<Id> imp
      * @throws MailboxException
      */
     protected List<Long> recent(final boolean reset, MailboxSession mailboxSession)
throws MailboxException {
+        if (reset) {
+            if (!isWriteable(mailboxSession)) {
+                throw new ReadOnlyException(new StoreMailboxPath<Id>(getMailboxEntity()),mailboxSession.getPathDelimiter());
+            }
+        }
         final MessageMapper<Id> messageMapper = mapperFactory.getMessageMapper(mailboxSession);
         
         return messageMapper.execute(new Mapper.Transaction<List<Long>>() {
@@ -616,7 +636,7 @@ public class StoreMessageManager<Id> imp
             public List<Long> run() throws MailboxException {
                 final List<Long> members = messageMapper.findRecentMessageUidsInMailbox(getMailboxEntity());
 
-                // Conver to MessageRanges so we may be able to optimize the flag update
+                // Convert to MessageRanges so we may be able to optimize the flag update
                 List<MessageRange> ranges = MessageRange.toRanges(members);
                 for (MessageRange range:ranges) {
                     if (reset) {
@@ -633,6 +653,7 @@ public class StoreMessageManager<Id> imp
 
     
     protected Map<Long, MessageMetaData> deleteMarkedInMailbox(final MessageRange range,
final MailboxSession session) throws MailboxException {
+
         final MessageMapper<Id> messageMapper = mapperFactory.getMessageMapper(session);
 
         return messageMapper.execute(new Mapper.Transaction<Map<Long, MessageMetaData>>()
{



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message