Trying to parse the attached EML file fails using MCOMessageParser.
Still mail client applications (at least Apple Mail) can open, parse and render the message (looks like parsing is somewhat lenient).
Parse in this case returns the whole message data.
Platform(s)
<macOS>
Piece of code
Trying to get attachments using this piece of code :
extension MCOMessageParser {
func allAttachments() -> [MCOAttachment] {
guard let main = mainPart() else {
return []
}
let attachments = parseAttachments(in: main)
// MailCore may return the whole itself in case it can't parse the message
// We are ensuring this does not happen by returning an empty array
if let first = attachments.first, first == main {
return []
}
return parseAttachments(in: main)
}
private func parseAttachments(in part: MCOAbstractPart) -> [MCOAttachment] {
if let message = part as? MCOMessagePart, let main = message.mainPart {
return parseAttachments(in: main)
} else if let multipart = part as? MCOMultipart {
var attachements = [MCOAttachment]()
for part in multipart.parts {
if let abstractPart = part as? MCOAbstractPart {
attachements.append(contentsOf: parseAttachments(in: abstractPart))
}
}
return attachements
} else if let attachment = part as? MCOAttachment {
return [attachment]
} else {
return []
}
}
}
Actual outcome
MailCore did return the whole data as an attachment.
Expected outcome
Expected MailCore to somehow parse data correctly.
Summary
Trying to parse the attached EML file fails using
MCOMessageParser
. Still mail client applications (at least Apple Mail) can open, parse and render the message (looks like parsing is somewhat lenient). Parse in this case returns the whole message data.Platform(s)
Piece of code
Trying to get attachments using this piece of code :
Actual outcome MailCore did return the whole data as an attachment.
Expected outcome Expected MailCore to somehow parse data correctly.