Hallo List,
hope i did it right - I inserted my first jira-issue :-)
Just the intendation doesn't look good.
Here's the diff again for your review with more comments
#####################################################
Index:
/home/frankf/workspace/James(SVN_trunk)/spoolmanager-function/src/main/java/org/apache/james/transport/matchers/HasHeader.java
===================================================================
---
/home/frankf/workspace/James(SVN_trunk)/spoolmanager-function/src/main/java/org/apache/james/transport/matchers/HasHeader.java
(revision 599566)
+++
/home/frankf/workspace/James(SVN_trunk)/spoolmanager-function/src/main/java/org/apache/james/transport/matchers/HasHeader.java
(working copy)
@@ -17,7 +17,17 @@
* under the License. *
****************************************************************/
-
+/*
+
*------------------------------------------------------------------------------*
+ *
+ * $Id$
+ * $HeadURL:
http://gandalf.globolog.local/svn/teamup/umg/trunk/src/java/org/apache/james/transport/matchers/HasHeader.java
$
+ * $Author$
+ * $Revision$
+ * $Date$
+ *
+
*------------------------------------------------------------------------------*
+ */
package org.apache.james.transport.matchers;
@@ -25,15 +35,20 @@
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="..." />
+ * use: <mailet match="{<header>[=value]}+" class="..." />
+ *
+ * This matcher checks if the header named is present and, and.
*
- * 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 HasHeader extends GenericMatcher {
@@ -38,8 +53,76 @@
*/
public class HasHeader extends GenericMatcher {
- public Collection match(Mail mail) throws javax.mail.MessagingException {
- return (mail.getMessage().getHeader(getCondition(), null) != null) ?
mail.getRecipients() : null;
- }
-}
+ private LinkedList conditionline_ = new LinkedList();
+
+ // set headernames and values
+ public void init() throws MessagingException {
+ StringTokenizer st = new StringTokenizer(getCondition(), "+");
+ conditionline_ = new LinkedList();
+
+ //separates the headernames from the matchline
+ 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:
+ // goes through the headernames one by one
+ for (Iterator it=conditionline_.iterator(); it.hasNext(); ) {
+ String element = (String)it.next();
+ StringTokenizer st = new StringTokenizer(element, "=",
false);
+ String header = new String();
+
+ // read the headername
+ if (st.hasMoreTokens()) {
+ header = st.nextToken().trim();
+ } else {
+ throw new MessagingException("Missing
headerName");
+ }
+
+ // try to read headervalue
+ String headerValue = new String();
+ if (st.hasMoreTokens()) {
+ headerValue = st.nextToken().trim();
+ } else {
+ headerValue = null;
+ }
+ // find headername in Mailheaders
+ String [] headerArray = message.getHeader(header);
+ if (headerArray != null && headerArray.length > 0) {
+ // if there is the headername specified without
the headervalue
+ // only the existence of the headername ist
performed
+ if (headerValue != null) {
+ //
+ if
(headerArray[0].trim().equalsIgnoreCase(headerValue)) {
+ // headername and value found
and match to the condition
+ match = true;
+ } else {
+ // headername and value found
but the value does not match the
condition
+ match = false;
+ // if one condition fails the
matcher returns false
+ break header;
+ };
+ } else {
+ // just the headername is specified
+ match = true;
+ }
+ } else {
+ // no headername is found
+ match = false;
+ // if one condition fails the matcher returns
false
+ break header;
+ }
+ }
+
+ return (match) ? mail.getRecipients() : null;
+
+ }
+}
#####################################################
On Friday 15 February 2008 10:51:55 Norman Maurer wrote:
> 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, <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> > 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: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
>
> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
--
Frank Fitzke
Projektmanager
Globolog GmbH - Lise-Meitner-Allee 4 -
44801 Bochum/Deutschland
T: +49 234 388 772 17 - F: +49 234 43 870 233
mailto:[EMAIL PROTECTED] *
http://www.globolog.com
___________________________________________
Globolog
Gesellschaft für Softwareentwicklung und -vertrieb und
Vertriebsgesellschaft für Zahlungsabwicklung und Couponing
mbH
Lise-Meitner-Allee 4 - 44801 Bochum - Tel.: +49 234 388772 0 - Fax: +49
234 43870-233 - Mail: [EMAIL PROTECTED] - Web:
www.globolog.com
Geschäftsführer: Rainer Schulz, Rainer Stecken - HRB
10560 Bochum - USt.IdNr.: DE244850223
Der Inhalt dieser Email, inklusive
seiner Anhänge, ist vertraulich und ausschließlich für den bezeichneten
Empfänger bestimmt. Wenn Sie nicht der vorgesehene Empfänger dieser Email
oder dessen Vertreter sind, so beachten Sie bitte, dass jede Form der
Kenntnisnahme, Nutzung, Veröffentlichung, Vervielfältigung oder Weitergabe
unzulässig ist. Wir bitten Sie in diesem Fall, sich mit dem Absender dieser
Email in Verbindung zu setzen.
This e-mail is intended exclusively for the
individual or entity to which it is addressed and may contain confidential
or legally privileged information, which may not be disclosed under current
legislation. Any form of disclosure, copying or distribution of this e-mail
is strictly prohibited. If you have received this message in error, please
notify the sender immediately by e-mail and delete all copies of the
message.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]