1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.jsieve;
21
22 import junit.framework.TestCase;
23
24 import org.apache.jsieve.exception.SieveException;
25 import org.apache.jsieve.mail.ActionReject;
26 import org.apache.jsieve.mail.MailAdapter;
27 import org.apache.jsieve.parser.generated.ParseException;
28 import org.apache.jsieve.utils.JUnitUtils;
29
30
31
32
33 public class MultilineTextTest extends TestCase {
34
35
36
37
38 public void testRejectMultilineMessage() throws Exception {
39 String message = "This is not a love song";
40 String script = "reject text:\n" + message + "\n.\n;";
41 ActionReject rejection = runRejectScript(script);
42 assertEquals(message, rejection.getMessage());
43 }
44
45
46
47
48
49 public void testRejectMultilineMessageWithWhitespace() throws Exception {
50 String message = "This is not a love song";
51 String script = "reject text: \t \t \n" + message + "\n.\n;";
52 ActionReject rejection = runRejectScript(script);
53 assertEquals(message, rejection.getMessage());
54 }
55
56
57
58
59
60 public void testRejectMultilineMessageWithDotsMidline() throws Exception {
61 String message = "This is not.....a love song";
62 String script = "reject text:\n" + message + "\n.\n;";
63 ActionReject rejection = runRejectScript(script);
64 assertEquals(message, rejection.getMessage());
65 }
66
67
68
69
70 public void testRejectMultilineMessageWithDotStuffing() throws Exception {
71 String lineOne = "This is not\n";
72 String lineTwo = ".A Love Story";
73 String script = "reject text:\n" + lineOne + '.' + lineTwo + "\n.\n;";
74 ActionReject rejection = runRejectScript(script);
75 assertEquals(lineOne + lineTwo, rejection.getMessage());
76 }
77
78
79
80
81 public void testRejectMultilineMessageWithMissedDotStuffing() throws Exception {
82 String lineOne = "This is not\n";
83 String lineTwo = ".A Love Story";
84 String script = "reject text:\n" + lineOne + lineTwo + "\n.\n;";
85 ActionReject rejection = runRejectScript(script);
86 assertEquals(lineOne + lineTwo, rejection.getMessage());
87 }
88
89
90
91
92 public void testNumberOfStuffedDotsInMultilineMessage() throws Exception {
93 String lineOne = "This is line 1.\n";
94 String lineTwo = "This is line 2.\n";
95 String lineThree = "........ This is line 3.\n";
96 String script = "reject text:\n" + lineOne + lineTwo + '.' + lineThree + "\n.\n;";
97 ActionReject rejection = runRejectScript(script);
98 assertEquals(lineOne + lineTwo + lineThree, rejection.getMessage());
99 }
100
101
102
103
104 public void testConsecutiveDotStuffedLineInMultilineMessage() throws Exception {
105 String lineOne = "This is line 1.\n";
106 String lineTwo = "This is line 2.\n";
107 String lineThree = "........ This is line 3.\n";
108 String lineFour = ".\n";
109 String lineFive = ".\n";
110 String script = "reject text:\n" + lineOne + lineTwo + '.' + lineThree + '.' + lineFour + '.' + lineFive + "\n.\n;";
111 ActionReject rejection = runRejectScript(script);
112 assertEquals(lineOne + lineTwo + lineThree + lineFour + lineFive, rejection.getMessage());
113 }
114
115 private ActionReject runRejectScript(String script) throws SieveException, ParseException {
116 MailAdapter mail = JUnitUtils.createMail();
117 JUnitUtils.interpret(mail, script);
118 assertTrue(mail.getActions().size() == 1);
119 Object action = mail.getActions().get(0);
120 assertTrue(action instanceof ActionReject);
121 ActionReject rejection = (ActionReject) action;
122 return rejection;
123 }
124 }