title: Mule ESB: how to filter emails based on subject or sender?
body: <p>I am new to Mule 3.3 and I am trying to use it to retrieve emails from a POP3 server and download the CSV attachments if the sender field and subject field contain certain keywords. I have used the example provided on Mulesoft website and I have successfully managed to scan my inbox for new emails and only download CSV attachments. However, I am now stuck because I can't figure out how to filter emails by subject and sender fields. </p>
  
  <p>Doing some research I have come across a <em>message-property-filter pattern</em> tag that can be applied to an endpoint, but I am not sure exactly to which endpoint to apply it, incoming or outgoing. Neither approach seems to work and I can't find a decent example showing how to use this tag. The basic algorithm I want to implement is as follows:</p>
  
  <pre><code>if email is from "Bob"
    if attachment of type "CSV"
      then download CSV attachment
  
  if email subject field contains "keyword"
    if attachment of type CSV
      then download CSV attachment
  </code></pre>
  
  <p>Here's the Mule xml I have so far:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:pop3s="http://www.mulesoft.org/schema/mule/pop3s" xmlns:pop3="http://www.mulesoft.org/schema/mule/pop3" 
  xmlns="http://www.mulesoft.org/schema/mule/core" 
  xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
  xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.1" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
  http://www.mulesoft.org/schema/mule/pop3s http://www.mulesoft.org/schema/mule/pop3s/current/mule-pop3s.xsd 
  http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd 
  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
  http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
  http://www.mulesoft.org/schema/mule/pop3 http://www.mulesoft.org/schema/mule/pop3/current/mule-pop3.xsd "&gt;
  
  
  &lt;expression-transformer expression="#[attachments-list:*.csv]" 
     name="returnAttachments" doc:name="Expression"&gt;
  &lt;/expression-transformer&gt;
  
  &lt;pop3s:connector name="POP3Connector" 
      checkFrequency="5000" 
      deleteReadMessages="false" 
      defaultProcessMessageAction="RECENT" 
      doc:name="POP3" 
      validateConnections="true"&gt;
  &lt;/pop3s:connector&gt;
  
  &lt;file:connector name="fileName" doc:name="File"&gt;
      &lt;file:expression-filename-parser /&gt;
  &lt;/file:connector&gt;
  
  &lt;flow name="incoming-orders" doc:name="incoming-orders"&gt;
  
      &lt;pop3s:inbound-endpoint user="my_username" 
          password="my_password" 
          host="pop.gmail.com" 
          port="995" 
          transformer-refs="returnAttachments"
          doc:name="GetMail" 
          connector-ref="POP3Connector" 
          responseTimeout="10000"/&gt;
      &lt;collection-splitter doc:name="Collection Splitter"/&gt;
  
      &lt;echo-component doc:name="Echo"/&gt;
  
      &lt;file:outbound-endpoint path="/attachments" 
          outputPattern="#[function:datestamp].csv"
          doc:name="File" responseTimeout="10000"&gt; 
          &lt;expression-transformer expression="payload.inputStream"/&gt;
          &lt;message-property-filter pattern="from=(.*)(bob@email.com)(.*)" caseSensitive="false"/&gt;
      &lt;/file:outbound-endpoint&gt;           
  &lt;/flow&gt;
  </code></pre>
  
  <p></p>
  
  <p>What is the best way to tackle this problem? </p>
  
  <p>Thanks in advance.</p>