Hi,
I am trying to do the following:
- Reading msg file and saving the body as rtf
- saving mail attachments on the disk
- creating pdf from rtf
- Attaching email attachment into pdf
But it looks like there is an IO operation involved at every step, which I believe is a network overhead. Can you look at the code and suggest if I can make it any better?
public static void main(String[] args) {
try {
String filePath = “D:\Manish\Tryouts\AsposeEval1\files\”;
String fileName = “msg_attachment_test2”;
//Instantiate an MSG file to load an MSG file from disk
MapiMessage outlookMessageFile = MapiMessage.fromFile(filePath + fileName + “.msg”);
BufferedWriter out = new BufferedWriter(new FileWriter(filePath + fileName + “.rtf”, false));
out.write(outlookMessageFile.getBodyRtf());
out.close();
Document docRTF = new Document(filePath + fileName + “.rtf”);
docRTF.save(filePath + fileName + “.pdf”);
PdfContentEditor editor = new PdfContentEditor();
editor.bindPdf(filePath + fileName + “.pdf”);
MapiAttachmentCollection attColl = outlookMessageFile.getAttachments();
Iterator iter = attColl.iterator();
while (iter.hasNext()) {
MapiAttachment outlookMessageAttachment = iter.next();
//Display attachment type
System.out.println("Att Type : " + outlookMessageAttachment.getAttachmentType());
//Display attached file name
System.out.println("File Name : " + outlookMessageAttachment.getLongFileName());
//Save attachment to the disk
if (outlookMessageAttachment.getLongFileName() != null) {
outlookMessageAttachment.save(filePath + “att\”
+ outlookMessageAttachment.getLongFileName());
Rectangle rect = new Rectangle(10, 10);
String document = filePath + “att\”
+ outlookMessageAttachment.getLongFileName();
editor.createFileAttachment(rect, “This mail has attachments”, document, 1, “PaperClip”);
}
}
editor.save(filePath + fileName + “.pdf”);
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
Thanks,
Manish