MapiCalendarExceptionInfo returns null body field when MapiCalendar is loaded from PST file

aspose-email-21.12

This is the code to reproduce the issue:

import com.aspose.email.*;

import java.io.File;
import java.util.Calendar;
import java.util.Date;

class TestMapiCalendarExceptionInfo {

	public static void main(String[] args) {
			new TestMapiCalendarExceptionInfo().test();
	}

	void test() {
		Date startDate = addHours(new Date(), 1);
		Date endDate = addHours(startDate, 1);

		// Create the meeting
		MapiCalendar meeting = new MapiCalendar("Zoom", "Meeting", "root", startDate,
			endDate, "", new MapiRecipientCollection());

		// Set timeZone
		MapiCalendarTimeZone timeZone = new MapiCalendarTimeZone("EST");
		meeting.setStartDateTimeZone(timeZone);
		meeting.setEndDateTimeZone(timeZone);

		// Create the recurrence
		MapiCalendarEventRecurrence recurrence = new MapiCalendarEventRecurrence();
		recurrence.setRecurrencePattern(new MapiCalendarDailyRecurrencePattern());
		MapiCalendarRecurrencePattern pattern = recurrence.getRecurrencePattern();
		pattern.setPatternType(MapiCalendarRecurrencePatternType.Day);
		pattern.setPeriod(1);
		pattern.setWeekStartDay(DayOfWeek.Sunday);
		pattern.setOccurrenceCount(5);
		pattern.setEndType(MapiCalendarRecurrenceEndType.EndAfterNOccurrences);
		meeting.setRecurrence(recurrence);

		// Modify the occurrence
		MapiCalendarExceptionInfo exceptionInfo = new MapiCalendarExceptionInfo();
		Date exceptionStartDate = addHours(startDate, 24);
		Date exceptionEndDate = addHours(exceptionStartDate, 1);
		exceptionInfo.setBody("Modified description");
		exceptionInfo.setOriginalStartDate(exceptionStartDate);
		exceptionInfo.setStartDateTime(exceptionStartDate);
		exceptionInfo.setEndDateTime(exceptionEndDate);
		exceptionInfo.setLocation("Teams");
		pattern.getModifiedInstanceDates().addItem(exceptionStartDate);
		pattern.getDeletedInstanceDates().addItem(exceptionStartDate);
		pattern.getExceptions().addItem(exceptionInfo);

		// Store to PST
		String file = System.getProperty("java.io.tmpdir") + File.separator + "MapiCalendarToPST" + System.currentTimeMillis() + " _out.pst";
		String calendarName = "Calendar";
		FolderInfo calendarFolder;
		try (PersonalStorage pst = PersonalStorage.create(file, FileFormatVersion.Unicode)) {
			calendarFolder = pst.createPredefinedFolder(calendarName, StandardIpmFolder.Appointments);
			calendarFolder.addMapiMessageItem(meeting);
		}

		// Load from PST
		PersonalStorage storage = PersonalStorage.fromFile(file);
		FolderInfo folderInfo = storage.getRootFolder().getSubFolder(calendarName);
		MessageInfoCollection messageInfoCollection = folderInfo.getContents();
		for (MessageInfo messageInfo : messageInfoCollection) {
			MapiCalendar calendar = (MapiCalendar) storage.extractMessage(messageInfo).toMapiMessageItem();
			String origBody = meeting.getRecurrence().getRecurrencePattern().getExceptions().get_Item(0).getBody();
			String loadedBody = calendar.getRecurrence().getRecurrencePattern().getExceptions().get_Item(0).getBody();
			if (!origBody.equals(loadedBody)) {
				System.out.println(String.format("\nExpected:%s\nActual\t:%s", origBody, loadedBody));
			}
		}
	}

	private Date addHours(Date date, int amount) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.HOUR, amount);
		return cal.getTime();
	}
}

@SergeiNikitin

We have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as EMAILJAVA-35020. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.