[
https://issues.apache.org/jira/browse/JAMES-836?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Frank Fitzke resolved JAMES-836.
--------------------------------
Resolution: Fixed
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;
+
+ }
+}
> The HasHeader-Matcher should check for headername and value
> -----------------------------------------------------------
>
> Key: JAMES-836
> URL: https://issues.apache.org/jira/browse/JAMES-836
> Project: James
> Issue Type: Improvement
> Components: Matchers/Mailets (bundled)
> Environment: all
> Reporter: Frank Fitzke
> Priority: Trivial
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> In the Source of HasHeader is a
> TODO: support lists of headers and values, e.g, match="{<header>[=value]}+"
> * [will require a complete rewrite from the current trivial one-liner]
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]