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 ie...@apache.org on 2012/12/26 13:10:35 UTC
svn commit: r1425890 - in /james/server/trunk: ./
dnsservice-api/src/test/java/org/apache/james/dnsservice/api/
mailetcontainer-api/src/test/java/org/apache/james/mailetcontainer/api/mock/
mailetcontainer-camel/src/main/java/org/apache/james/mailetcont...
Author: ieugen
Date: Wed Dec 26 12:10:34 2012
New Revision: 1425890
URL: http://svn.apache.org/viewvc?rev=1425890&view=rev
Log:
Seems I need to upgrade jsieve and the other dependencies before I continue
Added:
james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/BaseMatchersTest.java
Modified:
james/server/trunk/dnsservice-api/src/test/java/org/apache/james/dnsservice/api/AbstractDNSServiceTest.java
james/server/trunk/mailetcontainer-api/src/test/java/org/apache/james/mailetcontainer/api/mock/MockMailetContext.java
james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java
james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/MailetConfigImplTest.java
james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java
james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java
james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/XorTest.java
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/AbstractStorageQuota.java
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/MailboxQuotaFixed.java
james/server/trunk/pom.xml
james/server/trunk/protocols-smtp/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java
Modified: james/server/trunk/dnsservice-api/src/test/java/org/apache/james/dnsservice/api/AbstractDNSServiceTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/dnsservice-api/src/test/java/org/apache/james/dnsservice/api/AbstractDNSServiceTest.java?rev=1425890&r1=1425889&r2=1425890&view=diff
==============================================================================
--- james/server/trunk/dnsservice-api/src/test/java/org/apache/james/dnsservice/api/AbstractDNSServiceTest.java (original)
+++ james/server/trunk/dnsservice-api/src/test/java/org/apache/james/dnsservice/api/AbstractDNSServiceTest.java Wed Dec 26 12:10:34 2012
@@ -18,14 +18,15 @@
****************************************************************/
package org.apache.james.dnsservice.api;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
import org.apache.james.dnsservice.api.mock.MockDNSService;
-
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import org.junit.Ignore;
import org.junit.Test;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
/**
* Basic tests for AbstractDNSServer. The goal is to verify that the interface
* remains constants and that the built platform has access to the Internet.
@@ -60,7 +61,7 @@ public class AbstractDNSServiceTest {
/**
* Simple localhost resolution.
- *
+ *
* @throws UnknownHostException
*/
@Test
@@ -72,16 +73,17 @@ public class AbstractDNSServiceTest {
// We only can check if the returned localhost is not empty. Its value
// depends on the hosts file.
assertTrue(localHost.length() > 0);
-
}
/**
* Simple apache.org resolution.
- *
+ *
* @throws UnknownHostException
*/
@Test
+ @Ignore(value = "It requires internet connection!")
public void testApache() throws UnknownHostException {
+ //TODO: move to some sort of Live tests
assertEquals(true, DNS_SERVER.getByName("www.apache.org").toString().startsWith("www.apache.org"));
}
}
Modified: james/server/trunk/mailetcontainer-api/src/test/java/org/apache/james/mailetcontainer/api/mock/MockMailetContext.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/src/test/java/org/apache/james/mailetcontainer/api/mock/MockMailetContext.java?rev=1425890&r1=1425889&r2=1425890&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-api/src/test/java/org/apache/james/mailetcontainer/api/mock/MockMailetContext.java (original)
+++ james/server/trunk/mailetcontainer-api/src/test/java/org/apache/james/mailetcontainer/api/mock/MockMailetContext.java Wed Dec 26 12:10:34 2012
@@ -18,14 +18,22 @@
****************************************************************/
package org.apache.james.mailetcontainer.api.mock;
-import java.util.*;
-import javax.mail.MessagingException;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.MimeMessage;
import org.apache.mailet.HostAddress;
+import org.apache.mailet.LookupException;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import org.apache.mailet.MailetContext;
+import org.apache.mailet.TemporaryLookupException;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.MimeMessage;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
public class MockMailetContext implements MailetContext {
@@ -35,13 +43,16 @@ public class MockMailetContext implement
@Override
public void bounce(Mail arg0, String arg1) throws MessagingException {
throw new UnsupportedOperationException("Not implemented");
-
}
@Override
public void bounce(Mail arg0, String arg1, MailAddress arg2) throws MessagingException {
throw new UnsupportedOperationException("Not implemented");
+ }
+ @Override
+ public List<String> dnsLookup(String s, RecordType recordType) throws TemporaryLookupException, LookupException {
+ throw new UnsupportedOperationException("Not implemented");
}
@Override
@@ -133,6 +144,16 @@ public class MockMailetContext implement
}
@Override
+ public void log(LogLevel logLevel, String s) {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ @Override
+ public void log(LogLevel logLevel, String s, Throwable throwable) {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ @Override
public void removeAttribute(String arg0) {
attributes.remove(arg0);
}
@@ -140,7 +161,6 @@ public class MockMailetContext implement
@Override
public void sendMail(MimeMessage arg0) throws MessagingException {
throw new UnsupportedOperationException("Not implemented");
-
}
@Override
@@ -151,26 +171,15 @@ public class MockMailetContext implement
@Override
public void sendMail(MailAddress arg0, Collection arg1, MimeMessage arg2) throws MessagingException {
throw new UnsupportedOperationException("Not implemented");
-
}
@Override
public void sendMail(MailAddress arg0, Collection arg1, MimeMessage arg2, String arg3) throws MessagingException {
throw new UnsupportedOperationException("Not implemented");
-
}
@Override
public void setAttribute(String arg0, Object arg1) {
attributes.put(arg0, arg1);
}
-
- @Override
- public void storeMail(MailAddress arg0, MailAddress arg1, MimeMessage arg2) throws MessagingException {
- throw new UnsupportedOperationException("Not implemented");
- }
-
- public List<Mail> getSentMails() {
- return mails;
- }
}
Modified: james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java?rev=1425890&r1=1425889&r2=1425890&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java (original)
+++ james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java Wed Dec 26 12:10:34 2012
@@ -19,26 +19,6 @@
package org.apache.james.mailetcontainer.impl;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Vector;
-
-import javax.annotation.Resource;
-import javax.mail.Address;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.ParseException;
-
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.james.core.MailImpl;
@@ -54,15 +34,39 @@ import org.apache.james.mailetcontainer.
import org.apache.james.user.api.UsersRepository;
import org.apache.james.user.api.UsersRepositoryException;
import org.apache.mailet.HostAddress;
+import org.apache.mailet.LookupException;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import org.apache.mailet.MailetContext;
+import org.apache.mailet.TemporaryLookupException;
import org.apache.mailet.base.RFC2822Headers;
import org.slf4j.Logger;
+import javax.annotation.Resource;
+import javax.mail.Address;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.ParseException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Vector;
+
public class JamesMailetContext implements MailetContext, LogEnabled, Configurable {
- /** A hash table of server attributes These are the MailetContext attributes */
+ /**
+ * A hash table of server attributes These are the MailetContext attributes
+ */
private Hashtable<String, Object> attributes = new Hashtable<String, Object>();
protected DNSService dns;
@@ -99,6 +103,7 @@ public class JamesMailetContext implemen
/**
* @see org.apache.mailet.MailetContext#getMailServers(String)
*/
+ @Override
public Collection<String> getMailServers(String host) {
try {
return dns.findMXRecords(host);
@@ -112,6 +117,7 @@ public class JamesMailetContext implemen
/**
* @see org.apache.mailet.MailetContext#getAttribute(java.lang.String)
*/
+ @Override
public Object getAttribute(String key) {
return attributes.get(key);
}
@@ -120,6 +126,7 @@ public class JamesMailetContext implemen
* @see org.apache.mailet.MailetContext#setAttribute(java.lang.String,
* java.lang.Object)
*/
+ @Override
public void setAttribute(String key, Object object) {
attributes.put(key, object);
}
@@ -127,6 +134,7 @@ public class JamesMailetContext implemen
/**
* @see org.apache.mailet.MailetContext#removeAttribute(java.lang.String)
*/
+ @Override
public void removeAttribute(String key) {
attributes.remove(key);
}
@@ -134,9 +142,10 @@ public class JamesMailetContext implemen
/**
* @see org.apache.mailet.MailetContext#getAttributeNames()
*/
+ @Override
public Iterator<String> getAttributeNames() {
Vector<String> names = new Vector<String>();
- for (Enumeration<String> e = attributes.keys(); e.hasMoreElements();) {
+ for (Enumeration<String> e = attributes.keys(); e.hasMoreElements(); ) {
names.add(e.nextElement());
}
return names.iterator();
@@ -148,9 +157,10 @@ public class JamesMailetContext implemen
* is different than a mail-client's reply, which would use the Reply-To or
* From header. This will send the bounce with the server's postmaster as
* the sender.
- *
+ *
* @see org.apache.mailet.MailetContext#bounce(Mail, String)
*/
+ @Override
public void bounce(Mail mail, String message) throws MessagingException {
bounce(mail, message, getPostmaster());
}
@@ -181,9 +191,10 @@ public class JamesMailetContext implemen
* multipart (mixed)/ contentPartRoot (body) = mpContent (alternative)/ part
* (body) = message part (body) = original
* </p>
- *
+ *
* @see org.apache.mailet.MailetContext#bounce(Mail, String, MailAddress)
*/
+ @Override
public void bounce(Mail mail, String message, MailAddress bouncer) throws MessagingException {
if (mail.getSender() == null) {
if (log.isInfoEnabled())
@@ -206,17 +217,18 @@ public class JamesMailetContext implemen
LifecycleUtil.dispose(reply);
}
+ @Override
+ public List<String> dnsLookup(String s, RecordType recordType) throws TemporaryLookupException, LookupException {
+ throw new UnsupportedOperationException("Not implemented yet!");
+ }
+
/**
* Generates a bounce mail that is a bounce of the original message.
- *
- * @param bounceText
- * the text to be prepended to the message to describe the bounce
- * condition
- *
+ *
+ * @param bounceText the text to be prepended to the message to describe the bounce
+ * condition
* @return the bounce mail
- *
- * @throws MessagingException
- * if the bounce mail could not be created
+ * @throws MessagingException if the bounce mail could not be created
*/
private MailImpl rawBounce(Mail mail, String bounceText) throws MessagingException {
// This sends a message to the james component that is a bounce of the
@@ -227,7 +239,7 @@ public class JamesMailetContext implemen
reply.setSentDate(new Date());
Collection<MailAddress> recipients = new HashSet<MailAddress>();
recipients.add(mail.getSender());
- InternetAddress addr[] = { new InternetAddress(mail.getSender().toString()) };
+ InternetAddress addr[] = {new InternetAddress(mail.getSender().toString())};
reply.setRecipients(Message.RecipientType.TO, addr);
reply.setFrom(new InternetAddress(mail.getRecipients().iterator().next().toString()));
reply.setText(bounceText);
@@ -238,12 +250,13 @@ public class JamesMailetContext implemen
/**
* @see org.apache.mailet.MailetContext#isLocalUser(String)
*/
+ @Override
public boolean isLocalUser(String name) {
if (name == null) {
return false;
}
try {
- if (name.indexOf("@") == -1) {
+ if (!name.contains("@")) {
try {
return isLocalEmail(new MailAddress(name.toLowerCase(), domains.getDefaultDomain()));
} catch (DomainListException e) {
@@ -262,6 +275,7 @@ public class JamesMailetContext implemen
/**
* @see org.apache.mailet.MailetContext#isLocalEmail(org.apache.mailet.MailAddress)
*/
+ @Override
public boolean isLocalEmail(MailAddress mailAddress) {
if (mailAddress != null) {
String userName = mailAddress.toString().toLowerCase();
@@ -269,14 +283,13 @@ public class JamesMailetContext implemen
return false;
}
try {
- if (localusers.supportVirtualHosting() == false) {
+ if (!localusers.supportVirtualHosting()) {
userName = mailAddress.getLocalPart().toLowerCase();
}
return localusers.contains(userName);
} catch (UsersRepositoryException e) {
log("Unable to access UsersRepository", e);
-
}
}
return false;
@@ -285,6 +298,7 @@ public class JamesMailetContext implemen
/**
* @see org.apache.mailet.MailetContext#getPostmaster()
*/
+ @Override
public MailAddress getPostmaster() {
return postmaster;
}
@@ -292,6 +306,7 @@ public class JamesMailetContext implemen
/**
* @see org.apache.mailet.MailetContext#getMajorVersion()
*/
+ @Override
public int getMajorVersion() {
return 2;
}
@@ -299,11 +314,11 @@ public class JamesMailetContext implemen
/**
* @see org.apache.mailet.MailetContext#getMinorVersion()
*/
+ @Override
public int getMinorVersion() {
return 4;
}
-
/**
* Performs DNS lookups as needed to find servers which should or might
* support SMTP. Returns an Iterator over HostAddress, a specialized
@@ -312,13 +327,13 @@ public class JamesMailetContext implemen
* is done using MX records, and the HostAddress instances are returned
* sorted by MX priority. If no host is found for domainName, the Iterator
* returned will be empty and the first call to hasNext() will return false.
- *
+ *
+ * @param domainName - the domain for which to find mail servers
+ * @return an Iterator over HostAddress instances, sorted by priority
* @see org.apache.james.dnsservice.api.DNSService#getHostName(java.net.InetAddress)
* @since Mailet API v2.2.0a16-unstable
- * @param domainName
- * - the domain for which to find mail servers
- * @return an Iterator over HostAddress instances, sorted by priority
*/
+ @Override
public Iterator<HostAddress> getSMTPHostAddresses(String domainName) {
try {
return new MXHostAddressIterator(dns.findMXRecords(domainName).iterator(), dns, false, log);
@@ -328,9 +343,11 @@ public class JamesMailetContext implemen
return Collections.unmodifiableCollection(new ArrayList<HostAddress>(0)).iterator();
}
}
+
/**
* @see org.apache.mailet.MailetContext#getServerInfo()
*/
+ @Override
public String getServerInfo() {
return "Apache JAMES";
}
@@ -338,6 +355,7 @@ public class JamesMailetContext implemen
/**
* @see org.apache.mailet.MailetContext#isLocalServer(java.lang.String)
*/
+ @Override
public boolean isLocalServer(String name) {
try {
return domains.containsDomain(name);
@@ -350,37 +368,73 @@ public class JamesMailetContext implemen
/**
* @see org.apache.mailet.MailetContext#log(java.lang.String)
*/
+ @Override
+ @Deprecated
public void log(String arg0) {
log.info(arg0);
}
/**
* @see org.apache.mailet.MailetContext#log(java.lang.String,
- * java.lang.Throwable)
+ * java.lang.Throwable)
*/
+ @Override
+ @Deprecated
public void log(String arg0, Throwable arg1) {
log.info(arg0, arg1);
}
+ @Override
+ public void log(LogLevel logLevel, String s) {
+ switch (logLevel) {
+ case INFO:
+ log.info(s);
+ break;
+ case WARN:
+ log.warn(s);
+ break;
+ case ERROR:
+ log.error(s);
+ break;
+ default:
+ log.debug(s);
+ }
+ }
+
+ @Override
+ public void log(LogLevel logLevel, String s, Throwable throwable) {
+ switch (logLevel) {
+ case INFO:
+ log.info(s, throwable);
+ break;
+ case WARN:
+ log.warn(s, throwable);
+ break;
+ case ERROR:
+ log.error(s, throwable);
+ break;
+ default:
+ log.debug(s, throwable);
+ }
+ }
+
/**
* Place a mail on the spool for processing
- *
- * @param message
- * the message to send
- *
- * @throws MessagingException
- * if an exception is caught while placing the mail on the spool
+ *
+ * @param message the message to send
+ * @throws MessagingException if an exception is caught while placing the mail on the spool
*/
+ @Override
public void sendMail(MimeMessage message) throws MessagingException {
MailAddress sender = new MailAddress((InternetAddress) message.getFrom()[0]);
Collection<MailAddress> recipients = new HashSet<MailAddress>();
Address addresses[] = message.getAllRecipients();
if (addresses != null) {
- for (int i = 0; i < addresses.length; i++) {
+ for (Address address : addresses) {
// Javamail treats the "newsgroups:" header field as a
// recipient, so we want to filter those out.
- if (addresses[i] instanceof InternetAddress) {
- recipients.add(new MailAddress((InternetAddress) addresses[i]));
+ if (address instanceof InternetAddress) {
+ recipients.add(new MailAddress((InternetAddress) address));
}
}
}
@@ -388,9 +442,8 @@ public class JamesMailetContext implemen
}
/**
- * @see
- * org.apache.mailet.MailetContext#sendMail(org.apache.mailet.MailAddress,
- * java.util.Collection, javax.mail.internet.MimeMessage)
+ * @see org.apache.mailet.MailetContext#sendMail(org.apache.mailet.MailAddress,
+ * java.util.Collection, javax.mail.internet.MimeMessage)
*/
@SuppressWarnings("unchecked")
public void sendMail(MailAddress sender, Collection recipients, MimeMessage message) throws MessagingException {
@@ -399,17 +452,17 @@ public class JamesMailetContext implemen
/**
* TODO: Should we use the MailProcessorList or the MailQueue here ?
- *
+ *
* @see org.apache.mailet.MailetContext#sendMail(org.apache.mailet.Mail)
*/
+ @Override
public void sendMail(Mail mail) throws MessagingException {
processorList.service(mail);
}
/**
- * @see
- * org.apache.mailet.MailetContext#sendMail(org.apache.mailet.MailAddress,
- * java.util.Collection, javax.mail.internet.MimeMessage, java.lang.String)
+ * @see org.apache.mailet.MailetContext#sendMail(org.apache.mailet.MailAddress,
+ * java.util.Collection, javax.mail.internet.MimeMessage, java.lang.String)
*/
@SuppressWarnings("unchecked")
public void sendMail(MailAddress sender, Collection recipients, MimeMessage message, String state) throws MessagingException {
@@ -432,11 +485,9 @@ public class JamesMailetContext implemen
* The local field localDeliveryMailet will be removed when we remove the
* storeMail method.
* </p>
- *
+ *
* @deprecated since 2.2.0 look at the LocalDelivery code to find out how to
* do the local delivery.
- * @see org.apache.mailet.MailetContext#storeMail(org.apache.mailet.MailAddress,
- * org.apache.mailet.MailAddress, javax.mail.internet.MimeMessage)
*/
public void storeMail(MailAddress sender, MailAddress recipient, MimeMessage msg) throws MessagingException {
throw new UnsupportedOperationException("Was removed");
@@ -445,6 +496,7 @@ public class JamesMailetContext implemen
/**
* @see org.apache.james.lifecycle.api.LogEnabled#setLog(org.slf4j.Logger)
*/
+ @Override
public void setLog(Logger log) {
this.log = log;
}
@@ -452,6 +504,7 @@ public class JamesMailetContext implemen
/**
* @see org.apache.james.lifecycle.api.Configurable#configure(HierarchicalConfiguration)
*/
+ @Override
public void configure(HierarchicalConfiguration config) throws ConfigurationException {
try {
@@ -467,17 +520,15 @@ public class JamesMailetContext implemen
// list
String[] doms = domains.getDomains();
if (doms != null) {
- for (int i = 0; i < doms.length; i++) {
- String serverName = doms[i].toLowerCase(Locale.US);
+ for (String dom : doms) {
+ String serverName = dom.toLowerCase(Locale.US);
if (!("localhost".equals(serverName))) {
domainName = serverName; // ok, not localhost, so
- // use it
- continue;
+ // use it
}
}
}
-
// if we found a suitable domain, use it. Otherwise fallback to
// the
// host name.
@@ -486,9 +537,11 @@ public class JamesMailetContext implemen
try {
this.postmaster = new MailAddress(postMasterAddress);
if (!domains.containsDomain(postmaster.getDomain())) {
- StringBuffer warnBuffer = new StringBuffer(320).append("The specified postmaster address ( ").append(postmaster)
- .append(" ) is not a local address. This is not necessarily a problem, but it does mean that emails addressed to the postmaster will be routed to another server. For some configurations this may cause problems.");
- log.warn(warnBuffer.toString());
+ String warnBuffer = "The specified postmaster address ( " + postmaster + " ) is not a local " +
+ "address. This is not necessarily a problem, but it does mean that emails addressed to " +
+ "the postmaster will be routed to another server. For some configurations this may " +
+ "cause problems.";
+ log.warn(warnBuffer);
}
} catch (AddressException e) {
throw new ConfigurationException("Postmaster address " + postMasterAddress + "is invalid", e);
@@ -496,6 +549,5 @@ public class JamesMailetContext implemen
} catch (DomainListException e) {
throw new ConfigurationException("Unable to access DomainList", e);
}
-
}
}
Modified: james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/MailetConfigImplTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/MailetConfigImplTest.java?rev=1425890&r1=1425889&r2=1425890&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/MailetConfigImplTest.java (original)
+++ james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/MailetConfigImplTest.java Wed Dec 26 12:10:34 2012
@@ -18,23 +18,32 @@
****************************************************************/
package org.apache.james.mailetcontainer.impl;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import static org.junit.Assert.assertEquals;
+import org.junit.Before;
+import org.junit.Test;
+
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.DefaultConfigurationBuilder;
-import static org.junit.Assert.*;
-import org.junit.Test;
public class MailetConfigImplTest {
+ private DefaultConfigurationBuilder builder;
+ private MailetConfigImpl config;
+
+ @Before
+ public void setUp() throws Exception {
+ builder = new DefaultConfigurationBuilder();
+ config = new MailetConfigImpl();
+ }
+
@Test
public void testDotParamsFromXML() throws ConfigurationException {
- DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
builder.load(new ByteArrayInputStream("<mailet><mail.debug>true</mail.debug></mailet>".getBytes()));
- MailetConfigImpl config = new MailetConfigImpl();
config.setConfiguration(builder);
String param = config.getInitParameterNames().next();
@@ -44,10 +53,8 @@ public class MailetConfigImplTest {
@Test
public void testDotParamsFromConfig() throws ConfigurationException {
- DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
builder.addProperty("mail.debug", "true");
- MailetConfigImpl config = new MailetConfigImpl();
config.setConfiguration(builder);
String param = config.getInitParameterNames().next();
@@ -58,10 +65,8 @@ public class MailetConfigImplTest {
// See JAMES-1232
@Test
public void testParamWithComma() throws ConfigurationException {
- DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
builder.load(new ByteArrayInputStream("<mailet><whatever>value1,value2</whatever></mailet>".getBytes()));
- MailetConfigImpl config = new MailetConfigImpl();
config.setConfiguration(builder);
String param = config.getInitParameterNames().next();
@@ -71,23 +76,21 @@ public class MailetConfigImplTest {
@Test
public void testParamWithXmlSpace() throws ConfigurationException {
- DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
builder.setDelimiterParsingDisabled(true);
builder.load(new ByteArrayInputStream("<mailet><whatever xml:space=\"preserve\"> some text </whatever></mailet>".
getBytes()));
- MailetConfigImpl config = new MailetConfigImpl();
config.setConfiguration(builder);
String param = config.getInitParameterNames().next();
assertEquals("whatever", param);
assertEquals(" some text ", config.getInitParameter(param));
- List<String> parms = new ArrayList<String>();
+ List<String> params = new ArrayList<String>();
Iterator<String> iter = config.getInitParameterNames();
while (iter.hasNext()) {
- parms.add(iter.next());
+ params.add(iter.next());
}
- assertEquals(parms.size(), 1);
+ assertEquals(params.size(), 1);
}
}
Modified: james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java?rev=1425890&r1=1425889&r2=1425890&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java (original)
+++ james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java Wed Dec 26 12:10:34 2012
@@ -18,85 +18,47 @@
****************************************************************/
package org.apache.james.mailetcontainer.impl.matchers;
-import java.util.Arrays;
-import java.util.Collection;
-import javax.mail.MessagingException;
-import javax.mail.internet.ParseException;
-import org.apache.james.transport.matchers.All;
-import org.apache.james.transport.matchers.RecipientIs;
import org.apache.mailet.MailAddress;
-import org.apache.mailet.Matcher;
-import org.apache.mailet.base.test.FakeMail;
-import org.apache.mailet.base.test.FakeMailContext;
-import org.apache.mailet.base.test.FakeMatcherConfig;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import org.junit.Before;
import org.junit.Test;
-public class AndTest {
-
- private FakeMailContext context;
- private FakeMail mockedMail;
- private CompositeMatcher matcher;
-
- private void setupMockedMail() throws ParseException {
- mockedMail = new FakeMail();
- mockedMail.setRecipients(Arrays.asList(new MailAddress[]{
- new MailAddress("test@james.apache.org"),
- new MailAddress("test2@james.apache.org")}));
-
- }
-
- /**
- * Setup a composite Or matcher and test it
- * @throws MessagingException
- */
- private void setupMatcher() throws MessagingException {
- context = new FakeMailContext();
- matcher = new And();
- FakeMatcherConfig mci = new FakeMatcherConfig("And", context);
- matcher.init(mci);
- }
+import javax.mail.MessagingException;
+import java.util.Collection;
- private void setupChild(String match) throws MessagingException {
- Matcher child = null;
- if (match.equals("All")) {
- child = new All();
- } else {
- child = new RecipientIs();
- }
- FakeMatcherConfig sub = new FakeMatcherConfig(match, context);
- child.init(sub);
- matcher.add(child);
+public class AndTest extends BaseMatchersTest {
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ setupCompositeMatcher("And", And.class);
}
// test if all recipients was returned
@Test
public void testAndIntersectSameTwice() throws MessagingException {
- setupMockedMail();
- setupMatcher();
- setupChild("RecipientIs=test@james.apache.org");
- setupChild("RecipientIs=test@james.apache.org");
- setupChild("All");
-
- Collection matchedRecipients = matcher.match(mockedMail);
-
- assertNotNull(matchedRecipients);
- assertEquals(1, matchedRecipients.size());
- MailAddress address = (MailAddress) matchedRecipients.iterator().next();
- assertEquals(address, "test@james.apache.org");
+ setupChild("RecipientIs=test@james.apache.org");
+ setupChild("RecipientIs=test@james.apache.org");
+ setupChild("All");
+
+ Collection matchedRecipients = matcher.match(mockedMail);
+
+ assertNotNull(matchedRecipients);
+ assertEquals(1, matchedRecipients.size());
+ MailAddress address = (MailAddress) matchedRecipients.iterator().next();
+ assertEquals(address.toString(), "test@james.apache.org");
}
@Test
public void testAndNoIntersect() throws MessagingException {
- setupMockedMail();
- setupMatcher();
- setupChild("RecipientIs=test@james.apache.org");
- setupChild("RecipientIs=test2@james.apache.org");
+ setupChild("RecipientIs=test@james.apache.org");
+ setupChild("RecipientIs=test2@james.apache.org");
- Collection matchedRecipients = matcher.match(mockedMail);
+ Collection matchedRecipients = matcher.match(mockedMail);
- assertNotNull(matchedRecipients);
- assertEquals(0, matchedRecipients.size());
+ assertNotNull(matchedRecipients);
+ assertEquals(0, matchedRecipients.size());
}
}
Added: james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/BaseMatchersTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/BaseMatchersTest.java?rev=1425890&view=auto
==============================================================================
--- james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/BaseMatchersTest.java (added)
+++ james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/BaseMatchersTest.java Wed Dec 26 12:10:34 2012
@@ -0,0 +1,66 @@
+/****************************************************************
+ * 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.mailetcontainer.impl.matchers;
+
+import org.apache.james.mailet.standard.matchers.All;
+import org.apache.james.mailet.standard.matchers.RecipientIs;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.Matcher;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMailContext;
+import org.apache.mailet.base.test.FakeMatcherConfig;
+import org.junit.Before;
+
+import javax.mail.MessagingException;
+import java.util.Arrays;
+
+public class BaseMatchersTest {
+
+ protected FakeMailContext context;
+ protected FakeMail mockedMail;
+ protected CompositeMatcher matcher;
+
+ @Before
+ public void setUp() throws Exception {
+ mockedMail = new FakeMail();
+ mockedMail.setRecipients(Arrays.asList(new MailAddress("test@james.apache.org"),
+ new MailAddress("test2@james.apache.org")));
+ }
+
+ void setupCompositeMatcher(String matcherName, Class<? extends GenericCompositeMatcher> matcherClass)
+ throws Exception {
+ context = new FakeMailContext();
+ matcher = matcherClass.newInstance();
+ FakeMatcherConfig mci = new FakeMatcherConfig(matcherName, context);
+ matcher.init(mci);
+ }
+
+ void setupChild(String matcherName) throws MessagingException {
+ Matcher child;
+ if (matcherName.equals("All")) {
+ child = new All();
+ } else {
+ child = new RecipientIs();
+ }
+ FakeMatcherConfig sub = new FakeMatcherConfig(matcherName, context);
+ child.init(sub);
+ matcher.add(child);
+ }
+}
Modified: james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java?rev=1425890&r1=1425889&r2=1425890&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java (original)
+++ james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java Wed Dec 26 12:10:34 2012
@@ -19,72 +19,41 @@
package org.apache.james.mailetcontainer.impl.matchers;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import javax.mail.MessagingException;
-import javax.mail.internet.ParseException;
-import org.apache.james.transport.matchers.RecipientIs;
import org.apache.mailet.MailAddress;
-import org.apache.mailet.Matcher;
-import org.apache.mailet.base.test.FakeMail;
-import org.apache.mailet.base.test.FakeMailContext;
-import org.apache.mailet.base.test.FakeMatcherConfig;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import org.junit.Before;
import org.junit.Test;
-public class OrTest {
-
- private FakeMail mockedMail;
-
- private CompositeMatcher matcher;
-
- private void setupMockedMail() throws ParseException {
- mockedMail = new FakeMail();
- mockedMail.setRecipients(Arrays.asList(new MailAddress[] {
- new MailAddress("test@james.apache.org"),
- new MailAddress("test2@james.apache.org") }));
+import java.util.Collection;
+import java.util.Iterator;
- }
+public class OrTest extends BaseMatchersTest {
- /**
- * Setup a composite Or matcher and test it
- * @throws MessagingException
- */
- private void setupMatcher() throws MessagingException {
- FakeMailContext context = new FakeMailContext();
- matcher = new Or();
- FakeMatcherConfig mci = new FakeMatcherConfig("Or",context);
- matcher.init(mci);
- Matcher child = null;
- FakeMatcherConfig sub = null;
- child = new RecipientIs();
- sub = new FakeMatcherConfig("RecipientIsRegex=test@james.apache.org",context);
- child.init(sub);
- matcher.add(child);
- child = new RecipientIs();
- sub = new FakeMatcherConfig("RecipientIsRegex=test2@james.apache.org",context);
- child.init(sub);
- matcher.add(child);
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ setupCompositeMatcher("Or", Or.class);
}
// test if all recipients was returned
@Test
- public void testAllRecipientsReturned() throws MessagingException {
- setupMockedMail();
- setupMatcher();
+ public void testAllRecipientsReturned() throws Exception {
+ setupChild("RecipientIsRegex=test@james.apache.org");
+ setupChild("RecipientIsRegex=test2@james.apache.org");
Collection matchedRecipients = matcher.match(mockedMail);
assertNotNull(matchedRecipients);
assertEquals(matchedRecipients.size(), mockedMail.getRecipients().size());
-
+
// Now ensure they match the actual recipients
- Iterator iterator = matchedRecipients.iterator();
- MailAddress address = (MailAddress)iterator.next();
- assertEquals(address,"test@james.apache.org");
- address = (MailAddress)iterator.next();
- assertEquals(address,"test2@james.apache.org");
+ Iterator iterator = matchedRecipients.iterator();
+ MailAddress address = (MailAddress) iterator.next();
+ assertEquals(address, "test@james.apache.org");
+ address = (MailAddress) iterator.next();
+ assertEquals(address, "test2@james.apache.org");
}
}
Modified: james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/XorTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/XorTest.java?rev=1425890&r1=1425889&r2=1425890&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/XorTest.java (original)
+++ james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/XorTest.java Wed Dec 26 12:10:34 2012
@@ -18,89 +18,53 @@
****************************************************************/
package org.apache.james.mailetcontainer.impl.matchers;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import javax.mail.MessagingException;
-import javax.mail.internet.ParseException;
-import org.apache.james.transport.matchers.All;
-import org.apache.james.transport.matchers.RecipientIs;
import org.apache.mailet.MailAddress;
-import org.apache.mailet.Matcher;
import org.apache.mailet.base.test.FakeMail;
import org.apache.mailet.base.test.FakeMailContext;
-import org.apache.mailet.base.test.FakeMatcherConfig;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import org.junit.Before;
import org.junit.Test;
-public class XorTest {
-
- private FakeMailContext context;
- private FakeMail mockedMail;
- private CompositeMatcher matcher;
-
- private void setupMockedMail() throws ParseException {
- mockedMail = new FakeMail();
- mockedMail.setRecipients(Arrays.asList(new MailAddress[]{
- new MailAddress("test@james.apache.org"),
- new MailAddress("test2@james.apache.org")}));
-
- }
-
- /**
- * Setup a composite Or matcher and test it
- * @throws MessagingException
- */
- private void setupMatcher() throws MessagingException {
- context = new FakeMailContext();
- matcher = new Xor();
- FakeMatcherConfig mci = new FakeMatcherConfig("Xor", context);
- matcher.init(mci);
- }
+import javax.mail.MessagingException;
+import java.util.Collection;
+import java.util.Iterator;
- private void setupChild(String match) throws MessagingException {
- Matcher child = null;
- if (match.equals("All")) {
- child = new All();
- } else {
- child = new RecipientIs();
- }
- FakeMatcherConfig sub = new FakeMatcherConfig(match, context);
- child.init(sub);
- matcher.add(child);
+public class XorTest extends BaseMatchersTest {
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ setupCompositeMatcher("Xor", Xor.class);
}
// test if all recipients was returned
@Test
public void testIntersectSame() throws MessagingException {
- setupMockedMail();
- setupMatcher();
- setupChild("RecipientIsRegex=test@james.apache.org");
- setupChild("RecipientIsRegex=test@james.apache.org");
+ setupChild("RecipientIsRegex=test@james.apache.org");
+ setupChild("RecipientIsRegex=test@james.apache.org");
- Collection matchedRecipients = matcher.match(mockedMail);
+ Collection matchedRecipients = matcher.match(mockedMail);
- assertNotNull(matchedRecipients);
- assertEquals(0, matchedRecipients.size());
+ assertNotNull(matchedRecipients);
+ assertEquals(0, matchedRecipients.size());
}
@Test
public void testNoIntersect() throws MessagingException {
- setupMockedMail();
- setupMatcher();
- setupChild("RecipientIsRegex=test@james.apache.org");
- setupChild("RecipientIsRegex=test2@james.apache.org");
-
- Collection matchedRecipients = matcher.match(mockedMail);
-
- assertNotNull(matchedRecipients);
- assertEquals(2, matchedRecipients.size());
-
- Iterator iterator = matchedRecipients.iterator();
- MailAddress address = (MailAddress) iterator.next();
- assertEquals(address, "test@james.apache.org");
- address = (MailAddress) iterator.next();
- assertEquals(address, "test2@james.apache.org");
+ setupChild("RecipientIsRegex=test@james.apache.org");
+ setupChild("RecipientIsRegex=test2@james.apache.org");
+
+ Collection matchedRecipients = matcher.match(mockedMail);
+
+ assertNotNull(matchedRecipients);
+ assertEquals(2, matchedRecipients.size());
+
+ Iterator iterator = matchedRecipients.iterator();
+ MailAddress address = (MailAddress) iterator.next();
+ assertEquals(address, "test@james.apache.org");
+ address = (MailAddress) iterator.next();
+ assertEquals(address, "test2@james.apache.org");
}
}
Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/AbstractStorageQuota.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/AbstractStorageQuota.java?rev=1425890&r1=1425889&r2=1425890&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/AbstractStorageQuota.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/AbstractStorageQuota.java Wed Dec 26 12:10:34 2012
@@ -19,13 +19,6 @@
package org.apache.james.transport.matchers;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-
-import javax.annotation.Resource;
-import javax.mail.MessagingException;
-
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MessageManager;
@@ -37,6 +30,7 @@ import org.apache.james.mailbox.model.Ma
import org.apache.james.mailbox.model.MailboxQuery;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.MessageResult;
+import org.apache.james.mailet.standard.matchers.AbstractQuotaMatcher;
import org.apache.james.transport.util.MailetContextLog;
import org.apache.james.user.api.UsersRepository;
import org.apache.james.user.api.UsersRepositoryException;
@@ -44,6 +38,12 @@ import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import org.apache.mailet.MailetContext;
+import javax.annotation.Resource;
+import javax.mail.MessagingException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+
/**
* <p>
* Experimental: Abstract matcher checking whether a recipient has exceeded a
@@ -55,11 +55,11 @@ import org.apache.mailet.MailetContext;
* user or common to all of them).
* </p>
* <p>
- * This matcher need to calculate the mailbox size everytime it is called. This
+ * This matcher need to calculate the mailbox size every time it is called. This
* can slow down things if there are many mails in the mailbox. Some users also
* report big problems with the matcher if a JDBC based mailrepository is used.
* </p>
- *
+ *
* @since 2.2.0
*/
abstract public class AbstractStorageQuota extends AbstractQuotaMatcher {
@@ -72,15 +72,15 @@ abstract public class AbstractStorageQuo
}
@Resource(name = "usersrepository")
- public void setUsersRepository(UsersRepository localusers) {
- this.localusers = localusers;
+ public void setUsersRepository(UsersRepository localUsers) {
+ this.localUsers = localUsers;
}
/**
* The user repository for this mail server. Contains all the users with
* inboxes on this server.
*/
- private UsersRepository localusers;
+ private UsersRepository localUsers;
private MailetContextLog log;
@@ -90,9 +90,8 @@ abstract public class AbstractStorageQuo
* recipient is a known user in the local server.<br>
* If a subclass overrides this method it should "and"
* <code>super.isRecipientChecked</code> to its check.
- *
- * @param recipient
- * the recipient to check
+ *
+ * @param recipient the recipient to check
*/
protected boolean isRecipientChecked(MailAddress recipient) throws MessagingException {
MailetContext mailetContext = getMailetContext();
@@ -109,9 +108,8 @@ abstract public class AbstractStorageQuo
/**
* Gets the storage used in the recipient's inbox.
- *
- * @param recipient
- * the recipient to check
+ *
+ * @param recipient the recipient to check
*/
protected long getUsed(MailAddress recipient, Mail _) throws MessagingException {
long size = 0;
@@ -121,7 +119,7 @@ abstract public class AbstractStorageQuo
try {
// see if we need use the full email address as username or not.
// See JAMES-1197
- if (localusers.supportVirtualHosting()) {
+ if (localUsers.supportVirtualHosting()) {
username = recipient.toString().toLowerCase(Locale.US);
} else {
username = recipient.getLocalPart().toLowerCase(Locale.US);
@@ -133,11 +131,12 @@ abstract public class AbstractStorageQuo
manager.startProcessingRequest(session);
// get all mailboxes for the user to calculate the size
- // See JAMES-1198
- List<MailboxMetaData> mList = manager.search(new MailboxQuery(MailboxPath.inbox(session), "", session.getPathDelimiter()), session);
- for (int i = 0; i < mList.size(); i++) {
- MessageManager mailbox = manager.getMailbox(mList.get(i).getPath(), session);
- Iterator<MessageResult> results = mailbox.getMessages(MessageRange.all(), FetchGroupImpl.MINIMAL, session);
+ // TODO: See JAMES-1198
+ List<MailboxMetaData> mList = manager.search(new MailboxQuery(MailboxPath.inbox(session), "",
+ session.getPathDelimiter()), session);
+ for (MailboxMetaData aMList : mList) {
+ MessageManager mailbox = manager.getMailbox(aMList.getPath(), session);
+ Iterator<MessageResult> results = mailbox.getMessages(MessageRange.all(), FetchGroupImpl.MINIMAL, session);
while (results.hasNext()) {
size += results.next().getSize();
}
@@ -151,7 +150,5 @@ abstract public class AbstractStorageQuo
}
return size;
-
}
-
}
Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/MailboxQuotaFixed.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/MailboxQuotaFixed.java?rev=1425890&r1=1425889&r2=1425890&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/MailboxQuotaFixed.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/MailboxQuotaFixed.java Wed Dec 26 12:10:34 2012
@@ -18,12 +18,12 @@
****************************************************************/
package org.apache.james.transport.matchers;
-import javax.mail.MessagingException;
-
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import org.apache.mailet.Matcher;
+import javax.mail.MessagingException;
+
/**
* Matcher which can be used to set a quota for users Mailbox. This
* {@link Matcher} need to recalculate the used space of users mailbox on every
@@ -32,9 +32,8 @@ import org.apache.mailet.Matcher;
public class MailboxQuotaFixed extends AbstractStorageQuota {
/**
- * @see
- * org.apache.james.transport.matchers.AbstractQuotaMatcher
- * #getQuota(org.apache.mailet.MailAddress, org.apache.mailet.Mail)
+ * @see org.apache.james.mailet.standard.matchers.AbstractQuotaMatcher
+ * #getQuota(org.apache.mailet.MailAddress, org.apache.mailet.Mail)
*/
protected long getQuota(MailAddress arg0, Mail arg1) throws MessagingException {
return parseQuota(this.getCondition());
Modified: james/server/trunk/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/pom.xml?rev=1425890&r1=1425889&r2=1425890&view=diff
==============================================================================
--- james/server/trunk/pom.xml (original)
+++ james/server/trunk/pom.xml Wed Dec 26 12:10:34 2012
@@ -49,7 +49,7 @@
<module>filesystem-api</module>
<module>data-api</module>
<module>data-library</module>
- <module>data-hbase</module>
+ <!--<module>data-hbase</module>-->
<module>data-jpa</module>
<module>data-jcr</module>
<module>data-jdbc</module>
Modified: james/server/trunk/protocols-smtp/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols-smtp/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java?rev=1425890&r1=1425889&r2=1425890&view=diff
==============================================================================
--- james/server/trunk/protocols-smtp/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java (original)
+++ james/server/trunk/protocols-smtp/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java Wed Dec 26 12:10:34 2012
@@ -19,18 +19,6 @@
package org.apache.james.smtpserver;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-import javax.mail.MessagingException;
-import javax.mail.internet.AddressException;
-
import org.apache.james.core.MailImpl;
import org.apache.james.core.MimeMessageCopyOnWriteProxy;
import org.apache.james.core.MimeMessageInputStream;
@@ -50,7 +38,6 @@ import org.apache.james.protocols.smtp.S
import org.apache.james.protocols.smtp.core.AbstractHookableCmdHandler;
import org.apache.james.protocols.smtp.core.DataLineFilter;
import org.apache.james.protocols.smtp.dsn.DSNStatus;
-import org.apache.james.protocols.smtp.hook.Hook;
import org.apache.james.protocols.smtp.hook.HookResult;
import org.apache.james.protocols.smtp.hook.HookResultHook;
import org.apache.james.protocols.smtp.hook.MessageHook;
@@ -58,6 +45,17 @@ import org.apache.james.smtpserver.model
import org.apache.james.smtpserver.model.ProtocolMailAddressAdapter;
import org.apache.mailet.Mail;
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
/**
* Handles the calling of JamesMessageHooks
*/
@@ -69,15 +67,12 @@ public class DataLineJamesMessageHookHan
private List<MessageHook> mHandlers;
- /**
- * @see
- * org.apache.james.protocols.smtp.core.DataLineFilter#onLine(SMTPSession, byte[], LineHandler)
- */
+ @Override
public Response onLine(SMTPSession session, ByteBuffer lineByteBuffer, LineHandler<SMTPSession> next) {
-
+
byte[] line = new byte[lineByteBuffer.remaining()];
lineByteBuffer.get(line, 0, line.length);
-
+
MimeMessageInputStreamSource mmiss = (MimeMessageInputStreamSource) session.getAttachment(SMTPConstants.DATA_MIMEMESSAGE_STREAMSOURCE, State.Transaction);
try {
@@ -91,12 +86,12 @@ public class DataLineJamesMessageHookHan
List<MailAddress> recipientCollection = (List<MailAddress>) session.getAttachment(SMTPSession.RCPT_LIST, State.Transaction);
MailAddress mailAddress = (MailAddress) session.getAttachment(SMTPSession.SENDER, State.Transaction);
-
+
List<org.apache.mailet.MailAddress> rcpts = new ArrayList<org.apache.mailet.MailAddress>();
- for (MailAddress address: recipientCollection) {
+ for (MailAddress address : recipientCollection) {
rcpts.add(new MailetMailAddressAdapter(address));
}
-
+
MailetMailAddressAdapter mailetMailAddressAdapter = null;
if (mailAddress != MailAddress.nullSender()) {
mailetMailAddressAdapter = new MailetMailAddressAdapter(mailAddress);
@@ -114,7 +109,7 @@ public class DataLineJamesMessageHookHan
Response response = processExtensions(session, mail);
- session.popLineHandler();
+ session.popLineHandler();
return response;
} catch (MessagingException e) {
@@ -151,9 +146,6 @@ public class DataLineJamesMessageHookHan
return null;
}
- /**
- * @param session
- */
protected Response processExtensions(SMTPSession session, Mail mail) {
if (mail != null && messageHandlers != null) {
try {
@@ -164,8 +156,7 @@ public class DataLineJamesMessageHookHan
} catch (FileNotFoundException e) {
session.getLogger().debug("Unable to obtain OutputStream for Mail " + mail, e);
}
- for (int i = 0; i < mHandlers.size(); i++) {
- MessageHook rawHandler = mHandlers.get(i);
+ for (MessageHook rawHandler : mHandlers) {
session.getLogger().debug("executing james message handler " + rawHandler);
long start = System.currentTimeMillis();
@@ -173,10 +164,9 @@ public class DataLineJamesMessageHookHan
long executionTime = System.currentTimeMillis() - start;
if (rHooks != null) {
- for (int i2 = 0; i2 < rHooks.size(); i2++) {
- Object rHook = rHooks.get(i2);
+ for (HookResultHook rHook : rHooks) {
session.getLogger().debug("executing hook " + rHook);
- hRes = ((HookResultHook) rHook).onHookResult(session, hRes, executionTime, rawHandler);
+ hRes = rHook.onHookResult(session, hRes, executionTime, rawHandler);
}
}
@@ -189,18 +179,15 @@ public class DataLineJamesMessageHookHan
}
}
- int count = messageHandlers.size();
- for (int i = 0; i < count; i++) {
- Hook rawHandler = (Hook) messageHandlers.get(i);
- session.getLogger().debug("executing james message handler " + rawHandler);
+ for (JamesMessageHook messageHandler : messageHandlers) {
+ session.getLogger().debug("executing james message handler " + messageHandler);
long start = System.currentTimeMillis();
- HookResult hRes = ((JamesMessageHook) rawHandler).onMessage(session, (Mail) mail);
+ HookResult hRes = messageHandler.onMessage(session, mail);
long executionTime = System.currentTimeMillis() - start;
if (rHooks != null) {
- for (int i2 = 0; i2 < rHooks.size(); i2++) {
- Object rHook = rHooks.get(i2);
+ for (HookResultHook rHook : rHooks) {
session.getLogger().debug("executing hook " + rHook);
- hRes = ((HookResultHook) rHook).onHookResult(session, hRes, executionTime, rawHandler);
+ hRes = rHook.onHookResult(session, hRes, executionTime, messageHandler);
}
}
@@ -225,10 +212,7 @@ public class DataLineJamesMessageHookHan
return null;
}
- /**
- * @see org.apache.james.protocols.api.handler.ExtensibleHandler#wireExtensions(java.lang.Class,
- * java.util.List)
- */
+ @Override
public void wireExtensions(Class interfaceName, List extension) throws WiringException {
if (JamesMessageHook.class.equals(interfaceName)) {
this.messageHandlers = extension;
@@ -243,9 +227,7 @@ public class DataLineJamesMessageHookHan
}
}
- /**
- * @see org.apache.james.protocols.api.handler.ExtensibleHandler#getMarkerInterfaces()
- */
+ @Override
public List<Class<?>> getMarkerInterfaces() {
List<Class<?>> classes = new LinkedList<Class<?>>();
classes.add(JamesMessageHook.class);
@@ -255,17 +237,15 @@ public class DataLineJamesMessageHookHan
}
protected class MailToMailEnvelopeWrapper implements MailEnvelope {
- private Mail mail;
- private OutputStream out;
+ private final Mail mail;
+ private final OutputStream out;
public MailToMailEnvelopeWrapper(Mail mail, OutputStream out) {
this.mail = mail;
this.out = out;
}
- /**
- * @see org.apache.james.protocols.smtp.MailEnvelope#getMessageInputStream()
- */
+ @Override
public InputStream getMessageInputStream() throws IOException {
try {
return new MimeMessageInputStream(mail.getMessage());
@@ -274,43 +254,33 @@ public class DataLineJamesMessageHookHan
}
}
- /**
- * @see
- * org.apache.james.protocols.smtp.MailEnvelope#getMessageOutputStream()
- */
+ @Override
public OutputStream getMessageOutputStream() throws IOException {
return out;
}
- /**
- * @see org.apache.james.protocols.smtp.MailEnvelope#getRecipients()
- */
+ @Override
public List<MailAddress> getRecipients() {
return new ArrayList<MailAddress>(mail.getRecipients());
}
- /**
- * @see org.apache.james.protocols.smtp.MailEnvelope#getSender()
- */
+ @Override
public MailAddress getSender() {
try {
- return new ProtocolMailAddressAdapter( mail.getSender());
+ return new ProtocolMailAddressAdapter(mail.getSender());
} catch (MailAddressException e) {
// should not occur here, cause it should have happened before
throw new RuntimeException(e);
}
}
- /**
- * @see org.apache.james.protocols.smtp.MailEnvelope#getSize()
- */
+ @Override
public long getSize() {
try {
- return (long) mail.getMessageSize();
+ return mail.getMessageSize();
} catch (MessagingException e) {
return -1;
}
}
-
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org