def SetProperties( msg, propDict):
""" Given a Python dictionary, set the objects properties.
If the dictionary key is a string, then a property ID is queried
otherwise the ID is assumed native.
Coded for maximum efficiency wrt server calls - ie, maximum of
2 calls made to the object, regardless of the dictionary contents
(only 1 if dictionary full of int keys)
"""
newProps = []
# First pass over the properties we should get IDs for.
for key, val in propDict.iteritems():
if type(key) in [str, unicode]:
newProps.append((mapi.PS_PUBLIC_STRINGS, key))
# Query for the new IDs
if newProps: newIds = msg.GetIDsFromNames(newProps, mapi.MAPI_CREATE)
newIdNo = 0
newProps = []
for key, val in propDict.iteritems():
if type(key) in [str, unicode]:
type_val=type(val)
if type_val in [str, unicode]:
tagType = mapitags.PT_UNICODE
elif type_val==IntType:
tagType = mapitags.PT_I4
elif type_val==TimeType:
tagType = mapitags.PT_SYSTIME
else:
raise ValueError("The type of object %s(%s) can not be written" % (repr(val),type_val))
key = mapitags.PROP_TAG(tagType, mapitags.PROP_ID(newIds[newIdNo]))
newIdNo = newIdNo + 1
newProps.append( (key, val) )
msg.SetProps(newProps)
评论列表
文章目录