Author: rdonkin
Date: Thu Jul 23 11:00:34 2009
New Revision: 797013

URL: http://svn.apache.org/viewvc?rev=797013&view=rev
Log:
JSIEVE-57 Multiline and quoted strings require different pruning 
https://issues.apache.org/jira/browse/JSIEVE-57

Added:
    
james/jsieve/trunk/main/src/test/java/org/apache/jsieve/MultilineTextTest.java  
 (with props)
Modified:
    james/jsieve/trunk/main/src/main/jjtree/sieve/sieve.jjt

Modified: james/jsieve/trunk/main/src/main/jjtree/sieve/sieve.jjt
URL: 
http://svn.apache.org/viewvc/james/jsieve/trunk/main/src/main/jjtree/sieve/sieve.jjt?rev=797013&r1=797012&r2=797013&view=diff
==============================================================================
--- james/jsieve/trunk/main/src/main/jjtree/sieve/sieve.jjt (original)
+++ james/jsieve/trunk/main/src/main/jjtree/sieve/sieve.jjt Thu Jul 23 11:00:34 
2009
@@ -256,15 +256,23 @@
   (quoted_string = <QUOTED_STRING> | multi_line = <MULTI_LINE>)
   {
     final StringBuilder builder;
-    if (null != quoted_string)
+    if (null != quoted_string) {
       builder=new StringBuilder(quoted_string.image);
-    else if (null != multi_line)
+      // unquote
+      builder.deleteCharAt(builder.length() - 1);
+    } else if (null != multi_line) {
       builder=new StringBuilder(multi_line.image);
-    else
+      // remove prefixing 'text'
+      builder.delete(0,5);
+      // remove suffixing newline-dot-newline
+      builder.deleteCharAt(builder.length() - 1);
+      builder.deleteCharAt(builder.length() - 1);
+      builder.deleteCharAt(builder.length() - 1);
+    } else {
       builder=null;  
+    }
     if (builder != null) {
-        // Unescape and unquote
-        builder.deleteCharAt(builder.length() - 1);
+        // Unescape
         builder.deleteCharAt(0);
         int i = 0;
         while (i < builder.length()) {

Added: 
james/jsieve/trunk/main/src/test/java/org/apache/jsieve/MultilineTextTest.java
URL: 
http://svn.apache.org/viewvc/james/jsieve/trunk/main/src/test/java/org/apache/jsieve/MultilineTextTest.java?rev=797013&view=auto
==============================================================================
--- 
james/jsieve/trunk/main/src/test/java/org/apache/jsieve/MultilineTextTest.java 
(added)
+++ 
james/jsieve/trunk/main/src/test/java/org/apache/jsieve/MultilineTextTest.java 
Thu Jul 23 11:00:34 2009
@@ -0,0 +1,54 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.jsieve;
+
+import junit.framework.TestCase;
+
+import org.apache.jsieve.exception.SieveException;
+import org.apache.jsieve.mail.ActionReject;
+import org.apache.jsieve.mail.MailAdapter;
+import org.apache.jsieve.parser.generated.ParseException;
+import org.apache.jsieve.utils.JUnitUtils;
+
+/**
+ * Class RejectTest
+ */
+public class MultilineTextTest extends TestCase {
+    
+    /**
+     * Tests that a multiline message is correctly passed
+     */
+    public void testRejectMultilineMessage() throws Exception {
+        String message = "This is not a love song";
+        String script = "reject text:\n" + message + "\n.\n;";
+        ActionReject rejection = runRejectScript(script);        
+        assertEquals(message, rejection.getMessage());
+    }
+
+    private ActionReject runRejectScript(String script) throws SieveException, 
ParseException {
+        MailAdapter mail = JUnitUtils.createMail();
+        JUnitUtils.interpret(mail, script);
+        assertTrue(mail.getActions().size() == 1);
+        Object action = mail.getActions().get(0);
+        assertTrue(action instanceof ActionReject);
+        ActionReject rejection = (ActionReject) action;
+        return rejection;
+    }
+}

Propchange: 
james/jsieve/trunk/main/src/test/java/org/apache/jsieve/MultilineTextTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to