org.apache.jsieve.mail
Interface MailAdapter

All Known Implementing Classes:
ScriptCheckMailAdapter, SieveMailAdapter

public interface MailAdapter

Interface MailAdapter 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.

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.

Implementing parseAddresses

Apache Mime4J is a parser for MIME. It can easily be used to parse an address string into addresses. For example:

       import org.apache.james.mime4j.field.address.AddressList;
       import org.apache.james.mime4j.field.address.Mailbox;
       import org.apache.james.mime4j.field.address.MailboxList;
       import org.apache.james.mime4j.field.address.parser.ParseException;
       ...
       public Address[] parseAddresses(String arg) throws SieveMailException, InternetAddressException {
           try {
               final MailboxList list = AddressList.parse(arg).flatten();
               final int size = list.size();
               final Address[] results = new Address[size];
               for (int i=0;i<size;i++) {
                   final Mailbox mailbox = list.get(i);
                   results[i] = new AddressImpl(mailbox.getLocalPart(), mailbox.getDomain());
               }
               return null;
           } catch (ParseException e) {
               throw new InternetAddressException(e);
           }
       }
 


Nested Class Summary
static interface MailAdapter.Address
          Contains address data required for SIEVE processing.
 
Method Summary
 void addAction(Action action)
          Method addAction adds an Action to the List of Actions to be performed by the receiver.
 void executeActions()
          Method executeActions.
 java.util.List<Action> getActions()
          Method getActions answers the List of Actions accumulated by the receiver.
 java.lang.String getContentType()
          Method getContentType returns string/mime representation of the message type.
 java.util.List<java.lang.String> getHeader(java.lang.String name)
          Method getHeader answers a List of all of the headers in the receiver whose name is equal to the passed name.
 java.util.List<java.lang.String> getHeaderNames()
          Method getHeaderNames answers a List of all of the headers in the receiver.
 java.util.List<java.lang.String> getMatchingHeader(java.lang.String name)
           Method getMatchingHeader answers a List of all of the headers in the receiver with the passed name.
 int getSize()
          Method getSize answers the receiver's message size in octets.
 boolean isInBodyText(java.lang.String phraseCaseInsensitive)
          Is the given phrase found in the body text of this mail? This search should be case insensitive.
 MailAdapter.Address[] parseAddresses(java.lang.String headerName)
           Parses the named header value into individual addresses.
 void setContext(SieveContext context)
          Sets the context for the current sieve script execution.
 

Method Detail

setContext

void setContext(SieveContext context)

Sets the context for the current sieve script execution.

Sieve engines MUST set this property before any calls related to the execution of a script are made.

Implementations intended to be shared between separate threads of execution MUST ensure that they manage concurrency contexts, for example by storage in a thread local variable. Engines MUST - for a script execution - ensure that all calls are made within the same thread of execution.

Parameters:
context - the current context, or null to clear the contest once the execution of a script has completed.

getActions

java.util.List<Action> getActions()
Method getActions answers the List of Actions accumulated by the receiver. Implementations may elect to supply an unmodifiable collection.

Returns:
List of Action's, not null, possibly unmodifiable

getHeader

java.util.List<java.lang.String> getHeader(java.lang.String name)
                                           throws SieveMailException
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.

Parameters:
name -
Returns:
List not null, possibly empty, possible unmodifiable
Throws:
SieveMailException

getMatchingHeader

java.util.List<java.lang.String> getMatchingHeader(java.lang.String name)
                                                   throws SieveMailException

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.

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.

Parameters:
name -
Returns:
List, not null possibly empty, possible unmodifiable
Throws:
SieveMailException

getHeaderNames

java.util.List<java.lang.String> getHeaderNames()
                                                throws SieveMailException
Method getHeaderNames answers a List of all of the headers in the receiver. No duplicates are allowed.

Returns:
List, not null possible empty, possible unmodifiable
Throws:
SieveMailException

addAction

void addAction(Action action)
Method addAction adds an Action to the List of Actions to be performed by the receiver.

Parameters:
action -

executeActions

void executeActions()
                    throws SieveException
Method executeActions. Applies the Actions accumulated by the receiver.

Throws:
SieveException

getSize

int getSize()
            throws SieveMailException
Method getSize answers the receiver's message size in octets.

Returns:
int
Throws:
SieveMailException

getContentType

java.lang.String getContentType()
                                throws SieveMailException
Method getContentType returns string/mime representation of the message type.

Returns:
String
Throws:
SieveMailException

isInBodyText

boolean isInBodyText(java.lang.String phraseCaseInsensitive)
                     throws SieveMailException
Is the given phrase found in the body text of this mail? This search should be case insensitive.

Parameters:
phraseCaseInsensitive - the phrase to search
Returns:
true when the mail has a textual body and contains the phrase (case insensitive), false otherwise
Throws:
SieveMailException - when the search cannot be completed

parseAddresses

MailAdapter.Address[] parseAddresses(java.lang.String headerName)
                                     throws SieveMailException,
                                            InternetAddressException

Parses the named header value into individual addresses.

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.

Parameters:
headerName - name of the header whose value is to be split
Returns:
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
SieveMailException - when the header value cannot be read


Copyright © 2008-2009 The Apache Software Foundation. All Rights Reserved.