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 bt...@apache.org on 2015/09/22 12:30:38 UTC
svn commit: r1704549 -
/james/server/trunk/mailet/mailets/src/main/java/org/apache/james/transport/matchers/IsOverQuota.java
Author: btellier
Date: Tue Sep 22 10:30:36 2015
New Revision: 1704549
URL: http://svn.apache.org/viewvc?rev=1704549&view=rev
Log:
JAMES-511 Provide a IsOverQuota matcher based on efficient mailbox utilities
Added:
james/server/trunk/mailet/mailets/src/main/java/org/apache/james/transport/matchers/IsOverQuota.java
Added: james/server/trunk/mailet/mailets/src/main/java/org/apache/james/transport/matchers/IsOverQuota.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailet/mailets/src/main/java/org/apache/james/transport/matchers/IsOverQuota.java?rev=1704549&view=auto
==============================================================================
--- james/server/trunk/mailet/mailets/src/main/java/org/apache/james/transport/matchers/IsOverQuota.java (added)
+++ james/server/trunk/mailet/mailets/src/main/java/org/apache/james/transport/matchers/IsOverQuota.java Tue Sep 22 10:30:36 2015
@@ -0,0 +1,63 @@
+package org.apache.james.transport.matchers;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.GenericMatcher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import javax.mail.MessagingException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class IsOverQuota extends GenericMatcher {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(IsOverQuota.class);
+
+ private QuotaRootResolver quotaRootResolver;
+ private QuotaManager quotaManager;
+ private MailboxManager mailboxManager;
+
+ @Inject
+ public void setQuotaRootResolver(QuotaRootResolver quotaRootResolver) {
+ this.quotaRootResolver = quotaRootResolver;
+ }
+
+ @Inject
+ public void setQuotaManager(QuotaManager quotaManager) {
+ this.quotaManager = quotaManager;
+ }
+
+ @Inject
+ public void setMailboxManager(MailboxManager mailboxManager) {
+ this.mailboxManager = mailboxManager;
+ }
+
+ @Override
+ public Collection<MailAddress> match(Mail mail) throws MessagingException {
+ try {
+ List<MailAddress> result = new ArrayList<MailAddress>();
+ for (MailAddress mailAddress : mail.getRecipients()) {
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(mailAddress.getLocalPart(), LOGGER);
+ MailboxPath mailboxPath = MailboxPath.inbox(mailboxSession);
+ QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(mailboxPath);
+ if (quotaManager.getMessageQuota(quotaRoot).isOverQuota() &&
+ quotaManager.getStorageQuota(quotaRoot).isOverQuota()) {
+ result.add(mailAddress);
+ }
+ }
+ return result;
+ } catch(MailboxException e) {
+ throw new MessagingException("Exception while checking quotas", e);
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org