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 ba...@apache.org on 2007/09/21 11:32:05 UTC
svn commit: r578033 [4/5] - in
/james/jsieve/trunk/src/main/java/org/apache/jsieve: ./ commands/
commands/extensions/ commands/optional/ comparators/ exception/ mail/
mail/optional/ parser/ parser/address/ samples/james/ tests/
tests/optional/ util/check/
Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/ActionReject.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/ActionReject.java?rev=578033&r1=578032&r2=578033&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/ActionReject.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/ActionReject.java Fri Sep 21 02:32:00 2007
@@ -17,23 +17,21 @@
* under the License. *
****************************************************************/
-
package org.apache.jsieve.mail;
/**
* Class ActionReject encapsulates the information required to reject a mail.
* See RFC 3028, Section 4.1.
*/
-public class ActionReject implements Action
-{
+public class ActionReject implements Action {
private String fieldMessage;
/**
* Constructor for ActionReject.
+ *
* @param aMessage
*/
- public ActionReject(String aMessage)
- {
+ public ActionReject(String aMessage) {
this();
setMessage(aMessage);
}
@@ -41,35 +39,34 @@
/**
* Constructor ActionReject.
*/
- private ActionReject()
- {
+ private ActionReject() {
super();
}
-
/**
* @see java.lang.Object#toString()
*/
- public String toString()
- {
+ public String toString() {
return "Action: " + getClass().getName();
}
+
/**
* Returns the message explaining the reason for rejection.
+ *
* @return String
*/
- public String getMessage()
- {
+ public String getMessage() {
return fieldMessage;
}
/**
* Sets the message explaining the reason for rejection.
- * @param message The message to set
+ *
+ * @param message
+ * The message to set
*/
- protected void setMessage(String message)
- {
+ protected void setMessage(String message) {
fieldMessage = message;
}
-}
+}
Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/MailAdapter.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/MailAdapter.java?rev=578033&r1=578032&r2=578033&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/MailAdapter.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/MailAdapter.java Fri Sep 21 02:32:00 2007
@@ -17,7 +17,6 @@
* under the License. *
****************************************************************/
-
package org.apache.jsieve.mail;
import java.util.List;
@@ -27,94 +26,107 @@
import org.apache.jsieve.exception.SieveException;
/**
- * <p>Interface <code>MailAdapter</code> defines the minimum functionality required of
- * of a class implementing a mail message. This is the functionality neccesary to
- * implement the Commands and Tests that RFC32028 mandates MUST be implemented.
+ * <p>
+ * Interface <code>MailAdapter</code> defines the minimum functionality
+ * required of of a class implementing a mail message. This is the functionality
+ * neccesary to implement the Commands and Tests that RFC32028 mandates MUST be
+ * implemented.
* </p>
*
- * <p>Typically, implementations will wrap an application's pre-existing mail
+ * <p>
+ * Typically, implementations will wrap an application's pre-existing mail
* message implementation. It is expected that implementations will extend the
- * minimum level of functionality to provide support for Command and Test
- * extensions that exploit the capabilities of a particular application.</p>
+ * minimum level of functionality to provide support for Command and Test
+ * extensions that exploit the capabilities of a particular application.
+ * </p>
*/
-public interface MailAdapter
-{
+public interface MailAdapter {
/**
- * Method getActions answers the List of Actions accumulated by the receiver.
- * Implementations may elect to supply an unmodifiable collection.
- * @return <code>List</code> of {@link Action}'s, not null, possibly unmodifiable
+ * Method getActions answers the List of Actions accumulated by the
+ * receiver. Implementations may elect to supply an unmodifiable collection.
+ *
+ * @return <code>List</code> of {@link Action}'s, not null, possibly
+ * unmodifiable
*/
public List getActions();
-
+
/**
* Method getActionIteraror answers an Iterator over the List of Actions
- * accumulated by the receiver. Implementations may elect to supply
- * an unmodifiable iterator.
+ * accumulated by the receiver. Implementations may elect to supply an
+ * unmodifiable iterator.
+ *
* @return <code>ListIterator</code>, not null, possibly unmodifiable
*/
public ListIterator getActionsIterator();
-
+
/**
- * Method getHeader answers a List of all of the headers in the receiver whose
- * name is equal to the passed name. If no headers are found an empty List is
- * returned.
+ * Method getHeader answers a List of all of the headers in the receiver
+ * whose name is equal to the passed name. If no headers are found an empty
+ * List is returned.
*
* @param name
- * @return <code>List</code> not null, possibly empty, possible unmodifiable
+ * @return <code>List</code> not null, possibly empty, possible
+ * unmodifiable
* @throws SieveMailException
*/
public List getHeader(String name) throws SieveMailException;
-
+
/**
- * <p>Method getMatchingHeader answers a List of all of the headers in the
- * receiver with the passed name. If no headers are found an empty List is
+ * <p>
+ * Method getMatchingHeader answers a List of all of the headers in the
+ * receiver with the passed name. If no headers are found an empty List is
* returned.
* </p>
*
- * <p>This method differs from getHeader(String) in that it ignores case and the
- * whitespace prefixes and suffixes of a header name when performing the
+ * <p>
+ * This method differs from getHeader(String) in that it ignores case and
+ * the whitespace prefixes and suffixes of a header name when performing the
* match, as required by RFC 3028. Thus "From", "from ", " From" and " from "
* are considered equal.
* </p>
*
* @param name
- * @return <code>List</code>, not null possibly empty, possible unmodifiable
+ * @return <code>List</code>, not null possibly empty, possible
+ * unmodifiable
* @throws SieveMailException
*/
- public List getMatchingHeader(String name)
- throws SieveMailException;
-
+ public List getMatchingHeader(String name) throws SieveMailException;
+
/**
- * Method getHeaderNames answers a List of all of the headers in the receiver.
- * No duplicates are allowed.
- * @return <code>List</code>, not null possible empty, possible unmodifiable
+ * Method getHeaderNames answers a List of all of the headers in the
+ * receiver. No duplicates are allowed.
+ *
+ * @return <code>List</code>, not null possible empty, possible
+ * unmodifiable
* @throws SieveMailException
*/
- public List getHeaderNames() throws SieveMailException;
-
+ public List getHeaderNames() throws SieveMailException;
+
/**
- * Method addAction adds an Action to the List of Actions to be performed by the
- * receiver.
+ * Method addAction adds an Action to the List of Actions to be performed by
+ * the receiver.
+ *
* @param action
*/
- public void addAction(Action action);
-
+ public void addAction(Action action);
+
/**
* Method executeActions. Applies the Actions accumulated by the receiver.
*/
- public void executeActions() throws SieveException;
+ public void executeActions() throws SieveException;
/**
* Method getSize answers the receiver's message size in octets.
+ *
* @return int
* @throws SieveMailException
*/
int getSize() throws SieveMailException;
-
/**
- * Method getContentType returns string/mime representation of the
- * message type.
+ * Method getContentType returns string/mime representation of the message
+ * type.
+ *
* @return String
* @throws SieveMailException
*/
@@ -122,48 +134,55 @@
/**
* Method getContent returns object containing the message content.
+ *
* @return Object
* @throws SieveMailException
*/
public Object getContent() throws SieveMailException;
/**
- * <p>Parses the named header value into individual addresses.</p>
+ * <p>
+ * Parses the named header value into individual addresses.
+ * </p>
*
- * <p>Headers should be matched in a way that ignores case and the
- * whitespace prefixes and suffixes of a header name when performing the
- * match, as required by RFC 3028. Thus "From", "from ", " From" and " from "
- * are considered equal.
+ * <p>
+ * Headers should be matched in a way that ignores case and the whitespace
+ * prefixes and suffixes of a header name when performing the match, as
+ * required by RFC 3028. Thus "From", "from ", " From" and " from " are
+ * considered equal.
* </p>
*
- * @param headerName name of the header whose value is to be split
+ * @param headerName
+ * name of the header whose value is to be split
* @return addresses listed in the given header not null, possibly empty
- * @throws InternetAddressException when the header value is not an address
- * or list of addresses. Implemetations may elect to support only
- * standard headers known to containing one or more addresses rather
- * than parsing the value
- * content
- * @throws SieveMailException when the header value cannot be read
+ * @throws InternetAddressException
+ * when the header value is not an address or list of
+ * addresses. Implemetations may elect to support only
+ * standard headers known to containing one or more
+ * addresses rather than parsing the value content
+ * @throws SieveMailException
+ * when the header value cannot be read
*/
- public Address[] parseAddresses(String headerName) throws SieveMailException, InternetAddressException;
-
+ public Address[] parseAddresses(String headerName)
+ throws SieveMailException, InternetAddressException;
+
/**
* Contains address data required for SIEVE processing.
*/
public interface Address {
-
+
/**
- * Gets the local part of the email address.
- * Specified in
- * <a href='http://james.apache.org/server/rfclist/basic/rfc0822.txt'>RFC822</a>.
+ * Gets the local part of the email address. Specified in <a
+ * href='http://james.apache.org/server/rfclist/basic/rfc0822.txt'>RFC822</a>.
+ *
* @return local part, not null
*/
public String getLocalPart();
-
+
/**
- * Gets the domain part of the email address.
- * Specified in
- * <a href='http://james.apache.org/server/rfclist/basic/rfc0822.txt'>RFC822</a>.
+ * Gets the domain part of the email address. Specified in <a
+ * href='http://james.apache.org/server/rfclist/basic/rfc0822.txt'>RFC822</a>.
+ *
* @return domain, not null
*/
public String getDomain();
Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/MailUtils.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/MailUtils.java?rev=578033&r1=578032&r2=578033&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/MailUtils.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/MailUtils.java Fri Sep 21 02:32:00 2007
@@ -17,7 +17,6 @@
* under the License. *
****************************************************************/
-
package org.apache.jsieve.mail;
import java.util.ArrayList;
@@ -25,30 +24,29 @@
import java.util.List;
/**
- * Class MailUtils implements utility methods that are useful when processing Sieve
- * mail.
+ * Class MailUtils implements utility methods that are useful when processing
+ * Sieve mail.
*/
-public class MailUtils
-{
+public class MailUtils {
/**
* Constructor for MailUtils.
*/
- protected MailUtils()
- {
+ protected MailUtils() {
super();
}
-
/**
- * <p>Method getMatchingHeader answers a List of all of the headers in the mail
+ * <p>
+ * Method getMatchingHeader answers a List of all of the headers in the mail
* with the passed name. If no headers are found an empty List is returned.
* </p>
*
- * <p>This method differs from MailAdapter.getHeader(String) in that it
- * ignores case and whitespace prefixes and suffixes to a header name when
- * performing the match, as required by RFC 3028. Thus "From", "from ", " From"
- * and " from " are considered equal.
+ * <p>
+ * This method differs from MailAdapter.getHeader(String) in that it ignores
+ * case and whitespace prefixes and suffixes to a header name when
+ * performing the match, as required by RFC 3028. Thus "From", "from ", "
+ * From" and " from " are considered equal.
* </p>
*
* @param name
@@ -56,17 +54,15 @@
* @throws SieveMailException
*/
static public List getMatchingHeader(MailAdapter mail, String name)
- throws SieveMailException
- {
+ throws SieveMailException {
Iterator headerNamesIter = mail.getHeaderNames().iterator();
List matchedHeaderValues = new ArrayList(32);
- while (headerNamesIter.hasNext())
- {
+ while (headerNamesIter.hasNext()) {
String headerName = (String) headerNamesIter.next();
if (headerName.trim().equalsIgnoreCase(name))
matchedHeaderValues.addAll(mail.getHeader(headerName));
}
return matchedHeaderValues;
- }
+ }
}
Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/SieveMailException.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/SieveMailException.java?rev=578033&r1=578032&r2=578033&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/SieveMailException.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/SieveMailException.java Fri Sep 21 02:32:00 2007
@@ -17,51 +17,48 @@
* under the License. *
****************************************************************/
-
package org.apache.jsieve.mail;
import org.apache.jsieve.exception.SieveException;
/**
- * Class <code>SieveMailException</code> indicates an exceptional condition
+ * Class <code>SieveMailException</code> indicates an exceptional condition
* encountered while processing Sieve Mail.
*/
-public class SieveMailException extends SieveException
-{
+public class SieveMailException extends SieveException {
/**
* Constructor for SieveMailException.
*/
- public SieveMailException()
- {
+ public SieveMailException() {
super();
}
/**
* Constructor for SieveMailException.
+ *
* @param message
*/
- public SieveMailException(String message)
- {
+ public SieveMailException(String message) {
super(message);
}
/**
* Constructor for SieveMailException.
+ *
* @param message
* @param cause
*/
- public SieveMailException(String message, Throwable cause)
- {
+ public SieveMailException(String message, Throwable cause) {
super(message, cause);
}
/**
* Constructor for SieveMailException.
+ *
* @param cause
*/
- public SieveMailException(Throwable cause)
- {
+ public SieveMailException(Throwable cause) {
super(cause);
}
Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/optional/EnvelopeAccessors.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/optional/EnvelopeAccessors.java?rev=578033&r1=578032&r2=578033&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/optional/EnvelopeAccessors.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/mail/optional/EnvelopeAccessors.java Fri Sep 21 02:32:00 2007
@@ -17,7 +17,6 @@
* under the License. *
****************************************************************/
-
package org.apache.jsieve.mail.optional;
import java.util.List;
@@ -25,52 +24,48 @@
import org.apache.jsieve.mail.SieveMailException;
/**
- * Interface EnvelopeAccessors specifies the method signatures required to support
- * the Envelope Test.
+ * Interface EnvelopeAccessors specifies the method signatures required to
+ * support the Envelope Test.
*/
-public interface EnvelopeAccessors
-{
+public interface EnvelopeAccessors {
/**
- * Method getEnvelope answers a List of all of the envelope values in the
- * receiver whose name is equal to the passed name. If no values are found an
- * empty List is returned.
+ * Method getEnvelope answers a List of all of the envelope values in the
+ * receiver whose name is equal to the passed name. If no values are found
+ * an empty List is returned.
*
* @param name
* @return List
* @throws SieveMailException
*/
public List getEnvelope(String name) throws SieveMailException;
-
/**
- * Method getEnvelopeNames answers a List of the names of the envelope values in
- * the receiver.
- * No duplicates are allowed.
+ * Method getEnvelopeNames answers a List of the names of the envelope
+ * values in the receiver. No duplicates are allowed.
+ *
* @return List
* @throws SieveMailException
*/
- public List getEnvelopeNames() throws SieveMailException;
-
+ public List getEnvelopeNames() throws SieveMailException;
/**
- * <p>Method getMatchingEnvelope answers a List of all of the envelope values in
- * the receiver with the passed name. If no matching names are found an empty
- * List is returned.
+ * <p>
+ * Method getMatchingEnvelope answers a List of all of the envelope values
+ * in the receiver with the passed name. If no matching names are found an
+ * empty List is returned.
* </p>
*
- * <p>This method differs from getEnvelope(String) in that it ignores case and
- * the whitespace prefixes and suffixes of an envelope value name when performing
- * the match, as required by RFC 3028. Thus "From", "from ", " From" and " from "
- * are considered equal.
+ * <p>
+ * This method differs from getEnvelope(String) in that it ignores case and
+ * the whitespace prefixes and suffixes of an envelope value name when
+ * performing the match, as required by RFC 3028. Thus "From", "from ", "
+ * From" and " from " are considered equal.
* </p>
*
* @param name
* @return List
* @throws SieveMailException
*/
- public List getMatchingEnvelope(String name)
- throws SieveMailException;
-
-
+ public List getMatchingEnvelope(String name) throws SieveMailException;
}
Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/parser/SieveNode.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/parser/SieveNode.java?rev=578033&r1=578032&r2=578033&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/parser/SieveNode.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/parser/SieveNode.java Fri Sep 21 02:32:00 2007
@@ -17,7 +17,6 @@
* under the License. *
****************************************************************/
-
package org.apache.jsieve.parser;
import org.apache.jsieve.ScriptCoordinate;
@@ -28,76 +27,81 @@
*
* Creation Date: 27-Jan-04
*/
-public class SieveNode
-{
+public class SieveNode {
/**
* Constructor for SieveNode.
*/
- public SieveNode()
- {
+ public SieveNode() {
super();
}
private Token firstToken;
+
private Token lastToken;
-
+
/**
- * The name associated to this node or null
- */
+ * The name associated to this node or null
+ */
private String fieldName;
-
+
/**
- * The value associated to this node or null
- */
- private Object fieldValue;
+ * The value associated to this node or null
+ */
+ private Object fieldValue;
+
/**
* Returns the name.
+ *
* @return String
*/
- public String getName()
- {
+ public String getName() {
return fieldName;
}
/**
* Returns the value.
+ *
* @return Object
*/
- public Object getValue()
- {
+ public Object getValue() {
return fieldValue;
}
/**
* Sets the name.
- * @param name The name to set
+ *
+ * @param name
+ * The name to set
*/
- public void setName(String name)
- {
+ public void setName(String name) {
fieldName = name;
}
/**
* Sets the value.
- * @param value The value to set
+ *
+ * @param value
+ * The value to set
*/
- public void setValue(Object value)
- {
+ public void setValue(Object value) {
fieldValue = value;
}
/**
* Gets the first token comprising this node.
+ *
* @return <code>Token</code>, not null
*/
public Token getFirstToken() {
return firstToken;
}
-
+
/**
* Sets the first token comprising this node.
- * @param firstToken <code>Token</code>, not null
+ *
+ * @param firstToken
+ * <code>Token</code>, not null
*/
public void setFirstToken(Token firstToken) {
this.firstToken = firstToken;
@@ -105,6 +109,7 @@
/**
* Gets the last token comprising this node.
+ *
* @return <code>Token</code>, not null
*/
public Token getLastToken() {
@@ -113,23 +118,27 @@
/**
* Sets the last token comprising this node.
- * @param lastToken <code>Token</code>, not null
+ *
+ * @param lastToken
+ * <code>Token</code>, not null
*/
public void setLastToken(Token lastToken) {
this.lastToken = lastToken;
}
-
+
/**
* Gets the position of this node in the script.
- * @return <code>ScriptCoordinate</code> containing the position of this node,
- * not null
+ *
+ * @return <code>ScriptCoordinate</code> containing the position of this
+ * node, not null
*/
public ScriptCoordinate getCoordinate() {
final int lastColumn = lastToken.endColumn;
final int lastList = lastToken.endLine;
final int firstColumn = firstToken.beginColumn;
final int firstLine = firstToken.beginLine;
- final ScriptCoordinate scriptCoordinate = new ScriptCoordinate(firstLine, firstColumn, lastList, lastColumn);
+ final ScriptCoordinate scriptCoordinate = new ScriptCoordinate(
+ firstLine, firstColumn, lastList, lastColumn);
return scriptCoordinate;
}
}
Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/parser/address/SieveAddressBuilder.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/parser/address/SieveAddressBuilder.java?rev=578033&r1=578032&r2=578033&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/parser/address/SieveAddressBuilder.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/parser/address/SieveAddressBuilder.java Fri Sep 21 02:32:00 2007
@@ -25,7 +25,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
-import java.util.List;
import javax.mail.Header;
import javax.mail.Message;
@@ -53,36 +52,41 @@
/**
* Parses the value from the given message into addresses.
- * @param headerName header name, to be matched case insensitively
- * @param message <code>Message</code>, not null
+ *
+ * @param headerName
+ * header name, to be matched case insensitively
+ * @param message
+ * <code>Message</code>, not null
* @return <code>Address</code> array, not null possibly empty
* @throws SieveMailException
*/
- public static Address[] parseAddresses(final String headerName, final Message message) throws SieveMailException {
+ public static Address[] parseAddresses(final String headerName,
+ final Message message) throws SieveMailException {
try {
final SieveAddressBuilder builder = new SieveAddressBuilder();
- for (Enumeration en = message.getAllHeaders();en.hasMoreElements();) {
+ for (Enumeration en = message.getAllHeaders(); en.hasMoreElements();) {
final Header header = (Header) en.nextElement();
final String name = header.getName();
if (name.trim().equalsIgnoreCase(headerName)) {
builder.addAddresses(header.getValue());
}
}
-
+
final Address[] results = builder.getAddresses();
return results;
-
+
} catch (MessagingException ex) {
throw new SieveMailException(ex);
} catch (ParseException ex) {
throw new SieveMailException(ex);
}
}
-
+
private static final Address[] EMPTY_ADDRESSES = {};
private final Collection addresses;
+
private final Worker worker;
public SieveAddressBuilder() {
@@ -101,12 +105,12 @@
* Adds addresses in the given list.
*
* @param addressList
- * RFC822 address list
- * @throws ParseException
+ * RFC822 address list
+ * @throws ParseException
*/
public void addAddresses(String addressList) throws ParseException {
final StringReader reader = new StringReader(addressList);
- worker.addAddressses(reader, addresses);
+ worker.addAddressses(reader, addresses);
}
/**
@@ -122,12 +126,13 @@
}
/**
- * Performs the actual work.
- * Factored into an inner class so that the build interface is clean.
+ * Performs the actual work. Factored into an inner class so that the build
+ * interface is clean.
*/
private final class Worker extends BaseAddressListVisitor {
- public void addAddressses(final Reader reader, final Collection results) throws ParseException {
+ public void addAddressses(final Reader reader, final Collection results)
+ throws ParseException {
AddressListParser parser = new AddressListParser(reader);
ASTaddress_list root = parser.parse();
root.childrenAccept(this, results);
@@ -160,12 +165,12 @@
}
return data;
}
-
+
private String contents(AddressNode node) {
StringBuffer buffer = new StringBuffer(32);
Token last = node.lastToken;
Token next = node.firstToken;
- while(next != last) {
+ while (next != last) {
buffer.append(next.image);
next = next.next;
}
Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/ActionDispatcher.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/ActionDispatcher.java?rev=578033&r1=578032&r2=578033&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/ActionDispatcher.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/ActionDispatcher.java Fri Sep 21 02:32:00 2007
@@ -35,92 +35,88 @@
import org.apache.mailet.MailetContext;
/**
- * Singleton Class <code>ActionDispatcher</code> dynamically dispatches
- * an Action depending on the type of Action received at runtime.
+ * Singleton Class <code>ActionDispatcher</code> dynamically dispatches an
+ * Action depending on the type of Action received at runtime.
*/
-public class ActionDispatcher
-{
+public class ActionDispatcher {
/**
- * The sole instance of the receiver.
+ * The sole instance of the receiver.
*/
static private ActionDispatcher fieldInstance;
-
+
/**
- * A Map keyed by the type of Action. The values are the methods to invoke to
- * handle the Action.
- */
+ * A Map keyed by the type of Action. The values are the methods to invoke
+ * to handle the Action.
+ */
private Map fieldMethodMap;
/**
* Constructor for ActionDispatcher.
*/
- private ActionDispatcher()
- {
+ private ActionDispatcher() {
super();
}
/**
* Returns the sole instance of the receiver, lazily initialised.
+ *
* @return ActionDispatcher
*/
- public static synchronized ActionDispatcher getInstance()
- {
+ public static synchronized ActionDispatcher getInstance() {
ActionDispatcher instance = null;
- if (null == (instance = getInstanceBasic()))
- {
+ if (null == (instance = getInstanceBasic())) {
updateInstance();
return getInstance();
- }
+ }
return instance;
}
-
+
/**
* Returns the sole instance of the receiver.
+ *
* @return ActionDispatcher
*/
- private static ActionDispatcher getInstanceBasic()
- {
+ private static ActionDispatcher getInstanceBasic() {
return fieldInstance;
- }
-
+ }
+
/**
* Returns a new instance of the receiver.
+ *
* @return ActionDispatcher
*/
- protected static ActionDispatcher computeInstance()
- {
+ protected static ActionDispatcher computeInstance() {
return new ActionDispatcher();
- }
+ }
/**
* Sets the instance.
- * @param instance The instance to set
+ *
+ * @param instance
+ * The instance to set
*/
- protected static void setInstance(ActionDispatcher instance)
- {
+ protected static void setInstance(ActionDispatcher instance) {
fieldInstance = instance;
}
-
-
+
/**
* Resets the instance.
*/
- public static void resetInstance()
- {
+ public static void resetInstance() {
setInstance(null);
- }
-
+ }
+
/**
* Updates the instance.
*/
- protected static void updateInstance()
- {
+ protected static void updateInstance() {
setInstance(computeInstance());
}
-
+
/**
- * Method execute executes the passed Action by invoking the method mapped by the
- * receiver with a parameter of the EXACT type of Action.
+ * Method execute executes the passed Action by invoking the method mapped
+ * by the receiver with a parameter of the EXACT type of Action.
+ *
* @param anAction
* @param aMail
* @param aMailetContext
@@ -129,113 +125,82 @@
* @throws InvocationTargetException
* @throws MessagingException
*/
- public void execute(
- Action anAction,
- Mail aMail,
- MailetContext aMailetContext)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException,
- MessagingException
- {
+ public void execute(Action anAction, Mail aMail,
+ MailetContext aMailetContext) throws NoSuchMethodException,
+ IllegalAccessException, InvocationTargetException,
+ MessagingException {
Method actionMethod = (Method) getMethodMap().get(anAction.getClass());
if (null == actionMethod)
- throw new NoSuchMethodException(
- "Method accepting parameters ("
- + anAction.getClass().getName()
- + ", "
- + aMail.getClass().getName()
- + ", "
- + aMailetContext.getClass().getName()
- + ") not mapped.");
- actionMethod.invoke(
- null,
- new Object[] { anAction, aMail, aMailetContext });
+ throw new NoSuchMethodException("Method accepting parameters ("
+ + anAction.getClass().getName() + ", "
+ + aMail.getClass().getName() + ", "
+ + aMailetContext.getClass().getName() + ") not mapped.");
+ actionMethod.invoke(null, new Object[] { anAction, aMail,
+ aMailetContext });
}
-
+
/**
* Returns the methodMap, lazily initialised.
+ *
* @return Map
* @throws NoSuchMethodException
*/
- protected synchronized Map getMethodMap() throws NoSuchMethodException
- {
+ protected synchronized Map getMethodMap() throws NoSuchMethodException {
Map methodMap = null;
- if (null == (methodMap = getMethodMapBasic()))
- {
+ if (null == (methodMap = getMethodMapBasic())) {
updateMethodMap();
return getMethodMap();
- }
+ }
return methodMap;
}
-
+
/**
* Returns the methodMap.
+ *
* @return Map
*/
- private Map getMethodMapBasic()
- {
+ private Map getMethodMapBasic() {
return fieldMethodMap;
- }
-
+ }
+
/**
* Returns a new methodMap.
+ *
* @return Map
*/
- protected Map computeMethodMap() throws NoSuchMethodException
- {
+ protected Map computeMethodMap() throws NoSuchMethodException {
Map methodNameMap = new HashMap();
- methodNameMap.put(
- ActionFileInto.class,
- Actions.class.getMethod(
- "execute",
- new Class[] {
- ActionFileInto.class,
- Mail.class,
- MailetContext.class }));
- methodNameMap.put(
- ActionKeep.class,
- Actions.class.getMethod(
- "execute",
- new Class[] {
- ActionKeep.class,
- Mail.class,
- MailetContext.class }));
- methodNameMap.put(
- ActionRedirect.class,
- Actions.class.getMethod(
- "execute",
- new Class[] {
- ActionRedirect.class,
- Mail.class,
- MailetContext.class }));
- methodNameMap.put(
- ActionReject.class,
- Actions.class.getMethod(
- "execute",
- new Class[] {
- ActionReject.class,
- Mail.class,
- MailetContext.class }));
+ methodNameMap.put(ActionFileInto.class, Actions.class.getMethod(
+ "execute", new Class[] { ActionFileInto.class, Mail.class,
+ MailetContext.class }));
+ methodNameMap.put(ActionKeep.class, Actions.class
+ .getMethod("execute", new Class[] { ActionKeep.class,
+ Mail.class, MailetContext.class }));
+ methodNameMap.put(ActionRedirect.class, Actions.class.getMethod(
+ "execute", new Class[] { ActionRedirect.class, Mail.class,
+ MailetContext.class }));
+ methodNameMap.put(ActionReject.class, Actions.class.getMethod(
+ "execute", new Class[] { ActionReject.class, Mail.class,
+ MailetContext.class }));
return methodNameMap;
- }
+ }
/**
* Sets the methodMap.
- * @param methodMap The methodMap to set
+ *
+ * @param methodMap
+ * The methodMap to set
*/
- protected void setMethodMap(Map methodMap)
- {
+ protected void setMethodMap(Map methodMap) {
fieldMethodMap = methodMap;
}
-
+
/**
* Updates the methodMap.
+ *
* @throws NoSuchMethodException
*/
- protected void updateMethodMap() throws NoSuchMethodException
- {
+ protected void updateMethodMap() throws NoSuchMethodException {
setMethodMap(computeMethodMap());
}
Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/Actions.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/Actions.java?rev=578033&r1=578032&r2=578033&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/Actions.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/Actions.java Fri Sep 21 02:32:00 2007
@@ -49,15 +49,13 @@
* Singleton Class <code>Actions</code> implements <code>execute()</code>
* methods for each of the supported Actions.
*/
-public class Actions
-{
+public class Actions {
static private String fieldAttributePrefix;
/**
* Constructor for Actions.
*/
- private Actions()
- {
+ private Actions() {
super();
}
@@ -67,7 +65,8 @@
* </p>
*
* <p>
- * This implementation accepts any destination with the root of <code>INBOX</code>.
+ * This implementation accepts any destination with the root of
+ * <code>INBOX</code>.
* </p>
*
* <p>
@@ -87,22 +86,19 @@
* @throws MessagingException
*/
static public void execute(ActionFileInto anAction, Mail aMail,
- MailetContext aMailetContext) throws MessagingException
- {
+ MailetContext aMailetContext) throws MessagingException {
StringBuffer repositoryDestinationBuffer = null;
MailAddress recipient = null;
boolean delivered = false;
- try
- {
+ try {
recipient = getSoleRecipient(aMail);
// Validate and translate the destination
// Note that we do not check that the repository implementation
// supports the destination or that it exists. That is left
// to the repository implementation
int endOfRootDestination = anAction.getDestination().indexOf('/');
- String rootDestination = (endOfRootDestination > -1
- ? anAction.getDestination().substring(0,
- endOfRootDestination)
+ String rootDestination = (endOfRootDestination > -1 ? anAction
+ .getDestination().substring(0, endOfRootDestination)
: anAction.getDestination());
if (!rootDestination.equalsIgnoreCase("INBOX"))
throw new DestinationException("Folder: \""
@@ -113,10 +109,8 @@
.substring(endOfRootDestination).replace('/', '.'));
// Adapted from LocalDelivery Mailet
// Add qmail's de facto standard Delivered-To header
- MimeMessage localMessage = new MimeMessage(aMail.getMessage())
- {
- protected void updateHeaders() throws MessagingException
- {
+ MimeMessage localMessage = new MimeMessage(aMail.getMessage()) {
+ protected void updateHeaders() throws MessagingException {
if (getMessageID() == null)
super.updateHeaders();
else
@@ -136,19 +130,14 @@
aMailetContext
.storeMail(aMail.getSender(), recipient, localMessage);
delivered = true;
- }
- catch (MessagingException ex)
- {
+ } catch (MessagingException ex) {
aMailetContext.log("Error while storing mail.", ex);
throw ex;
- }
- finally
- {
+ } finally {
// Ensure the mail is always ghosted
aMail.setState(Mail.GHOST);
}
- if (delivered)
- {
+ if (delivered) {
aMailetContext.log("Filed Message ID: "
+ aMail.getMessage().getMessageID()
+ " into destination: \""
@@ -172,8 +161,7 @@
* @throws MessagingException
*/
public static void execute(ActionKeep anAction, Mail aMail,
- MailetContext aMailetContext) throws MessagingException
- {
+ MailetContext aMailetContext) throws MessagingException {
ActionFileInto action = new ActionFileInto("INBOX");
execute(action, aMail, aMailetContext);
}
@@ -187,8 +175,7 @@
* @throws MessagingException
*/
public static void execute(ActionRedirect anAction, Mail aMail,
- MailetContext aMailetContext) throws MessagingException
- {
+ MailetContext aMailetContext) throws MessagingException {
detectAndHandleLocalLooping(aMail, aMailetContext, "redirect");
Collection recipients = new ArrayList(1);
recipients.add(new InternetAddress(anAction.getAddress()));
@@ -215,8 +202,7 @@
* @throws MessagingException
*/
public static void execute(ActionReject anAction, Mail aMail,
- MailetContext aMailetContext) throws MessagingException
- {
+ MailetContext aMailetContext) throws MessagingException {
detectAndHandleLocalLooping(aMail, aMailetContext, "reject");
// Create the MDN part
@@ -230,13 +216,10 @@
humanText.append(anAction.getMessage());
String reporting_UA_name = null;
- try
- {
+ try {
reporting_UA_name = InetAddress.getLocalHost()
.getCanonicalHostName();
- }
- catch (UnknownHostException ex)
- {
+ } catch (UnknownHostException ex) {
reporting_UA_name = "localhost";
}
@@ -245,8 +228,7 @@
String[] originalRecipients = aMail.getMessage().getHeader(
"Original-Recipient");
String original_recipient = null;
- if (null != originalRecipients && originalRecipients.length > 0)
- {
+ if (null != originalRecipients && originalRecipients.length > 0) {
original_recipient = originalRecipients[0];
}
@@ -255,7 +237,7 @@
String original_message_id = aMail.getMessage().getMessageID();
- DispositionModifier modifiers[] = {new ModifierError()};
+ DispositionModifier modifiers[] = { new ModifierError() };
Disposition disposition = new Disposition(new ActionModeAutomatic(),
new SendingModeAutomatic(), new TypeDeleted(), modifiers);
@@ -269,18 +251,14 @@
reply.setContent(multiPart);
reply.saveChanges();
Address[] recipientAddresses = reply.getAllRecipients();
- if (null != recipientAddresses)
- {
+ if (null != recipientAddresses) {
Collection recipients = new ArrayList(recipientAddresses.length);
- for (int i = 0; i < recipientAddresses.length; i++)
- {
+ for (int i = 0; i < recipientAddresses.length; i++) {
recipients.add(new MailAddress(
(InternetAddress) recipientAddresses[i]));
}
aMailetContext.sendMail(null, recipients, reply);
- }
- else
- {
+ } else {
aMailetContext
.log("Unable to send reject MDN. Could not determine the recipient.");
}
@@ -296,12 +274,11 @@
* @throws MessagingException
*/
protected static MailAddress getSoleRecipient(Mail aMail)
- throws MessagingException
- {
- if (aMail.getRecipients() == null) {
- throw new MessagingException("Invalid number of recipients - 0"
- + ". Exactly 1 recipient is expected.");
- } else if (1 != aMail.getRecipients().size())
+ throws MessagingException {
+ if (aMail.getRecipients() == null) {
+ throw new MessagingException("Invalid number of recipients - 0"
+ + ". Exactly 1 recipient is expected.");
+ } else if (1 != aMail.getRecipients().size())
throw new MessagingException("Invalid number of recipients - "
+ new Integer(aMail.getRecipients().size()).toString()
+ ". Exactly 1 recipient is expected.");
@@ -313,11 +290,9 @@
*
* @return String
*/
- protected static String getAttributePrefix()
- {
+ protected static String getAttributePrefix() {
String value = null;
- if (null == (value = getAttributePrefixBasic()))
- {
+ if (null == (value = getAttributePrefixBasic())) {
updateAttributePrefix();
return getAttributePrefix();
}
@@ -329,8 +304,7 @@
*
* @return String
*/
- private static String getAttributePrefixBasic()
- {
+ private static String getAttributePrefixBasic() {
return fieldAttributePrefix;
}
@@ -339,26 +313,24 @@
*
* @return String
*/
- protected static String computeAttributePrefix()
- {
+ protected static String computeAttributePrefix() {
return Actions.class.getPackage().getName() + ".";
}
/**
* Sets the attributePrefix.
*
- * @param attributePrefix The attributePrefix to set
+ * @param attributePrefix
+ * The attributePrefix to set
*/
- protected static void setAttributePrefix(String attributePrefix)
- {
+ protected static void setAttributePrefix(String attributePrefix) {
fieldAttributePrefix = attributePrefix;
}
/**
* Updates the attributePrefix.
*/
- protected static void updateAttributePrefix()
- {
+ protected static void updateAttributePrefix() {
setAttributePrefix(computeAttributePrefix());
}
@@ -373,13 +345,11 @@
*/
protected static void detectAndHandleLocalLooping(Mail aMail,
MailetContext aMailetContext, String anAttributeSuffix)
- throws MessagingException
- {
+ throws MessagingException {
MailAddress thisRecipient = getSoleRecipient(aMail);
MailAddress lastRecipient = (MailAddress) aMail
.getAttribute(getAttributePrefix() + anAttributeSuffix);
- if (null != lastRecipient && lastRecipient.equals(thisRecipient))
- {
+ if (null != lastRecipient && lastRecipient.equals(thisRecipient)) {
MessagingException ex = new MessagingException(
"This message is looping! Message ID: "
+ aMail.getMessage().getMessageID());
Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/DestinationException.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/DestinationException.java?rev=578033&r1=578032&r2=578033&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/DestinationException.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/DestinationException.java Fri Sep 21 02:32:00 2007
@@ -25,33 +25,31 @@
* Class <code>DestinationException</code> is thrown when a target
* destionaition is invalid.
*/
-public class DestinationException extends MessagingException
-{
+public class DestinationException extends MessagingException {
/**
* Constructor for DestinationException.
*/
- public DestinationException()
- {
+ public DestinationException() {
super();
}
/**
* Constructor for DestinationException.
+ *
* @param arg0
*/
- public DestinationException(String arg0)
- {
+ public DestinationException(String arg0) {
super(arg0);
}
/**
* Constructor for DestinationException.
+ *
* @param arg0
* @param arg1
*/
- public DestinationException(String arg0, Exception arg1)
- {
+ public DestinationException(String arg0, Exception arg1) {
super(arg0, arg1);
}
Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/JSieve.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/JSieve.java?rev=578033&r1=578032&r2=578033&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/JSieve.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/JSieve.java Fri Sep 21 02:32:00 2007
@@ -43,96 +43,94 @@
/**
* <p>
- * Class JSieve is a DEMONSTRATION Mailet that invokes JSieve to
- * perform mail processing. There is a single configuration parameter,
- * <code>scriptURL</code>. This a URL pointing to the resource containing
- * the Sieve script to run.
+ * Class JSieve is a DEMONSTRATION Mailet that invokes JSieve to perform mail
+ * processing. There is a single configuration parameter, <code>scriptURL</code>.
+ * This a URL pointing to the resource containing the Sieve script to run.
* </p>
*
* <p>
- * This Mailet is intended to replace the <code>LocalDelivery</code>
- * Mailet in James. Sieve's Keep Action is functionally equivalent to the
+ * This Mailet is intended to replace the <code>LocalDelivery</code> Mailet in
+ * James. Sieve's Keep Action is functionally equivalent to the
* <code>LocalDelivery</code> Mailet's processing. The Sieve script may
- * explicitily or implicitly invoke this Action, and/or any other
- * configured Action. Actions are configured in class
- * <code>ActionDispatcher</code>.
+ * explicitily or implicitly invoke this Action, and/or any other configured
+ * Action. Actions are configured in class <code>ActionDispatcher</code>.
* </p>
*
- * <p>IMPORTANT NOTES</p>
+ * <p>
+ * IMPORTANT NOTES
+ * </p>
*
* <p>
* This is NOT production quality code! It is a test harness for exercising
- * jSieve. At least the feutures listed below would be required to consider
- * this of production quality.
+ * jSieve. At least the feutures listed below would be required to consider this
+ * of production quality.
* </p>
*
- * <p>REQUIRED FEATURES</p>
+ * <p>
+ * REQUIRED FEATURES
+ * </p>
*
* <p>
- * To be truly useful, this mailet needs to be configurable to invoke
- * user specific Sieve scripts so that indivual users have control of their
- * mail processing.
+ * To be truly useful, this mailet needs to be configurable to invoke user
+ * specific Sieve scripts so that indivual users have control of their mail
+ * processing.
* </p>
*
* <p>
- * In a Mailet environment, a generic Sieve command to invoke a Mailet
- * would be extremely powerful as jSieve could then leverage the abilities
- * of all available Mailets. Currently, Sieve must wastefully duplicate
- * the same behaviour as Sieve commands.
- * </p>
+ * In a Mailet environment, a generic Sieve command to invoke a Mailet would be
+ * extremely powerful as jSieve could then leverage the abilities of all
+ * available Mailets. Currently, Sieve must wastefully duplicate the same
+ * behaviour as Sieve commands.
+ * </p>
*
- * <p>The converse also applies. Provision should be made for a Mailet to
- * reuse jSieve commands. As the primary difference between the two is
- * that Sieve deals with a single recipient while Mailets deal with
- * multiple recipients, a Mailet could simply iterate over all of its
- * recipients invoking the Sieve command for each recipient.
+ * <p>
+ * The converse also applies. Provision should be made for a Mailet to reuse
+ * jSieve commands. As the primary difference between the two is that Sieve
+ * deals with a single recipient while Mailets deal with multiple recipients, a
+ * Mailet could simply iterate over all of its recipients invoking the Sieve
+ * command for each recipient.
* </p>
*/
-public class JSieve extends GenericMailet
-{
+public class JSieve extends GenericMailet {
private static final Random random = new Random();
+
private URL fieldScriptURL;
+
private Node fieldStartNode;
/**
* Constructor for JSieve.
*/
- public JSieve()
- {
+ public JSieve() {
super();
}
/**
* @see org.apache.mailet.Mailet#service(Mail)
*/
- public void service(Mail mail) throws MessagingException
- {
+ public void service(Mail mail) throws MessagingException {
// If the mail has no recipients, do nothing
if (mail.getRecipients().isEmpty())
return;
// Sieve expects a single recipient. If the mail has more we need to
// clone the mail, with each mail having a single recipient and
// resend them.
- if (mail.getRecipients().size() == 1)
- {
+ if (mail.getRecipients().size() == 1) {
// Evaluate the mail against the script.
// The default state for the mail is GHOST.
// Actions executed as a result of evaluating the script may
// change this.
mail.setState(Mail.GHOST);
evaluate(mail);
- }
- else
- {
+ } else {
Iterator recipientsIter = mail.getRecipients().iterator();
List recipients = new ArrayList(1);
- while (recipientsIter.hasNext())
- {
- // MailImpl mailClone = duplicate((MailImpl) mail);
+ while (recipientsIter.hasNext()) {
+ // MailImpl mailClone = duplicate((MailImpl) mail);
recipients.clear();
recipients.add(recipientsIter.next());
- // mailClone.setRecipients(recipients);
- // getMailetContext().sendMail(mailClone);
+ // mailClone.setRecipients(recipients);
+ // getMailetContext().sendMail(mailClone);
getMailetContext().sendMail(mail.getSender(), recipients,
mail.getMessage(), mail.getState());
}
@@ -141,8 +139,7 @@
}
}
- protected MailImpl duplicate(MailImpl aMail) throws MessagingException
- {
+ protected MailImpl duplicate(MailImpl aMail) throws MessagingException {
// duplicates the Mail object, to be able to modify the new mail
// keeping
// the original untouched
@@ -150,15 +147,12 @@
// We don't need to use the original Remote Address and Host,
// and doing so would likely cause a loop with spam detecting
// matchers.
- try
- {
- newMail.setRemoteAddr(java.net.InetAddress
- .getLocalHost().getHostAddress());
- newMail.setRemoteHost(java.net.InetAddress
- .getLocalHost().getHostName());
- }
- catch (java.net.UnknownHostException _)
- {
+ try {
+ newMail.setRemoteAddr(java.net.InetAddress.getLocalHost()
+ .getHostAddress());
+ newMail.setRemoteHost(java.net.InetAddress.getLocalHost()
+ .getHostName());
+ } catch (java.net.UnknownHostException _) {
newMail.setRemoteAddr("127.0.0.1");
newMail.setRemoteHost("localhost");
}
@@ -170,34 +164,29 @@
*
* Borrowed from org.apache.james.transport.mailets.AbstractRedirect
*
- * @param mail the mail to use as the basis for the new mail name
+ * @param mail
+ * the mail to use as the basis for the new mail name
* @return a new name
*/
- private String newName(MailImpl mail) throws MessagingException
- {
+ private String newName(MailImpl mail) throws MessagingException {
String oldName = mail.getName();
// Checking if the original mail name is too long, perhaps because of a
// loop caused by a configuration error.
// it could cause a "null pointer exception" in AvalonMailRepository
// much
// harder to understand.
- if (oldName.length() > 76)
- {
+ if (oldName.length() > 76) {
int count = 0;
int index = 0;
- while ((index = oldName.indexOf('!', index + 1)) >= 0)
- {
+ while ((index = oldName.indexOf('!', index + 1)) >= 0) {
count++;
}
// It looks like a configuration loop. It's better to stop.
- if (count > 7)
- {
+ if (count > 7) {
throw new MessagingException(
"Unable to create a new message name: too long."
+ " Possible loop in config.xml.");
- }
- else
- {
+ } else {
oldName = oldName.substring(0, 76);
}
}
@@ -212,19 +201,15 @@
* @param aMail
* @throws MessagingException
*/
- protected void evaluate(Mail aMail) throws MessagingException
- {
+ protected void evaluate(Mail aMail) throws MessagingException {
// Evaluate the script against the mail
- try
- {
+ try {
MailAdapter aMailAdapter = new SieveMailAdapter(aMail,
getMailetContext());
log("Evaluating " + aMailAdapter.toString() + "against \""
+ getScriptURL().toExternalForm() + "\"");
SieveFactory.getInstance().evaluate(aMailAdapter, getStartNode());
- }
- catch (SieveException ex)
- {
+ } catch (SieveException ex) {
log("Exception evaluating Sieve script", ex);
// If there were errors, we redirect the email to the ERROR
// processor.
@@ -247,18 +232,17 @@
*
* @return URL
*/
- public URL getScriptURL()
- {
+ public URL getScriptURL() {
return fieldScriptURL;
}
/**
* Sets the scriptURL.
*
- * @param scriptURL The scriptURL to set
+ * @param scriptURL
+ * The scriptURL to set
*/
- protected void setScriptURL(URL scriptURL)
- {
+ protected void setScriptURL(URL scriptURL) {
fieldScriptURL = scriptURL;
}
@@ -268,11 +252,9 @@
* @return Node
* @throws MessagingException
*/
- public Node getStartNode() throws MessagingException
- {
+ public Node getStartNode() throws MessagingException {
Node node = null;
- if (null == (node = getStartNodeBasic()))
- {
+ if (null == (node = getStartNodeBasic())) {
updateStartNode();
return getStartNode();
}
@@ -284,8 +266,7 @@
*
* @return Node
*/
- private Node getStartNodeBasic()
- {
+ private Node getStartNodeBasic() {
return fieldStartNode;
}
@@ -295,14 +276,11 @@
* @return Node
* @throws MessagingException
*/
- protected Node computeStartNode() throws MessagingException
- {
+ protected Node computeStartNode() throws MessagingException {
Object content = null;
- try
- {
+ try {
content = getScriptURL().getContent();
- if (!(content instanceof InputStream))
- {
+ if (!(content instanceof InputStream)) {
String msg = "Cannot get an InputStream for "
+ getScriptURL().toExternalForm();
log(msg);
@@ -310,16 +288,12 @@
}
return SieveFactory.getInstance().parse(
new BufferedInputStream((InputStream) content));
- }
- catch (IOException ex)
- {
+ } catch (IOException ex) {
String msg = "Exception getting contents of script URL: "
+ getScriptURL().toExternalForm();
log(msg, ex);
throw new MessagingException(msg, ex);
- }
- catch (ParseException ex)
- {
+ } catch (ParseException ex) {
String msg = "Exception parsing Sieve script: "
+ getScriptURL().toExternalForm();
log(msg, ex);
@@ -330,10 +304,10 @@
/**
* Sets the startNode.
*
- * @param startNode The startNode to set
+ * @param startNode
+ * The startNode to set
*/
- protected void setStartNode(Node startNode)
- {
+ protected void setStartNode(Node startNode) {
fieldStartNode = startNode;
}
@@ -342,23 +316,18 @@
*
* @throws MessagingException
*/
- protected void updateStartNode() throws MessagingException
- {
+ protected void updateStartNode() throws MessagingException {
setStartNode(computeStartNode());
}
/**
* @see org.apache.mailet.GenericMailet#init()
*/
- public void init() throws MessagingException
- {
+ public void init() throws MessagingException {
super.init();
- try
- {
+ try {
setScriptURL(new URL(getInitParameter("scriptURL")));
- }
- catch (MalformedURLException e)
- {
+ } catch (MalformedURLException e) {
throw new MailetException(
"Error in configuration parameter \"scriptURL\"", e);
}
Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/SieveMailAdapter.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/SieveMailAdapter.java?rev=578033&r1=578032&r2=578033&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/SieveMailAdapter.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/samples/james/SieveMailAdapter.java Fri Sep 21 02:32:00 2007
@@ -18,6 +18,7 @@
****************************************************************/
package org.apache.jsieve.samples.james;
+
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -43,217 +44,200 @@
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import org.apache.mailet.MailetContext;
+
/**
* <p>
* Class <code>SieveMailAdapter</code> implements a <code>MailAdapter</code>
* for use in a Mailet environment.
* </p>
*/
-public class SieveMailAdapter implements MailAdapter, EnvelopeAccessors
-{
+public class SieveMailAdapter implements MailAdapter, EnvelopeAccessors {
/**
* The Mail being adapted.
*/
private Mail fieldMail;
+
/**
* The MailetContext.
*/
private MailetContext fieldMailetContext;
+
/**
* List of Actions to perform.
*/
private List fieldActions;
+
/**
* Constructor for SieveMailAdapter.
*/
- private SieveMailAdapter()
- {
+ private SieveMailAdapter() {
super();
}
+
/**
* Constructor for SieveMailAdapter.
*
* @param aMail
* @param aMailetContext
*/
- public SieveMailAdapter(Mail aMail, MailetContext aMailetContext)
- {
+ public SieveMailAdapter(Mail aMail, MailetContext aMailetContext) {
this();
setMail(aMail);
setMailetContext(aMailetContext);
}
+
/**
* Returns the message.
*
* @return MimeMessage
*/
- protected MimeMessage getMessage() throws MessagingException
- {
+ protected MimeMessage getMessage() throws MessagingException {
return getMail().getMessage();
}
+
/**
* Returns the List of actions.
*
* @return List
*/
- public List getActions()
- {
+ public List getActions() {
List actions = null;
- if (null == (actions = getActionsBasic()))
- {
+ if (null == (actions = getActionsBasic())) {
updateActions();
return getActions();
}
return actions;
}
+
/**
* Returns a new List of actions.
*
* @return List
*/
- protected List computeActions()
- {
+ protected List computeActions() {
return new ArrayList();
}
+
/**
* Returns the List of actions.
*
* @return List
*/
- private List getActionsBasic()
- {
+ private List getActionsBasic() {
return fieldActions;
}
+
/**
* Adds an Action.
*
- * @param action The action to set
+ * @param action
+ * The action to set
*/
- public void addAction(Action action)
- {
+ public void addAction(Action action) {
getActions().add(action);
}
+
/**
* @see org.apache.jsieve.mail.MailAdapter#executeActions()
*/
- public void executeActions() throws SieveException
- {
- // Log log = Logger.getLog();
- // boolean isDebugEnabled = log.isDebugEnabled();
+ public void executeActions() throws SieveException {
+ // Log log = Logger.getLog();
+ // boolean isDebugEnabled = log.isDebugEnabled();
ListIterator actionsIter = getActionsIterator();
- while (actionsIter.hasNext())
- {
+ while (actionsIter.hasNext()) {
Action action = (Action) actionsIter.next();
getMailetContext().log("Executing action: " + action.toString());
- try
- {
+ try {
ActionDispatcher.getInstance().execute(action, getMail(),
getMailetContext());
- }
- catch (NoSuchMethodException e)
- {
+ } catch (NoSuchMethodException e) {
throw new SieveException(e.getMessage());
- }
- catch (IllegalAccessException e)
- {
+ } catch (IllegalAccessException e) {
throw new SieveException(e.getMessage());
- }
- catch (InvocationTargetException e)
- {
+ } catch (InvocationTargetException e) {
throw new SieveException(e.getMessage());
- }
- catch (MessagingException e)
- {
+ } catch (MessagingException e) {
throw new SieveException(e.getMessage());
}
}
}
+
/**
* Sets the actions.
*
- * @param actions The actions to set
+ * @param actions
+ * The actions to set
*/
- protected void setActions(List actions)
- {
+ protected void setActions(List actions) {
fieldActions = actions;
}
+
/**
* Updates the actions.
*/
- protected void updateActions()
- {
+ protected void updateActions() {
setActions(computeActions());
}
+
/**
* @see org.apache.jsieve.mail.MailAdapter#getActionsIterator()
*/
- public ListIterator getActionsIterator()
- {
+ public ListIterator getActionsIterator() {
return getActions().listIterator();
}
+
/**
* @see org.apache.jsieve.mail.MailAdapter#getHeader(String)
*/
- public List getHeader(String name) throws SieveMailException
- {
- try
- {
+ public List getHeader(String name) throws SieveMailException {
+ try {
String[] headers = getMessage().getHeader(name);
return (headers == null ? new ArrayList(0) : Arrays.asList(headers));
- }
- catch (MessagingException ex)
- {
+ } catch (MessagingException ex) {
throw new SieveMailException(ex);
}
}
+
/**
* @see org.apache.jsieve.mail.MailAdapter#getHeaderNames()
*/
- public List getHeaderNames() throws SieveMailException
- {
+ public List getHeaderNames() throws SieveMailException {
Set headerNames = new HashSet();
- try
- {
+ try {
Enumeration allHeaders = getMessage().getAllHeaders();
- while (allHeaders.hasMoreElements())
- {
+ while (allHeaders.hasMoreElements()) {
headerNames.add(((Header) allHeaders.nextElement()).getName());
}
return new ArrayList(headerNames);
- }
- catch (MessagingException ex)
- {
+ } catch (MessagingException ex) {
throw new SieveMailException(ex);
}
}
+
/**
* @see org.apache.jsieve.mail.MailAdapter#getMatchingHeader(String)
*/
- public List getMatchingHeader(String name) throws SieveMailException
- {
+ public List getMatchingHeader(String name) throws SieveMailException {
return MailUtils.getMatchingHeader(this, name);
}
+
/**
* @see org.apache.jsieve.mail.MailAdapter#getSize()
*/
- public int getSize() throws SieveMailException
- {
- try
- {
+ public int getSize() throws SieveMailException {
+ try {
return getMessage().getSize();
- }
- catch (MessagingException ex)
- {
+ } catch (MessagingException ex) {
throw new SieveMailException(ex);
}
}
+
/**
* Method getEnvelopes.
*
* @return Map
*/
- protected Map getEnvelopes()
- {
+ protected Map getEnvelopes() {
Map envelopes = new HashMap(2);
if (null != getEnvelopeFrom())
envelopes.put("From", getEnvelopeFrom());
@@ -261,110 +245,108 @@
envelopes.put("To", getEnvelopeTo());
return envelopes;
}
+
/**
* @see org.apache.jsieve.mail.optional.EnvelopeAccessors#getEnvelope(String)
*/
- public List getEnvelope(String name) throws SieveMailException
- {
+ public List getEnvelope(String name) throws SieveMailException {
List values = new ArrayList(1);
Object value = getEnvelopes().get(name);
if (null != value)
values.add(value);
return values;
}
+
/**
* @see org.apache.jsieve.mail.optional.EnvelopeAccessors#getEnvelopeNames()
*/
- public List getEnvelopeNames() throws SieveMailException
- {
+ public List getEnvelopeNames() throws SieveMailException {
return new ArrayList(getEnvelopes().keySet());
}
+
/**
* @see org.apache.jsieve.mail.optional.EnvelopeAccessors#getMatchingEnvelope(String)
*/
- public List getMatchingEnvelope(String name) throws SieveMailException
- {
+ public List getMatchingEnvelope(String name) throws SieveMailException {
Iterator envelopeNamesIter = getEnvelopeNames().iterator();
List matchedEnvelopeValues = new ArrayList(32);
- while (envelopeNamesIter.hasNext())
- {
+ while (envelopeNamesIter.hasNext()) {
String envelopeName = (String) envelopeNamesIter.next();
if (envelopeName.trim().equalsIgnoreCase(name))
matchedEnvelopeValues.addAll(getEnvelope(envelopeName));
}
return matchedEnvelopeValues;
}
+
/**
* Returns the from.
*
* @return String
*/
- public String getEnvelopeFrom()
- {
- MailAddress sender = getMail().getSender();
+ public String getEnvelopeFrom() {
+ MailAddress sender = getMail().getSender();
return (null == sender ? "" : sender.toString());
}
+
/**
* Returns the sole recipient or null if there isn't one.
*
* @return String
*/
- public String getEnvelopeTo()
- {
+ public String getEnvelopeTo() {
String recipient = null;
Iterator recipientIter = getMail().getRecipients().iterator();
if (recipientIter.hasNext())
recipient = recipientIter.next().toString();
return recipient;
}
+
/**
* Returns the mail.
*
* @return Mail
*/
- public Mail getMail()
- {
+ public Mail getMail() {
return fieldMail;
}
+
/**
* Sets the mail.
*
- * @param mail The mail to set
+ * @param mail
+ * The mail to set
*/
- protected void setMail(Mail mail)
- {
+ protected void setMail(Mail mail) {
fieldMail = mail;
}
+
/**
* Returns the mailetContext.
*
* @return MailetContext
*/
- public MailetContext getMailetContext()
- {
+ public MailetContext getMailetContext() {
return fieldMailetContext;
}
+
/**
* Sets the mailetContext.
*
- * @param mailetContext The mailetContext to set
+ * @param mailetContext
+ * The mailetContext to set
*/
- protected void setMailetContext(MailetContext mailetContext)
- {
+ protected void setMailetContext(MailetContext mailetContext) {
fieldMailetContext = mailetContext;
}
+
/**
* @see java.lang.Object#toString()
*/
- public String toString()
- {
+ public String toString() {
String messageID = null;
- try
- {
+ try {
messageID = getMail().getMessage().getMessageID();
- }
- catch (MessagingException e)
- {
+ } catch (MessagingException e) {
messageID = "<" + e.getMessage() + ">";
}
return getClass().getName() + " Envelope From: "
@@ -373,17 +355,22 @@
+ (null == getEnvelopeTo() ? "null" : getEnvelopeTo())
+ " Message ID: " + (null == messageID ? "null" : messageID);
}
+
public Object getContent() throws SieveMailException {
// TODO Auto-generated method stub
return null;
}
+
public String getContentType() throws SieveMailException {
// TODO Auto-generated method stub
return null;
}
- public Address[] parseAddresses(String headerName) throws SieveMailException {
+
+ public Address[] parseAddresses(String headerName)
+ throws SieveMailException {
try {
- return SieveAddressBuilder.parseAddresses(headerName, getMail().getMessage());
+ return SieveAddressBuilder.parseAddresses(headerName, getMail()
+ .getMessage());
} catch (MessagingException e) {
throw new SieveMailException(e);
}
Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/tests/AbstractCompatatorTest.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/tests/AbstractCompatatorTest.java?rev=578033&r1=578032&r2=578033&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/tests/AbstractCompatatorTest.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/tests/AbstractCompatatorTest.java Fri Sep 21 02:32:00 2007
@@ -23,7 +23,6 @@
import java.util.List;
import java.util.ListIterator;
-
import org.apache.jsieve.Arguments;
import org.apache.jsieve.SieveContext;
import org.apache.jsieve.StringListArgument;
@@ -35,119 +34,114 @@
import org.apache.jsieve.mail.MailAdapter;
import org.apache.jsieve.mail.SieveMailException;
-public abstract class AbstractCompatatorTest extends AbstractTest implements AddressPartTags, ComparatorTags, MatchTypeTags, ComparatorNames {
+public abstract class AbstractCompatatorTest extends AbstractTest implements
+ AddressPartTags, ComparatorTags, MatchTypeTags, ComparatorNames {
public AbstractCompatatorTest() {
super();
}
/**
- * <p>From RFC 3028, Section 5.1... </p>
+ * <p>
+ * From RFC 3028, Section 5.1...
+ * </p>
* <code>
* Syntax: address [ADDRESS-PART] [COMPARATOR] [MATCH-TYPE]
* <header-list: string-list> <key-list: string-list>
* </code>
- * <p>Note that the spec. then goes on to give an example where the
- * order of the optional parts is different, so I am assuming that the order of
- * the optional parts is optional too!</p>
+ * <p>
+ * Note that the spec. then goes on to give an example where the order of
+ * the optional parts is different, so I am assuming that the order of the
+ * optional parts is optional too!
+ * </p>
*
- * @see org.apache.jsieve.tests.AbstractTest#executeBasic(MailAdapter, Arguments, SieveContext)
+ * @see org.apache.jsieve.tests.AbstractTest#executeBasic(MailAdapter,
+ * Arguments, SieveContext)
*/
- protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context) throws SieveException {
+ protected boolean executeBasic(MailAdapter mail, Arguments arguments,
+ SieveContext context) throws SieveException {
String addressPart = null;
String comparator = null;
String matchType = null;
List headerNames = null;
List keys = null;
-
+
ListIterator argumentsIter = arguments.getArgumentList().listIterator();
boolean stop = false;
-
+
// Tag processing
- while (!stop && argumentsIter.hasNext())
- {
+ while (!stop && argumentsIter.hasNext()) {
Object argument = argumentsIter.next();
- if (argument instanceof TagArgument)
- {
+ if (argument instanceof TagArgument) {
String tag = ((TagArgument) argument).getTag();
-
+
// [ADDRESS-PART]?
if (null == addressPart
- && (tag.equals(LOCALPART_TAG)
- || tag.equals(DOMAIN_TAG)
- || tag.equals(ALL_TAG)))
+ && (tag.equals(LOCALPART_TAG) || tag.equals(DOMAIN_TAG) || tag
+ .equals(ALL_TAG)))
addressPart = tag;
- // [COMPARATOR]?
- else if (null == comparator && tag.equals(COMPARATOR_TAG))
- {
+ // [COMPARATOR]?
+ else if (null == comparator && tag.equals(COMPARATOR_TAG)) {
// The next argument must be a stringlist
- if (argumentsIter.hasNext())
- {
+ if (argumentsIter.hasNext()) {
argument = argumentsIter.next();
- if (argument instanceof StringListArgument)
- {
- List stringList =
- ((StringListArgument) argument).getList();
+ if (argument instanceof StringListArgument) {
+ List stringList = ((StringListArgument) argument)
+ .getList();
if (stringList.size() != 1)
- throw new SyntaxException("Expecting exactly one String");
+ throw new SyntaxException(
+ "Expecting exactly one String");
comparator = (String) stringList.get(0);
- }
- else
+ } else
throw new SyntaxException("Expecting a StringList");
}
}
// [MATCH-TYPE]?
- else if (
- null == matchType
- && (tag.equals(IS_TAG)
- || tag.equals(CONTAINS_TAG)
- || tag.equals(MATCHES_TAG)))
+ else if (null == matchType
+ && (tag.equals(IS_TAG) || tag.equals(CONTAINS_TAG) || tag
+ .equals(MATCHES_TAG)))
matchType = tag;
else
- throw context.getCoordinate().syntaxException("Found unexpected TagArgument");
- }
- else
- {
+ throw context.getCoordinate().syntaxException(
+ "Found unexpected TagArgument");
+ } else {
// Stop when a non-tag argument is encountered
argumentsIter.previous();
stop = true;
}
}
-
+
// The next argument MUST be a string-list of header names
- if (argumentsIter.hasNext())
- {
+ if (argumentsIter.hasNext()) {
Object argument = argumentsIter.next();
if (argument instanceof StringListArgument)
headerNames = ((StringListArgument) argument).getList();
}
if (null == headerNames)
- throw context.getCoordinate().syntaxException("Expecting a StringList of header names");
-
+ throw context.getCoordinate().syntaxException(
+ "Expecting a StringList of header names");
+
// The next argument MUST be a string-list of keys
- if (argumentsIter.hasNext())
- {
+ if (argumentsIter.hasNext()) {
Object argument = argumentsIter.next();
if (argument instanceof StringListArgument)
keys = ((StringListArgument) argument).getList();
- }
- else if (null == keys)
- throw context.getCoordinate().syntaxException("Expecting a StringList of keys");
-
+ } else if (null == keys)
+ throw context.getCoordinate().syntaxException(
+ "Expecting a StringList of keys");
+
if (argumentsIter.hasNext())
- throw context.getCoordinate().syntaxException("Found unexpected arguments");
-
- return match(
- mail,
- (addressPart == null ? ALL_TAG : addressPart),
- (comparator == null ? ASCII_CASEMAP_COMPARATOR : comparator),
- (matchType == null ? IS_TAG : matchType),
- headerNames,
- keys);
+ throw context.getCoordinate().syntaxException(
+ "Found unexpected arguments");
+
+ return match(mail, (addressPart == null ? ALL_TAG : addressPart),
+ (comparator == null ? ASCII_CASEMAP_COMPARATOR : comparator),
+ (matchType == null ? IS_TAG : matchType), headerNames, keys);
}
/**
* Method match.
+ *
* @param mail
* @param addressPart
* @param comparator
@@ -157,26 +151,22 @@
* @return boolean
* @throws SieveMailException
*/
- protected boolean match(MailAdapter mail, String addressPart, String comparator, String matchType, List headerNames, List keys) throws SieveException {
+ protected boolean match(MailAdapter mail, String addressPart,
+ String comparator, String matchType, List headerNames, List keys)
+ throws SieveException {
// Iterate over the header names looking for a match
boolean isMatched = false;
Iterator headerNamesIter = headerNames.iterator();
- while (!isMatched && headerNamesIter.hasNext())
- {
- isMatched =
- match(
- mail,
- addressPart,
- comparator,
- matchType,
- (String) headerNamesIter.next(),
- keys);
+ while (!isMatched && headerNamesIter.hasNext()) {
+ isMatched = match(mail, addressPart, comparator, matchType,
+ (String) headerNamesIter.next(), keys);
}
return isMatched;
}
/**
* Method match.
+ *
* @param mail
* @param addressPart
* @param comparator
@@ -186,26 +176,22 @@
* @return boolean
* @throws SieveMailException
*/
- protected boolean match(MailAdapter mail, String addressPart, String comparator, String matchType, String headerName, List keys) throws SieveException {
+ protected boolean match(MailAdapter mail, String addressPart,
+ String comparator, String matchType, String headerName, List keys)
+ throws SieveException {
// Iterate over the keys looking for a match
boolean isMatched = false;
Iterator keysIter = keys.iterator();
- while (!isMatched && keysIter.hasNext())
- {
- isMatched =
- match(
- mail,
- addressPart,
- comparator,
- matchType,
- headerName,
- (String) keysIter.next());
+ while (!isMatched && keysIter.hasNext()) {
+ isMatched = match(mail, addressPart, comparator, matchType,
+ headerName, (String) keysIter.next());
}
return isMatched;
}
/**
* Method match.
+ *
* @param mail
* @param addressPart
* @param comparator
@@ -215,15 +201,19 @@
* @return boolean
* @throws SieveMailException
*/
- protected abstract boolean match(MailAdapter mail, String addressPart, String comparator,
- String matchType, String headerName, String key) throws SieveException;
+ protected abstract boolean match(MailAdapter mail, String addressPart,
+ String comparator, String matchType, String headerName, String key)
+ throws SieveException;
/**
- * @see org.apache.jsieve.tests.AbstractTest#validateArguments(Arguments, SieveContext)
+ * @see org.apache.jsieve.tests.AbstractTest#validateArguments(Arguments,
+ * SieveContext)
*/
- protected void validateArguments(Arguments arguments, SieveContext context) throws SieveException {
+ protected void validateArguments(Arguments arguments, SieveContext context)
+ throws SieveException {
if (arguments.hasTests())
- throw context.getCoordinate().syntaxException("Found unexpected tests");
+ throw context.getCoordinate().syntaxException(
+ "Found unexpected tests");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org