BodyPartStructure Object

The BodyPartStructure object provides access to properties of the structure of a MIME part of a message, including the structure of all MIME parts nested in the given part.

A reference to the BodyPartStructure object is returned by BodyStructure property of the Envelope object when the envelopes were retrieved using IMAP4.RetrieveEnvelopesEx method, with AlsoGetBodyStructure parameter set to True.

Syntax

BodyPartStructure.property

 

Collections
SubParts Contains structures for all of the MIME parts nested in the given part.
Properties
ContentCommonType The general content type of the MIME part.
ContentID Content-ID of the MIME part
ContentSubType The content sub type of the MIME part.
Description A textual description of the MIME part.
Disposition The content disposition of the MIME part.
Filename The filename of the MIME part.
IsMultipart Denotes whether the MIME part does contain nested parts.
LineCount The number of text lines in the MIME part.
Size The size of the MIME part in its original (undecoded) state.

 

Remarks

With MailBee, the entire structure of the MIME parts of a message is a tree of BodyPartStructure objects. The root BodyPartStructure object provides access to the smaller parts; each of these parts provides access to its own sub parts, and so on.

The total number of BodyPartStructure objects within the tree depends on the message complexity. In the simplest case (a message without any attachments and alternative text bodies), the whole tree contains only one BodyPartStructure object.

A MIME part which contains any sub parts is called multipart. For such a part, IsMultipart property returns True and SubParts property returns a reference to the collection of BodyPartStructure objects where each BodyPartStructure object describes structure of one of the sub parts.

If IsMultipart is False, the MIME part is singlepart and the SubParts collection is not available.

Note: Multipart MIME parts perform only grouping function: they group smaller MIME parts into larger parts. In other words, multipart MIME part cannot have its own content (such as text body or attachment data) besides nested sub parts.

 

Example

The following example retrieves a message from the server, and iterates through all of the MIME parts of the message, building the MIME parts tree. For each branch of the tree, the content type of the respective MIME part is used. Finally, the tree is displayed. GetTree function is a key part of the example.

Final output greatly depends on the particular message structure, but for the complex message it may look like this:

multipart/mixed
--multipart/related
----multipart/alternative
-------text/plain
-------text/html
----image/gif
----image/gif
----image/jpeg
--application/octet-stream
' Returns a string which contains content types
' of the given part and all its sub parts
Function GetTree(objBodyPart, nOffset)
  Dim objSubPart

  ' Content type of the part
  GetTree = _
    String(nOffset * 2, "-") & _
    objBodyPart.ContentCommonType & "/" & _
    objBodyPart.ContentSubType

  ' If the part is multipart, add content types of
  ' the sub parts to the string
  If objBodyPart.IsMultipart Then
    For Each objSubPart In objBodyPart.SubParts
      GetTree = GetTree & vbCrLf & GetTree(objSubPart, nOffset + 1)
      ' In ASP, use "<br>" instead of vbCrLf
    Next
  End If
End Function

Dim objIMAP4, objEnvelopes

' Using Visual Basic to create object
Set objIMAP4 = CreateObject("MailBee.IMAP4")

' Using ASP to create object
' Set objIMAP4 = Server.CreateObject("MailBee.IMAP4")

' Unlock IMAP4 object
objIMAP4.LicenseKey = "put your license key here"

' Set IMAP4 server name
objIMAP4.ServerName = "mail.server.com"

' Set user credentials
objIMAP4.UserName = "jdoe"
objIMAP4.Password = "secret"

' Connect to the server and
' log in email account
If objIMAP4.Connect Then

  ' Select Inbox folder
  If objIMAP4.SelectMailbox("Inbox") Then

    ' Get envelope and body structure for
    ' the first message in the inbox
    Set objEnvelopes = _
      objIMAP4.RetrieveEnvelopesEx(1, 1, False, True)

    ' Check for errors
    If Not objIMAP4.IsError Then
      If objEnvelopes.Count > 0 Then
        ' The message is ok,
        ' display its body structure
        MsgBox GetTree(objEnvelopes(1).BodyStructure, 0)
        ' In ASP, use Response.Write instead of MsgBox
      End If
    End If
  End If

  ' Close the connection
  objIMAP4.Disconnect
End If

 

See Also

BodyPartStructures Collection, Envelope Object

 


Send feedback to AfterLogic
Copyright © 2002-2024, AfterLogic Corporation. All rights reserved.