Pkg.XST — API for parsing Microsoft Outlook PST/OST files

Overview

The Pkg.XST module contains the API for parsing Microsoft Outlook PST/OST files.

Parsing a PST file

The following code example demonstrates how to parse a PST file:

from Pro.Core import *
from Pkg.XST import *

def enumerateContents(folder, depth, max_depth):
    if not folder or depth >= max_depth:
        return
    print((depth * "  ") + "Folder:", str(folder))
    depth += 1
    if folder.GetMessageCount() > 0:
        for message in folder.GetMessages():
            print((depth * "  ") + "Message:", str(message))
            if message.HasAttachments():
                for attachment in message.GetAttachments():
                    print(((depth+1) * "  ") + "Attachment:", str(attachment))
    folders = folder.GetFolders()
    for child in folders:
        enumerateContents(child, depth, max_depth)

def parseXST(fname):
    c = createContainerFromFile(fname)
    if c.isNull():
        return
    obj = XSTObject()
    if not obj.Load(c) or not obj.Initialize():
        return
    enumerateContents(obj.GetRootFolder(), 0, 10)

Module API

Pkg.XST module API.

Classes:

XSTAttachment()

Represents a message attachment (file, embedded message, etc.).

XSTFolder()

Represents a folder that may contain subfolders and messages.

XSTItem()

Base class for items stored in Outlook PST/OST files (folders, messages, attachments).

XSTMessage()

Represents a mail message item.

XSTObject()

Represents a PST/OST object.

class XSTAttachment

Bases: Pkg.XST.XSTItem

Represents a message attachment (file, embedded message, etc.).

Methods:

GetData(*[, wo, c])

Retrieves the binary data stream of the attachment.

GetName()

Returns the attachment name.

GetSize()

Returns the size of the attachment payload in bytes.

GetData(*, wo: Optional[Pro.Core.NTIWait] = None, c: Optional[Pro.Core.NTContainer] = None)Pro.Core.NTContainer

Retrieves the binary data stream of the attachment.

Parameters
  • wo (Optional[NTIWait]) – Optional wait object for long-running extraction.

  • c (Optional[NTContainer]) – Optional container hint/target. If provided, the data is written to this container.

Returns

Returns the attachment data.

Return type

NTContainer

GetName()str
Returns

Returns the attachment name.

Return type

str

GetSize()int
Returns

Returns the size of the attachment payload in bytes.

Return type

int

class XSTFolder

Bases: Pkg.XST.XSTItem

Represents a folder that may contain subfolders and messages.

Methods:

GetDisplayName()

Returns the display name.

GetFolders(*[, wo])

Retrieves the subfolders of this folder.

GetMessageCount()

Returns the number of messages contained in this folder.

GetMessages(*[, wo])

Retrieves the messages contained in this folder.

GetDisplayName()str
Returns

Returns the display name.

Return type

str

GetFolders(*, wo: Optional[Pro.Core.NTIWait] = None)List[Pkg.XST.XSTFolder]

Retrieves the subfolders of this folder.

Parameters

wo (Optional[NTIWait]) – Optional wait object for long-running enumeration.

Returns

A list of XSTFolder objects.

Return type

List[XSTFolder]

See also GetMessages().

GetMessageCount()int
Returns

Returns the number of messages contained in this folder.

Return type

int

GetMessages(*, wo: Optional[Pro.Core.NTIWait] = None)List[Pkg.XST.XSTMessage]

Retrieves the messages contained in this folder.

Parameters

wo (Optional[NTIWait]) – Optional wait object for long-running enumeration.

Returns

Returns a list of XSTMessage objects.

Return type

List[XSTMessage]

See also GetMessageCount().

class XSTItem

Base class for items stored in Outlook PST/OST files (folders, messages, attachments).

Attributes:

ATTACHMENT

Represents an attachment item.

FOLDER

Represents a folder item.

MESSAGE

Represents a message item.

Methods:

GetItemType()

Returns one of FOLDER, MESSAGE, or ATTACHMENT.

ATTACHMENT

Represents an attachment item.

FOLDER

Represents a folder item.

GetItemType()int
Returns

Returns one of FOLDER, MESSAGE, or ATTACHMENT.

Return type

int

MESSAGE

Represents a message item.

class XSTMessage

Bases: Pkg.XST.XSTItem

Represents a mail message item.

Methods:

Dump(out)

Writes a textual representation of the message to a text stream.

GetAttachments(*[, wo])

Retrieves the list of attachments associated with this message.

GetBcc()

Returns a comma-separated list of the blind carbon copy recipients (Bcc).

GetBody()

Returns the message body as text.

GetCc()

Returns a comma-separated list of the carbon copy recipients (Cc).

GetFrom()

Returns the sender (display name and/or address).

GetReceivedTime()

Retrieves the received/delivered time as an ISO date/time string.

GetSubject()

Returns the subject line.

GetSubmittedTime()

Returns the submitted/sent time as an ISO date/time string.

GetTime()

Returns ISO date/time string.

GetTo()

Returns a comma-separated list of the primary recipients (To).

HasAttachments()

Returns True if attachments exist; otherwise returns False.

Dump(out: Pro.Core.NTTextStream)

Writes a textual representation of the message to a text stream.

Parameters

out (NTTextStream) – The output text stream.

GetAttachments(*, wo: Optional[Pro.Core.NTIWait] = None)List[Pkg.XST.XSTAttachment]

Retrieves the list of attachments associated with this message.

Parameters

wo (Optional[NTIWait]) – Optional wait object for long-running enumeration.

Returns

Returns a list of XSTAttachment objects.

Return type

List[XSTAttachment]

See also HasAttachments().

GetBcc()str
Returns

Returns a comma-separated list of the blind carbon copy recipients (Bcc).

Return type

str

GetBody()str
Returns

Returns the message body as text.

Return type

str

GetCc()str
Returns

Returns a comma-separated list of the carbon copy recipients (Cc).

Return type

str

GetFrom()str
Returns

Returns the sender (display name and/or address).

Return type

str

GetReceivedTime()str

Retrieves the received/delivered time as an ISO date/time string.

Returns

Returns the received/delivered time as an ISO date/time string.

Return type

str

See also GetSubmittedTime().

GetSubject()str
Returns

Returns the subject line.

Return type

str

GetSubmittedTime()str
Returns

Returns the submitted/sent time as an ISO date/time string.

Return type

str

See also GetReceivedTime().

GetTime()str
Returns

Returns ISO date/time string.

Return type

str

See also GetSubmittedTime() and GetReceivedTime().

GetTo()str
Returns

Returns a comma-separated list of the primary recipients (To).

Return type

str

HasAttachments()bool
Returns

Returns True if attachments exist; otherwise returns False.

Return type

bool

See also GetAttachments().

class XSTObject

Bases: Pro.Core.CFFObject

Represents a PST/OST object.

Methods:

GetFolderTree(*[, wo])

Builds and returns a object tree of the folder hierarchy.

GetRootFolder()

Returns root XSTFolder if available; otherwise returns None.

GetFolderTree(*, wo: Optional[Pro.Core.NTIWait] = None)Pro.Core.NTObjectTree

Builds and returns a object tree of the folder hierarchy.

Hint

This method is useful to show the folder structure in a tree control.

Parameters

wo (Optional[NTIWait]) – Optional wait object for long-running traversal.

Returns

Returns an NTObjectTree representing the folder structure.

Return type

NTObjectTree

See also GetRootFolder().

GetRootFolder()Optional[Pkg.XST.XSTFolder]
Returns

Returns root XSTFolder if available; otherwise returns None.

Return type

Optional[XSTFolder]

See also GetFolderTree().