在解析 Mbox、按条件过滤消息并将这些消息写入新流 => 文件后,生成的 Mbox 缺少 FROM 行。你能告诉我我是否犯了代码错误或者 MimeParser 函数中是否存在错误?
示例代码:
using System.IO;
using MimeKit;
namespace mboxScan
{
class Program
{
static void Main(string[] args)
{
// Grab local .mbox file
var stream = MboxStream(@"C:\temp\user.mbox");
// Filter logic
string fromFilter = "it@abc.com";
// Load every message from a Unix mbox
var parser = new MimeParser(stream, MimeFormat.Mbox);
// Create new stream for results
var exportStream = new MemoryStream();
while (!parser.IsEndOfStream)
{
var message = parser.ParseMessage();
if (message.From.ToString().Contains(fromFilter))
{
// Write this message to exportStream
message.WriteTo(exportStream);
}
}
// ** Save exportStream to new MBOX
exportStream.Position = 0;
using (var fileStream = File.Create(@"C:\temp\results.mbox"))
{
exportStream.Seek(0, SeekOrigin.Begin);
exportStream.CopyTo(fileStream);
}
}
static Stream MboxStream(string s)
{
Stream fs = File.OpenRead(s);
return fs;
}
}
}
结果开始于:
送到了(送去了: