|
1 | 1 | package org.simplejavamail.converter;
|
2 | 2 |
|
3 | 3 | import jakarta.mail.util.ByteArrayDataSource;
|
| 4 | +import net.fortuna.ical4j.data.CalendarBuilder; |
| 5 | +import net.fortuna.ical4j.data.ParserException; |
| 6 | +import net.fortuna.ical4j.model.Calendar; |
| 7 | +import net.fortuna.ical4j.model.Property; |
4 | 8 | import org.assertj.core.api.Condition;
|
5 | 9 | import org.jetbrains.annotations.NotNull;
|
6 | 10 | import org.junit.jupiter.api.Test;
|
|
17 | 21 |
|
18 | 22 | import java.io.File;
|
19 | 23 | import java.io.IOException;
|
| 24 | +import java.io.StringReader; |
20 | 25 | import java.util.ArrayList;
|
21 | 26 | import java.util.HashMap;
|
22 | 27 | import java.util.List;
|
| 28 | +import java.util.Optional; |
23 | 29 | import java.util.regex.Matcher;
|
24 | 30 |
|
25 | 31 | import static demo.ResourceFolderHelper.determineResourceFolder;
|
@@ -419,6 +425,56 @@ public void testGithub551_ContentTransferEncodingEndsWithSpaceBug() {
|
419 | 425 | assertThat(emailMime.getContentTransferEncoding()).isEqualTo(BIT7);
|
420 | 426 | }
|
421 | 427 |
|
| 428 | + @Test |
| 429 | + public void testGithub552_BrokenCalendarMethod() throws ParserException, IOException { |
| 430 | + Email emailMime = EmailConverter.emlToEmail(new File(RESOURCE_TEST_MESSAGES + "/#552 broken calendar method.eml")); |
| 431 | + |
| 432 | + assertThat(emailMime.getCalendarMethod()).isEqualTo(CalendarMethod.REQUEST); |
| 433 | + assertThat(emailMime.getCalendarText()).isNotEmpty(); |
| 434 | + |
| 435 | + Calendar calendar = new CalendarBuilder() |
| 436 | + .build(new StringReader(emailMime.getCalendarText())); |
| 437 | + |
| 438 | + assertThat(getPropertyValue(calendar, "SUMMARY")).contains("TestYandex"); |
| 439 | + assertThat(getPropertyValue(calendar, "DTSTART")).contains("20240813T170000"); |
| 440 | + assertThat(getPropertyValue(calendar, "DTEND")).contains("20240813T173000"); |
| 441 | + assertThat(getPropertyValue(calendar, "UID")).contains("141zhi60x8914s7bzxzq27i0syandex.ru"); |
| 442 | + assertThat(getPropertyValue(calendar, "SEQUENCE")).contains("0"); |
| 443 | + assertThat(getPropertyValue(calendar, "DTSTAMP")).contains("20240813T135030Z"); |
| 444 | + assertThat(getPropertyValue(calendar, "CREATED")).contains("20240813T135030Z"); |
| 445 | + assertThat(getPropertyValue(calendar, "LAST-MODIFIED")).contains("20240813T135030Z"); |
| 446 | + assertThat(getPropertyValue(calendar, "ORGANIZER")) |
| 447 | + .hasValueSatisfying(org -> assertThat(org).contains("mailto:")) |
| 448 | + .hasValueSatisfying(org -> assertThat(org).contains("ipopov")); |
| 449 | + assertThat(calendar.getComponent("VEVENT") |
| 450 | + .map(e -> e.getProperties("ATTENDEE"))) |
| 451 | + .hasValueSatisfying( |
| 452 | + attendees -> assertThat(attendees).satisfiesExactlyInAnyOrder( |
| 453 | + attendeeProp -> assertThat(attendeeProp.getValue()).satisfies(attendee -> { |
| 454 | + assertThat(attendee).contains("mailto:"); |
| 455 | + assertThat(attendee).contains("ipopov"); |
| 456 | + }), |
| 457 | + attendeeProp -> assertThat(attendeeProp.getValue()).satisfies(attendee -> { |
| 458 | + assertThat(attendee).contains("mailto:"); |
| 459 | + assertThat(attendee).contains("skyvv1sp"); |
| 460 | + }) |
| 461 | + ) |
| 462 | + ); |
| 463 | + assertThat(getPropertyValue(calendar, "URL")).contains("https://calendar.yandex.ru/event?event_id=2182739972"); |
| 464 | + assertThat(getPropertyValue(calendar, "TRANSP")).contains("OPAQUE"); |
| 465 | + assertThat(getPropertyValue(calendar, "CATEGORIES")).contains("Мои события"); |
| 466 | + assertThat(getPropertyValue(calendar, "CLASS")).contains("PRIVATE"); |
| 467 | + assertThat(getPropertyValue(calendar, "DESCRIPTION")).contains(""); |
| 468 | + assertThat(getPropertyValue(calendar, "LOCATION")).contains(""); |
| 469 | + } |
| 470 | + |
| 471 | + private static @NotNull Optional<String> getPropertyValue(Calendar calendar, String propertyName) { |
| 472 | + return calendar |
| 473 | + .getComponent("VEVENT") |
| 474 | + .flatMap(e -> e.getProperty(propertyName)) |
| 475 | + .map(Property::getValue); |
| 476 | + } |
| 477 | + |
422 | 478 | @NotNull
|
423 | 479 | private List<AttachmentResource> asList(AttachmentResource attachment) {
|
424 | 480 | List<AttachmentResource> collectionAttachment = new ArrayList<>();
|
|
0 commit comments