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 rd...@apache.org on 2008/11/21 16:06:09 UTC
svn commit: r719593 - in /james/server/trunk:
imapserver-function/src/main/java/org/apache/james/imapserver/
imapserver-function/src/main/java/org/apache/james/imapserver/sieve/
imapserver-function/src/main/resources/org/apache/james/imapserver/ phoeni...
Author: rdonkin
Date: Fri Nov 21 07:06:08 2008
New Revision: 719593
URL: http://svn.apache.org/viewvc?rev=719593&view=rev
Log:
Revised design for supporting Sieve mailet. ImapServer now exports the Sieve API. A specialist subclass - org.apache.james.imapserver.sieve.SieveMailet - adapts the sieve mailet for James. This seems a little clumsy. A more elegant solution would be to use AspetJ to enhance to class.
Added:
james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/sieve/SieveMailet.java
Removed:
james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/sieve/PosterMailboxAdapter.java
Modified:
james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/DefaultImapFactory.java
james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java
james/server/trunk/imapserver-function/src/main/resources/org/apache/james/imapserver/ImapServer.xinfo
james/server/trunk/phoenix-deployment/build.xml
james/server/trunk/stage/org.apache.james/jars/apache-jsieve-0.3-SNAPSHOT.jar
james/server/trunk/stage/org.apache.james/jars/apache-jsieve-mailet-0.3-SNAPSHOT.jar
Modified: james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/DefaultImapFactory.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/DefaultImapFactory.java?rev=719593&r1=719592&r2=719593&view=diff
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/DefaultImapFactory.java (original)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/DefaultImapFactory.java Fri Nov 21 07:06:08 2008
@@ -32,6 +32,7 @@
import org.apache.james.mailboxmanager.torque.DefaultMailboxManagerProvider;
import org.apache.james.mailboxmanager.torque.DefaultMailboxManager;
import org.apache.james.mailboxmanager.torque.DefaultUserManager;
+import org.apache.james.mailboxmanager.manager.MailboxManagerProvider;
import org.apache.james.services.FileSystem;
import org.apache.james.user.impl.file.FileUserMetaDataRepository;
@@ -40,15 +41,16 @@
private final ImapEncoder encoder;
private final ImapDecoder decoder;
private final ImapProcessor processor;
+ private final MailboxManagerProvider mailbox;
public DefaultImapFactory(FileSystem fileSystem, UsersRepository users, Logger logger) {
super();
decoder = new DefaultImapDecoderFactory().buildImapDecoder();
encoder = new DefaultImapEncoderFactory().buildImapEncoder();
- processor = DefaultImapProcessorFactory.createDefaultProcessor(
- new DefaultMailboxManagerProvider(
- new DefaultMailboxManager(new DefaultUserManager(
- new FileUserMetaDataRepository("var/users"), users), fileSystem, logger)));
+ mailbox = new DefaultMailboxManagerProvider(
+ new DefaultMailboxManager(new DefaultUserManager(
+ new FileUserMetaDataRepository("var/users"), users), fileSystem, logger));
+ processor = DefaultImapProcessorFactory.createDefaultProcessor(mailbox);
}
@@ -57,4 +59,12 @@
{
return new ImapRequestHandler(decoder, processor, encoder);
}
+
+ /**
+ * This is required until James supports IoC assembly.
+ * @return the mailbox
+ */
+ public final MailboxManagerProvider getMailbox() {
+ return mailbox;
+ }
}
Modified: james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java?rev=719593&r1=719592&r2=719593&view=diff
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java (original)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java Fri Nov 21 07:06:08 2008
@@ -19,6 +19,11 @@
package org.apache.james.imapserver;
+import java.util.Date;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.service.ServiceException;
@@ -28,9 +33,14 @@
import org.apache.james.api.user.UsersRepository;
import org.apache.james.imap.main.ImapRequestHandler;
import org.apache.james.imapserver.DefaultImapFactory;
+import org.apache.james.mailboxmanager.MailboxSession;
+import org.apache.james.mailboxmanager.mailbox.Mailbox;
+import org.apache.james.mailboxmanager.manager.MailboxManager;
+import org.apache.james.mailboxmanager.manager.MailboxManagerProvider;
import org.apache.james.services.FileSystem;
import org.apache.james.socket.AbstractJamesService;
import org.apache.james.socket.ProtocolHandler;
+import org.apache.jsieve.mailet.Poster;
/**
* TODO: this is a quick cut-and-paste hack from POP3Server. Should probably be
@@ -40,7 +50,7 @@
*
* <p>Also responsible for loading and parsing IMAP specific configuration.</p>
*/
-public class ImapServer extends AbstractJamesService implements ImapConstants
+public class ImapServer extends AbstractJamesService implements ImapConstants, Poster
{
private static final String softwaretype = "JAMES "+VERSION+" Server " + Constants.SOFTWARE_VERSION;
@@ -103,4 +113,71 @@
protected Object getConfigurationData() {
return null;
}
+
+ public void post(String url, MimeMessage mail)throws MessagingException {
+ final int endOfScheme = url.indexOf(':');
+ if (endOfScheme < 0) {
+ throw new MessagingException("Malformed URI");
+ } else {
+ final String scheme = url.substring(0, endOfScheme);
+ if ("mailbox".equals(scheme)) {
+ final int startOfUser = endOfScheme + 2;
+ final int endOfUser = url.indexOf('@', startOfUser);
+ if (endOfUser < 0) {
+ // TODO: when user missing, append to a default location
+ throw new MessagingException("Shared mailbox is not supported");
+ } else {
+ final String user = url.substring(startOfUser, endOfUser);
+ final int startOfHost = endOfUser + 1;
+ final int endOfHost = url.indexOf('/', startOfHost);
+ final String host = url.substring(startOfHost, endOfHost);
+ if (!"localhost".equals(host)) {
+ //TODO: possible support for clustering?
+ throw new MessagingException("Only local mailboxes are supported");
+ } else {
+ final String urlPath;
+ final int length = url.length();
+ if (endOfHost == length) {
+ urlPath = "INBOX";
+ } else {
+ urlPath = url.substring(endOfHost, length);
+ }
+ // This allows Sieve scripts to use a standard delimiter regardless of mailbox implementation
+ final String mailbox = urlPath.replace('/', MailboxManager.HIERARCHY_DELIMITER);
+ postToMailbox(user, mail, mailbox);
+ }
+ }
+ } else {
+ // TODO: add support for more protocols
+ // TODO: for example mailto: for forwarding over SMTP
+ // TODO: for example xmpp: for forwarding over Jabber
+ throw new MessagingException("Unsupported protocol");
+ }
+ }
+ }
+
+ public void postToMailbox(String username, MimeMessage mail, String destination) throws MessagingException {
+ final MailboxManagerProvider mailboxManagerProvider = factory.getMailbox();
+ if (destination == null || "".equals(destination)) {
+ destination = "INBOX";
+ }
+ final String name = mailboxManagerProvider.getMailboxManager().resolve(username, destination);
+ final MailboxManager mailboxManager = mailboxManagerProvider.getMailboxManager();
+ final MailboxSession session = mailboxManager.createSession();
+ try
+ {
+ final Mailbox mailbox = mailboxManager.getMailbox(name, true);
+
+ if (mailbox == null) {
+ final String error = "Mailbox for user " + username
+ + " was not found on this server.";
+ throw new MessagingException(error);
+ }
+ mailbox.appendMessage(mail, new Date(), null, session);
+ }
+ finally
+ {
+ session.close();
+ }
+ }
}
Added: james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/sieve/SieveMailet.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/sieve/SieveMailet.java?rev=719593&view=auto
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/sieve/SieveMailet.java (added)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/sieve/SieveMailet.java Fri Nov 21 07:06:08 2008
@@ -0,0 +1,47 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.imapserver.sieve;
+
+import javax.mail.MessagingException;
+
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.james.Constants;
+import org.apache.jsieve.mailet.Poster;
+import org.apache.jsieve.mailet.SieveToMultiMailbox;
+import org.apache.mailet.MailetConfig;
+
+/**
+ * Contains avalon bindings.
+ */
+public class SieveMailet extends SieveToMultiMailbox {
+
+ @Override
+ public void init(MailetConfig config) throws MessagingException {
+ ServiceManager compMgr = (ServiceManager)getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER);
+ try {
+ Poster poster = (Poster) compMgr.lookup("");
+ setPoster(poster);
+ } catch (ServiceException e) {
+ throw new MessagingException("IMAP not installed", e);
+ }
+ super.init(config);
+ }
+}
Modified: james/server/trunk/imapserver-function/src/main/resources/org/apache/james/imapserver/ImapServer.xinfo
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/resources/org/apache/james/imapserver/ImapServer.xinfo?rev=719593&r1=719592&r2=719593&view=diff
==============================================================================
--- james/server/trunk/imapserver-function/src/main/resources/org/apache/james/imapserver/ImapServer.xinfo (original)
+++ james/server/trunk/imapserver-function/src/main/resources/org/apache/james/imapserver/ImapServer.xinfo Fri Nov 21 07:06:08 2008
@@ -24,6 +24,10 @@
<block>
<version>1.0</version>
</block>
+
+ <services>
+ <service name="org.apache.jsieve.mailet.Poster" version="1.0" />
+ </services>
<dependencies>
<dependency>
Modified: james/server/trunk/phoenix-deployment/build.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/build.xml?rev=719593&r1=719592&r2=719593&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/build.xml (original)
+++ james/server/trunk/phoenix-deployment/build.xml Fri Nov 21 07:06:08 2008
@@ -597,7 +597,8 @@
<include name="${jars-prefix}*-store-${version}.jar" />
</lib>
<lib dir='${lib.dir}/${path.lib.james}'>
- <include name='apache-james-imap*.jar'/>
+ <include name='apache-james-imap*.jar'/>
+ <include name='apache-jsieve*.jar'/>
</lib>
<zipfileset dir="${conf.dir}" fullpath="conf/sqlResources.xml">
<include name="sqlResources.xml"/>
Modified: james/server/trunk/stage/org.apache.james/jars/apache-jsieve-0.3-SNAPSHOT.jar
URL: http://svn.apache.org/viewvc/james/server/trunk/stage/org.apache.james/jars/apache-jsieve-0.3-SNAPSHOT.jar?rev=719593&r1=719592&r2=719593&view=diff
==============================================================================
Binary files - no diff available.
Modified: james/server/trunk/stage/org.apache.james/jars/apache-jsieve-mailet-0.3-SNAPSHOT.jar
URL: http://svn.apache.org/viewvc/james/server/trunk/stage/org.apache.james/jars/apache-jsieve-mailet-0.3-SNAPSHOT.jar?rev=719593&r1=719592&r2=719593&view=diff
==============================================================================
Binary files - no diff available.
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org