aspNetIMAP

BodyStructure Class

An object that represents the BodyStructure data supplied by IMAP4.

For a list of all members of this type, see BodyStructure Members.

System.Object
BodyStructure

publicclassBodyStructure

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

The BodyStructure object is a class that describes the format of a mime message, on an IMAP server without actually having to download the entire message. The message is parsed on the server, and its hierarchy is sent back to the client. Because Mime messages are nested, a BodyStructure can also contain other BodyStructures. To find or inspect child BodyStructures, check out BodyStructure.Sections.

Although there are exceptions, each BodyStructure can be considered to map to a Mime message body part. For example, if a message contains a text/plain and a text/html part, there are actually three BodyStructures; the BodyStructure of the overall message, the BodyStructure of the text/plain part, and the BodyStructure of the text/html part.

Because the IMAP protocol is complicated, we found numerous parsing errors and exceptions when testing against various IMAP servers. Although we have tried to compensate for these problems, we are sure many more still exist. Because mail server companies focus on transporting mail, and not parsing it, we found their server side parsing implementations to be generally week. If you happen to find a bodystructure that does not "seem quite right", feel free to email us the IMAP log, for further inspection.

Example

          [CS]
IMAP4 imap = new IMAP4( "127.0.0.1" );
imap.Username = "dave@blah.com";
imap.Password = "test";
 
imap.Logger  = new IMAPLog( "c:\\imap.log" ); 
imap.Login();
 
MailFolder mf = imap.SelectInbox();
 
//grab the BodyStructure of the newest message
int count = mf.MessageCount;
 
BodyStructure bs = mf.FetchClient.BodyStructure( count );
 
BodyStructureAttachment[] attachments = bs.Attachments();
 
foreach(BodyStructureAttachment bsa in attachments )
{
    //write out the name and the id
    Console.WriteLine( "{0}:{1}", bsa.BodyStructureId, bsa.Name  );
}
 
Console.WriteLine( "Done" );
Console.ReadLine();
    
          [VB.NET]
Dim imap As New IMAP4("127.0.0.1")
imap.Username = "dave@blah.com"
imap.Password = "test"
 
imap.Logger = New IMAPLog("c:\imap.log")
imap.Login()
 
Dim mf As MailFolder = imap.SelectInbox()
 
'grab the BodyStructure of the newest message
Dim count As Integer = mf.MessageCount
 
Dim bs As BodyStructure = mf.FetchClient.BodyStructure(count)
 
Dim attachments As BodyStructureAttachment() = bs.Attachments()
 
Dim bsa As BodyStructureAttachment
For Each bsa In  attachments
   'write out the name and the id
   Console.WriteLine("{0}:{1}", bsa.BodyStructureId, bsa.Name)
Next bsa
 
Console.WriteLine("Done")
Console.ReadLine()
    

Requirements

Namespace: aspNetIMAP

Assembly: aspNetIMAP (in aspNetIMAP.dll)

See Also

BodyStructure Members | aspNetIMAP Namespace