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 fr...@globolog.com on 2008/02/14 14:46:35 UTC

Matcher for your review

Hello Developer-List,

i had to rewrite an existing matcher (HasHeader) and found a TODO in the 
source that would match my requirements.

Here my changes for your review.
-------------------------------------------------------------------------------
package org.apache.james.transport.matchers;

import org.apache.mailet.GenericMatcher;
import org.apache.mailet.Mail;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.StringTokenizer;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

/**
 * use: <mailet match="HasHeader=<header>" class="..." />
 *
 * This matcher simply checks to see if the header named is present.
 * If complements the AddHeader mailet.
 *
 * TODO: support lists of headers and values, e.g, match="{<header>[=value]}+"
 *       [will require a complete rewrite from the current trivial one-liner]
 *
 */
public class HasHeaderWithValue extends GenericMatcher {

	private LinkedList conditionline_ = new LinkedList();

	public void init() throws MessagingException {
		StringTokenizer st = new StringTokenizer(getCondition(), "+");
		conditionline_ = new LinkedList();
		
		while (st.hasMoreTokens()) {
			String condition = st.nextToken().trim();
			conditionline_.add(condition);
		}
	}

	public Collection match(Mail mail) throws javax.mail.MessagingException {
		boolean match = false;
		MimeMessage message = (MimeMessage) mail.getMessage();

		header:
		for (Iterator it=conditionline_.iterator(); it.hasNext(); ) {
			String element = (String)it.next();
			StringTokenizer st = new StringTokenizer(element, "=", false);
			String header = new String();

			if (st.hasMoreTokens()) {
				header = st.nextToken().trim();
			} else {
				throw new MessagingException("Missing headerName");
			}

			String headerValue = new String();
			if (st.hasMoreTokens()) {
				headerValue = st.nextToken().trim();
			} else {
				headerValue = null;
			}

			String [] headerArray = message.getHeader(header);
			if (headerArray != null && headerArray.length > 0) {
				if (headerValue != null) {
					if (headerArray[0].trim().equalsIgnoreCase(headerValue)) {
						match = true;
					} else {
						match = false;
						break header;
					};
				} else {
					match = true;
				}	        	
			} else {
				match = false;
				break header;
			}
		}
		
		return (match) ? mail.getRecipients() : null;

	}
}
-------------------------------------------------------------------------------

best regards
     Frank

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: Matcher for your review

Posted by Robert Burrell Donkin <ro...@gmail.com>.
On Feb 15, 2008 9:51 AM, Norman Maurer <no...@apache.org> wrote:
>
> Am Donnerstag, den 14.02.2008, 23:25 +0100 schrieb Sascha Fröhlich:

<snip>

> > for some of us is it or will it be the first time to contribute to an
> > open source project - I figured out some guide lines from the James
> > project page (http://jakarta.apache.org/site/source.html), is that the
> > right way to contribute code?

feel free to chat on this list: it's for developers which means anyone
who has any interest in contributing

the code needs to come in through JIRA as patches and some limited
discuss of patches sometimes happens as JIRA comments but this list is
the primary mechanism for development

> this guideline should be fine. You can find more infos at
> http://james.apache.org/contribute.html too..

see also http://www.apache.org/foundation/how-it-works.html and
http://www.apache.org/dev/contributors.html

> The best way to contribute code is to create a diff and open an "issue"
> on jira ( https://issues.apache.org/jira/browse/JAMES ) .

+1

and then follow up on list

- robert

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: Matcher for your review

Posted by Norman Maurer <no...@apache.org>.
Am Donnerstag, den 14.02.2008, 23:25 +0100 schrieb Sascha Fröhlich:
> Robert Burrell Donkin schrieb:
> > On Thu, Feb 14, 2008 at 1:46 PM,  <fr...@globolog.com> wrote:
> >   
> >> Hello Developer-List,
> >>     
> >
> > hi frank
> >
> >   
> >>  i had to rewrite an existing matcher (HasHeader) and found a TODO in the
> >>  source that would match my requirements.
> >>
> >>  Here my changes for your review.
> >>     
> >
> > thanks for contributing your patch.
> >
> > i wonder whether it would it be possible to submit a diff (preferrably
> > unified using eg svn diff): it's much easier for us to review and
> > apply in that form
> >
> > - robert
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> > For additional commands, e-mail: server-dev-help@james.apache.org
> >
> >   
> Hi there,
> 
> for some of us is it or will it be the first time to contribute to an 
> open source project - I figured out some guide lines from the James 
> project page (http://jakarta.apache.org/site/source.html), is that the 
> right way to contribute code?
> 
> Greetings and thanks for the great work so far,
> 
> Sascha
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
> 

Hi Sascha,

this guideline should be fine. You can find more infos at
http://james.apache.org/contribute.html too..

The best way to contribute code is to create a diff and open an "issue"
on jira ( https://issues.apache.org/jira/browse/JAMES ) .

bye
Norman


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: Matcher for your review

Posted by Sascha Fröhlich <sa...@gmail.com>.
Robert Burrell Donkin schrieb:
> On Thu, Feb 14, 2008 at 1:46 PM,  <fr...@globolog.com> wrote:
>   
>> Hello Developer-List,
>>     
>
> hi frank
>
>   
>>  i had to rewrite an existing matcher (HasHeader) and found a TODO in the
>>  source that would match my requirements.
>>
>>  Here my changes for your review.
>>     
>
> thanks for contributing your patch.
>
> i wonder whether it would it be possible to submit a diff (preferrably
> unified using eg svn diff): it's much easier for us to review and
> apply in that form
>
> - robert
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
>   
Hi there,

for some of us is it or will it be the first time to contribute to an 
open source project - I figured out some guide lines from the James 
project page (http://jakarta.apache.org/site/source.html), is that the 
right way to contribute code?

Greetings and thanks for the great work so far,

Sascha

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: Matcher for your review

Posted by Robert Burrell Donkin <ro...@gmail.com>.
On Thu, Feb 14, 2008 at 1:46 PM,  <fr...@globolog.com> wrote:
> Hello Developer-List,

hi frank

>  i had to rewrite an existing matcher (HasHeader) and found a TODO in the
>  source that would match my requirements.
>
>  Here my changes for your review.

thanks for contributing your patch.

i wonder whether it would it be possible to submit a diff (preferrably
unified using eg svn diff): it's much easier for us to review and
apply in that form

- robert

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org