Aspose Team,
We’re trying to extract messages from PST file with the Aspose.Email Java library (version 20.5). We got the NullPointerException error when extracting some of the messages form the sample pst file. Following is the stack trace.
java.lang.NullPointerException
at com.aspose.email.zapz.d(SourceFile:2536)
at com.aspose.email.zapz.b(SourceFile:307)
at com.aspose.email.zapz.d(SourceFile:1350)
at com.aspose.email.zzc.h(SourceFile:526)
at com.aspose.email.zzc.(SourceFile:98)
at com.aspose.email.zavb.(SourceFile:66)
at com.aspose.email.zahh.a(SourceFile:321)
at com.aspose.email.zavk.b(SourceFile:346)
at com.aspose.email.zavk.a(SourceFile:305)
at com.aspose.email.PersonalStorage.extractMessage(SourceFile:627)
at com.aspose.email.PersonalStorage.extractMessage(SourceFile:643)
at ExtractPst.extractFolder(ExtractPst.java:32)
at ExtractPst.extractFolder(ExtractPst.java:43)
at ExtractPst.extractFolder(ExtractPst.java:43)
at ExtractPst.extractFolder(ExtractPst.java:43)
at ExtractPst.extractFolder(ExtractPst.java:43)
at ExtractPst.main(ExtractPst.java:19)
Following is the sample code for reproducing the problem. Please advise if we miss something or there is a bug in the library.
import com.aspose.email.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Iterator;
public class ExtractPst {
private static int messageNumber = 0;
public static void main(String[] args) {
try {
String filepath = "/home/ubuntu/winshare/Sample_Files/Archives/Pst/NullPointerException.pst";
String outpath = "/home/ubuntu/winshare/temp/pstout4";
PersonalStorage pst = PersonalStorage.fromFile(filepath, false);
FolderInfo rootFolder = pst.getRootFolder();
extractFolder(pst, rootFolder, Paths.get(outpath));
}
catch(Throwable ex) {
ex.printStackTrace();
}
}
private static void extractFolder(PersonalStorage pst, FolderInfo folder, Path outDirectory) throws Exception {
Iterator<String> iterable = folder.enumerateMessagesEntryId().iterator();
while(iterable.hasNext()){
String messageEntryId = iterable.next();
String fileName = Paths.get(outDirectory.toString(), String.valueOf(messageNumber)).toString();
System.out.println(String.format("Processing messageEntryId %s", messageEntryId));
MapiMessage message = pst.extractMessage(messageEntryId);
IMapiMessageItem item = message.toMapiMessageItem();
if (item instanceof MapiContact) {
((MapiContact) item).save(fileName + ".vcf", 0);
} else {
message.save(fileName + ".msg", new MsgSaveOptions(MailMessageSaveType.getOutlookMessageFormat()));
}
messageNumber++;
}
for (FolderInfo subFolder : folder.getSubFolders()) {
extractFolder(pst, subFolder, outDirectory);
}
}
}
Thank you for your help.
Xiaohong Yang