MailMessage to MapiMessage - Content Disposition changed

Hi,

  1. I am reading emails (MapiMessage) from PST file one by one.
  2. Convting MapiMesage to MailMessage
    MapiMessage.save(“C/tmp/mail”);
    MailMessage localMailMessage = MailMessage.load(“C/tmp/mail”);

3 Modifying the attachment in message
Removing the old attachment from MailMessage instance and then adding new attachment

Attachment attachment = new Attachment(filePath, mediaType);
attachment.getContentType().setMediaType(mediaType);
attachment.getContentType().setName(dispName);

attachment.getContentDisposition().setInline(false);
attachment.getContentDisposition().setFileName(dispName);
  1. Now converting MailMessage instance to MapiMessage instance
    MapiMessage mapiMessage = MapiMessage.fromMailMessage(localMailMessage );

  2. Now updating this MapiMessage instance in PST file

So the problem is, the Content-Disposition is changed to “inline” where as I have given inline false.

@harindra.chaudhary,

I have observed your requirements and suggest you to please first try using latest Aspose.Email for .NET 19.10 on your end. If there is still an issue then please share the working sample project along with source files reproducing the issue on your end.

My production version is Aspose Java aspose-email-6.1.0.0-jdk16.jar. But I tried with latest version “aspose-email-19.10-jdk16.jar” also.

Below is the sample project -
//-------------------------------------------

package com.seclore.pst;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import com.aspose.email.Attachment;
import com.aspose.email.AttachmentCollection;
import com.aspose.email.FolderInfo;
import com.aspose.email.MailMessage;
import com.aspose.email.MapiMessage;
import com.aspose.email.PersonalStorage;

public class NewPST
{
public static void main(String[] args)
{
PersonalStorage pst = PersonalStorage.create(“C:/pst/tmp/NewPst.pst”, 0);

	//Create a folder at root of PST
	pst.getRootFolder().addSubFolder("MyInbox");

	//Add message to newly created folder
	FolderInfo folder = pst.getRootFolder().getSubFolder("MyInbox");
	
	MailMessage mail1 = newMailWithoutAttacment();
	MailMessage mail2 = newMailWithAttacment();
    
	MapiMessage msg1 = MapiMessage.fromMailMessage(mail1);
	mail1.dispose();
	
	MapiMessage msg2 = MapiMessage.fromMailMessage(mail2);
	mail2.dispose();
	
	folder.addMessage( msg1 );
	folder.addMessage( msg2 );
	
	pst.dispose();
	System.out.println("done");
	
}

public static MailMessage newMailWithAttacment() 
{
	MailMessage mail = new MailMessage("acmeuserfrom@gmail.com.com", "acmeuserto@gmail.com",
			"SubTestMail", "BodyTestMail");
	
	String attachemntFilePath = "C:/pst/tmp/SamplePDF.pdf";
	
	String mediaType = getContentTypeFromFileName(attachemntFilePath);
	
	
	Attachment attachment = new Attachment(attachemntFilePath, mediaType);
	
	//Setting attachment name
	attachment.setName("SamplePDF.pdf");
	
	// Setting Content-Type: application/pdf; name="SamplePDF.pdf"
	attachment.getContentType().setMediaType(mediaType);
    attachment.getContentType().setName("SamplePDF.pdf");
    
    // Setting  Content-Disposition: attachment; filename="SamplePDF.pdf"
    attachment.getContentDisposition().setInline(false);
    attachment.getContentDisposition().setFileName("SamplePDF.pdf");
    
    attachment.setContentId("hdh56uyt57324t87t24875t8243t58");
    
    AttachmentCollection  attachmentCollection = mail.getAttachments();
    attachmentCollection.addItem(attachment);

	return mail;
}

private static String getContentTypeFromFileName(String pPath) 
{
	Path path = new File(pPath).toPath();
	try {
		return Files.probeContentType(path);
	}
	catch (IOException e) 
	{
		e.printStackTrace();
	}
	return "application/octet-stream";
}

public static MailMessage newMailWithoutAttacment() 
{
	MailMessage mail = new MailMessage("acmeuserfrom@gmail.com.com", "acmeuserfrom@gmail.com.com",
			"SubTestMailNoAttach", "BodyTestMailNoAttach");
	return mail;
}

}

// -------------------------
// Thanks

@harindra.chaudhary,

Can you please share source file as well for further investigation. You have only shared sample code with us.

SamplePDF.pdf (3.0 KB)

NewPST.zip (1.0 KB)

Sending you the SamplePDF and Source code

@harindra.chaudhary,

Thanks for sharing file. I am requesting PST file form which you are reading emails so that we may further investigate to help you out.

Hi @Adnan.Ahmad

I getting the issue when creating the new PST also.

Hi Adnan.Ahmad,

Send you the PST fileSampleSourcePST.zip (87.0 KB)

@harindra.chaudhary,

I have been able to observe the issue. An issue with ID EMAILJAVA-34614 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed