We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

MapiCalendarExceptionInfo getAttachments returns null when MapiCalendar is loaded from PST file

This is the code to reproduce the issue:

import com.aspose.email.*;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;

class TestMapiCalendarExceptionInfo {

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

	void test() throws Exception {
		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());
		meeting.getAttachments().add("root.txt", "root".getBytes(StandardCharsets.UTF_8));

		// 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");
		MapiAttachmentCollection attachments = new MapiAttachmentCollection();
		attachments.add("modified attachment.txt", "modified attachment".getBytes(StandardCharsets.UTF_8));
		exceptionInfo.setAttachments(attachments);
		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();
			MapiAttachment origAttachment = meeting.getRecurrence().getRecurrencePattern().getExceptions().get_Item(0)
				.getAttachments().get_Item(0);
			MapiAttachment loadedAttachment = calendar.getRecurrence().getRecurrencePattern().getExceptions().get_Item(0)
				.getAttachments().get_Item(0);

			if (!origAttachment.getFileName().equals(loadedAttachment.getFileName())) {
				throw new Exception(String.format("\nExpected:%s\nActual\t:%s",
					origAttachment.getFileName(), loadedAttachment.getFileName()));
			}
			if (!Arrays.equals(origAttachment.getBinaryData(), loadedAttachment.getBinaryData())) {
				throw new Exception(String.format("\nExpected:%s\nActual\t:%s",
					new String(origAttachment.getBinaryData(), StandardCharsets.UTF_8),
					new String(loadedAttachment.getBinaryData(), StandardCharsets.UTF_8)));
			}
		}
	}

	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-35021. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.