by Dave
26. March 2011 01:34
One of the capabilities of ListNanny, is for it to be able to parse MBX (sometimes called MBox or Mailbox) files. It can parse and classify individual bounces found within those files.
However, another use, is to simply use ListNanny to convert the MBX file into it's individual emails.
Here is a short, but complete code example on how to do this.
[C#]
//counter used for naming individual files
private int mbxCounter = 0;
private void ExtractMBX()
{
//mbx path (change to match your system)
string mbxPath = @"D:\temp\main.mbx";
//processing engine found in ListNanny
ProcessingEngine pe = new ProcessingEngine();
//wire up the OnBeforeParse file event
pe.BeforeParseFile += new BeforeParseFileEventHandler( OnBeforeFileParse );
pe.ProcessMBXFile( mbxPath );
}
private void OnBeforeFileParse( object sender, BeforeParseFileEventArgs e )
{
//in this event, we will extract the email, save it to a file
//email file path
string emailFile = @"d:\temp\MBXFiles\ExractedFile" + mbxCounter.ToString("00000") + ".eml";
//write out the file
string contents = e.Contents;
StreamWriter sw = new StreamWriter(emailFile);
sw.Write( contents );
sw.Flush();
//tell ListNanny to ignore any further processing
e.IgnoreFile = true;
e.Contents = string.Empty;
mbxCounter++;
}
[VB.NET]
'counter used for naming individual files
Private mbxCounter As Integer = 0
Private Sub ExtractMBX()
'mbx path (change to match your system)
Dim mbxPath As String = "D:\temp\main.mbx"
'processing engine found in ListNanny
Dim pe As New ProcessingEngine()
'wire up the OnBeforeParse file event
AddHandler pe.BeforeParseFile, AddressOf OnBeforeFileParse
pe.ProcessMBXFile(mbxPath)
End Sub 'ExtractMBX
Private Sub OnBeforeFileParse(sender As Object, e As BeforeParseFileEventArgs)
'in this event, we will extract the email, save it to a file
'email file path
Dim emailFile As String = "d:\temp\MBXFiles\ExractedFile" + mbxCounter.ToString("00000") + ".eml"
'write out the file
Dim contents As String = e.Contents
Dim sw As New StreamWriter(emailFile)
sw.Write(contents)
sw.Flush()
'tell ListNanny to ignore any further processing
e.IgnoreFile = True
e.Contents = String.Empty
mbxCounter += 1
End Sub
As always, if anyone has any questions, let me know through the Contact Us page. Thanks! Dave