import junit.framework.TestCase;
public class ReplaceContentTest extends TestCase {
public void testService() throws MessagingException, IOException {
Mailet mailet;
FakeMailetConfig mci;
MimeMessage message;
Mail mail;
mailet = new ReplaceContent();
mci = new FakeMailetConfig("Test", new FakeMailContext());
mci.setProperty("subjectPattern", "/prova/PROVA/i/,/a/e//,/o/o/i/");
mci.setProperty("bodyPattern", "/prova/PROVA/i/," + "/a/e//,"
+ "/o/o/i/,/\\u00E8/e'//," + "/prova([^\\/]*?)ble/X$1Y/im/,"
+ "/X(.\\n)Y/P$1Q//," + "/\\/\\/,//");
mailet.init(mci);
message = new MimeMessage(Session.getDefaultInstance(new Properties()));
message.setSubject("una prova");
message.setText("Sto facendo una prova di scrittura/ \u00E8 solo una prova.\n"
+ "Bla bla bla bla.\n");
mail = new FakeMail(message);
mailet.service(mail);
assertEquals("une PRoVA", mail.getMessage().getSubject());
assertEquals("Sto fecendo une PRoVA di scritture, e' solo une P.\n"
+ "Q ble ble ble.\n", mail.getMessage().getContent());
// ------------------
mailet = new ReplaceContent();
mci = new FakeMailetConfig("Test", new FakeMailContext());
mci.setProperty("subjectPatternFile","#/org/apache/james/mailet/standard/mailets/replaceSubject.patterns");
mailet.init(mci);
message = new MimeMessage(Session.getDefaultInstance(new Properties()));
message.setSubject("re: r:ri:una prova");
message.setText("Sto facendo una prova di scrittura/ \u00E8 solo una prova.\n"
+ "Bla bla bla bla.\n");
mail = new FakeMail(message);
mailet.service(mail);
assertEquals("Re: Re: Re: una prova", mail.getMessage().getSubject());
// ------------------
mailet = new ReplaceContent();
mci = new FakeMailetConfig("Test", new FakeMailContext());
mci.setProperty("bodyPattern", "/--messaggio originale--/<quote>/i/,"
+
// "/<quote>([^\\0]*)(\\r\\n)([^>]+)/<quote>$1$2>$3/imr/,"+
"/<quote>(.*)(\\r\\n)([^>]+)/<quote>$1$2>$3/imrs/,"
+ "/<quote>\\r\\n//im/");
mailet.init(mci);
message = new MimeMessage(Session.getDefaultInstance(new Properties()));
message.setSubject("una prova");
message.setText("Prova.\r\n" + "\r\n" + "--messaggio originale--\r\n"
+ "parte del\r\n" + "messaggio\\ che\\0 deve0 essere\r\n"
+ "quotato. Vediamo se\r\n" + "ce la fa.");
mail = new FakeMail(message);
mailet.service(mail);
assertEquals("una prova", mail.getMessage().getSubject());
assertEquals("Prova.\r\n" + "\r\n" + ">parte del\r\n"
+ ">messaggio\\ che\\0 deve0 essere\r\n"
+ ">quotato. Vediamo se\r\n" + ">ce la fa.", mail.getMessage()
.getContent());
// ------------------
mailet = new ReplaceContent();
mci = new FakeMailetConfig("Test", new FakeMailContext());
mci.setProperty("bodyPattern", "/\\u2026/...//");
mailet.init(mci);
message = new MimeMessage(Session.getDefaultInstance(new Properties()));
message.setSubject("una prova");
message.setText("Prova \u2026 di replace \u2026");
mail = new FakeMail(message);
mailet.service(mail);
assertEquals("una prova", mail.getMessage().getSubject());
assertEquals("Prova ... di replace ...", mail.getMessage().getContent());
}