Skip to content

Commit

Permalink
JAMES-2100 ICAL4J parsing should be lenient
Browse files Browse the repository at this point in the history
  • Loading branch information
chibenwa committed Jul 27, 2017
1 parent 111acf7 commit 343dc84
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
9 changes: 7 additions & 2 deletions mailet/icalendar/pom.xml
Expand Up @@ -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>
Expand All @@ -208,6 +209,10 @@
<version>1.7.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions 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
Expand Up @@ -25,6 +25,7 @@

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;
Expand Down Expand Up @@ -222,4 +223,28 @@ public void serviceShouldFilterResultWhenErrorParsing() throws Exception {
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);
}
}
45 changes: 45 additions & 0 deletions 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:ouazana@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:baechler@linagora.com
ATTENDEE;CUTYPE=INDIVIDUAL;RSVP=TRUE;CN=Laura ROYET;PARTSTAT=NEEDS-ACTION;
X-OBM-ID=723:MAILTO:royet@linagora.com
ATTENDEE;CUTYPE=INDIVIDUAL;RSVP=TRUE;CN=Raphael OUAZANA;PARTSTAT=ACCEPTED;
X-OBM-ID=128:MAILTO:ouazana@linagora.com
ATTENDEE;CUTYPE=INDIVIDUAL;RSVP=TRUE;CN=Luc DUZAN;PARTSTAT=NEEDS-ACTION;X-
OBM-ID=715:MAILTO:duzan@linagora.com
ATTENDEE;CUTYPE=RESOURCE;CN=Salle de reunion Lyon;PARTSTAT=ACCEPTED;X-OBM-
ID=66:MAILTO:noreply@linagora.com
ATTENDEE;CUTYPE=INDIVIDUAL;RSVP=TRUE;CN=Antoine DUPRAT;PARTSTAT=NEEDS-ACTI
ON;X-OBM-ID=453:MAILTO:duprat@linagora.com
ATTENDEE;CUTYPE=INDIVIDUAL;RSVP=TRUE;CN=Benoît TELLIER;PARTSTAT=NEEDS-ACTI
ON;X-OBM-ID=623:MAILTO:tellier@linagora.com
ATTENDEE;CUTYPE=INDIVIDUAL;RSVP=TRUE;CN=Quynh Quynh N NGUYEN;PARTSTAT=NEED
S-ACTION;X-OBM-ID=769:MAILTO:nguyen@linagora.com
END:VEVENT
END:VCALENDAR

0 comments on commit 343dc84

Please sign in to comment.