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 bt...@apache.org on 2015/09/22 12:39:34 UTC
svn commit: r1704564 - in /james/protocols/trunk/imap/src:
main/java/org/apache/james/imap/decode/parser/
test/java/org/apache/james/imap/decode/parser/
Author: btellier
Date: Tue Sep 22 10:39:31 2015
New Revision: 1704564
URL: http://svn.apache.org/viewvc?rev=1704564&view=rev
Log:
PROTOCOLS-108 Adding parser for Quota commands
Added:
james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/GetQuotaCommandParser.java
james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/GetQuotaRootCommandParser.java
james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/SetQuotaCommandParser.java
james/protocols/trunk/imap/src/test/java/org/apache/james/imap/decode/parser/GetQuotaParserTest.java
james/protocols/trunk/imap/src/test/java/org/apache/james/imap/decode/parser/GetQuotaRootParserTest.java
james/protocols/trunk/imap/src/test/java/org/apache/james/imap/decode/parser/SetQuotaCommandParserTest.java
Modified:
james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/ImapParserFactory.java
Added: james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/GetQuotaCommandParser.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/GetQuotaCommandParser.java?rev=1704564&view=auto
==============================================================================
--- james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/GetQuotaCommandParser.java (added)
+++ james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/GetQuotaCommandParser.java Tue Sep 22 10:39:31 2015
@@ -0,0 +1,45 @@
+/****************************************************************
+ * 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.imap.decode.parser;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapConstants;
+import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.decode.ImapRequestLineReader;
+import org.apache.james.imap.decode.base.AbstractImapCommandParser;
+import org.apache.james.imap.message.request.GetQuotaRequest;
+import org.apache.james.protocols.imap.DecodingException;
+
+/**
+ * GETQUOTA command parser
+ */
+public class GetQuotaCommandParser extends AbstractImapCommandParser {
+ public GetQuotaCommandParser() {
+ super(ImapCommand.authenticatedStateCommand(ImapConstants.GETQUOTA_COMMAND_NAME));
+ }
+
+ @Override
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, ImapSession session) throws DecodingException {
+ final String quotaRoot = request.atom();
+ request.eol();
+ return new GetQuotaRequest(tag, command, quotaRoot);
+ }
+}
Added: james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/GetQuotaRootCommandParser.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/GetQuotaRootCommandParser.java?rev=1704564&view=auto
==============================================================================
--- james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/GetQuotaRootCommandParser.java (added)
+++ james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/GetQuotaRootCommandParser.java Tue Sep 22 10:39:31 2015
@@ -0,0 +1,47 @@
+/****************************************************************
+ * 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.imap.decode.parser;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapConstants;
+import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.decode.ImapRequestLineReader;
+import org.apache.james.imap.decode.base.AbstractImapCommandParser;
+import org.apache.james.imap.message.request.GetQuotaRootRequest;
+import org.apache.james.protocols.imap.DecodingException;
+
+/**
+ * Get Quota root command parser
+ */
+public class GetQuotaRootCommandParser extends AbstractImapCommandParser {
+
+ public GetQuotaRootCommandParser() {
+ super(ImapCommand.authenticatedStateCommand(ImapConstants.GETQUOTAROOT_COMMAND_NAME));
+ }
+
+ @Override
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, ImapSession session) throws DecodingException {
+ final String mailboxName = request.mailbox();
+ request.eol();
+ return new GetQuotaRootRequest(tag, command, mailboxName);
+ }
+
+}
Modified: james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/ImapParserFactory.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/ImapParserFactory.java?rev=1704564&r1=1704563&r2=1704564&view=diff
==============================================================================
--- james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/ImapParserFactory.java (original)
+++ james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/ImapParserFactory.java Tue Sep 22 10:39:31 2015
@@ -28,6 +28,7 @@ import org.apache.james.imap.decode.Dele
import org.apache.james.imap.decode.ImapCommandParser;
import org.apache.james.imap.decode.ImapCommandParserFactory;
import org.apache.james.imap.decode.MessagingImapCommandParser;
+import org.apache.james.imap.processor.GetQuotaRootProcessor;
/**
* A factory for ImapCommand instances, provided based on the command name.
@@ -101,6 +102,11 @@ public class ImapParserFactory implement
_imapCommands.put(ImapConstants.ENABLE_COMMAND_NAME, EnableCommandParser.class);
+ // RFC2087
+ // GETQUOTAROOT, GETQUOTA, SETQUOTA
+ _imapCommands.put(ImapConstants.GETQUOTAROOT_COMMAND_NAME, GetQuotaRootCommandParser.class);
+ _imapCommands.put(ImapConstants.GETQUOTA_COMMAND_NAME, GetQuotaCommandParser.class);
+ _imapCommands.put(ImapConstants.SETQUOTA_COMMAND_NAME, SetQuotaCommandParser.class);
}
Added: james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/SetQuotaCommandParser.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/SetQuotaCommandParser.java?rev=1704564&view=auto
==============================================================================
--- james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/SetQuotaCommandParser.java (added)
+++ james/protocols/trunk/imap/src/main/java/org/apache/james/imap/decode/parser/SetQuotaCommandParser.java Tue Sep 22 10:39:31 2015
@@ -0,0 +1,65 @@
+/****************************************************************
+ * 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.imap.decode.parser;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapConstants;
+import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.decode.ImapRequestLineReader;
+import org.apache.james.imap.decode.base.AbstractImapCommandParser;
+import org.apache.james.imap.message.request.SetQuotaRequest;
+import org.apache.james.protocols.imap.DecodingException;
+
+/**
+ * SETQUOTA command parser
+ */
+public class SetQuotaCommandParser extends AbstractImapCommandParser {
+
+ public SetQuotaCommandParser() {
+ super(ImapCommand.authenticatedStateCommand(ImapConstants.SETQUOTA_COMMAND_NAME));
+ }
+
+ @Override
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, ImapSession session) throws DecodingException {
+ final String quotaRoot = request.atom();
+ SetQuotaRequest setQuotaRequest = new SetQuotaRequest(tag, command, quotaRoot);
+ // We now parse resource limit declaration
+ // It has the following shape : (RESOURCE1 1024000) (RESOURCE2 2048000)\n
+ request.nextWordChar();
+ while ( request.nextChar() == '(') {
+ request.consume();
+ String resource = request.atom();
+ request.nextWordChar();
+ long limit = request.number(true);
+ request.nextWordChar();
+ request.consumeChar(')');
+ setQuotaRequest.addResourceLimit(resource, limit);
+ // Consume white spaces
+ // Do not use nextWorldChar as it throws an exception on end of lines
+ while(request.nextChar() == ' ') {
+ request.consume();
+ }
+ }
+ request.eol();
+ return setQuotaRequest;
+ }
+
+}
Added: james/protocols/trunk/imap/src/test/java/org/apache/james/imap/decode/parser/GetQuotaParserTest.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/imap/src/test/java/org/apache/james/imap/decode/parser/GetQuotaParserTest.java?rev=1704564&view=auto
==============================================================================
--- james/protocols/trunk/imap/src/test/java/org/apache/james/imap/decode/parser/GetQuotaParserTest.java (added)
+++ james/protocols/trunk/imap/src/test/java/org/apache/james/imap/decode/parser/GetQuotaParserTest.java Tue Sep 22 10:39:31 2015
@@ -0,0 +1,49 @@
+/****************************************************************
+ * 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.imap.decode.parser;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
+import org.apache.james.imap.message.request.GetQuotaRequest;
+import org.apache.james.protocols.imap.DecodingException;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * GetQuotaRootParser Test
+ */
+public class GetQuotaParserTest {
+
+ @Test
+ public void testQuotaParsing() throws DecodingException {
+ GetQuotaCommandParser parser = new GetQuotaCommandParser();
+ ImapCommand command = ImapCommand.anyStateCommand("Command");
+ String commandString = "quotaRoot \n";
+ InputStream inputStream = new ByteArrayInputStream(commandString.getBytes());
+ ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, null);
+ GetQuotaRequest request = (GetQuotaRequest) parser.decode(command, lineReader, "A003", null);
+ GetQuotaRequest expected = new GetQuotaRequest("A003", command, "quotaRoot");
+ assertEquals(expected.getQuotaRoot(), request.getQuotaRoot());
+ }
+}
Added: james/protocols/trunk/imap/src/test/java/org/apache/james/imap/decode/parser/GetQuotaRootParserTest.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/imap/src/test/java/org/apache/james/imap/decode/parser/GetQuotaRootParserTest.java?rev=1704564&view=auto
==============================================================================
--- james/protocols/trunk/imap/src/test/java/org/apache/james/imap/decode/parser/GetQuotaRootParserTest.java (added)
+++ james/protocols/trunk/imap/src/test/java/org/apache/james/imap/decode/parser/GetQuotaRootParserTest.java Tue Sep 22 10:39:31 2015
@@ -0,0 +1,62 @@
+/****************************************************************
+ * 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.imap.decode.parser;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
+import org.apache.james.imap.message.request.GetQuotaRootRequest;
+import org.apache.james.protocols.imap.DecodingException;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for GetQuotaRootCommandParser
+ */
+public class GetQuotaRootParserTest {
+
+ @Test
+ public void testNonQuotedMailbox() throws DecodingException {
+ GetQuotaRootCommandParser parser = new GetQuotaRootCommandParser();
+ ImapCommand command = ImapCommand.anyStateCommand("Command");
+ String commandString = "INBOX\n";
+ InputStream inputStream = new ByteArrayInputStream(commandString.getBytes());
+ ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, null);
+ GetQuotaRootRequest request = (GetQuotaRootRequest) parser.decode(command, lineReader, "A003", null);
+ GetQuotaRootRequest expected = new GetQuotaRootRequest("A003", command, "INBOX");
+ assertEquals(expected.getMailboxName(), request.getMailboxName());
+ }
+
+ @Test
+ public void testQuotedMailbox() throws DecodingException {
+ GetQuotaRootCommandParser parser = new GetQuotaRootCommandParser();
+ ImapCommand command = ImapCommand.anyStateCommand("Command");
+ String commandString = "\"INBOX\" \n";
+ InputStream inputStream = new ByteArrayInputStream(commandString.getBytes());
+ ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, null);
+ GetQuotaRootRequest request = (GetQuotaRootRequest) parser.decode(command, lineReader, "A003", null);
+ GetQuotaRootRequest expected = new GetQuotaRootRequest("A003", command, "INBOX");
+ assertEquals(expected.getMailboxName(), request.getMailboxName());
+ }
+
+}
Added: james/protocols/trunk/imap/src/test/java/org/apache/james/imap/decode/parser/SetQuotaCommandParserTest.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/imap/src/test/java/org/apache/james/imap/decode/parser/SetQuotaCommandParserTest.java?rev=1704564&view=auto
==============================================================================
--- james/protocols/trunk/imap/src/test/java/org/apache/james/imap/decode/parser/SetQuotaCommandParserTest.java (added)
+++ james/protocols/trunk/imap/src/test/java/org/apache/james/imap/decode/parser/SetQuotaCommandParserTest.java Tue Sep 22 10:39:31 2015
@@ -0,0 +1,56 @@
+/****************************************************************
+ * 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.imap.decode.parser;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
+import org.apache.james.imap.message.request.SetQuotaRequest;
+import org.apache.james.protocols.imap.DecodingException;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * SETQUOTA command parser test...
+ */
+public class SetQuotaCommandParserTest {
+
+ @Test
+ public void testQuotaParsing() throws DecodingException {
+ SetQuotaCommandParser parser = new SetQuotaCommandParser();
+ ImapCommand command = ImapCommand.anyStateCommand("Command");
+ String commandString = "quotaRoot (STORAGE 512) ( MESSAGE 1024 ) \n";
+ InputStream inputStream = new ByteArrayInputStream(commandString.getBytes());
+ ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, null);
+ SetQuotaRequest request = (SetQuotaRequest) parser.decode(command, lineReader, "A003", null);
+ assertEquals("quotaRoot", request.getQuotaRoot());
+ List<SetQuotaRequest.ResourceLimit> list = request.getResourceLimits();
+ assertEquals("STORAGE", list.get(0).getResource());
+ assertEquals(512, list.get(0).getLimit());
+ assertEquals("MESSAGE", list.get(1).getResource());
+ assertEquals(1024, list.get(1).getLimit());
+ assertEquals(2, list.size());
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org