Closed markb-trustifi closed 4 years ago
Thanks. 1.3.0 will have msg in msg support.
This listAttachmentsRecursively
utility function will help to flatten attachment files included in msg in msg.
function listAttachmentsRecursively(fieldsData, delimiter) {
const attachments = []
const walk = (fieldsData, prefix, attachments) => {
for (const att of fieldsData.attachments) {
if (att.innerMsgContent) {
walk(att.innerMsgContentFields, att.name + delimiter, attachments);
}
else {
attachments.push({
fileName: prefix + att.fileName,
attachmentRef: att,
})
}
}
}
walk(fieldsData, "", attachments)
return attachments
}
const msgFileBuffer = fs.readFileSync(msgFilePath)
const testMsg = new MsgReader(msgFileBuffer)
const testMsgInfo = testMsg.getFileData()
fs.mkdirSync(path.resolve(saveToDir), { recursive: true })
const attachments = listAttachmentsRecursively(testMsgInfo, "_");
for (let attachment of attachments) {
const attFilePath = path.resolve(saveToDir, attachment.fileName);
fs.writeFileSync(attFilePath, testMsg.getAttachment(attachment.attachmentRef).content)
}
H:\Proj\msgreader>node cli list-att test/msgInMsgInMsg.msg
I have attachments!_green.png
blue.png
Thank you for update. It is working now!
For example, this file cannot be parsed: Undeliverable NDR with graph protection2.zip