Author: norman
Date: Sun Nov 19 13:15:24 2006
New Revision: 476925

URL: http://svn.apache.org/viewvc?view=rev&rev=476925
Log:
Add LISTMAPPING command to RemoteManager. Part of JAMES-706

Modified:
    
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java

Modified: 
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java?view=diff&rev=476925&r1=476924&r2=476925
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
 Sun Nov 19 13:15:24 2006
@@ -26,6 +26,7 @@
 import java.net.Socket;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
@@ -91,6 +92,7 @@
         "SHOWMATCHERINFO",
         "ADDMAPPING",
         "REMOVEMAPPING",
+        "LISTMAPPING",
         "QUIT",
         "SHUTDOWN"
     });
@@ -112,6 +114,7 @@
     private final static String ADD_MAPPING_ACTION = "ADD_MAPPING";
     private final static String REMOVE_MAPPING_ACTION = "REMOVE_MAPPING";
 
+    
     /**
      * Set the configuration data for the handler.
      *
@@ -505,6 +508,7 @@
         out.println("user [repositoryname]                                     
              change to another user repository");
         out.println("addmapping [table=virtualusertablename] [EMAIL PROTECTED] 
mapping             add mapping for the given emailaddress");
         out.println("removemapping [table=virtualusertablename] [EMAIL 
PROTECTED] mapping          remove mapping for the given emailaddress");
+        out.println("listmapping [table=virtualusertablename] [EMAIL 
PROTECTED]                    list all mappings for the given emailaddress");
         out.println("listspool [spoolrepositoryname] ([header=name] 
[regex=value])           list all mails which reside in the spool and have an 
error state");
         out.println("flushspool [spoolrepositoryname] ([key] | [header=name] 
[regex=value])  try to resend the mail assing to the given key. If no key is 
given all mails get resend");
         out.println("deletespool [spoolrepositoryname] ([key] | [header=name] 
[regex=value]) delete the mail assign to the given key. If no key is given all 
mails get deleted");
@@ -1461,6 +1465,66 @@
         }
         return true;
     }
+
+    private boolean doLISTMAPPING(String argument) {
+        String[] args = null;
+        String table = null;
+        String user = null;
+        String domain = null;
+
+        if (argument != null)
+            args = argument.split(" ");
+
+        // check if the command was called correct
+        if (argument == null || argument.trim().equals("") || args.length < 1 
|| args.length > 2) {
+            writeLoggedFlushedResponse("Usage: LISTMAPPING [table=table] 
[EMAIL PROTECTED]");
+            return true;
+        }
+
+        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 {
+            writeLoggedFlushedResponse("Usage: LISTMAPPING [table=table] 
[EMAIL PROTECTED]");
+                return true;
+            }
+        } else {
+            if (args[0].indexOf("@") > 0) {
+                user = getMappingValue(args[0].split("@")[0]);
+                domain = getMappingValue(args[0].split("@")[1]);
+            } else {
+            writeLoggedFlushedResponse("Usage: LISTMAPPING [table=table] 
[EMAIL PROTECTED]");
+                return true;
+            }
+        }
+        
+        try {
+            Collection mappings = 
theConfigData.getVirtualUserTableManagement().getUserDomainMappings(table, 
user, domain);
+            if (mappings == null) {
+                out.println("No mappings found");
+                out.flush();
+            } else {
+                out.println("Mappings:");
+                
+                Iterator m = mappings.iterator();
+                while(m.hasNext()) {
+                    out.println(m.next());
+                }
+                out.flush();
+            }
+        } catch (VirtualUserTableManagementException e) {
+            getLogger().error("Error on  removing mapping: " + e);
+            out.println("Error on removing mapping: " + e);
+            out.flush();
+        } catch (IllegalArgumentException e) {
+            getLogger().error("Error on removing mapping: " + e);
+            out.println("Error on removing mapping: " + e);
+            out.flush();
+        }
+        return true;
+    }
     
     private String getMappingValue(String raw) {
         if (raw.equals("*")) {
@@ -1494,6 +1558,7 @@
             }
             mapping = args[1];
         }
+        
         if (action.equals(ADD_MAPPING_ACTION)) {
             return 
theConfigData.getVirtualUserTableManagement().addMapping(table, user, domain, 
mapping);
         } else if (action.equals(REMOVE_MAPPING_ACTION)){



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to