Author: eric
Date: Tue Dec 28 14:41:50 2010
New Revision: 1053359

URL: http://svn.apache.org/viewvc?rev=1053359&view=rev
Log:
Skeleton for james 2.3 import - to be further discussed/developed for conf, 
packaging,... (JAMES-1052)

Added:
    
james/server/trunk/container-spring/src/main/config/james/importjames23-usersrepository.xml
    james/server/trunk/container-spring/src/main/config/james/importjames23.xml
    
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/tool/
    
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/tool/James23Importer.java
Modified:
    
james/server/trunk/container-spring/src/main/config/james/context/james-server-context.xml

Modified: 
james/server/trunk/container-spring/src/main/config/james/context/james-server-context.xml
URL: 
http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/config/james/context/james-server-context.xml?rev=1053359&r1=1053358&r2=1053359&view=diff
==============================================================================
--- 
james/server/trunk/container-spring/src/main/config/james/context/james-server-context.xml
 (original)
+++ 
james/server/trunk/container-spring/src/main/config/james/context/james-server-context.xml
 Tue Dec 28 14:41:50 2010
@@ -87,6 +87,13 @@
               <!-- no alias needed -->
               <value></value>
             </entry>
+            <entry>
+              <key>
+                <value>importjames23-usersrepository</value>
+              </key>
+<!--               no alias needed -->
+              <value></value>
+            </entry>
           </map>
         </property>
     </bean>
@@ -318,6 +325,11 @@
     <bean id="mailboxcopier" 
class="org.apache.james.mailbox.copier.MailboxCopierImpl"/>
           
     <!-- 
+      Mailbox Import
+     -->
+    <bean id="importjames23" 
class="org.apache.james.container.spring.tool.James23Importer"/>
+          
+    <!-- 
     ===========================================================================
        Database DataSource
     ===========================================================================

Added: 
james/server/trunk/container-spring/src/main/config/james/importjames23-usersrepository.xml
URL: 
http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/config/james/importjames23-usersrepository.xml?rev=1053359&view=auto
==============================================================================
--- 
james/server/trunk/container-spring/src/main/config/james/importjames23-usersrepository.xml
 (added)
+++ 
james/server/trunk/container-spring/src/main/config/james/importjames23-usersrepository.xml
 Tue Dec 28 14:41:50 2010
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+  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.                                           
+ -->
+<importjames23-usersrepository 
class="org.apache.james.user.file.UsersFileRepository">
+  <destination URL="file://var/users/" />
+  <ignoreCase>true</ignoreCase>
+  <enableAliases>true</enableAliases>
+  <enableForwarding>true</enableForwarding>
+  <enableVirtualHosting>false</enableVirtualHosting>
+</importjames23-usersrepository>

Added: 
james/server/trunk/container-spring/src/main/config/james/importjames23.xml
URL: 
http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/config/james/importjames23.xml?rev=1053359&view=auto
==============================================================================
--- james/server/trunk/container-spring/src/main/config/james/importjames23.xml 
(added)
+++ james/server/trunk/container-spring/src/main/config/james/importjames23.xml 
Tue Dec 28 14:41:50 2010
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!--
+  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.                                           
+ -->
+<importjames23>
+  <repositoryPath>file://var/mail/inboxes</repositoryPath>
+</importjames23>

Added: 
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/tool/James23Importer.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/tool/James23Importer.java?rev=1053359&view=auto
==============================================================================
--- 
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/tool/James23Importer.java
 (added)
+++ 
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/tool/James23Importer.java
 Tue Dec 28 14:41:50 2010
@@ -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.container.spring.tool;
+
+import java.util.Iterator;
+
+import javax.annotation.Resource;
+import javax.mail.MessagingException;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.james.lifecycle.api.Configurable;
+import org.apache.james.lifecycle.api.LogEnabled;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailrepository.api.MailRepository;
+import org.apache.james.mailrepository.api.MailRepositoryStore;
+import 
org.apache.james.mailrepository.api.MailRepositoryStore.MailRepostoryStoreException;
+import org.apache.james.user.api.UsersRepository;
+import org.apache.mailet.Mail;
+
+public class James23Importer implements Configurable, LogEnabled {
+    
+    /**
+     * The logger.
+     */
+    private Log log;
+    
+    /**
+     * The configuration.
+     */
+    private HierarchicalConfiguration config;
+
+    /**
+     * James 2.3 user repository defined by configuration.
+     */
+    @Resource(name = "importjames23-usersrepository")
+    private UsersRepository james23UsersRepository;
+    
+    /**
+     * James 3.0 users repository.
+     */
+    @Resource(name="usersrepository")
+    private UsersRepository usersRepository;
+
+    /**
+     * The mail repository store needed to select the james 2.3 mail 
repository.
+     */
+    @Resource(name="mailrepositorystore")
+    private MailRepositoryStore mailRepositoryStore;
+
+    /**
+     * The mailbox manager needed to copy the mails to.
+     */
+    @Resource(name="mailboxmanager")
+    private MailboxManager mailboxManager;
+
+    /**
+     * Copy 2.3 users to 3.0 users (taking virtualDomains into account)
+     * Copy 2.3 mails to 3.0 mails.
+     * 
+     * TODO: This is just a skeleton to talk about the architecture (conf,...)
+     * 
+     * @throws MailRepostoryStoreException
+     * @throws MessagingException
+     */
+    public void importFromJames23() throws MailRepostoryStoreException, 
MessagingException {
+        
+        String james23MailRepositoryPath = config.getString("repositoryPath");
+        
+        Iterator<String> j23uIt = james23UsersRepository.list();
+        
+        while (j23uIt.hasNext()) {
+            String user = j23uIt.next();
+            System.out.println("James 2.3 user:" + user);
+            MailRepository mailRepository = 
mailRepositoryStore.select(james23MailRepositoryPath + "/" + user);
+            Iterator<String> sr = mailRepository.list();
+            while (sr.hasNext()) {
+                Mail mail = mailRepository.retrieve(sr.next());
+                System.out.println(mail.getMessage().getSubject() 
+                        + ": " + mail.getMessage().getSize() 
+                        + " - " + mail.getMessage().getLineCount());
+            }
+        }
+        
+    }
+
+    /* (non-Javadoc)
+     * @see 
org.apache.james.lifecycle.api.LogEnabled#setLog(org.apache.commons.logging.Log)
+     */
+    public void setLog(Log log) {
+        this.log = log;
+    }
+
+    /* (non-Javadoc)
+     * @see 
org.apache.james.lifecycle.api.Configurable#configure(org.apache.commons.configuration.HierarchicalConfiguration)
+     */
+    public void configure(HierarchicalConfiguration config) throws 
ConfigurationException {
+        this.config = config;
+    }
+    
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to