VB如何从mime编码的文本文件中提取附件

时间:2014-06-25 19:46:46

标签: vb.net mime

我们使用第三方公司进行采购。有些PO有Word,Excel等支持文档。公司可以在包含mime编码文档的txt文件中提供给我们的文件。示例如下。

寻找VB解决方案来读取此文件并将文档提取到磁盘。任何帮助将不胜感激。

-------------------------------MIME_BOUNDARY_FOR_ATTACHMENTS
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <a4aad5dd-c89e-4c48-8c82-fac53938d751@sciquest.com>
Content-Disposition: attachment; filename="happy_path_reqs.png"

‰PNG
IHDR   È   ¥   2²  € IDATxÚì]`TUÖNOè`n¯ %4»»k_ËZ鮺ºÝ†kTºÒ{jX‘
µ)&ؼBßÛGËY3pV£O!@â­È(i f’刘ðî]Û³©¬@¼B;ÿš„=´†kË Mî
µ)&ؼBßÛGËY3pV£O!@â­È(i f’刘ðî]Û³©¬@¼B;ÿš„=´†kË Mî
µ)&ؼBßÛGËY3pV£O!@â­È(i f’刘ðî]Û³©¬@¼B;ÿš„=´†kË Mî
µ)&ؼBßÛGËY3pV£O!@â­È(i f’刘ðî]Û³©¬@¼B;ÿš„=´†kË Mî
-------------------------------MIME_BOUNDARY_FOR_ATTACHMENTS--

1 个答案:

答案 0 :(得分:1)

我不熟悉VB.NET,但您应该能够使用MimeKit来解析这些MIME格式的文件。我已经使用它很长一段时间了。

在C#中,你会做这样的事情:

var message = MimeMessage.Load ("email.msg");

foreach (var attachment in message.Attachments) {
    using (var stream = File.Create (attachment.FileName))
        attachment.ContentObject.DecodeTo (stream);
}

在VB.NET中,它可能是这样的:

Dim message As MimeMessage.Load ("email.msg")

For Each attachment As MimePart In message.Attachments
    Dim stream As File.Create (attachment.FileName)
    attachment.ContentObject.DecodeTo (stream)
    stream.Dispose ()
Next