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 sb...@apache.org on 2012/01/26 15:45:43 UTC
svn commit: r1236201 [2/5] - in /james/mangesieve: ./ api/ api/src/
api/src/main/ api/src/main/java/ api/src/main/java/org/
api/src/main/java/org/apache/ api/src/main/java/org/apache/james/
api/src/main/java/org/apache/james/managesieve/ api/src/main/j...
Added: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/LineCommands.java
URL: http://svn.apache.org/viewvc/james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/LineCommands.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/LineCommands.java (added)
+++ james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/LineCommands.java Thu Jan 26 14:45:39 2012
@@ -0,0 +1,32 @@
+/*
+ * 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.managesieve.api.commands;
+
+/**
+ * <code>LineCommands</code>
+ *
+ * <p>Commands specific to the line oriented protocol defined by RFC 5804
+ *
+ * @see <a href=http://tools.ietf.org/html/rfc5804#section-1.8>RFC 5804 Transport</a>
+ */
+public interface LineCommands extends Authenticate, Unauthenticate, Logout, Noop {
+
+}
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/LineCommands.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/LineCommands.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/ListScripts.java
URL: http://svn.apache.org/viewvc/james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/ListScripts.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/ListScripts.java (added)
+++ james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/ListScripts.java Thu Jan 26 14:45:39 2012
@@ -0,0 +1,37 @@
+/*
+ * 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.managesieve.api.commands;
+
+import java.util.List;
+
+import org.apache.james.managesieve.api.AuthenticationRequiredException;
+import org.apache.james.managesieve.api.ScriptSummary;
+
+/**
+ * <code>ListScripts</code>
+ *
+ * @see <a href=http://tools.ietf.org/html/rfc5804#section-2.7>RFC 5804 LISTSCRIPTS Command</a>
+ */
+public interface ListScripts {
+
+ abstract public List<ScriptSummary> listScripts() throws AuthenticationRequiredException;
+
+}
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/ListScripts.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/ListScripts.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Logout.java
URL: http://svn.apache.org/viewvc/james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Logout.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Logout.java (added)
+++ james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Logout.java Thu Jan 26 14:45:39 2012
@@ -0,0 +1,33 @@
+/*
+ * 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.managesieve.api.commands;
+
+
+/**
+ * <code>Logout</code>
+ *
+ * @see <a href=http://tools.ietf.org/html/rfc5804#section-2.3>RFC 5804 LOGOUT Command</a>
+ */
+public interface Logout {
+
+ abstract public void logout();
+
+}
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Logout.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Logout.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Noop.java
URL: http://svn.apache.org/viewvc/james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Noop.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Noop.java (added)
+++ james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Noop.java Thu Jan 26 14:45:39 2012
@@ -0,0 +1,35 @@
+/*
+ * 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.managesieve.api.commands;
+
+
+/**
+ * <code>Noop</code>
+ *
+ * @see <a href=http://tools.ietf.org/html/rfc5804#section-2.13>RFC 5804 NOOP Command</a>
+ */
+public interface Noop {
+
+ abstract public void noop();
+
+ abstract public String noop(String tag);
+
+}
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Noop.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Noop.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/PutScript.java
URL: http://svn.apache.org/viewvc/james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/PutScript.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/PutScript.java (added)
+++ james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/PutScript.java Thu Jan 26 14:45:39 2012
@@ -0,0 +1,38 @@
+/*
+ * 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.managesieve.api.commands;
+
+import java.util.List;
+
+import org.apache.james.managesieve.api.AuthenticationRequiredException;
+import org.apache.james.managesieve.api.QuotaExceededException;
+import org.apache.james.managesieve.api.SyntaxException;
+
+/**
+ * <code>PutScript</code>
+ *
+ * @see <a href=http://tools.ietf.org/html/rfc5804#section-2.6>RFC 5804 PUTSCRIPT Command</a>
+ */
+public interface PutScript {
+
+ abstract public List<String> putScript(String name, String content) throws AuthenticationRequiredException, SyntaxException, QuotaExceededException;
+
+}
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/PutScript.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/PutScript.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/RenameScript.java
URL: http://svn.apache.org/viewvc/james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/RenameScript.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/RenameScript.java (added)
+++ james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/RenameScript.java Thu Jan 26 14:45:39 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.managesieve.api.commands;
+
+import org.apache.james.managesieve.api.AuthenticationRequiredException;
+import org.apache.james.managesieve.api.DuplicateException;
+import org.apache.james.managesieve.api.ScriptNotFoundException;
+
+/**
+ * <code>RenameScript</code>
+ *
+ * @see <a href=http://tools.ietf.org/html/rfc5804#section-2.11>RFC 5804 RENAMESCRIPT Command</a>
+ */
+public interface RenameScript {
+
+ abstract public void renameScript(String oldName, String newName) throws AuthenticationRequiredException, ScriptNotFoundException, DuplicateException;
+
+}
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/RenameScript.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/RenameScript.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/SetActive.java
URL: http://svn.apache.org/viewvc/james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/SetActive.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/SetActive.java (added)
+++ james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/SetActive.java Thu Jan 26 14:45:39 2012
@@ -0,0 +1,35 @@
+/*
+ * 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.managesieve.api.commands;
+
+import org.apache.james.managesieve.api.AuthenticationRequiredException;
+import org.apache.james.managesieve.api.ScriptNotFoundException;
+
+/**
+ * <code>SetActive</code>
+ *
+ * @see <a href=http://tools.ietf.org/html/rfc5804#section-2.8>RFC 5804 SETACTIVE Command</a>
+ */
+public interface SetActive {
+
+ abstract public void setActive(String name) throws AuthenticationRequiredException, ScriptNotFoundException;
+
+}
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/SetActive.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/SetActive.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/StartTLS.java
URL: http://svn.apache.org/viewvc/james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/StartTLS.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/StartTLS.java (added)
+++ james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/StartTLS.java Thu Jan 26 14:45:39 2012
@@ -0,0 +1,32 @@
+/*
+ * 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.managesieve.api.commands;
+
+/**
+ * <code>StartTLS</code>
+ *
+ * @see <a href=http://tools.ietf.org/html/rfc5804#section-2.2>RFC 5804 STARTTLS Command</a>
+ */
+public interface StartTLS {
+
+ abstract public void startTLS();
+
+}
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/StartTLS.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/StartTLS.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Unauthenticate.java
URL: http://svn.apache.org/viewvc/james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Unauthenticate.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Unauthenticate.java (added)
+++ james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Unauthenticate.java Thu Jan 26 14:45:39 2012
@@ -0,0 +1,35 @@
+/*
+ * 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.managesieve.api.commands;
+
+import org.apache.james.managesieve.api.AuthenticationRequiredException;
+
+
+/**
+ * <code>Unauthenticate</code>
+ *
+ * @see <a href=http://tools.ietf.org/html/rfc5804#section-2.14.1>RFC 5804 UNAUTHENTICATE Command</a>
+ */
+public interface Unauthenticate {
+
+ abstract public void unauthenticate() throws AuthenticationRequiredException;
+
+}
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Unauthenticate.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/api/src/main/java/org/apache/james/managesieve/api/commands/Unauthenticate.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Propchange: james/mangesieve/core/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jan 26 14:45:39 2012
@@ -0,0 +1,7 @@
+target*
+
+.settings
+
+.project
+
+.classpath
Added: james/mangesieve/core/pom.xml
URL: http://svn.apache.org/viewvc/james/mangesieve/core/pom.xml?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/core/pom.xml (added)
+++ james/mangesieve/core/pom.xml Thu Jan 26 14:45:39 2012
@@ -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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.james</groupId>
+ <artifactId>managesieve</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>managesieve-core</artifactId>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>managesieve-api</artifactId>
+ <version>${project.version}</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>managesieve-mock</artifactId>
+ <version>${project.version}</version>
+ <type>jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Propchange: james/mangesieve/core/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/core/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/mangesieve/core/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java
URL: http://svn.apache.org/viewvc/james/mangesieve/core/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/core/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java (added)
+++ james/mangesieve/core/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java Thu Jan 26 14:45:39 2012
@@ -0,0 +1,279 @@
+/*
+ * 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.managesieve.core;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.james.managesieve.api.AuthenticationRequiredException;
+import org.apache.james.managesieve.api.DuplicateException;
+import org.apache.james.managesieve.api.DuplicateUserException;
+import org.apache.james.managesieve.api.IsActiveException;
+import org.apache.james.managesieve.api.ManageSieveRuntimeException;
+import org.apache.james.managesieve.api.QuotaExceededException;
+import org.apache.james.managesieve.api.ScriptNotFoundException;
+import org.apache.james.managesieve.api.ScriptSummary;
+import org.apache.james.managesieve.api.Session;
+import org.apache.james.managesieve.api.SieveParser;
+import org.apache.james.managesieve.api.SieveRepository;
+import org.apache.james.managesieve.api.StorageException;
+import org.apache.james.managesieve.api.SyntaxException;
+import org.apache.james.managesieve.api.UserNotFoundException;
+import org.apache.james.managesieve.api.Session.UserListener;
+import org.apache.james.managesieve.api.commands.CoreCommands;
+
+/**
+ * <code>CoreProcessor</code>
+ */
+public class CoreProcessor implements CoreCommands {
+
+ public static final String IMPLEMENTATION_DESCRIPTION = "Apache ManageSieve v1.0";
+ public static final String MANAGE_SIEVE_VERSION = "1.0";
+
+ private SieveRepository _repository = null;
+ private Session _session = null;
+ private SieveParser _parser = null;
+
+ /**
+ * Creates a new instance of CoreProcessor.
+ *
+ */
+ private CoreProcessor() {
+ super();
+ }
+
+ /**
+ * Creates a new instance of CoreProcessor.
+ *
+ */
+ public CoreProcessor(Session session, SieveRepository repository, SieveParser parser) {
+ this();
+ _session = session;
+ _repository = repository;
+ _parser = parser;
+
+ // Ensure the session user is defined in the repository
+ _session.addUserListener(new UserListener() {
+
+ public void notifyChange(String user) {
+ ensureUser(user);
+ }
+ });
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.commands.Capability#capability()
+ */
+ public Map<Capabilities, String> capability() {
+ Map<Capabilities, String> capabilities = new HashMap<Capabilities, String>();
+ capabilities.put(Capabilities.IMPLEMENTATION, IMPLEMENTATION_DESCRIPTION);
+ capabilities.put(Capabilities.VERSION, MANAGE_SIEVE_VERSION);
+ StringBuilder builder = new StringBuilder();
+ for (String extension : _parser.getExtensions())
+ {
+ builder.append(extension).append(' ');
+ }
+ String extensions = builder.toString().trim();
+ if (!extensions.isEmpty())
+ {
+ capabilities.put(Capabilities.SIEVE, extensions);
+ }
+ if (isAuthenticated())
+ {
+ capabilities.put(Capabilities.OWNER, getUser());
+ }
+ capabilities.put(Capabilities.GETACTIVE, null);
+ return capabilities;
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.commands.CheckScript#checkScript(java.lang.String)
+ */
+ public List<String> checkScript(String content) throws AuthenticationRequiredException,
+ SyntaxException {
+ authenticationCheck();
+ return _parser.parse(content);
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.commands.DeleteScript#deleteScript(java.lang.String)
+ */
+ public void deleteScript(String name) throws AuthenticationRequiredException,
+ ScriptNotFoundException, IsActiveException {
+ authenticationCheck();
+ try {
+ _repository.deleteScript(getUser(), name);
+ } catch (StorageException ex) {
+ throw new ManageSieveRuntimeException(ex);
+ } catch (UserNotFoundException ex) {
+ // Should not happen as the UserListener should ensure the session user is defined in the repository
+ throw new ManageSieveRuntimeException(ex);
+ }
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.commands.GetScript#getScript(java.lang.String)
+ */
+ public String getScript(String name) throws AuthenticationRequiredException,
+ ScriptNotFoundException {
+ authenticationCheck();
+ String script = null;
+ try {
+ script = _repository.getScript(getUser(), name);
+ } catch (UserNotFoundException ex) {
+ // Should not happen as the UserListener should ensure the session user is defined in the repository
+ throw new ManageSieveRuntimeException(ex);
+ }
+ return script;
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.commands.HaveSpace#haveSpace(java.lang.String, long)
+ */
+ public void haveSpace(String name, long size) throws AuthenticationRequiredException,
+ QuotaExceededException {
+ authenticationCheck();
+ try {
+ _repository.haveSpace(getUser(), name, size);
+ } catch (UserNotFoundException ex) {
+ // Should not happen as the UserListener should ensure the session user is defined in the repository
+ throw new ManageSieveRuntimeException(ex);
+ }
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.commands.ListScripts#listScripts()
+ */
+ public List<ScriptSummary> listScripts() throws AuthenticationRequiredException {
+ authenticationCheck();
+ List<ScriptSummary> summaries = null;
+ try {
+ summaries = _repository.listScripts(getUser());
+ } catch (UserNotFoundException ex) {
+ // Should not happen as the UserListener should ensure the session user is defined in the repository
+ throw new ManageSieveRuntimeException(ex);
+ }
+ return summaries;
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.commands.PutScript#putScript(java.lang.String, java.lang.String)
+ */
+ public List<String> putScript(String name, String content)
+ throws AuthenticationRequiredException, SyntaxException, QuotaExceededException {
+ authenticationCheck();
+ List<String> warnings = _parser.parse(content);
+ try {
+ _repository.putScript(getUser(), name, content);
+ } catch (UserNotFoundException ex) {
+ // Should not happen as the UserListener should ensure the session user is defined in the repository
+ throw new ManageSieveRuntimeException(ex);
+ } catch (StorageException ex) {
+ throw new ManageSieveRuntimeException(ex);
+ }
+ return warnings;
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.commands.RenameScript#renameScript(java.lang.String, java.lang.String)
+ */
+ public void renameScript(String oldName, String newName)
+ throws AuthenticationRequiredException, ScriptNotFoundException,
+ DuplicateException {
+ authenticationCheck();
+ try {
+ _repository.renameScript(getUser(), oldName, newName);
+ } catch (UserNotFoundException ex) {
+ // Should not happen as the UserListener should ensure the session user is defined in the repository
+ throw new ManageSieveRuntimeException(ex);
+ } catch (StorageException ex) {
+ throw new ManageSieveRuntimeException(ex);
+ }
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.commands.SetActive#setActive(java.lang.String)
+ */
+ public void setActive(String name) throws AuthenticationRequiredException,
+ ScriptNotFoundException {
+ authenticationCheck();
+ try {
+ _repository.setActive(getUser(), name);
+ } catch (UserNotFoundException ex) {
+ // Should not happen as the UserListener should ensure the session user is defined in the repository
+ throw new ManageSieveRuntimeException(ex);
+ } catch (StorageException ex) {
+ throw new ManageSieveRuntimeException(ex);
+ }
+ }
+
+ protected String getUser()
+ {
+ return _session.getUser();
+ }
+
+ protected void ensureUser(String user)
+ {
+ if (!_repository.hasUser(user))
+ {
+ try {
+ _repository.addUser(user);
+ } catch (DuplicateUserException ex) {
+ // Should never happen as we checked first!
+ throw new ManageSieveRuntimeException(ex);
+ } catch (StorageException ex) {
+ throw new ManageSieveRuntimeException(ex);
+ }
+ }
+ }
+
+ protected void authenticationCheck() throws AuthenticationRequiredException
+ {
+ if (!isAuthenticated())
+ {
+ throw new AuthenticationRequiredException();
+ }
+ }
+
+ protected boolean isAuthenticated()
+ {
+ return _session.isAuthenticated();
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.commands.GetActive#getActive()
+ */
+ public String getActive() throws AuthenticationRequiredException, ScriptNotFoundException {
+ authenticationCheck();
+
+ String script = null;
+ try {
+ script = _repository.getActive(getUser());
+ } catch (UserNotFoundException ex) {
+ // Should not happen as the UserListener should ensure the session
+ // user is defined in the repository
+ throw new ManageSieveRuntimeException(ex);
+ }
+ return script;
+ }
+
+}
Propchange: james/mangesieve/core/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/core/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/mangesieve/core/src/main/java/org/apache/james/managesieve/transcode/LineToCore.java
URL: http://svn.apache.org/viewvc/james/mangesieve/core/src/main/java/org/apache/james/managesieve/transcode/LineToCore.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/core/src/main/java/org/apache/james/managesieve/transcode/LineToCore.java (added)
+++ james/mangesieve/core/src/main/java/org/apache/james/managesieve/transcode/LineToCore.java Thu Jan 26 14:45:39 2012
@@ -0,0 +1,213 @@
+/*
+ * 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.managesieve.transcode;
+
+import java.util.InputMismatchException;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Scanner;
+
+import org.apache.james.managesieve.api.ArgumentException;
+import org.apache.james.managesieve.api.AuthenticationRequiredException;
+import org.apache.james.managesieve.api.DuplicateException;
+import org.apache.james.managesieve.api.IsActiveException;
+import org.apache.james.managesieve.api.QuotaExceededException;
+import org.apache.james.managesieve.api.ScriptNotFoundException;
+import org.apache.james.managesieve.api.ScriptSummary;
+import org.apache.james.managesieve.api.SyntaxException;
+import org.apache.james.managesieve.api.commands.CoreCommands;
+import org.apache.james.managesieve.api.commands.Capability.Capabilities;
+import org.apache.james.managesieve.util.ParserUtils;
+
+/**
+ * <code>LineToCore</code>
+ */
+public class LineToCore{
+
+ private CoreCommands _core = null;
+
+ /**
+ * Creates a new instance of LineToCore.
+ *
+ */
+ private LineToCore() {
+ super();
+ }
+
+ /**
+ * Creates a new instance of LineToCore.
+ *
+ * @param core
+ */
+ public LineToCore(CoreCommands core) {
+ this();
+ _core = core;
+ }
+
+ public Map<Capabilities, String> capability(String args) throws ArgumentException
+ {
+ if (!args.trim().isEmpty())
+ {
+ throw new ArgumentException("Too many arguments: " + args);
+ }
+ return _core.capability();
+ }
+
+ public void deleteScript(String args) throws AuthenticationRequiredException, ScriptNotFoundException, IsActiveException, ArgumentException
+ {
+ String scriptName = ParserUtils.getScriptName(args);
+ if (null == scriptName || scriptName.isEmpty())
+ {
+ throw new ArgumentException("Missing argument: script name");
+ }
+
+ Scanner scanner = new Scanner(args.substring(scriptName.length()).trim()).useDelimiter("\\A");
+ if (scanner.hasNext())
+ {
+ throw new ArgumentException("Too many arguments: " + scanner.next());
+ }
+ _core.deleteScript(ParserUtils.unquote(scriptName));
+ }
+
+ public String getScript(String args) throws AuthenticationRequiredException, ScriptNotFoundException, ArgumentException
+ {
+ String scriptName = ParserUtils.getScriptName(args);
+ if (null == scriptName || scriptName.isEmpty())
+ {
+ throw new ArgumentException("Missing argument: script name");
+ }
+ Scanner scanner = new Scanner(args.substring(scriptName.length()).trim()).useDelimiter("\\A");
+ if (scanner.hasNext())
+ {
+ throw new ArgumentException("Too many arguments: " + scanner.next());
+ }
+ return _core.getScript(ParserUtils.unquote(scriptName));
+ }
+
+ public List<String> checkScript(String args) throws ArgumentException, AuthenticationRequiredException, SyntaxException
+ {
+ if (args.trim().isEmpty())
+ {
+ throw new ArgumentException("Missing argument: script content");
+ }
+ return _core.checkScript(args);
+ }
+
+ public void haveSpace(String args) throws AuthenticationRequiredException,
+ QuotaExceededException, ArgumentException {
+ String scriptName = ParserUtils.getScriptName(args);
+ if (null == scriptName || scriptName.isEmpty()) {
+ throw new ArgumentException("Missing argument: script name");
+ }
+
+ Scanner scanner = new Scanner(args.substring(scriptName.length()).trim());
+ long size = 0;
+
+ try {
+ size = scanner.nextLong();
+ } catch (InputMismatchException ex) {
+ throw new ArgumentException("Invalid argument: script size");
+ } catch (NoSuchElementException ex) {
+ throw new ArgumentException("Missing argument: script size");
+ }
+
+ scanner.useDelimiter("\\A");
+ if (scanner.hasNext()) {
+ throw new ArgumentException("Too many arguments: " + scanner.next().trim());
+ }
+ _core.haveSpace(ParserUtils.unquote(scriptName), size);
+ }
+
+ public List<ScriptSummary> listScripts(String args) throws AuthenticationRequiredException, ArgumentException {
+ if (!args.trim().isEmpty())
+ {
+ throw new ArgumentException("Too many arguments: " + args);
+ }
+ return _core.listScripts();
+ }
+
+ public List<String> putScript(String args)
+ throws AuthenticationRequiredException, SyntaxException, QuotaExceededException, ArgumentException {
+ String scriptName = ParserUtils.getScriptName(args);
+ if (null == scriptName || scriptName.isEmpty())
+ {
+ throw new ArgumentException("Missing argument: script name");
+ }
+ Scanner scanner = new Scanner(args.substring(scriptName.length()).trim()).useDelimiter("\\A");
+ if (!scanner.hasNext())
+ {
+ throw new ArgumentException("Missing argument: script content");
+ }
+ String content = scanner.next();
+ return _core.putScript(ParserUtils.unquote(scriptName), content);
+ }
+
+ public void renameScript(String args)
+ throws AuthenticationRequiredException, ScriptNotFoundException,
+ DuplicateException, ArgumentException {
+ String oldName = ParserUtils.getScriptName(args);
+ if (null == oldName || oldName.isEmpty())
+ {
+ throw new ArgumentException("Missing argument: old script name");
+ }
+
+ String newName = ParserUtils.getScriptName(args.substring(oldName.length()));
+ if (null == newName || newName.isEmpty())
+ {
+ throw new ArgumentException("Missing argument: new script name");
+ }
+
+ Scanner scanner = new Scanner(args.substring(oldName.length() + 1 + newName.length()).trim()).useDelimiter("\\A");
+ if (scanner.hasNext())
+ {
+ throw new ArgumentException("Too many arguments: " + scanner.next());
+ }
+ _core.renameScript(oldName, newName);
+ }
+
+ public void setActive(String args) throws AuthenticationRequiredException,
+ ScriptNotFoundException, ArgumentException {
+ String scriptName = ParserUtils.getScriptName(args);
+ if (null == scriptName || scriptName.isEmpty())
+ {
+ throw new ArgumentException("Missing argument: script name");
+ }
+
+ Scanner scanner = new Scanner(args.substring(scriptName.length()).trim()).useDelimiter("\\A");
+ if (scanner.hasNext())
+ {
+ throw new ArgumentException("Too many arguments: " + scanner.next());
+ }
+ _core.setActive(ParserUtils.unquote(scriptName));
+ }
+
+ public String getActive(String args) throws AuthenticationRequiredException, ScriptNotFoundException, ArgumentException
+ {
+ Scanner scanner = new Scanner(args.trim()).useDelimiter("\\A");
+ if (scanner.hasNext())
+ {
+ throw new ArgumentException("Too many arguments: " + scanner.next());
+ }
+ return _core.getActive();
+ }
+
+}
Propchange: james/mangesieve/core/src/main/java/org/apache/james/managesieve/transcode/LineToCore.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/core/src/main/java/org/apache/james/managesieve/transcode/LineToCore.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/mangesieve/core/src/main/java/org/apache/james/managesieve/transcode/LineToCoreToLine.java
URL: http://svn.apache.org/viewvc/james/mangesieve/core/src/main/java/org/apache/james/managesieve/transcode/LineToCoreToLine.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/core/src/main/java/org/apache/james/managesieve/transcode/LineToCoreToLine.java (added)
+++ james/mangesieve/core/src/main/java/org/apache/james/managesieve/transcode/LineToCoreToLine.java Thu Jan 26 14:45:39 2012
@@ -0,0 +1,254 @@
+/*
+ * 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.managesieve.transcode;
+
+import java.util.List;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.apache.james.managesieve.api.ArgumentException;
+import org.apache.james.managesieve.api.AuthenticationRequiredException;
+import org.apache.james.managesieve.api.DuplicateException;
+import org.apache.james.managesieve.api.IsActiveException;
+import org.apache.james.managesieve.api.QuotaExceededException;
+import org.apache.james.managesieve.api.ScriptNotFoundException;
+import org.apache.james.managesieve.api.ScriptSummary;
+import org.apache.james.managesieve.api.SyntaxException;
+import org.apache.james.managesieve.api.commands.Capability.Capabilities;
+
+/**
+ * <code>LineToCoreToLine</code>
+ */
+public class LineToCoreToLine {
+
+ private LineToCore _lineToCore = null;
+
+ /**
+ * Creates a new instance of LineToCoreToLine.
+ *
+ */
+ private LineToCoreToLine() {
+ super();
+ }
+
+ public LineToCoreToLine(LineToCore lineToCore) {
+ this();
+ _lineToCore = lineToCore;
+ }
+
+ public String capability(String args) {
+ Set<Entry<Capabilities, String>> entries = null;
+ try {
+ entries =_lineToCore.capability(args).entrySet();
+ } catch (ArgumentException ex) {
+ return "NO \"" + ex.getMessage() + "\"";
+ }
+
+ StringBuilder builder = new StringBuilder();
+ for (Entry<Capabilities, String> entry : entries)
+ {
+ builder
+ .append(entry.getKey().toString())
+ .append(' ')
+ .append(null == entry.getValue() ? "" : entry.getValue())
+ .append("\r\n");
+ }
+ builder.append("OK");
+ return builder.toString();
+ }
+
+ public String checkScript(String args) {
+ List<String> warnings = null;
+ try {
+ warnings = _lineToCore.checkScript(args);
+ } catch (AuthenticationRequiredException ex) {
+ return "NO";
+ } catch (ArgumentException ex) {
+ return "NO \"" + ex.getMessage() + "\"";
+ } catch (SyntaxException ex) {
+ return "NO \"Syntax Error: " + ex.getMessage() + "\"";
+ }
+
+ StringBuilder builder = new StringBuilder();
+ if (!warnings.isEmpty()) {
+ builder.append("OK (WARNINGS)");
+ for (String warning : warnings) {
+ builder
+ .append(" \"")
+ .append(warning)
+ .append('"');
+ }
+ } else {
+ builder.append("OK");
+ }
+ return builder.toString();
+ }
+
+ public String deleteScript(String args) {
+ try {
+ _lineToCore.deleteScript(args);
+ } catch (AuthenticationRequiredException ex) {
+ return "NO";
+ } catch (ScriptNotFoundException ex) {
+ return "NO (NONEXISTENT) \"There is no script by that name\"";
+ } catch (IsActiveException ex) {
+ return "NO (ACTIVE) \"You may not delete an active script\"";
+ } catch (ArgumentException ex) {
+ return "NO \"" + ex.getMessage() + "\"";
+ }
+ return "OK";
+ }
+
+ public String getScript(String args) {
+ String content = null;
+ try {
+ content = _lineToCore.getScript(args);
+ } catch (AuthenticationRequiredException ex) {
+ return "NO";
+ } catch (ScriptNotFoundException ex) {
+ return "NO (NONEXISTENT) \"There is no script by that name\"";
+ } catch (ArgumentException ex) {
+ return "NO \"" + ex.getMessage() + "\"";
+ }
+ StringBuilder builder = new StringBuilder(content);
+ builder
+ .append("\r\n")
+ .append("OK");
+ return builder.toString();
+ }
+
+ public String haveSpace(String args) {
+ try {
+ _lineToCore.haveSpace(args);
+ } catch (AuthenticationRequiredException ex) {
+ return "NO";
+ } catch (QuotaExceededException ex) {
+ return "NO (QUOTA/MAXSIZE) \"Quota exceeded\"";
+ } catch (ArgumentException ex) {
+ return "NO \"" + ex.getMessage() + "\"";
+ }
+ return "OK";
+ }
+
+ public String listScripts(String args) {
+ List<ScriptSummary> summaries = null;
+ try {
+ summaries = _lineToCore.listScripts(args);
+ } catch (AuthenticationRequiredException ex) {
+ return "NO";
+ } catch (ArgumentException ex) {
+ return "NO \"" + ex.getMessage() + "\"";
+ }
+ StringBuilder builder = new StringBuilder();
+ for (ScriptSummary summary : summaries)
+ {
+ builder
+ .append('"')
+ .append(summary.getName())
+ .append('"');
+ if (summary.isActive())
+ {
+ builder
+ .append(' ')
+ .append("ACTIVE");
+ }
+ builder
+ .append("\r\n");
+ }
+ builder.append("OK");
+ return builder.toString();
+ }
+
+ public String putScript(String args) {
+ List<String> warnings = null;
+ try {
+ warnings = _lineToCore.putScript(args);
+ } catch (AuthenticationRequiredException ex) {
+ return "NO";
+ } catch (SyntaxException ex) {
+ return "NO \"Syntax Error: " + ex.getMessage() + "\"";
+ } catch (QuotaExceededException ex) {
+ return "NO (QUOTA/MAXSIZE) \"Quota exceeded\"";
+ } catch (ArgumentException ex) {
+ return "NO \"" + ex.getMessage() + "\"";
+ }
+ StringBuilder builder = new StringBuilder();
+ if (!warnings.isEmpty()) {
+ builder.append("OK (WARNINGS)");
+ for (String warning : warnings) {
+ builder
+ .append(" \"")
+ .append(warning)
+ .append('"');
+ }
+ } else {
+ builder.append("OK");
+ }
+ return builder.toString();
+ }
+
+ public String renameScript(String args) {
+ try {
+ _lineToCore.renameScript(args);
+ } catch (AuthenticationRequiredException ex) {
+ return "NO";
+ } catch (ScriptNotFoundException ex) {
+ return "NO (NONEXISTENT) \"There is no script by that name\"";
+ } catch (DuplicateException ex) {
+ return "NO (ALREADYEXISTS) \"A script with that name already exists\"";
+ } catch (ArgumentException ex) {
+ return "NO \"" + ex.getMessage() + "\"";
+ }
+ return "OK";
+ }
+
+ public String setActive(String args) {
+ try {
+ _lineToCore.setActive(args);
+ } catch (AuthenticationRequiredException ex) {
+ return "NO";
+ } catch (ScriptNotFoundException ex) {
+ return "NO (NONEXISTENT) \"There is no script by that name\"";
+ } catch (ArgumentException ex) {
+ return "NO \"" + ex.getMessage() + "\"";
+ }
+ return "OK";
+ }
+
+ public String getActive(String args) {
+ String content = null;
+ try {
+ content = _lineToCore.getActive(args);
+ } catch (AuthenticationRequiredException ex) {
+ return "NO";
+ } catch (ScriptNotFoundException ex) {
+ return "NO (NONEXISTENT) \"" + ex.getMessage() + "\"";
+ } catch (ArgumentException ex) {
+ return "NO \"" + ex.getMessage() + "\"";
+ }
+ StringBuilder builder = new StringBuilder(content);
+ builder
+ .append("\r\n")
+ .append("OK");
+ return builder.toString();
+ }
+
+}
Propchange: james/mangesieve/core/src/main/java/org/apache/james/managesieve/transcode/LineToCoreToLine.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/core/src/main/java/org/apache/james/managesieve/transcode/LineToCoreToLine.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/mangesieve/core/src/main/java/org/apache/james/managesieve/util/ParserUtils.java
URL: http://svn.apache.org/viewvc/james/mangesieve/core/src/main/java/org/apache/james/managesieve/util/ParserUtils.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/core/src/main/java/org/apache/james/managesieve/util/ParserUtils.java (added)
+++ james/mangesieve/core/src/main/java/org/apache/james/managesieve/util/ParserUtils.java Thu Jan 26 14:45:39 2012
@@ -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.managesieve.util;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * <code>ParserUtils</code>
+ */
+public class ParserUtils {
+
+ private static final Pattern SCRIPT_NAME_REGEX = Pattern.compile("[^\\s\"']+|\"[^\"]*\"|'[^']*'");
+
+ public static String getScriptName(String args) {
+ Matcher regexMatcher = SCRIPT_NAME_REGEX.matcher(args);
+ regexMatcher.find();
+ String name = null;
+ try {
+ name = regexMatcher.group();
+ } catch(IllegalStateException ex)
+ {
+ // no op
+ }
+ return name;
+ }
+
+ public static String unquote(String quoted) {
+ String result = quoted;
+ if (quoted.startsWith("\"") && quoted.endsWith("\"")) {
+ result = quoted.substring(1, quoted.length() - 1);
+ } else if (quoted.startsWith("'") && quoted.endsWith("'")) {
+ result = quoted.substring(1, quoted.length() - 1);
+ }
+ return result;
+ }
+
+}
Propchange: james/mangesieve/core/src/main/java/org/apache/james/managesieve/util/ParserUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/core/src/main/java/org/apache/james/managesieve/util/ParserUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/mangesieve/core/src/main/java/org/apache/james/managesieve/util/SettableSession.java
URL: http://svn.apache.org/viewvc/james/mangesieve/core/src/main/java/org/apache/james/managesieve/util/SettableSession.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/core/src/main/java/org/apache/james/managesieve/util/SettableSession.java (added)
+++ james/mangesieve/core/src/main/java/org/apache/james/managesieve/util/SettableSession.java Thu Jan 26 14:45:39 2012
@@ -0,0 +1,96 @@
+/*
+ * 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.managesieve.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.james.managesieve.api.Session;
+
+/**
+ * <code>SettableSession</code>
+ */
+public class SettableSession implements Session {
+
+ String _user = null;
+ boolean _isAuthenticated = false;
+ List<UserListener> _userListeners = new ArrayList<UserListener>();
+ List<AuthenticationListener> _authenticationListeners = new ArrayList<AuthenticationListener>();
+
+ /**
+ * @see org.apache.james.managesieve.api.Session#addAuthenticationListener(org.apache.james.managesieve.api.Session.AuthenticationListener)
+ */
+ public void addAuthenticationListener(AuthenticationListener listener) {
+ _authenticationListeners.add(listener);
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.Session#addUserListener(org.apache.james.managesieve.api.Session.UserListener)
+ */
+ public void addUserListener(UserListener listener) {
+ _userListeners.add(listener);
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.Session#getUser()
+ */
+ public String getUser() {
+ return _user;
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.Session#isAuthenticated()
+ */
+ public boolean isAuthenticated() {
+ return _isAuthenticated;
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.Session#removeAuthenticationListener(org.apache.james.managesieve.api.Session.AuthenticationListener)
+ */
+ public void removeAuthenticationListener(AuthenticationListener listener) {
+ _authenticationListeners.remove(listener);
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.Session#removeUserListener(org.apache.james.managesieve.api.Session.UserListener)
+ */
+ public void removeUserListener(UserListener listener) {
+ _userListeners.remove(listener);
+ }
+
+ public void setAuthentication(boolean isAuthenticated) {
+ _isAuthenticated = isAuthenticated;
+ for(AuthenticationListener listener : _authenticationListeners)
+ {
+ listener.notifyChange(isAuthenticated);
+ }
+ }
+
+ public void setUser(String user) {
+ _user = user;
+ for(UserListener listener : _userListeners)
+ {
+ listener.notifyChange(user);
+ }
+ }
+
+}
Propchange: james/mangesieve/core/src/main/java/org/apache/james/managesieve/util/SettableSession.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/core/src/main/java/org/apache/james/managesieve/util/SettableSession.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/mangesieve/core/src/test/java/org/apache/james/managesieve/core/CoreProcessorTestCase.java
URL: http://svn.apache.org/viewvc/james/mangesieve/core/src/test/java/org/apache/james/managesieve/core/CoreProcessorTestCase.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/core/src/test/java/org/apache/james/managesieve/core/CoreProcessorTestCase.java (added)
+++ james/mangesieve/core/src/test/java/org/apache/james/managesieve/core/CoreProcessorTestCase.java Thu Jan 26 14:45:39 2012
@@ -0,0 +1,491 @@
+/*
+ * 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.managesieve.core;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.james.managesieve.api.AuthenticationRequiredException;
+import org.apache.james.managesieve.api.DuplicateException;
+import org.apache.james.managesieve.api.IsActiveException;
+import org.apache.james.managesieve.api.QuotaExceededException;
+import org.apache.james.managesieve.api.ScriptNotFoundException;
+import org.apache.james.managesieve.api.ScriptSummary;
+import org.apache.james.managesieve.api.SieveRepository;
+import org.apache.james.managesieve.api.StorageException;
+import org.apache.james.managesieve.api.SyntaxException;
+import org.apache.james.managesieve.api.UserNotFoundException;
+import org.apache.james.managesieve.api.commands.CoreCommands;
+import org.apache.james.managesieve.api.commands.Capability.Capabilities;
+import org.apache.james.managesieve.mock.MockSession;
+import org.apache.james.managesieve.mock.MockSieveParser;
+import org.apache.james.managesieve.mock.MockSieveRepository;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * <code>CoreProcessorTestCase</code>
+ */
+public class CoreProcessorTestCase {
+
+ /**
+ * setUp.
+ *
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * tearDown.
+ *
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * Test method for {@link org.apache.james.managesieve.core.CoreProcessor#CoreProcessor(org.apache.james.managesieve.api.Session, org.apache.james.managesieve.api.SieveRepository, org.apache.james.managesieve.api.SieveParser)}.
+ */
+ @Test
+ public final void testCoreProcessor() {
+ CoreProcessor core = new CoreProcessor(new MockSession(), new MockSieveRepository(), new MockSieveParser());
+ assertTrue(core instanceof CoreCommands);
+ }
+
+ /**
+ * Test method for {@link org.apache.james.managesieve.core.CoreProcessor#capability()}.
+ */
+ @Test
+ public final void testCapability() {
+ MockSession session = new MockSession();
+ MockSieveParser parser = new MockSieveParser();
+ CoreProcessor core = new CoreProcessor(session, new MockSieveRepository(), parser);
+
+ // Unauthenticated
+ session.setAuthentication(false);
+ parser.setExtensions(Arrays.asList(new String[]{"a","b","c"}));
+ Map<Capabilities, String> capabilities = core.capability();
+ assertEquals(CoreProcessor.IMPLEMENTATION_DESCRIPTION, capabilities.get(Capabilities.IMPLEMENTATION));
+ assertEquals(CoreProcessor.MANAGE_SIEVE_VERSION, capabilities.get(Capabilities.VERSION));
+ assertEquals("a b c", capabilities.get(Capabilities.SIEVE));
+ assertFalse(capabilities.containsKey(Capabilities.OWNER));
+ assertTrue(capabilities.containsKey(Capabilities.GETACTIVE));
+
+ // Authenticated
+ session.setAuthentication(true);
+ parser.setExtensions(Arrays.asList(new String[]{"a","b","c"}));
+ session.setUser("test");
+ capabilities = core.capability();
+ assertEquals(CoreProcessor.IMPLEMENTATION_DESCRIPTION, capabilities.get(Capabilities.IMPLEMENTATION));
+ assertEquals(CoreProcessor.MANAGE_SIEVE_VERSION, capabilities.get(Capabilities.VERSION));
+ assertEquals("a b c", capabilities.get(Capabilities.SIEVE));
+ assertEquals("test", capabilities.get(Capabilities.OWNER));
+ assertTrue(capabilities.containsKey(Capabilities.GETACTIVE));
+ }
+
+ /**
+ * Test method for {@link org.apache.james.managesieve.core.CoreProcessor#checkScript(java.lang.String)}.
+ * @throws SyntaxException
+ * @throws AuthenticationRequiredException
+ */
+ @Test
+ public final void testCheckScript() throws AuthenticationRequiredException, SyntaxException {
+ MockSession session = new MockSession();
+ CoreProcessor core = new CoreProcessor(session, new MockSieveRepository(), new MockSieveParser());
+
+ // Unauthorised
+ boolean success = false;
+ session.setAuthentication(false);
+ try {
+ core.checkScript("warning");
+ } catch (AuthenticationRequiredException ex) {
+ success = true;
+ }
+ assertTrue("Expected AuthenticationRequiredException", success);
+
+ // Authorised
+ session.setAuthentication(true);
+ session.setUser("test");
+ List<String> warnings = core.checkScript("warning");
+ assertEquals(2, warnings.size());
+ assertEquals("warning1", warnings.get(0));
+ assertEquals("warning2", warnings.get(1));
+
+ // Syntax
+ success = false;
+ session.setAuthentication(true);
+ session.setUser("test");
+ try {
+ core.checkScript("SyntaxException");
+ } catch (SyntaxException ex) {
+ success = true;
+ }
+ assertTrue("Expected SyntaxException", success);
+ }
+
+ /**
+ * Test method for {@link org.apache.james.managesieve.core.CoreProcessor#deleteScript(java.lang.String)}.
+ * @throws IsActiveException
+ * @throws ScriptNotFoundException
+ * @throws AuthenticationRequiredException
+ * @throws QuotaExceededException
+ * @throws StorageException
+ * @throws UserNotFoundException
+ */
+ @Test
+ public final void testDeleteScript() throws ScriptNotFoundException, IsActiveException, AuthenticationRequiredException, UserNotFoundException, StorageException, QuotaExceededException {
+ MockSession session = new MockSession();
+ SieveRepository repository = new MockSieveRepository();
+ CoreProcessor core = new CoreProcessor(session, repository, new MockSieveParser());
+
+ // Unauthorised
+ boolean success = false;
+ session.setAuthentication(false);
+ try {
+ core.deleteScript("script");
+ } catch (AuthenticationRequiredException ex) {
+ success = true;
+ }
+ assertTrue("Expected AuthenticationRequiredException", success);
+
+ // Authorised - non-existent script
+ success = false;
+ session.setAuthentication(true);
+ session.setUser("test");
+ try {
+ core.deleteScript("script");
+ } catch (ScriptNotFoundException ex) {
+ success = true;
+ }
+ assertTrue("Expected ScriptNotFoundException", success);
+
+ // Authorised - existent script
+ session.setAuthentication(true);
+ session.setUser("test");
+ repository.putScript("test", "script", "content");
+ core.deleteScript("script");
+ success = false;
+ try {
+ repository.getScript("test", "script");
+ } catch (ScriptNotFoundException ex) {
+ success = true;
+ }
+ assertTrue("Expected ScriptNotFoundException", success);
+
+ // Authorised - active script
+ success = false;
+ session.setAuthentication(true);
+ session.setUser("test");
+ repository.putScript("test", "script", "content");
+ repository.setActive("test", "script");
+ try {
+ core.deleteScript("script");
+ } catch (IsActiveException ex) {
+ success = true;
+ }
+ assertTrue("Expected IsActiveException", success);
+ }
+
+ /**
+ * Test method for {@link org.apache.james.managesieve.core.CoreProcessor#getScript(java.lang.String)}.
+ * @throws ScriptNotFoundException
+ * @throws AuthenticationRequiredException
+ * @throws QuotaExceededException
+ * @throws StorageException
+ * @throws UserNotFoundException
+ */
+ @Test
+ public final void testGetScript() throws ScriptNotFoundException, AuthenticationRequiredException, UserNotFoundException, StorageException, QuotaExceededException {
+ MockSession session = new MockSession();
+ SieveRepository repository = new MockSieveRepository();
+ CoreProcessor core = new CoreProcessor(session, repository, new MockSieveParser());
+
+ // Unauthorised
+ boolean success = false;
+ session.setAuthentication(false);
+ try {
+ core.getScript("script");
+ } catch (AuthenticationRequiredException ex) {
+ success = true;
+ }
+ assertTrue("Expected AuthenticationRequiredException", success);
+
+ // Authorised - non-existent script
+ success = false;
+ session.setAuthentication(true);
+ session.setUser("test");
+ try {
+ core.getScript("script");
+ } catch (ScriptNotFoundException ex) {
+ success = true;
+ }
+ assertTrue("Expected ScriptNotFoundException", success);
+
+ // Authorised - existent script
+ session.setAuthentication(true);
+ session.setUser("test");
+ repository.putScript("test", "script", "content");
+ core.getScript("script");
+ }
+
+ /**
+ * Test method for {@link org.apache.james.managesieve.core.CoreProcessor#haveSpace(java.lang.String, long)}.
+ * @throws QuotaExceededException
+ * @throws AuthenticationRequiredException
+ */
+ @Test
+ public final void testHaveSpace() throws QuotaExceededException, AuthenticationRequiredException {
+ MockSession session = new MockSession();
+ SieveRepository repository = new MockSieveRepository();
+ CoreProcessor core = new CoreProcessor(session, repository, new MockSieveParser());
+
+ // Unauthorised
+ boolean success = false;
+ session.setAuthentication(false);
+ try {
+ core.haveSpace("script", Long.MAX_VALUE);
+ } catch (AuthenticationRequiredException ex) {
+ success = true;
+ }
+ assertTrue("Expected AuthenticationRequiredException", success);
+
+ // Authorised - existent script
+ session.setAuthentication(true);
+ session.setUser("test");
+ core.haveSpace("script", Long.MAX_VALUE);
+ }
+
+ /**
+ * Test method for {@link org.apache.james.managesieve.core.CoreProcessor#listScripts()}.
+ * @throws AuthenticationRequiredException
+ * @throws QuotaExceededException
+ * @throws StorageException
+ * @throws UserNotFoundException
+ */
+ @Test
+ public final void testListScripts() throws AuthenticationRequiredException, UserNotFoundException, StorageException, QuotaExceededException {
+ MockSession session = new MockSession();
+ SieveRepository repository = new MockSieveRepository();
+ CoreProcessor core = new CoreProcessor(session, repository, new MockSieveParser());
+
+ // Unauthorised
+ boolean success = false;
+ session.setAuthentication(false);
+ try {
+ core.listScripts();
+ } catch (AuthenticationRequiredException ex) {
+ success = true;
+ }
+ assertTrue("Expected AuthenticationRequiredException", success);
+
+ // Authorised - non-existent script
+ success = false;
+ session.setAuthentication(true);
+ session.setUser("test");
+ List<ScriptSummary> summaries = core.listScripts();
+ assertTrue(summaries.isEmpty());
+
+ // Authorised - existent script
+ session.setAuthentication(true);
+ session.setUser("test");
+ repository.putScript("test", "script", "content");
+ summaries = core.listScripts();
+ assertEquals(1, summaries.size());
+ }
+
+ /**
+ * Test method for {@link org.apache.james.managesieve.core.CoreProcessor#putScript(java.lang.String, java.lang.String)}.
+ * @throws QuotaExceededException
+ * @throws SyntaxException
+ * @throws AuthenticationRequiredException
+ * @throws ScriptNotFoundException
+ * @throws UserNotFoundException
+ */
+ @Test
+ public final void testPutScript() throws SyntaxException, QuotaExceededException, AuthenticationRequiredException, UserNotFoundException, ScriptNotFoundException {
+ MockSession session = new MockSession();
+ SieveRepository repository = new MockSieveRepository();
+ CoreProcessor core = new CoreProcessor(session, repository, new MockSieveParser());
+
+ // Unauthorised
+ boolean success = false;
+ session.setAuthentication(false);
+ try {
+ core.putScript("script", "content");
+ } catch (AuthenticationRequiredException ex) {
+ success = true;
+ }
+ assertTrue("Expected AuthenticationRequiredException", success);
+
+ // Authorised
+ success = false;
+ session.setAuthentication(true);
+ session.setUser("test");
+ core.putScript("script", "content");
+ assertEquals("content", repository.getScript("test", "script"));
+
+ // Syntax
+ success = false;
+ session.setAuthentication(true);
+ session.setUser("test");
+ try {
+ core.putScript("script", "SyntaxException");
+ } catch (SyntaxException ex) {
+ success = true;
+ }
+ assertTrue("Expected SyntaxException", success);
+ }
+
+ /**
+ * Test method for {@link org.apache.james.managesieve.core.CoreProcessor#renameScript(java.lang.String, java.lang.String)}.
+ * @throws DuplicateException
+ * @throws IsActiveException
+ * @throws ScriptNotFoundException
+ * @throws QuotaExceededException
+ * @throws SyntaxException
+ * @throws AuthenticationRequiredException
+ * @throws StorageException
+ * @throws UserNotFoundException
+ */
+ @Test
+ public final void testRenameScript() throws ScriptNotFoundException, IsActiveException, DuplicateException, AuthenticationRequiredException, SyntaxException, QuotaExceededException, UserNotFoundException, StorageException {
+ MockSession session = new MockSession();
+ SieveRepository repository = new MockSieveRepository();
+ CoreProcessor core = new CoreProcessor(session, repository, new MockSieveParser());
+
+ // Unauthorised
+ boolean success = false;
+ session.setAuthentication(false);
+ try {
+ core.renameScript("oldName", "newName");
+ } catch (AuthenticationRequiredException ex) {
+ success = true;
+ }
+ assertTrue("Expected AuthenticationRequiredException", success);
+
+ // Authorised
+ success = false;
+ session.setAuthentication(true);
+ session.setUser("test");
+ repository.putScript("test", "oldName", "content");
+ core.renameScript("oldName", "newName");
+ assertEquals("content", repository.getScript("test", "oldName"));
+ }
+
+ /**
+ * Test method for {@link org.apache.james.managesieve.core.CoreProcessor#setActive(java.lang.String)}.
+ * @throws ScriptNotFoundException
+ * @throws AuthenticationRequiredException
+ * @throws QuotaExceededException
+ * @throws StorageException
+ * @throws UserNotFoundException
+ */
+ @Test
+ public final void testSetActive() throws ScriptNotFoundException, AuthenticationRequiredException, UserNotFoundException, StorageException, QuotaExceededException {
+ MockSession session = new MockSession();
+ SieveRepository repository = new MockSieveRepository();
+ CoreProcessor core = new CoreProcessor(session, repository, new MockSieveParser());
+
+ // Unauthorised
+ boolean success = false;
+ session.setAuthentication(false);
+ try {
+ core.setActive("script");
+ } catch (AuthenticationRequiredException ex) {
+ success = true;
+ }
+ assertTrue("Expected AuthenticationRequiredException", success);
+
+ // Authorised
+ success = false;
+ session.setAuthentication(true);
+ session.setUser("test");
+ repository.putScript("test", "script", "content");
+ core.setActive("script");
+ assertEquals("content", repository.getActive("test"));
+ }
+
+ /**
+ * testGetActive.
+ *
+ * @throws ScriptNotFoundException
+ * @throws AuthenticationRequiredException
+ * @throws UserNotFoundException
+ * @throws StorageException
+ * @throws QuotaExceededException
+ */
+ @Test
+ public final void testGetActive() throws ScriptNotFoundException,
+ AuthenticationRequiredException, UserNotFoundException, StorageException,
+ QuotaExceededException {
+ MockSession session = new MockSession();
+ SieveRepository repository = new MockSieveRepository();
+ CoreProcessor core = new CoreProcessor(session, repository, new MockSieveParser());
+
+ // Unauthorised
+ boolean success = false;
+ session.setAuthentication(false);
+ try {
+ core.getActive();
+ } catch (AuthenticationRequiredException ex) {
+ success = true;
+ }
+ assertTrue("Expected AuthenticationRequiredException", success);
+
+ // Authorised - non-existent script
+ success = false;
+ session.setAuthentication(true);
+ session.setUser("test");
+ try {
+ core.getActive();
+ } catch (ScriptNotFoundException ex) {
+ success = true;
+ }
+ assertTrue("Expected ScriptNotFoundException", success);
+
+ // Authorised - existent script, inactive
+ session.setAuthentication(true);
+ session.setUser("test");
+ repository.putScript("test", "script", "content");
+ try {
+ core.getActive();
+ } catch (ScriptNotFoundException ex) {
+ success = true;
+ }
+ assertTrue("Expected ScriptNotFoundException", success);
+
+ // Authorised - existent script, active
+ session.setAuthentication(true);
+ session.setUser("test");
+ repository.setActive("test", "script");
+ core.getActive();
+ }
+
+}
Propchange: james/mangesieve/core/src/test/java/org/apache/james/managesieve/core/CoreProcessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/core/src/test/java/org/apache/james/managesieve/core/CoreProcessorTestCase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Propchange: james/mangesieve/jsieve/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jan 26 14:45:39 2012
@@ -0,0 +1,7 @@
+target*
+
+.settings
+
+.classpath
+
+.project
Added: james/mangesieve/jsieve/pom.xml
URL: http://svn.apache.org/viewvc/james/mangesieve/jsieve/pom.xml?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/jsieve/pom.xml (added)
+++ james/mangesieve/jsieve/pom.xml Thu Jan 26 14:45:39 2012
@@ -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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.james</groupId>
+ <artifactId>managesieve</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>managesieve-jsieve</artifactId>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>managesieve-core</artifactId>
+ <version>${project.version}</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>apache-jsieve</artifactId>
+ <version>${jsieve.version}</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+</project>
Propchange: james/mangesieve/jsieve/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/jsieve/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/mangesieve/jsieve/src/main/java/org/apache/james/managesieve/jsieve/Parser.java
URL: http://svn.apache.org/viewvc/james/mangesieve/jsieve/src/main/java/org/apache/james/managesieve/jsieve/Parser.java?rev=1236201&view=auto
==============================================================================
--- james/mangesieve/jsieve/src/main/java/org/apache/james/managesieve/jsieve/Parser.java (added)
+++ james/mangesieve/jsieve/src/main/java/org/apache/james/managesieve/jsieve/Parser.java Thu Jan 26 14:45:39 2012
@@ -0,0 +1,91 @@
+/*
+ * 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.managesieve.jsieve;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.managesieve.api.SieveParser;
+import org.apache.james.managesieve.api.SyntaxException;
+import org.apache.jsieve.ConfigurationManager;
+import org.apache.jsieve.SieveFactory;
+import org.apache.jsieve.parser.generated.ParseException;
+
+/**
+ * <code>Parser</code>
+ */
+public class Parser implements SieveParser {
+
+ private static final List<String> EMPTY_WARNINGS = new ArrayList<String>(0);
+
+ private SieveFactory _sieveFactory = null;
+
+ /**
+ * Creates a new instance of Parser.
+ *
+ */
+ public Parser() {
+ super();
+ }
+
+ /**
+ * Creates a new instance of Parser.
+ *
+ * @param sieveFactory
+ */
+ public Parser(ConfigurationManager manager) {
+ this();
+ setConfigurationManager(manager);
+ }
+
+ /**
+ * setConfigurationManager.
+ *
+ * @param manager The <code>ConfigurationManager</code> to set
+ */
+ @Resource(name = "jsieveconfigurationmanager")
+ public void setConfigurationManager(ConfigurationManager manager) {
+ _sieveFactory = manager.build();
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.SieveParser#getExtensions()
+ */
+ public List<String> getExtensions() {
+ return _sieveFactory.getExtensions();
+ }
+
+ /**
+ * @see org.apache.james.managesieve.api.SieveParser#parse(java.lang.String)
+ */
+ public List<String> parse(String content) throws SyntaxException {
+ try {
+ _sieveFactory.parse(new ByteArrayInputStream(content.getBytes()));
+ } catch (ParseException ex) {
+ throw new SyntaxException(ex);
+ }
+ return EMPTY_WARNINGS;
+ }
+
+}
Propchange: james/mangesieve/jsieve/src/main/java/org/apache/james/managesieve/jsieve/Parser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/mangesieve/jsieve/src/main/java/org/apache/james/managesieve/jsieve/Parser.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Propchange: james/mangesieve/mailet/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jan 26 14:45:39 2012
@@ -0,0 +1,7 @@
+target*
+
+.settings
+
+.classpath
+
+.project
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org