Calendar Invitation Body Is Missing when Opened in Outlook

Hi there. I am having an issue whereby I convert a calendar invitation from .eml to .msg and the body of the invite (simple plain text) is missing when the .msg is opened in Outlook.

Please find beneath a Maven project containing a single test demonstrating the problem (beneath) and a zip containing the EML source file referenced in the test. The PR_BODY_W property is set with the expected “Test body” but when opened in Outlook no body is displayed. Can you please investigate this or help me to understand why?

Thanks very much.

MissingCalendarBody21.8.zip (36.9 KB)

Sample_Meeting_For_JIRA.zip (3.5 KB)

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
import org.junit.Test;

import com.aspose.email.AlternateView;
import com.aspose.email.Appointment;
import com.aspose.email.AppointmentLoadOptions;
import com.aspose.email.HeaderCollection;
import com.aspose.email.MailMessage;
import com.aspose.email.MapiConversionOptions;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertTrue;

import javax.mail.BodyPart;
import javax.mail.Header;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.internet.ContentType;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.ParameterList;
import javax.mail.internet.ParseException;
import javax.mail.util.SharedByteArrayInputStream;

import com.aspose.email.MapiMessage;
import com.aspose.email.MapiPropertyTag;

public class TestMissingCalendarBody {

    static String sourcePath="/TODO/Sample_Meeting_For_JIRA.eml";
    static final ContentType DEFAULT_CONTENT_TYPE = new ContentType("text", "plain", (ParameterList)null);

    private static ContentType parseContentType(final String contentTypeString) {
        if (StringUtils.isBlank(contentTypeString)) {
            return DEFAULT_CONTENT_TYPE;
        } else {
            try {
                return new ContentType(contentTypeString);
            } catch (ParseException var2) {
                return DEFAULT_CONTENT_TYPE;
            }
        }
    }

    @Test
    public void testEmailParser() throws IOException, MessagingException {
        try (InputStream is = new FileInputStream(new File(sourcePath))) {
            // Given
            MailMessage mailMessage = new MailMessage();
            mailMessage.setBodyEncoding(Charset.forName("UTF-8"));
            mailMessage.getHeaders().remove("X-Unsent");

            Properties sessionProps = new Properties();
            sessionProps.setProperty( "mail.mime.address.strict", "false");
            SharedByteArrayInputStream sh = new SharedByteArrayInputStream(IOUtils.toByteArray(is));
            Session session = Session.getInstance(sessionProps);

            MimeMessage mimeMessage = new MimeMessage(session, sh);
            mimeMessage.removeHeader("Content-Transfer-Encoding");

            byte[] contents;
            try (InputStream inputStream = mimeMessage.getInputStream()) {
                contents = IOUtils.toByteArray(inputStream);
            }

            Charset charset = UTF_8;
            String contentString = new String(contents, charset);
            byte[] contentBytes = contentString.getBytes(charset);

            AppointmentLoadOptions appointmentLoadOptions = new AppointmentLoadOptions();
            appointmentLoadOptions.setApplyLocalTZ(false);
            appointmentLoadOptions.setIgnoreSmtpAddressCheck(true);

            Appointment appointment = Appointment.load(new ByteArrayInputStream(contentBytes), appointmentLoadOptions);

            AlternateView view = appointment.requestApointment();
            mailMessage.getAlternateViews().addItem(view);

            mailMessage.setDate(new Date());
            mailMessage.setTimeZoneOffset(0);
            mailMessage.setSubjectEncoding(Charset.forName("UTF-8"));

            HeaderCollection hc = mailMessage.getHeaders();

            Enumeration<Header> headers = mimeMessage.getAllHeaders();
            while(headers.hasMoreElements()) {
                Header header = headers.nextElement();
                hc.add(header.getName(),header.getValue());
            }

            MapiConversionOptions mapiConversionOption = new MapiConversionOptions();
            mapiConversionOption.setPreserveOriginalAddresses(true);
            mapiConversionOption.setPreserveOriginalDates(true);
            mapiConversionOption.setPreserveSignature(true);
            mapiConversionOption.setUseBodyCompression(true);
            mapiConversionOption.setFormat(MapiConversionOptions.getUnicodeFormat().getFormat());
            mapiConversionOption.setPreserveEmbeddedMessageFormat(false);
            mapiConversionOption.setForcedRtfBodyForAppointment(false);

            // When
            MapiMessage mapiMsg = MapiMessage.fromMailMessage(mailMessage, mapiConversionOption);

            mapiMsg.save("/TODO/converted.msg");

            // Then
            System.out.println(mapiMsg.getProperties().get_Item(MapiPropertyTag.PR_BODY_W).getString());
        }
    }
}

@curtisyamada,
Thank you for contacting support. Unfortunately, I was unable to find the cause of the problem. Please try to isolate it from your application code and share a code example demonstrating the problem in Aspose.Email API.