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 no...@apache.org on 2009/10/04 17:10:51 UTC
svn commit: r821546 [4/5] - in /james/server/trunk:
avalon-socket-library/src/main/java/org/apache/james/socket/
core-api/src/test/java/org/ core-api/src/test/java/org/apache/
core-api/src/test/java/org/apache/james/
core-api/src/test/java/org/apache/j...
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListMappingCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListMappingCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListMappingCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListMappingCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,118 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.james.api.vut.management.VirtualUserTableManagementException;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+public class ListMappingCmdHandler extends AbstractMappingCmdHandler {
+ private CommandHelp help = new CommandHelp("listmapping ([table=virtualusertablename]) [user@domain]","list all mappings for the given emailaddress");
+
+ public final static String COMMAND_NAME = "LISTMAPPING";
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession,
+ * java.lang.String, java.lang.String)
+ */
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+ RemoteManagerResponse response;
+ String[] args = null;
+ String table = null;
+ String user = null;
+ String domain = null;
+
+ if (parameters != null)
+ args = parameters.split(" ");
+
+ // check if the command was called correct
+ if (parameters == null || parameters.trim().equals("") || args.length < 1 || args.length > 2) {
+ response = new RemoteManagerResponse("Usage: " + help.getSyntax());
+ return response;
+ } else {
+ if (args[0].startsWith("table=")) {
+ table = args[0].substring("table=".length());
+ if (args[1].indexOf("@") > 0) {
+ user = getMappingValue(args[1].split("@")[0]);
+ domain = getMappingValue(args[1].split("@")[1]);
+ } else {
+ response = new RemoteManagerResponse("Usage: " + help.getSyntax());
+ return response;
+
+ }
+ } else {
+ if (args[0].indexOf("@") > 0) {
+ user = getMappingValue(args[0].split("@")[0]);
+ domain = getMappingValue(args[0].split("@")[1]);
+ } else {
+ response = new RemoteManagerResponse("Usage: " + help.getSyntax());
+ return response;
+
+ }
+ }
+
+ try {
+ Collection mappings = vutManagement.getUserDomainMappings(table, user, domain);
+ if (mappings == null) {
+ response = new RemoteManagerResponse("No mappings found");
+ } else {
+ response = new RemoteManagerResponse("Mappings:");
+
+ Iterator m = mappings.iterator();
+ while (m.hasNext()) {
+ response.appendLine(m.next().toString());
+ }
+ }
+ } catch (VirtualUserTableManagementException e) {
+ session.getLogger().error("Error on listing mapping: " + e);
+ response = new RemoteManagerResponse("Error on listing mapping: " + e);
+ } catch (IllegalArgumentException e) {
+ session.getLogger().error("Error on listing mapping: " + e);
+ response = new RemoteManagerResponse("Error on listing mapping: " + e);
+ }
+ }
+
+ return response;
+
+ }
+
+ /**
+ * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+ */
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListMatchersCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListMatchersCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListMatchersCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListMatchersCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+public class ListMatchersCmdHandler extends ShowMatcherInfoCmdHandler {
+
+ private final static String COMMAND_NAME = "LISTMATCHERS";
+ private CommandHelp help = new CommandHelp("listmatchers [processorname]","list names of all matchers for specified processor");
+
+ @Override
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+ @Override
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+ @Override
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String params) {
+ RemoteManagerResponse response = null;
+ if (params == null || !processorExists(params)) {
+ response = new RemoteManagerResponse("Usage: " + getHelp().getSyntax());
+ response.appendLine("The list of valid processor names can be retrieved using command LISTPROCESSORS");
+ return response;
+ }
+ String[] matcherNames = processorManagementService.getMatcherNames(params);
+ response = new RemoteManagerResponse("Existing matchers in processor: " + matcherNames.length);
+ for (int i = 0; i < matcherNames.length; i++) {
+ response.appendLine((i + 1) + ". " + matcherNames[i]);
+ }
+ return response;
+ }
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListProcessorsCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListProcessorsCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListProcessorsCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListProcessorsCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,63 @@
+package org.apache.james.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.management.ProcessorManagementService;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+public class ListProcessorsCmdHandler implements CommandHandler{
+
+ private final static String COMMAND_NAME = "LISTPROCESSORS";
+ private CommandHelp help = new CommandHelp("listprocessors [processorname]","list names of all processors");
+
+ protected ProcessorManagementService processorManagementService;
+
+
+ /**
+ * Set the ProcessorManagementService
+ *
+ * @param processorManagement the ProcessorManagementService
+ */
+ @Resource(name="processormanagement")
+
+ public final void setProcessorManagement(ProcessorManagementService processorManagement) {
+ this.processorManagementService = processorManagement;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+ */
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession, java.lang.String, java.lang.String)
+ */
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String params) {
+ RemoteManagerResponse response = null;
+ String[] processorNames = processorManagementService.getProcessorNames();
+ response = new RemoteManagerResponse("Existing processors: " + processorNames.length);
+ for (int i = 0; i < processorNames.length; i++) {
+ response.appendLine("\t" + processorNames[i]);
+ }
+ return response;
+ }
+
+ /**
+ * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListSpoolCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListSpoolCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListSpoolCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListSpoolCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,132 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.management.SpoolFilter;
+import org.apache.james.management.SpoolManagementService;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+/**
+ * Handler called upon receipt of a LISTSPOOL command
+ */
+public class ListSpoolCmdHandler implements CommandHandler {
+
+
+
+ private final static String COMMAND_NAME = "LISTSPOOL";
+ private CommandHelp help = new CommandHelp("listspool [spoolrepositoryname] ([header=name] [regex=value])","list all mails which reside in the spool and have an error state");
+ private SpoolManagementService spoolManagement;
+
+ /**
+ * Set the SpoolManagementService
+ *
+ * @param spoolManagement
+ * the SpoolManagementService
+ */
+ @Resource(name = "spoolmanagement")
+ public final void setSpoolManagement(SpoolManagementService spoolManagement) {
+ this.spoolManagement = spoolManagement;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+ */
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession,
+ * java.lang.String, java.lang.String)
+ */
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+ RemoteManagerResponse response;
+ int count = 0;
+ String[] args = null;
+ String headername = null;
+ String regex = null;
+
+ if (parameters != null)
+ args = parameters.split(" ");
+
+ // check if the command was called correct
+ if ((parameters == null) || (parameters.trim().equals("")) || args.length < 1 || args.length > 3 || (args.length > 1 && !args[1].startsWith(RemoteManagerSession.HEADER_IDENTIFIER))
+ || (args.length > 2 && !args[2].startsWith(RemoteManagerSession.REGEX_IDENTIFIER))) {
+ response = new RemoteManagerResponse("Usage: " + help.getSyntax());
+ return response;
+ }
+
+ String url = args[0];
+
+ if (args.length > 1) {
+ headername = args[1].substring(RemoteManagerSession.HEADER_IDENTIFIER.length());
+ regex = args[2].substring(RemoteManagerSession.REGEX_IDENTIFIER.length());
+ }
+
+ try {
+ List spoolItems;
+
+ if (headername == null || regex == null) {
+ spoolItems = spoolManagement.getSpoolItems(url, SpoolFilter.ERRORMAIL_FILTER);
+ } else {
+ spoolItems = spoolManagement.getSpoolItems(url, new SpoolFilter(SpoolFilter.ERROR_STATE, headername, regex));
+ }
+
+ count = spoolItems.size();
+ if (count > 0) {
+ response = new RemoteManagerResponse("Messages in spool:");
+ for (Iterator iterator = spoolItems.iterator(); iterator.hasNext();) {
+ String item = (String) iterator.next();
+ response.appendLine(item);
+ }
+ response.appendLine("Number of spooled mails: " + count);
+ } else {
+ response = new RemoteManagerResponse("Number of spooled mails: " + count);
+
+ }
+
+ } catch (Exception e) {
+ response = new RemoteManagerResponse("Error opening the spoolrepository " + e.getMessage());
+
+ session.getLogger().error("Error opening the spoolrepository " + e.getMessage());
+ }
+ return response;
+ }
+
+ /**
+ * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListUsersCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListUsersCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListUsersCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ListUsersCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,127 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.api.user.UsersStore;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+import org.apache.james.services.MailServer;
+
+public class ListUsersCmdHandler implements CommandHandler{
+
+ private final static String COMMAND_NAME = "LISTUSERS";
+ private CommandHelp help = new CommandHelp("listusers","display existing accounts");
+
+ protected UsersStore uStore;
+ protected MailServer mailServer;
+
+ /**
+ * Sets the users store.
+ *
+ * @param users
+ * the users to set
+ */
+ @Resource(name = "users-store")
+ public final void setUsers(UsersStore uStore) {
+ this.uStore = uStore;
+ }
+
+
+ /**
+ * Sets the mail server.
+ * @param mailServer the mailServer to set
+ */
+ @Resource(name="James")
+ public final void setMailServer(MailServer mailServer) {
+ this.mailServer = mailServer;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+ */
+ public CommandHelp getHelp() {
+ return help;
+ }
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+ RemoteManagerResponse response;
+ UsersRepository users = uStore.getRepository(((String) session.getState().get(RemoteManagerSession.CURRENT_USERREPOSITORY)));
+
+ if (parameters == null) {
+ response = new RemoteManagerResponse("Existing accounts " + users.countUsers());
+ for (Iterator it = users.list(); it.hasNext();) {
+ response.appendLine("user: " + (String) it.next());
+ }
+ return response;
+ } else {
+ if(mailServer.supportVirtualHosting() == false) {
+ response = new RemoteManagerResponse("Virtualhosting not supported");
+ return response;
+ }
+
+ ArrayList userList = getDomainUserList(users,parameters);
+ response = new RemoteManagerResponse("Existing accounts from domain " + parameters + " " + userList.size());
+ for (int i = 0; i <userList.size(); i++) {
+ response.appendLine("user: " + userList.get(i));
+ }
+ return response;
+ }
+ }
+
+ /**
+ * Return an ArrayList which contains all usernames for the given domain
+ *
+ * @param domain the domain
+ * @return ArrayList which contains the users
+ */
+ protected ArrayList getDomainUserList(UsersRepository users, String domain) {
+ ArrayList userList = new ArrayList();
+
+ for (Iterator it = users.list(); it.hasNext();) {
+ String user = (String) it.next();
+ if (user.endsWith(domain)) {
+ userList.add(user);
+ }
+ }
+
+ return userList;
+ }
+
+
+ /**
+ * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/MemStatCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/MemStatCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/MemStatCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/MemStatCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,60 @@
+package org.apache.james.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+/**
+ * Handler called upon receipt of an MEMSTAT command.
+ *
+ */
+public class MemStatCmdHandler implements CommandHandler {
+ private CommandHelp help = new CommandHelp("memstat ([-gc])","shows memory usage. When called with -gc the garbage collector get called");
+
+ public final static String COMMAND_NAME = "MEMSTAT";
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession,
+ * java.lang.String, java.lang.String)
+ */
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+ RemoteManagerResponse response = new RemoteManagerResponse("Current memory statistics:");
+ response.appendLine("\tFree Memory: " + Runtime.getRuntime().freeMemory());
+ response.appendLine("\tTotal Memory: " + Runtime.getRuntime().totalMemory());
+ response.appendLine("\tMax Memory: " + Runtime.getRuntime().maxMemory());
+
+ if ("-gc".equalsIgnoreCase(parameters)) {
+ System.gc();
+ response.appendLine("And after System.gc():");
+ response.appendLine("\tFree Memory: " + Runtime.getRuntime().freeMemory());
+ response.appendLine("\tTotal Memory: " + Runtime.getRuntime().totalMemory());
+ response.appendLine("\tMax Memory: " + Runtime.getRuntime().maxMemory());
+ }
+
+ return response;
+ }
+
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+ */
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/MoveMailsCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/MoveMailsCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/MoveMailsCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/MoveMailsCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,135 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.management.SpoolFilter;
+import org.apache.james.management.SpoolManagementService;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+/**
+ * Handler called upon receipt of a MOVEMAILS command
+ */
+public class MoveMailsCmdHandler implements CommandHandler {
+
+ private final static String COMMAND_NAME = "MOVEMAILS";
+ private CommandHelp help = new CommandHelp(
+ "movemails [srcSpoolrepositoryname] [dstSpoolrepositoryname] ([header=headername] [regex=regexValue]) [srcstate=sourcestate] [dststate=destinationstate]",
+ "move mails from the source repository to the destination repository");
+ private SpoolManagementService spoolManagement;
+
+ /**
+ * Set the SpoolManagementService
+ *
+ * @param spoolManagement
+ * the SpoolManagementService
+ */
+ @Resource(name = "spoolmanagement")
+ public final void setSpoolManagement(SpoolManagementService spoolManagement) {
+ this.spoolManagement = spoolManagement;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+ */
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession,
+ * java.lang.String, java.lang.String)
+ */
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+ RemoteManagerResponse response;
+ String[] args = null;
+
+ if (parameters != null)
+ args = parameters.split(" ");
+
+ // check if the command was called correct
+ if ((parameters == null || parameters.trim().equals("")) || (args.length < 2 || args.length > 6)) {
+ response = new RemoteManagerResponse("Usage: " + help.getSyntax());
+ }
+
+ String srcUrl = args[0];
+ String dstUrl = args[1];
+
+ String dstState = null;
+ String srcState = null;
+ String header = null;
+ String regex = null;
+
+ for (int i = 2; i < args.length; i++) {
+ if (args[i].startsWith(RemoteManagerSession.HEADER_IDENTIFIER)) {
+ header = args[i].substring(RemoteManagerSession.HEADER_IDENTIFIER.length());
+ } else if (args[i].startsWith(RemoteManagerSession.REGEX_IDENTIFIER)) {
+ header = args[i].substring(RemoteManagerSession.REGEX_IDENTIFIER.length());
+ } else if (args[i].startsWith("srcstate=")) {
+ header = args[i].substring("srcstate=".length());
+ } else if (args[i].startsWith("dststate=")) {
+ header = args[i].substring("dststate=".length());
+ } else {
+ response = new RemoteManagerResponse("Unexpected parameter " + args[i]);
+ response.appendLine("Usage: " + help.getSyntax());
+ return response;
+ }
+ }
+
+ if ((header != null && regex == null) || (header == null && regex != null)) {
+ if (regex == null) {
+ response = new RemoteManagerResponse("Bad parameters: used header without regex");
+ } else {
+ response = new RemoteManagerResponse("Bad parameters: used regex without header");
+ }
+ response.appendLine("Usage: " + help.getSyntax());
+ return response;
+ }
+
+ try {
+ int count = spoolManagement.moveSpoolItems(srcUrl, dstUrl, dstState, new SpoolFilter(srcState, header, regex));
+
+ response = new RemoteManagerResponse("Number of moved mails: " + count);
+
+ } catch (Exception e) {
+ response = new RemoteManagerResponse("Error opening the spoolrepository " + e.getMessage());
+
+ session.getLogger().error("Error opeing the spoolrepository " + e.getMessage());
+ }
+ return response;
+ }
+
+ /**
+ * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/QuitCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/QuitCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/QuitCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/QuitCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+public class QuitCmdHandler implements CommandHandler {
+ public final static String COMMAND_NAME = "QUIT";
+ private CommandHelp help = new CommandHelp("quit","close connection");
+
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession,
+ * java.lang.String, java.lang.String)
+ */
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+ RemoteManagerResponse response = new RemoteManagerResponse("Bye");
+ response.setEndSession(true);
+ return response;
+ }
+
+ /**
+ * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+ */
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoteManagerCommandDispatcherLineHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoteManagerCommandDispatcherLineHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoteManagerCommandDispatcherLineHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoteManagerCommandDispatcherLineHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,136 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.LineHandler;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+import org.apache.james.socket.AbstractCommandDispatcher;
+import org.apache.james.socket.LogEnabled;
+
+public class RemoteManagerCommandDispatcherLineHandler extends AbstractCommandDispatcher<CommandHandler> implements LineHandler, LogEnabled{
+ /** This log is the fall back shared by all instances */
+ private static final Log FALLBACK_LOG = LogFactory
+ .getLog(RemoteManagerCommandDispatcherLineHandler.class);
+ private UnknownCmdHandler unknownCmdHandler = new UnknownCmdHandler();
+ /**
+ * Non context specific log should only be used when no context specific log
+ * is available
+ */
+ private Log serviceLog = FALLBACK_LOG;
+
+ /**
+ * @see org.apache.james.socket.AbstractCommandDispatcher#getLog()
+ */
+ protected Log getLog() {
+ return serviceLog;
+ }
+
+ /**
+ * @see org.apache.james.socket.AbstractCommandDispatcher#getMandatoryCommands()
+ */
+ protected List<String> getMandatoryCommands() {
+ return new ArrayList<String>();
+ }
+
+ /**
+ * @see org.apache.james.socket.AbstractCommandDispatcher#getUnknownCommandHandler()
+ */
+ protected CommandHandler getUnknownCommandHandler() {
+ return unknownCmdHandler;
+ }
+
+
+ /**
+ * (non-Javadoc)
+ * @see org.apache.james.socket.AbstractCommandDispatcher#getUnknownCommandHandlerIdentifier()
+ */
+ protected String getUnknownCommandHandlerIdentifier() {
+ return UnknownCmdHandler.COMMAND_NAME;
+ }
+
+ /**
+ * (non-Javadoc)
+ * @see org.apache.james.socket.ExtensibleHandler#getMarkerInterfaces()
+ */
+ @SuppressWarnings("unchecked")
+ public List<Class<?>> getMarkerInterfaces() {
+ List mList = new ArrayList();
+ mList.add(CommandHandler.class);
+ return mList;
+ }
+ /**
+ * @see org.apache.james.socket.LogEnabled#setLog(org.apache.commons.logging.Log)
+ */
+ public void setLog(Log log) {
+ this.serviceLog = log;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.LineHandler#onLine(org.apache.james.remotemanager.RemoteManagerSession, java.lang.String)
+ */
+ public void onLine(RemoteManagerSession session, String cmdString) {
+ String curCommandName = null;
+ String curCommandArgument = null;
+ if (cmdString == null) {
+ }
+ int spaceIndex = cmdString.indexOf(" ");
+ if (spaceIndex > 0) {
+ curCommandName = cmdString.substring(0, spaceIndex);
+ curCommandArgument = cmdString.substring(spaceIndex + 1);
+ } else {
+ curCommandName = cmdString;
+ }
+ curCommandName = curCommandName.toUpperCase(Locale.US);
+
+ if (session.getLogger().isDebugEnabled()) {
+ session.getLogger().debug("Command received: " + cmdString);
+ }
+
+ // fetch the command handlers registered to the command
+ List<CommandHandler> commandHandlers = getCommandHandlers(
+ curCommandName, session);
+ if (commandHandlers == null) {
+ // end the session
+ RemoteManagerResponse resp = new RemoteManagerResponse( "Local configuration error: unable to find a command handler.");
+ resp.setEndSession(true);
+ session.writeRemoteManagerResponse(resp);
+ } else {
+ int count = commandHandlers.size();
+ for (int i = 0; i < count; i++) {
+ RemoteManagerResponse response = commandHandlers.get(i).onCommand(
+ session, curCommandName, curCommandArgument);
+ if (response != null) {
+ session.writeRemoteManagerResponse(response);
+ break;
+ }
+ }
+
+ }
+ }
+
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoveDomainCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoveDomainCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoveDomainCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoveDomainCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,92 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.management.DomainListManagementException;
+import org.apache.james.management.DomainListManagementService;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+/**
+ * Handler which is called when a REMOVEDOMAIN command is dispatched
+ *
+ */
+public class RemoveDomainCmdHandler implements CommandHandler{
+
+ private final static String COMMAND_NAME = "REMOVEDOMAIN";
+ private CommandHelp help = new CommandHelp("removedomain [domainname]","remove domain from local domains");
+
+ private DomainListManagementService domService;
+
+ @Resource(name="domainlistmanagement")
+ public final void setDomainListManagement(DomainListManagementService domService) {
+ this.domService = domService;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+ */
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession, java.lang.String, java.lang.String)
+ */
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+ RemoteManagerResponse response = null;
+ // check if the command was called correct
+ if (parameters == null) {
+ response = new RemoteManagerResponse("Usage: REMOVEDOMAIN domain");
+ return response;
+ }
+
+ try {
+ if(domService.removeDomain(parameters)) {
+ response = new RemoteManagerResponse("Removing domain " + parameters + " successful");
+
+ } else {
+ response = new RemoteManagerResponse("Removing domain " + parameters + " fail");
+ }
+ } catch (DomainListManagementException e) {
+ session.getLogger().error("Error on removing domain: " + e);
+ response = new RemoteManagerResponse("Error on removing domain: " + e);
+ }
+ return response;
+ }
+
+ /**
+ * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoveMappingCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoveMappingCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoveMappingCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoveMappingCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,78 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.james.api.vut.management.VirtualUserTableManagementException;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+public class RemoveMappingCmdHandler extends AbstractMappingCmdHandler {
+ private CommandHelp help = new CommandHelp("removemapping ([table=virtualusertablename]) [user@domain] [mapping]","remove mapping for the given emailaddress");
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession,
+ * java.lang.String, java.lang.String)
+ */
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+ RemoteManagerResponse response;
+ String[] args = null;
+
+ if (parameters != null)
+ args = parameters.split(" ");
+
+ // check if the command was called correct
+ if (parameters == null || parameters.trim().equals("") || args.length < 2 || args.length > 3) {
+ response = new RemoteManagerResponse("Usage: " + help.getSyntax());
+ } else {
+ try {
+ response = new RemoteManagerResponse("Removing mapping successful: " + mappingAction(args, REMOVE_MAPPING_ACTION));
+ } catch (VirtualUserTableManagementException e) {
+ session.getLogger().error("Error on removing mapping: " + e);
+ response = new RemoteManagerResponse("Error on removing mapping: " + e);
+ } catch (IllegalArgumentException e) {
+ session.getLogger().error("Error on removing mapping: " + e);
+ response = new RemoteManagerResponse("Error on removing mapping: " + e);
+ }
+ }
+ return response;
+ }
+
+ /**
+ * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(REMOVE_MAPPING_ACTION);
+ return commands;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+ */
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ResetBayesianDataCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ResetBayesianDataCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ResetBayesianDataCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ResetBayesianDataCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,89 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.management.BayesianAnalyzerManagementException;
+import org.apache.james.management.BayesianAnalyzerManagementService;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+public class ResetBayesianDataCmdHandler implements CommandHandler{
+ private final static String COMMAND_NAME = "RESETBAYESIANDATA";
+ private CommandHelp help = new CommandHelp("resetbayesiandata","reset trained BayesianAnalysis data");
+
+ private BayesianAnalyzerManagementService bayesianAnalyzerManagement;
+
+ /**
+ * Set the BayesianAnalyzerManagementService
+ *
+ * @param bayesianAnalyzerManagement the BayesianAnalyzerManagementService
+ */
+ @Resource(name="bayesiananalyzermanagement")
+ public final void setBayesianAnalyzerManagement(BayesianAnalyzerManagementService bayesianAnalyzerManagement) {
+ this.bayesianAnalyzerManagement = bayesianAnalyzerManagement;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+ */
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession, java.lang.String, java.lang.String)
+ */
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+ RemoteManagerResponse response;
+ try {
+ // stop watchdog cause feeding can take some time
+ session.getWatchdog().stop();
+
+ bayesianAnalyzerManagement.resetData();
+ response = new RemoteManagerResponse("Reseted the BayesianAnalysis data");
+
+ } catch (BayesianAnalyzerManagementException e) {
+ session.getLogger().error("Error on reseting BayesianAnalysis data: " + e);
+ response = new RemoteManagerResponse("Error on reseting BayesianAnalysis data: " + e);
+ } finally {
+ session.getWatchdog().start();
+ }
+
+ return response;
+ }
+
+
+ /**
+ * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/SetAliasCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/SetAliasCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/SetAliasCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/SetAliasCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,133 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.api.user.JamesUser;
+import org.apache.james.api.user.User;
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.api.user.UsersStore;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+/**
+ * Handler called upon receipt of an SETALIAS command.
+ *
+ */
+public class SetAliasCmdHandler implements CommandHandler{
+ public final static String COMMAND_NAME = "SETALIAS";
+ private CommandHelp help = new CommandHelp("setalias [user] [alias]","locally forwards all email for 'user' to 'alias'");
+
+ private UsersStore uStore;
+
+ /**
+ * Sets the users store.
+ *
+ * @param users
+ * the users to set
+ */
+ @Resource(name = "users-store")
+ public final void setUsers(UsersStore uStore) {
+ this.uStore = uStore;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+ */
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession, java.lang.String, java.lang.String)
+ */
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+ RemoteManagerResponse response;
+ int breakIndex = -1;
+ if ((parameters == null) ||
+ (parameters.equals("")) ||
+ ((breakIndex = parameters.indexOf(" ")) < 0)) {
+ response = new RemoteManagerResponse("Usage: " + help.getSyntax());
+ return response;
+ }
+ String username = parameters.substring(0,breakIndex);
+ String alias = parameters.substring(breakIndex + 1);
+ if (username.equals("") || alias.equals("")) {
+ response = new RemoteManagerResponse("Usage: " + help.getSyntax());
+ return response;
+ }
+ UsersRepository users = uStore.getRepository((String) session.getState().get(RemoteManagerSession.CURRENT_USERREPOSITORY));
+
+ User baseuser = users.getUserByName(username);
+ if (baseuser == null) {
+ response = new RemoteManagerResponse("No such user " + username);
+ return response;
+ }
+ if (! (baseuser instanceof JamesUser ) ) {
+ response = new RemoteManagerResponse("Can't set alias for this user type.");
+ return response;
+ }
+
+
+ JamesUser user = (JamesUser) baseuser;
+ JamesUser aliasUser = (JamesUser) users.getUserByName(alias);
+ if (aliasUser == null) {
+ response = new RemoteManagerResponse("Alias unknown to server - create that user first.");
+ return response;
+ }
+
+ boolean success = user.setAlias(alias);
+ if (success) {
+ user.setAliasing(true);
+ users.updateUser(user);
+ StringBuilder responseBuffer =
+ new StringBuilder(64)
+ .append("Alias for ")
+ .append(username)
+ .append(" set to:")
+ .append(alias);
+ String responseString = responseBuffer.toString();
+ response = new RemoteManagerResponse(responseString);
+ session.getLogger().info(responseString);
+ } else {
+ response = new RemoteManagerResponse("Error setting alias");
+ session.getLogger().error("Error setting alias");
+ }
+ return response;
+ }
+
+ /**
+ * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/SetForwardingCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/SetForwardingCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/SetForwardingCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/SetForwardingCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,119 @@
+package org.apache.james.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Resource;
+import javax.mail.internet.ParseException;
+
+import org.apache.james.api.user.JamesUser;
+import org.apache.james.api.user.User;
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.api.user.UsersStore;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+import org.apache.mailet.MailAddress;
+
+/**
+ * Handler called upon receipt of an SETFORWARDING command
+ *
+ */
+public class SetForwardingCmdHandler implements CommandHandler{
+
+ private final static String COMMAND_NAME = "SETFORWARDING";
+ private CommandHelp help = new CommandHelp("setforwarding [username] [emailaddress]","forwards a user's email to another email address");
+
+ private UsersStore uStore;
+
+ /**
+ * Sets the users store.
+ *
+ * @param users
+ * the users to set
+ */
+ @Resource(name = "users-store")
+ public final void setUsers(UsersStore uStore) {
+ this.uStore = uStore;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+ */
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession, java.lang.String, java.lang.String)
+ */
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+ RemoteManagerResponse response;
+ int breakIndex = -1;
+ if ((parameters == null) ||
+ (parameters.equals("")) ||
+ ((breakIndex = parameters.indexOf(" ")) < 0)) {
+ response = new RemoteManagerResponse("Usage: " + help.getSyntax());
+ return response;
+ }
+ String username = parameters.substring(0,breakIndex);
+ String forward = parameters.substring(breakIndex + 1);
+ if (username.equals("") || forward.equals("")) {
+ response = new RemoteManagerResponse("Usage: " + help.getSyntax());
+ return response;
+ }
+ UsersRepository users = uStore.getRepository((String) session.getState().get(RemoteManagerSession.CURRENT_USERREPOSITORY));
+
+ // Verify user exists
+ User baseuser = users.getUserByName(username);
+ if (baseuser == null) {
+ response = new RemoteManagerResponse("No such user " + username);
+ return response;
+ } else if (! (baseuser instanceof JamesUser ) ) {
+ response = new RemoteManagerResponse("Can't set forwarding for this user type.");
+ return response;
+ }
+ JamesUser user = (JamesUser)baseuser;
+ // Verify acceptable email address
+ MailAddress forwardAddr;
+ try {
+ forwardAddr = new MailAddress(forward);
+ } catch(ParseException pe) {
+ session.getLogger().error("Parse exception with that email address: ", pe);
+ response = new RemoteManagerResponse("Forwarding address not added for " + username);
+ return response;
+ }
+
+ boolean success = user.setForwardingDestination(forwardAddr);
+ if (success) {
+ user.setForwarding(true);
+ users.updateUser(user);
+ StringBuilder responseBuffer =
+ new StringBuilder(64)
+ .append("Forwarding destination for ")
+ .append(username)
+ .append(" set to:")
+ .append(forwardAddr.toString());
+ String responseString = responseBuffer.toString();
+ response = new RemoteManagerResponse(responseString);
+ session.getLogger().info(responseString);
+ } else {
+ response = new RemoteManagerResponse("Error setting forwarding");
+ session.getLogger().error("Error setting forwarding");
+ }
+ return response;
+ }
+
+
+ /**
+ * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/SetPasswordCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/SetPasswordCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/SetPasswordCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/SetPasswordCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,121 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.api.user.User;
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.api.user.UsersStore;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+
+/**
+ * Handler method called upon receipt of an SETPASSWORD command.
+ */
+public class SetPasswordCmdHandler implements CommandHandler{
+
+ private final static String COMMAND_NAME = "SETPASSWORD";
+ private CommandHelp help = new CommandHelp("setpassword [username] [password]","sets a user's password");
+
+ private UsersStore uStore;
+
+
+ /**
+ * Sets the users store.
+ * @param users the users to set
+ */
+ @Resource(name="users-store")
+ public final void setUsers(UsersStore uStore) {
+ this.uStore = uStore;
+ }
+
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+ */
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession, java.lang.String, java.lang.String)
+ */
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+ RemoteManagerResponse response = null;
+
+ int breakIndex = -1;
+ if ((parameters == null) ||
+ (parameters.equals("")) ||
+ ((breakIndex = parameters.indexOf(" ")) < 0)) {
+ response = new RemoteManagerResponse("Usage: " + getHelp().getSyntax());
+ return response;
+ }
+ String username = parameters.substring(0,breakIndex);
+ String passwd = parameters.substring(breakIndex + 1);
+
+ if (username.equals("") || passwd.equals("")) {
+ response = new RemoteManagerResponse("Usage: " + getHelp().getSyntax());
+ return response;
+ }
+
+ UsersRepository users = uStore.getRepository((String)session.getState().get(RemoteManagerSession.CURRENT_USERREPOSITORY));
+
+
+ User user = users.getUserByName(username);
+ if (user == null) {
+ response = new RemoteManagerResponse("No such user " + username);
+ return response;
+ }
+ boolean success = user.setPassword(passwd);
+ if (success) {
+ users.updateUser(user);
+ StringBuilder responseBuffer =
+ new StringBuilder(64)
+ .append("Password for ")
+ .append(username)
+ .append(" reset");
+ String responseString = responseBuffer.toString();
+ response = new RemoteManagerResponse(responseString);
+ session.getLogger().info(responseString);
+ } else {
+ response = new RemoteManagerResponse("Error resetting password");
+ session.getLogger().error("Error resetting password");
+ }
+ return response;
+ }
+
+ /**
+ * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowAliasCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowAliasCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowAliasCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowAliasCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,120 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.api.user.JamesUser;
+import org.apache.james.api.user.User;
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.api.user.UsersStore;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+/**
+ * Handler called upon receipt of an SHOWALIAS command.
+ *
+ */
+public class ShowAliasCmdHandler implements CommandHandler {
+
+ private final static String COMMAND_NAME = "SHOWALIAS";
+ private CommandHelp help = new CommandHelp("showalias [username]","shows a user's current email alias");
+
+ private UsersStore uStore;
+
+ /**
+ * Sets the users store.
+ *
+ * @param users
+ * the users to set
+ */
+ @Resource(name = "users-store")
+ public final void setUsers(UsersStore uStore) {
+ this.uStore = uStore;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+ */
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession, java.lang.String, java.lang.String)
+ */
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+ RemoteManagerResponse response;
+ if ( parameters == null || parameters.equals("") ) {
+ response = new RemoteManagerResponse("Usage: " + help.getSyntax());
+ return response;
+ }
+
+ UsersRepository users = uStore.getRepository((String) session.getState().get(RemoteManagerSession.CURRENT_USERREPOSITORY));
+
+ User baseuser = users.getUserByName(parameters);
+ if (baseuser == null) {
+ response = new RemoteManagerResponse("No such user " + parameters);
+ return response;
+ } else if (! (baseuser instanceof JamesUser ) ) {
+ response = new RemoteManagerResponse("Can't show aliases for this user type.");
+ return response;
+ }
+
+ JamesUser user = (JamesUser)baseuser;
+ if ( user == null ) {
+ response = new RemoteManagerResponse("No such user " + parameters);
+ return response;
+ }
+
+ if ( !user.getAliasing() ) {
+ response = new RemoteManagerResponse("User " + parameters + " does not currently have an alias");
+ return response;
+ }
+
+ String alias = user.getAlias();
+
+ if ( alias == null || alias.equals("") ) { // defensive programming -- neither should occur
+ String errmsg = "For user " + parameters + ", the system indicates that aliasing is set but no alias was found";
+ response = new RemoteManagerResponse(errmsg);
+ session.getLogger().error(errmsg);
+ return response;
+ }
+
+ response = new RemoteManagerResponse("Current alias for " + parameters + " is: " + alias);
+ return response;
+ }
+
+ /**
+ * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowForwardingCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowForwardingCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowForwardingCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowForwardingCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,120 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.api.user.JamesUser;
+import org.apache.james.api.user.User;
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.api.user.UsersStore;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+import org.apache.mailet.MailAddress;
+
+/**
+ * Handler called upon receipt of an SHOWFORWARDING command.
+ *
+ */
+public class ShowForwardingCmdHandler implements CommandHandler{
+
+ private final static String COMMAND_NAME = "SHOWFORWARDING";
+ private CommandHelp help = new CommandHelp("showforwarding [username]","shows a user's current email forwarding");
+
+ private UsersStore uStore;
+
+ /**
+ * Sets the users store.
+ *
+ * @param users
+ * the users to set
+ */
+ @Resource(name = "users-store")
+ public final void setUsers(UsersStore uStore) {
+ this.uStore = uStore;
+ }
+
+ /**
+ * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+ */
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+ RemoteManagerResponse response;
+ if ( parameters == null || parameters.equals("") ) {
+ response = new RemoteManagerResponse("Usage: " + help.getSyntax());
+ return response;
+ }
+
+ UsersRepository users = uStore.getRepository((String) session.getState().get(RemoteManagerSession.CURRENT_USERREPOSITORY));
+
+
+ // Verify user exists
+ User baseuser = users.getUserByName(parameters);
+ if (baseuser == null) {
+ response = new RemoteManagerResponse("No such user " + parameters);
+ return response;
+ } else if (! (baseuser instanceof JamesUser ) ) {
+ response = new RemoteManagerResponse("Can't set forwarding for this user type.");
+ return response;
+ }
+ JamesUser user = (JamesUser)baseuser;
+ if ( user == null ) {
+ response = new RemoteManagerResponse("No such user " + parameters);
+ return response;
+ }
+
+ if ( !user.getForwarding() ) {
+ response = new RemoteManagerResponse("User " + parameters + " is not currently being forwarded");
+ return response;
+ }
+
+ MailAddress fwdAddr = user.getForwardingDestination();
+
+ if ( fwdAddr == null ) { // defensive programming -- should not occur
+ String errmsg = "For user " + parameters + ", the system indicates that forwarding is set but no forwarding destination was found";
+ response = new RemoteManagerResponse(errmsg);
+ session.getLogger().error(errmsg);
+ return response;
+ }
+
+ response = new RemoteManagerResponse("Current forwarding destination for " + parameters + " is: " + fwdAddr);
+ return response;
+ }
+
+
+ /**
+ * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+}
Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowMailetInfoCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowMailetInfoCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowMailetInfoCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowMailetInfoCmdHandler.java Sun Oct 4 15:10:49 2009
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+public class ShowMailetInfoCmdHandler extends ShowMatcherInfoCmdHandler{
+
+ private final static String COMMAND_NAME = "SHOWMAILETINFO";
+ private CommandHelp help = new CommandHelp("showmailetinfo [processorname] [#index]","shows configuration for mailet of specified processor at given index");
+
+ @Override
+ public CommandHelp getHelp() {
+ return help;
+ }
+
+ @Override
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+ @Override
+ public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String params) {
+ RemoteManagerResponse response = null;
+ Object[] parameters = extractMailetInfoParameters(session,params, "MAILET");
+ if (parameters == null) return response;
+
+ // extract parsed parameters
+ String processorName = (String) parameters[0];
+ int index = ((Integer)parameters[1]).intValue();
+
+ String[] mailetParameters = null;
+ try {
+ mailetParameters = processorManagementService.getMailetParameters(processorName, index);
+ } catch (RuntimeException e) {
+ // fall thru with NULL
+ }
+ if (mailetParameters == null) {
+ response = new RemoteManagerResponse("The index is not referring to an existing mailet");
+ return response;
+ }
+ response = new RemoteManagerResponse("Mailet parameters: " + mailetParameters.length);
+ for (int i = 0; i < mailetParameters.length; i++) {
+ String parameter = (String) mailetParameters[i];
+ response.appendLine("\t" + parameter);
+ }
+ return response;
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org