c# - Mimekit: parse filtered Mbox results to new Mbox -


after parsing mbox, filtering message(s) condition, , writing messages new stream => file, resulting mbox missing lines. can tell me if i'm making code mistake or if there bug in mimeparser function?

example code:

    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 unix mbox                 var parser = new mimeparser(stream, mimeformat.mbox);                  // create new stream results                 var exportstream = new memorystream();                  while (!parser.isendofstream)                 {                     var message = parser.parsemessage();                     if (message.from.tostring().contains(fromfilter))                     {                         // write message exportstream                          message.writeto(exportstream);                           }                                                                 }                  // ** save exportstream 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;             }         }     } 

and results start with:

delivered-to:

sorry folks - you're watching me learn in real-time ;-) parser.mboxmarker first "from " line , it's rightfully not part of message object properties because it's aspect of mbox format, not message. in mind - can capture line , insert memory before message.writeto() function such:

var topline = parser.mboxmarker; memorystream mstream =    new memorystream(asciiencoding.default.getbytes(topline));             mstream.writeto(exportstream);             mstream.dispose(); 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -