JAMES-2100 ICAL4J parsing should be lenient
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/343dc844 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/343dc844 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/343dc844 Branch: refs/heads/master Commit: 343dc8442caacaa93ed58fd28396c2b5e6667946 Parents: 111acf7 Author: benwa <btell...@linagora.com> Authored: Thu Jul 27 10:12:15 2017 +0700 Committer: benwa <btell...@linagora.com> Committed: Thu Jul 27 15:08:06 2017 +0700 ---------------------------------------------------------------------- mailet/icalendar/pom.xml | 9 +++- .../src/main/resources/ical4j.properties | 5 +++ .../transport/mailets/ICalendarParserTest.java | 25 +++++++++++ .../src/test/resources/ics/ics_with_error.ics | 45 ++++++++++++++++++++ 4 files changed, 82 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/343dc844/mailet/icalendar/pom.xml ---------------------------------------------------------------------- diff --git a/mailet/icalendar/pom.xml b/mailet/icalendar/pom.xml index 3f43aea..46817d1 100644 --- a/mailet/icalendar/pom.xml +++ b/mailet/icalendar/pom.xml @@ -182,8 +182,9 @@ <artifactId>guava</artifactId> </dependency> <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> @@ -209,6 +210,10 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> + <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>${assertj-3.version}</version><!--$NO-MVN-MAN-VER$--> http://git-wip-us.apache.org/repos/asf/james-project/blob/343dc844/mailet/icalendar/src/main/resources/ical4j.properties ---------------------------------------------------------------------- diff --git a/mailet/icalendar/src/main/resources/ical4j.properties b/mailet/icalendar/src/main/resources/ical4j.properties new file mode 100644 index 0000000..3a4a9ec --- /dev/null +++ b/mailet/icalendar/src/main/resources/ical4j.properties @@ -0,0 +1,5 @@ +ical4j.unfolding.relaxed=true +ical4j.parsing.relaxed=true +ical4j.validation.relaxed=true +ical4j.compatibility.outlook=true +ical4j.compatibility.notes=true \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/343dc844/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/ICalendarParserTest.java ---------------------------------------------------------------------- diff --git a/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/ICalendarParserTest.java b/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/ICalendarParserTest.java index a57e8cc..1d4dffe 100644 --- a/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/ICalendarParserTest.java +++ b/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/ICalendarParserTest.java @@ -25,6 +25,7 @@ import java.util.Map; import javax.mail.MessagingException; +import org.apache.commons.io.IOUtils; import org.apache.mailet.Mail; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMailetConfig; @@ -222,4 +223,28 @@ public class ICalendarParserTest { public void getMailetInfoShouldReturn() throws MessagingException { assertThat(mailet.getMailetInfo()).isEqualTo("Calendar Parser"); } + + @Test + @SuppressWarnings("unchecked") + public void parsingShouldBeLenient() throws Exception { + FakeMailetConfig mailetConfiguration = FakeMailetConfig.builder() + .mailetName("ICalendarParser") + .setProperty(SOURCE_ATTRIBUTE, SOURCE_CUSTOM_ATTRIBUTE) + .setProperty(DESTINATION_ATTRIBUTE, DESTINATION_CUSTOM_ATTRIBUTE) + .build(); + mailet.init(mailetConfiguration); + + Map<String, byte[]> attachments = ImmutableMap.<String, byte[]>builder() + .put("key", IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("ics/ics_with_error.ics"))) + .build(); + + Mail mail = FakeMail.builder() + .attribute(SOURCE_CUSTOM_ATTRIBUTE, (Serializable) attachments) + .build(); + + mailet.service(mail); + + Map<String, Calendar> expectedCalendars = (Map<String, Calendar>)mail.getAttribute(DESTINATION_CUSTOM_ATTRIBUTE); + assertThat(expectedCalendars).hasSize(1); + } } http://git-wip-us.apache.org/repos/asf/james-project/blob/343dc844/mailet/icalendar/src/test/resources/ics/ics_with_error.ics ---------------------------------------------------------------------- diff --git a/mailet/icalendar/src/test/resources/ics/ics_with_error.ics b/mailet/icalendar/src/test/resources/ics/ics_with_error.ics new file mode 100644 index 0000000..8ee5a7b --- /dev/null +++ b/mailet/icalendar/src/test/resources/ics/ics_with_error.ics @@ -0,0 +1,45 @@ +BEGIN:VCALENDAR +PRODID:-//Aliasource Groupe LINAGORA//OBM Calendar 3.2.1-rc2//FR +CALSCALE:GREGORIAN +X-OBM-TIME:1483703436 +VERSION:2.0 +METHOD:REQUEST +BEGIN:VEVENT +CREATED:20170106T115035Z +LAST-MODIFIED:20170106T115036Z +DTSTAMP:20170106T115036Z +DTSTART;TZID="Pacific Time (US & Canada),Tijuana":20041011T223000 +DURATION:PT1H30M +TRANSP:OPAQUE +SEQUENCE:0 +VEVENT:62 +SUMMARY:Sprint planning #23 +DESCRIPTION: +CLASS:PUBLIC +PRIORITY:5 +ORGANIZER;X-OBM-ID=128;CN=Raphael OUAZANA:MAILTO:ouaz...@linagora.com +X-OBM-DOMAIN:linagora.com +X-OBM-DOMAIN-UUID:02874f7c-d10e-102f-acda-0015176f7922 +LOCATION:Hangout +CATEGORIES: +X-OBM-COLOR: +UID:f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047fe + b2aab16e43439a608f28671ab7c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc +ATTENDEE;CUTYPE=INDIVIDUAL;RSVP=TRUE;CN=Matthieu EXT_BAECHLER;PARTSTAT=NEE + DS-ACTION;X-OBM-ID=302:MAILTO:baech...@linagora.com +ATTENDEE;CUTYPE=INDIVIDUAL;RSVP=TRUE;CN=Laura ROYET;PARTSTAT=NEEDS-ACTION; + X-OBM-ID=723:MAILTO:ro...@linagora.com +ATTENDEE;CUTYPE=INDIVIDUAL;RSVP=TRUE;CN=Raphael OUAZANA;PARTSTAT=ACCEPTED; + X-OBM-ID=128:MAILTO:ouaz...@linagora.com +ATTENDEE;CUTYPE=INDIVIDUAL;RSVP=TRUE;CN=Luc DUZAN;PARTSTAT=NEEDS-ACTION;X- + OBM-ID=715:MAILTO:du...@linagora.com +ATTENDEE;CUTYPE=RESOURCE;CN=Salle de reunion Lyon;PARTSTAT=ACCEPTED;X-OBM- + ID=66:MAILTO:nore...@linagora.com +ATTENDEE;CUTYPE=INDIVIDUAL;RSVP=TRUE;CN=Antoine DUPRAT;PARTSTAT=NEEDS-ACTI + ON;X-OBM-ID=453:MAILTO:dup...@linagora.com +ATTENDEE;CUTYPE=INDIVIDUAL;RSVP=TRUE;CN=Benoît TELLIER;PARTSTAT=NEEDS-ACTI + ON;X-OBM-ID=623:MAILTO:tell...@linagora.com +ATTENDEE;CUTYPE=INDIVIDUAL;RSVP=TRUE;CN=Quynh Quynh N NGUYEN;PARTSTAT=NEED + S-ACTION;X-OBM-ID=769:MAILTO:ngu...@linagora.com +END:VEVENT +END:VCALENDAR --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org