int numberOfAttachments = msg.getNumberOfAttachments();
String outputDirPath = ThunderbirdMboxFileIngestModule.getModuleOutputPath() + File.separator;
for (int x = 0; x < numberOfAttachments; x++) {
String filename = "";
try {
PSTAttachment attach = msg.getAttachment(x);
long size = attach.getAttachSize();
if (size >= services.getFreeDiskSpace()) {
continue;
}
// both long and short filenames can be used for attachments
filename = attach.getLongFilename();
if (filename.isEmpty()) {
filename = attach.getFilename();
}
String uniqueFilename = msg.getDescriptorNodeId() + "-" + filename;
String outPath = outputDirPath + uniqueFilename;
saveAttachmentToDisk(attach, outPath);
EmailMessage.Attachment attachment = new EmailMessage.Attachment();
long crTime = attach.getCreationTime().getTime() / 1000;
long mTime = attach.getModificationTime().getTime() / 1000;
String relPath = getRelModuleOutputPath() + File.separator + uniqueFilename;
attachment.setName(filename);
attachment.setCrTime(crTime);
attachment.setmTime(mTime);
attachment.setLocalPath(relPath);
attachment.setSize(attach.getFilesize());
email.addAttachment(attachment);
} catch (PSTException | IOException ex) {
addErrorMessage(
NbBundle.getMessage(this.getClass(), "PstParser.extractAttch.errMsg.failedToExtractToDisk",
filename));