Author: rdonkin
Date: Thu Jul 23 22:04:11 2009
New Revision: 797242
URL: http://svn.apache.org/viewvc?rev=797242&view=rev
Log:
JSIEVE-35 Replaced getContent with isInBodyText
https://issues.apache.org/jira/browse/JSIEVE-35
Modified:
james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java
james/jsieve/trunk/main/src/main/java/org/apache/jsieve/mail/MailAdapter.java
james/jsieve/trunk/main/src/main/java/org/apache/jsieve/tests/optional/Body.java
james/jsieve/trunk/main/src/test/java/org/apache/jsieve/util/check/ScriptCheckMailAdapter.java
james/jsieve/trunk/main/src/test/java/org/apache/jsieve/utils/SieveMailAdapter.java
james/jsieve/trunk/util/src/main/java/org/apache/jsieve/util/check/ScriptCheckMailAdapter.java
Modified:
james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java
URL:
http://svn.apache.org/viewvc/james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java?rev=797242&r1=797241&r2=797242&view=diff
==============================================================================
---
james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java
(original)
+++
james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java
Thu Jul 23 22:04:11 2009
@@ -19,6 +19,7 @@
package org.apache.jsieve.mailet;
import java.io.IOException;
+import java.lang.ref.PhantomReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -79,6 +80,8 @@
private final ActionDispatcher dispatcher;
private final Poster poster;
+
+ private String contentText;
/**
* Constructor for SieveMailAdapter.
@@ -333,6 +336,7 @@
protected void setMail(Mail mail)
{
fieldMail = mail;
+ contentText = null;
}
/**
* Returns the mailetContext.
@@ -373,15 +377,6 @@
+ " Message ID: " + (null == messageID ? "null" : messageID);
}
- public Object getContent() throws SieveMailException {
- try {
- return getMessage().getContent();
- } catch (MessagingException e) {
- throw new SieveMailException(e);
- } catch (IOException e) {
- throw new SieveMailException(e);
- }
- }
public String getContentType() throws SieveMailException {
try {
return getMessage().getContentType();
@@ -455,4 +450,20 @@
public void post(MailAddress sender, Collection recipients, MimeMessage
mail) throws MessagingException {
getMailetContext().sendMail(sender, recipients, mail);
}
+
+
+ public boolean isInBodyText(String phraseCaseInsensitive) throws
SieveMailException {
+ try {
+ if (contentText == null) {
+ contentText =
getMessage().getContent().toString().toLowerCase();
+ }
+ return contentText.contains(phraseCaseInsensitive);
+ } catch (MessagingException e) {
+ throw new SieveMailException(e);
+ } catch (IOException e) {
+ throw new SieveMailException(e);
+ }
+ }
+
+
}
Modified:
james/jsieve/trunk/main/src/main/java/org/apache/jsieve/mail/MailAdapter.java
URL:
http://svn.apache.org/viewvc/james/jsieve/trunk/main/src/main/java/org/apache/jsieve/mail/MailAdapter.java?rev=797242&r1=797241&r2=797242&view=diff
==============================================================================
---
james/jsieve/trunk/main/src/main/java/org/apache/jsieve/mail/MailAdapter.java
(original)
+++
james/jsieve/trunk/main/src/main/java/org/apache/jsieve/mail/MailAdapter.java
Thu Jul 23 22:04:11 2009
@@ -162,16 +162,15 @@
public String getContentType() throws SieveMailException;
/**
- * Method getContent returns object containing the message content. TODO:
- * This is poorly defined. TODO: This is used to search a mail body and
- * needs to return a string. TODO: But creating a string is not efficient.
- * TODO: It would be better to allow the adapter to search.
- *
- * @return Object
- * @throws SieveMailException
+ * Is the given phrase found in the body text of this mail?
+ * This search should be case insensitive.
+ * @param phraseInLowerCase the phrase to search
+ * @return true when the mail has a textual body and contains the phrase
+ * (case insensitive), false otherwise
+ * @throws SieveMailException when the search cannot be completed
*/
- public Object getContent() throws SieveMailException;
-
+ public boolean isInBodyText(final String phraseCaseInsensitive) throws
SieveMailException;
+
/**
* <p>
* Parses the named header value into individual addresses.
Modified:
james/jsieve/trunk/main/src/main/java/org/apache/jsieve/tests/optional/Body.java
URL:
http://svn.apache.org/viewvc/james/jsieve/trunk/main/src/main/java/org/apache/jsieve/tests/optional/Body.java?rev=797242&r1=797241&r2=797242&view=diff
==============================================================================
---
james/jsieve/trunk/main/src/main/java/org/apache/jsieve/tests/optional/Body.java
(original)
+++
james/jsieve/trunk/main/src/main/java/org/apache/jsieve/tests/optional/Body.java
Thu Jul 23 22:04:11 2009
@@ -82,14 +82,12 @@
if (mail.getContentType().indexOf("text/") != 0) {
throw new SieveMailException("Message is not of type 'text'");
}
- String body = (String) mail.getContent();
- body = body.toLowerCase();
// Compare each test string with body, ignoring case
ListIterator iter = strings.getList().listIterator();
while (iter.hasNext()) {
- String str = (String) iter.next();
- if (body.indexOf(str.toLowerCase()) != -1) {
+ String phrase = (String) iter.next();
+ if (mail.isInBodyText(phrase)) {
return true;
}
}
Modified:
james/jsieve/trunk/main/src/test/java/org/apache/jsieve/util/check/ScriptCheckMailAdapter.java
URL:
http://svn.apache.org/viewvc/james/jsieve/trunk/main/src/test/java/org/apache/jsieve/util/check/ScriptCheckMailAdapter.java?rev=797242&r1=797241&r2=797242&view=diff
==============================================================================
---
james/jsieve/trunk/main/src/test/java/org/apache/jsieve/util/check/ScriptCheckMailAdapter.java
(original)
+++
james/jsieve/trunk/main/src/test/java/org/apache/jsieve/util/check/ScriptCheckMailAdapter.java
Thu Jul 23 22:04:11 2009
@@ -259,17 +259,11 @@
return result;
}
- /**
- * Method getContent returns object containing the message content.
- *
- * @return Object
- * @throws SieveMailException
- */
- public Object getContent() throws SieveMailException {
- Object result = null;
+ public boolean isInBodyText(String phraseCaseInsensitive) throws
SieveMailException {
+ boolean result = false;
if (mail != null) {
try {
- result = mail.getContent();
+ result =
mail.getContent().toString().toLowerCase().contains(phraseCaseInsensitive);
} catch (MessagingException e) {
throw new SieveMailException(e);
} catch (IOException e) {
Modified:
james/jsieve/trunk/main/src/test/java/org/apache/jsieve/utils/SieveMailAdapter.java
URL:
http://svn.apache.org/viewvc/james/jsieve/trunk/main/src/test/java/org/apache/jsieve/utils/SieveMailAdapter.java?rev=797242&r1=797241&r2=797242&view=diff
==============================================================================
---
james/jsieve/trunk/main/src/test/java/org/apache/jsieve/utils/SieveMailAdapter.java
(original)
+++
james/jsieve/trunk/main/src/test/java/org/apache/jsieve/utils/SieveMailAdapter.java
Thu Jul 23 22:04:11 2009
@@ -66,6 +66,8 @@
*/
private List<Action> fieldActions;
+ private String contentAsLowerCaseString;
+
/**
* Constructor for SieveMailAdapter.
*/
@@ -239,19 +241,6 @@
}
}
- /**
- * @see org.apache.jsieve.mail.MailAdapter#getContent()
- */
- public Object getContent() throws SieveMailException {
- try {
- return getMessage().getContent();
- } catch (MessagingException ex) {
- throw new SieveMailException(ex);
- } catch (IOException ex) {
- throw new SieveMailException(ex);
- }
- }
-
public Address[] parseAddresses(final String headerName)
throws SieveMailException {
return parseAddresses(headerName, getMessage());
@@ -290,4 +279,21 @@
}
}
+ public boolean isInBodyText(String phraseCaseInsensitive) throws
SieveMailException {
+ try {
+ return
contentAsText().indexOf(phraseCaseInsensitive.toLowerCase()) != -1;
+ } catch (MessagingException ex) {
+ throw new SieveMailException(ex);
+ } catch (IOException ex) {
+ throw new SieveMailException(ex);
+ }
+ }
+
+ private String contentAsText() throws IOException, MessagingException {
+ if (contentAsLowerCaseString == null) {
+ contentAsLowerCaseString =
getMessage().getContent().toString().toLowerCase();
+ }
+ return contentAsLowerCaseString;
+ }
+
}
Modified:
james/jsieve/trunk/util/src/main/java/org/apache/jsieve/util/check/ScriptCheckMailAdapter.java
URL:
http://svn.apache.org/viewvc/james/jsieve/trunk/util/src/main/java/org/apache/jsieve/util/check/ScriptCheckMailAdapter.java?rev=797242&r1=797241&r2=797242&view=diff
==============================================================================
---
james/jsieve/trunk/util/src/main/java/org/apache/jsieve/util/check/ScriptCheckMailAdapter.java
(original)
+++
james/jsieve/trunk/util/src/main/java/org/apache/jsieve/util/check/ScriptCheckMailAdapter.java
Thu Jul 23 22:04:11 2009
@@ -261,26 +261,6 @@
return result;
}
- /**
- * Method getContent returns object containing the message content.
- *
- * @return Object
- * @throws SieveMailException
- */
- public Object getContent() throws SieveMailException {
- Object result = null;
- if (mail != null) {
- try {
- result = mail.getContent();
- } catch (MessagingException e) {
- throw new SieveMailException(e);
- } catch (IOException e) {
- throw new SieveMailException(e);
- }
- }
- return result;
- }
-
public Address[] parseAddresses(String headerName)
throws SieveMailException {
return parseAddresses(headerName, mail);
@@ -319,4 +299,18 @@
}
}
+ public boolean isInBodyText(String phraseCaseInsensitive) throws
SieveMailException {
+ boolean result = false;
+ if (mail != null) {
+ try {
+ result =
mail.getContent().toString().toLowerCase().contains(phraseCaseInsensitive);
+ } catch (MessagingException e) {
+ throw new SieveMailException(e);
+ } catch (IOException e) {
+ throw new SieveMailException(e);
+ }
+ }
+ return result;
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]