Product SiteDocumentation Site

3.2. Modules

The default MAPI package imports the c+\+ bindings, functions and methods. However, there are also some other modules that make life easier for the Python MAPI programmer:

3.2.1. MAPI.Struct

Python representations of MAPI structs. These contain data that cannot be described as a simple int or string. Naming of classes in this module mirrors the MAPI Struct as in c+\+ and provides convenient constructors to create data structures from Python
import MAPI.Struct
import MAPI.Tags

prop = SPropValue(MAPI.Tags.PR_SUBJECT, 'hello, world!')

3.2.2. MAPI.Time

Since MAPI uses a timestamp format that is not very common in the Python world called FILETIME (100-ns periods since 1 jan 1601), MAPI.Time offers an easy way to convert to and from the standard epoch-based timestamps normally used in Unix:
import MAPI.Time

t = FileTime(10000000000000)
print t.unixtime

t = unixtime(1234567890)
print t.filetime
All PT_SYSTIME values in MAPI will be converted to/from this format.

Note

FILETIME has a much wider time frame and greater precision than unix timestamps. Allthough in practice a precision of 1 second is usually fine, it may cause subtle problems if you are assuming the full FILETIME precision.

3.2.3. MAPI.Tags

The MAPI.Tags module contains constants for all well-known MAPI property tags:
import MAPI.Tags

print MAPI.Tags.PR_SUBJECT
print MAPI.Tags.PR_SUBJECT_A
print MAPI.Tags.PR_SUBJECT_W
The constants are identical to those used in c+\+ MAPI. By default, string tags use the PT_STRING8 (terminal charset) type. If you wish to use the PT_UNICODE variant, either use the _W type (eg PR_SUBJECT_W) or use the following construct:
import MAPI
MAPI.unicode = True
import MAPI.Tags

print PROP_TYPE(MAPI.Tags.PR_SUBJECT)
# outputs 31 (PT_UNICODE)
This will cause all properties to default to the PT_UNICODE property type.

3.2.4. MAPI.Defs

Provides convenience functions (also identical to their c+\+ counterparts) to create, test and modify property tags, and other utility functions:
import MAPI.Defs

PR_SUBJECT = MAPI.Defs.PROP_TAG(PT_STRING8, 0x0037)
type = MAPI.Defs.PROP_TYPE(PR_SUBJECT)
id = MAPI.Defs.PROP_ID(PR_SUBJECT)

3.2.5. MAPI.Util

MAPI.Util contains some useful functions for profile creation.

3.2.5.1. OpenECSession()

Opens a session for the given user/password pair on the specified path for a Zarafa server.
import MAPI
from MAPI.Util import *

session = OpenECSession('joe','password','file:///var/run/zarafa')

3.2.5.2. GetDefaultStore()

Opens the default store in a session.
import MAPI
from MAPI.Util import *

session = OpenECSession('joe','password','file:///var/run/zarafa')
store = GetDefaultStore(session)