ImapLogNewEntry Event |
Namespace: MailBee.ImapMail
This event is raised only if logging is turned on (Enabled is true).
MailBee raises this event BEFORE adding the entry into the the log. Since many properties of NewEntry object are editable, the developer can change the data MailBee will put into the log or even cancel logging the current entry at all. This may be useful the developer wishes to log only those entires which meet certain criteria.
Note |
---|
Entries added by the developer (through WriteLine(String) method call) do not cause this event to be raised. Thus, it's safe to add user-defined log entries even in the LogNewEntry event handler itself. This does not cause endless recursion which would otherwise occur if WriteLine(String) method called in LogNewEntry event handler raised this event again. |
using System; using MailBee; using MailBee.ImapMail; class Sample { // LogNewEntry event handler private static void OnLogNewEntry(object sender, LogNewEntryEventArgs e) { if ( !(e.NewEntry.MessageType == LogMessageType.Recv || e.NewEntry.MessageType == LogMessageType.Send) ) { // Do not add this entry if it does not indicate any data transfer, // and put our own message instead. e.NewEntry.AddThisEntry = false; ((Imap)sender).Log.WriteLine("UNWANTED MESSAGE REMOVED"); // Note: we could produce similar results just by writing new values // into MessageText and MessageComment properties of the original entry. // The code above uses Log.WriteLine method just to show how to add new // entries in the event handler itself. You may comment 2 code lines above // and uncomment 2 code lines below to use the alternate approach. // // e.NewEntry.MessageText = "UNWANTED MESSAGE REMOVED"; // e.NewEntry.MessageComment = string.Empty; } } // The actual code static void Main(string[] args) { Imap imp = new Imap(); // Enable logging the POP3 session into a file imp.Log.Enabled = true; imp.Log.Filename = @"C:\Temp\log.txt"; imp.Log.Clear(); // Subscribe to the LogNewEntry event imp.LogNewEntry += new LogNewEntryEventHandler(OnLogNewEntry); // Do something which would produce some network traffic imp.Connect("mail.domain.com"); imp.Login("jdoe", "secret"); imp.Disconnect(); } }