Pkg.XST — 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:
Represents a message attachment (file, embedded message, etc.).
Represents a folder that may contain subfolders and messages.
XSTItem()Base class for items stored in Outlook PST/OST files (folders, messages, attachments).
Represents a mail message item.
Represents a PST/OST object.
- class XSTAttachment¶
Bases:
Pkg.XST.XSTItemRepresents 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
- 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.XSTItemRepresents a folder that may contain subfolders and messages.
Methods:
Returns the display name.
GetFolders(*[, wo])Retrieves the subfolders of this folder.
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
XSTFolderobjects.- 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
XSTMessageobjects.- Return type
List[XSTMessage]
See also
GetMessageCount().
- class XSTItem¶
Base class for items stored in Outlook PST/OST files (folders, messages, attachments).
Attributes:
Represents an attachment item.
Represents a folder item.
Represents a message item.
Methods:
Returns one of
FOLDER,MESSAGE, orATTACHMENT.
- ATTACHMENT¶
Represents an attachment item.
- FOLDER¶
Represents a folder item.
- GetItemType() → int¶
- Returns
Returns one of
FOLDER,MESSAGE, orATTACHMENT.- Return type
int
- MESSAGE¶
Represents a message item.
- class XSTMessage¶
Bases:
Pkg.XST.XSTItemRepresents 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).
Retrieves the received/delivered time as an ISO date/time string.
Returns the subject line.
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).
Returns
Trueif attachments exist; otherwise returnsFalse.
- 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
XSTAttachmentobjects.- 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()andGetReceivedTime().
- GetTo() → str¶
- Returns
Returns a comma-separated list of the primary recipients (To).
- Return type
str
- HasAttachments() → bool¶
- Returns
Returns
Trueif attachments exist; otherwise returnsFalse.- Return type
bool
See also
GetAttachments().
- class XSTObject¶
Bases:
Pro.Core.CFFObjectRepresents a PST/OST object.
Methods:
GetFolderTree(*[, wo])Builds and returns a object tree of the folder hierarchy.
Returns root
XSTFolderif available; otherwise returnsNone.
- 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
NTObjectTreerepresenting the folder structure.- Return type
See also
GetRootFolder().
- GetRootFolder() → Optional[Pkg.XST.XSTFolder]¶
- Returns
Returns root
XSTFolderif available; otherwise returnsNone.- Return type
Optional[XSTFolder]
See also
GetFolderTree().