The purpose is to gain access to the message information in code by extracting it from a
raw email message. For this we will parse the content of the email using the IMessage interface.
We assume we have a string containing a MIME encoded email, which we will send as input parameter to the constructor of our parsing class. Using an ADODB object, will write the string directly into a stream and then flush it in order to access the message.
public class EmailParser { private Message _msg = null; public EmailParser(string sContent) { ADODB.StreamClass strc = new ADODB.StreamClass(); strc.Open(Missing.Value, ADODB.ConnectModeEnum.adModeUnknown, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, "", ""); strc.Type = ADODB.StreamTypeEnum.adTypeText; strc.Charset = "UTF-8"; strc.WriteText(sContent, ADODB.StreamWriteEnum.adWriteChar); strc.Position = 0; strc.Type = StreamTypeEnum.adTypeBinary; strc.Flush(); _msg = new CDO.MessageClass(); _msg.DataSource.OpenObject(strc, "_Stream"); } } |
The CDO Message object provides access to the email header information, bodyparts and attachments. We can then simply expose the needed properties:
public string Subject { get { return _msg.Subject; } } public string From { get { return _msg.From; } } public string To { get { return _msg.To } } public string ReplyTo { get { return _msg.ReplyTo; } } public string CC { get { return _msg.CC; } } public DateTime SentOn { get { return _msg.SentOn; } } public DateTime ReceivedTime { get { return _msg.ReceivedTime; } } |
Excepting messages with a single text body part, in which case the IMessage.Fields collection can be used directly, to proper retrieve the body message, one should iterate through the BodyPart objects that make up the hierarchy of content and structural units of a message.
Another particularity are the message attachments. A simple way to retrieve them is the following:
foreach (CDO.IBodyPart bp in _msg.Attachments) { ADODB.Stream stm = bp.GetDecodedContentStream(); byte[] bf = (byte[])stm.Read(stm.Size); string sFileName = bp.FileName; if (bp.FileName == "") { switch (bp.ContentMediaType.Trim().ToLower()) { case "image/jpeg": sFileName = "unknown" + nEmbeddedUnknownCounter + ".jpg"; break; case "image/gif": sFileName = "unknown" + nEmbeddedUnknownCounter + ".gif"; break; default: sFileName = "unknown" + nEmbeddedUnknownCounter; break; } } } |
Finally, there’s another very important peculiarity of what does Cialis that brings it so high above its alternatives. It is the only med that is available in two versions – one intended for use on as-needed basis and one intended for daily use. As you might know, Viagra and Levitra only come in the latter of these two forms and should be consumed shortly before expected sexual activity to ensure best effect. Daily Cialis, in its turn, contains low doses of Tadalafil, which allows to build its concentration up in your system gradually over time and maintain it on acceptable levels, which, consequently, makes it possible for you to enjoy sex at any moment without having to time it.
Thanx for this interesting post. But I had difficult time navigating around your website because I kept getting 502 bad gateway error. Just thought to let you know.
November 15, 2009 at 10:42 pm