简体   繁体   English

Golang:尝试解析 Outlook 消息文件(电子邮件)格式错误的 MIME header 时遇到问题:缺少冒号:

[英]Golang: Encountering issue trying to parse Outlook msg files (emails) malformed MIME header: missing colon:

I have a task to parse both eml and msg formatted email files using Go. There's a wonderful package for parsing EML files, however, with MSG, no matter what package I research and attempt to implement, I encounter the same error every single time.我的任务是使用 Go 解析 eml 和 msg 格式的 email 文件。有一个很棒的 package 用于解析 EML 文件,但是,对于 MSG,无论我研究并尝试实现什么 package,我每次都会遇到同样的错误。

malformed MIME header: missing colon:格式错误的 MIME header:缺少冒号:

It isn't the msg file itself.它不是 msg 文件本身。 I have the same service in .NET which reads the msg file perfectly (MsgReader library).我在 .NET 中有相同的服务,它可以完美地读取 msg 文件(MsgReader 库)。

Could someone suggest a package I could use in Go to read msg files?有人可以建议我可以在 Go 中使用 package 来读取 msg 文件吗? I wonder if it's an encoding issue (this wasn't a problem with eml files).我想知道这是否是编码问题(这不是 eml 文件的问题)。

I've tried using these packages:我试过使用这些包:

As an example, here is one function I've tried to read an msg file.例如,这是一个 function 我试图读取一个 msg 文件。

func parse_msg_file() {

    var filePath string = "c://messages//kraken.msg"
    var reader io.Reader

    f, err := os.Open(filePath)
    checkerr(err, "file "+filePath+" not found or can not be readed")

    defer f.Close()

    reader = bufio.NewReader(f)

    msg, err := email.ParseMessage(reader)
    checkerr(err, "failed to parse raw msg file")
    if msg == nil {
        checkerr(err, "failed to parse raw msg file")
    }
}

and the output when I call the function is:当我拨打 function 时,output 是:

malformed MIME header: missing colon: "\xd0\xcf\x11\u0871\x1a\xe1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00>\x00\x03\x00\xfe\xff\t\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\t\x00\x00\x00\x02\x00\x00\x00\xfe\xff\xff\xff\x00\x00\x00\x00\x03\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xffR\x00o\x00o\x00t\x00 \x00E\x00n\x00t\x00r\x00y\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x16\x00\x05\x00\xff\xff\xff\xff\xff\xff\xff\xff\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\t-0r$\xd9\x01"
exit status 255

Just to add to my comment, I have searched for "msg parsers in go" in Google and it has brought up this repository - https://github.com/oucema001/OutlookMessageParser-Go .只是添加到我的评论中,我在 Google 中搜索了“go 中的 msg 解析器”,它提出了这个存储库 - https://github.com/oucema001/OutlookMessageParser -Go。 I don't know if it actually works - it's pretty old, and no documentation, so unlikely it'll be easy to use, but you can start from there.我不知道它是否真的有效——它很旧,没有文档,所以不太可能容易使用,但你可以从那里开始。

The Compound File Binary File Format is复合文件二进制文件格式

a general-purpose file format that provides a file-system-like structure within a file for the storage of arbitrary, application-specific streams of data.一种通用文件格式,在文件中提供类似文件系统的结构,用于存储任意的、特定于应用程序的数据流。

I believe that this stuff all came from Microsoft's old OLE/COM stuff (Object Linking and Embedding/Component Object Model).我相信这些东西都来自微软的旧 OLE/COM 东西(对象链接和嵌入/组件 Object 模型)。

FWIW, here's a parser for the Compound File Binary File Format. FWIW,这是复合文件二进制文件格式的解析器。 No idea if it works, or anything else about it, but it might be, at least, a jumping-off point for you.不知道它是否有效,也不知道它是否有效,但它可能至少是你的一个起点。

https://github.com/richardlehane/mscfb https://github.com/richardlehane/mscfb

[Edited to note] [编辑注意]

Seems that the above package is a dependency of https://github.com/oucema001/OutlookMessageParser-Go , referenced in this answer by @astax .似乎上面的 package 是https://github.com/oucema001/OutlookMessageParser -Go 的依赖项,@astax 在这个答案中引用了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM