View Javadoc

1   /*
2    * $Id: MailSubjectRegExFilter.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.providers.email.filters;
12  
13  import org.mule.routing.filters.RegExFilter;
14  
15  import javax.mail.Message;
16  import javax.mail.MessagingException;
17  
18  /**
19   * <code>MailSubjectRegExFilter</code> applies a regular expression to a Mail
20   * Message subject.
21   */
22  public class MailSubjectRegExFilter extends AbstractMailFilter
23  {
24      private RegExFilter filter = new RegExFilter();
25  
26      public boolean accept(Message message)
27      {
28          try
29          {
30              return filter.accept(message.getSubject());
31          }
32          catch (MessagingException e)
33          {
34              logger.warn("Failed to read message subject: " + e.getMessage(), e);
35              return false;
36          }
37      }
38  
39      public void setPattern(String pattern)
40      {
41          filter.setPattern(pattern);
42      }
43  
44      public String getPattern()
45      {
46          return filter.getPattern();
47      }
48  }