def test_success_conversion(store, icaltomapi, message): ical = open(os.path.join(dir_path, 'ics/success.ics'), 'rb').read() # As defined in namedprops.h DISPID_APPT_TS_REF = 0x25 NAMED_PROP_UID = MAPINAMEID(PSETID_Kopano_CalDav, MNID_ID, DISPID_APPT_TS_REF) NAMED_PROP_CATEGORY = MAPINAMEID(PS_PUBLIC_STRINGS, MNID_STRING, 'Keywords') properties = store.GetIDsFromNames([NAMED_PROP_UID, NAMED_PROP_CATEGORY], MAPI_CREATE) EXPECTED_MESSAGES = 1 UID = CHANGE_PROP_TYPE(properties[0], PT_BINARY) #0x85100102 CATEGORY = CHANGE_PROP_TYPE(properties[1], PT_MV_UNICODE) #0x850B101E START_DATE_PT_SYSTIME = 135547524000000000 END_DATE_PT_SYSTIME = 135547920000000000 prop_dic = { UID: [b'*****@*****.**'], PR_SUBJECT: [b'A dream holiday in the mountains'], CATEGORY: [['Holidays']], PR_SENDER_NAME_W: ['John Holidays'], PR_SENDER_EMAIL_ADDRESS_W: ['*****@*****.**'], PR_START_DATE: [FileTime(START_DATE_PT_SYSTIME)], PR_END_DATE: [FileTime(END_DATE_PT_SYSTIME)], } assert_item_count_from_ical(icaltomapi, ical, EXPECTED_MESSAGES) assert_properties_from_ical(icaltomapi, message, prop_dic)
def blocks(self, start=None, end=None): """ Freebusy blocks :param start: start of period :param end: end of period """ eid = _bdec(self.store.user.userid) if start: ftstart = datetime_to_filetime(start) else: ftstart = FileTime(0) if end: ftend = datetime_to_filetime(end) else: ftend = FileTime(0xFFFFFFFFFFFFFFFF) fb = libfreebusy.IFreeBusySupport() fb.Open(self.store.server.mapisession, self.store.mapiobj, False) fbdata = fb.LoadFreeBusyData([eid], None) if fbdata in (0, 1): # XXX what? return data, status = fbdata fb.Close() enum = data.EnumBlocks(ftstart, ftend) while True: blocks = enum.Next(100) if blocks: for block in blocks: yield FreeBusyBlock(block) else: break
def test_round_trip_all_day_dstart_dend_style_not_date_incorrect(store, icaltomapi, mapitoical, message): ical = open(os.path.join(dir_path, 'ics/allday_dstart_dend_style_incorrect.ics'), 'rb').read() # As defined in namedprops.h DISPID_ALL_DAY_EVENT = 0x8215 EXPECTED_MESSAGES = 1 START_DATE_PT_SYSTIME = 132587712000000000 END_DATE_PT_SYSTIME = 132588576000000000 ALL_DAY_NAMEID = MAPINAMEID(PSETID_Appointment, MNID_ID, DISPID_ALL_DAY_EVENT) ALL_DAY_PROP = CHANGE_PROP_TYPE( store.GetIDsFromNames([ALL_DAY_NAMEID], MAPI_CREATE)[0], PT_BOOLEAN ) prop_dic = { PR_START_DATE: [FileTime(START_DATE_PT_SYSTIME)], PR_END_DATE: [FileTime(END_DATE_PT_SYSTIME)], ALL_DAY_PROP: [False] } assert_item_count_from_ical(icaltomapi, ical, EXPECTED_MESSAGES) assert_properties_from_ical(icaltomapi, message, prop_dic) # Reverting back to ical. mapitoical.AddMessage(message, '', 0) method, converted_ical = mapitoical.Finalize(icalmapi.M2IC_NO_VTIMEZONE) split_ical = converted_ical.split(b'\r\n') assert b'PUBLISH' == method assert b'DTSTART:20210226T000000Z' in split_ical assert b'DTEND:20210227T000000Z' in split_ical
def test_publish_fb(store, freebusy_user): eid = store.GetProps([PR_MAILBOX_OWNER_ENTRYID], 0)[0].Value update, status = freebusy_user.LoadFreeBusyUpdate([eid], None) assert status == 1 assert update timestamp = int(time.time()) update.PublishFreeBusy([FreeBusyBlock(0, timestamp, 1)]) update.SaveChanges(unixtime(0), unixtime(timestamp)) data, status = freebusy_user.LoadFreeBusyData([eid], None) start, end = data.GetFBPublishRange() assert start assert end enum = data.EnumBlocks(FileTime(0), FileTime(0xFFFFFFFFFFFFFFFF)) blocks = enum.Next(100) assert blocks assert blocks[0].status == 1 # Reset freebusy update.ResetPublishedFreeBusy() update.SaveChanges(unixtime(0), unixtime(timestamp)) data, status = freebusy_user.LoadFreeBusyData([eid], None) enum = data.EnumBlocks(FileTime(0), FileTime(0xFFFFFFFFFFFFFFFF)) blocks = enum.Next(100) assert not blocks
def blocks(self, start=None, end=None): """Return all :class:`freebusy blocks <FreeBusyBlock>` for the given period. :param start: start of period (must be localtime (naive) or non-naive datetime instance) :param end: end of period (must be localtime (naive) or non-naive datetime instance) """ eid = _bdec(self.store.user.userid) if start: ftstart = _utils.datetime_to_filetime(start) else: ftstart = FileTime(0) if end: ftend = _utils.datetime_to_filetime(end) else: ftend = FileTime(0xFFFFFFFFFFFFFFFF) fb = libfreebusy.IFreeBusySupport() try: fb.Open(self.store.server.mapisession, self.store.mapiobj, False) except MAPI.Struct.MAPIErrorNotFound: raise NotFoundError("public store not found") fbdata = fb.LoadFreeBusyData([eid], None) if fbdata in (0, 1): # TODO what? return data, status = fbdata fb.Close() enum = data.EnumBlocks(ftstart, ftend) while True: blocks = enum.Next(100) if blocks: for block in blocks: yield FreeBusyBlock(block) else: break
def test_copyprops(root, message): tags = [ PROP_TAG(PT_SHORT, 0x6602), PROP_TAG(PT_LONG, 0x6603), PROP_TAG(PT_FLOAT, 0x6604), PROP_TAG(PT_DOUBLE, 0x6605), PROP_TAG(PT_CURRENCY, 0x6606), PROP_TAG(PT_APPTIME, 0x6607), PROP_TAG(PT_BOOLEAN, 0x6608), PROP_TAG(PT_LONGLONG, 0x6609), PROP_TAG(PT_STRING8, 0x6610), PROP_TAG(PT_UNICODE, 0x6611), PROP_TAG(PT_SYSTIME, 0x6612), PROP_TAG(PT_CLSID, 0x6613), PROP_TAG(PT_BINARY, 0x6614)] props = [ SPropValue(PROP_TAG(PT_SHORT, 0x6602), 1), SPropValue(PROP_TAG(PT_LONG, 0x6603), 2), SPropValue(PROP_TAG(PT_FLOAT, 0x6604), 3), SPropValue(PROP_TAG(PT_DOUBLE, 0x6605), 4), SPropValue(PROP_TAG(PT_CURRENCY, 0x6606), 5), SPropValue(PROP_TAG(PT_APPTIME, 0x6607), 6), SPropValue(PROP_TAG(PT_BOOLEAN, 0x6608), True), SPropValue(PROP_TAG(PT_LONGLONG, 0x6609), 7), SPropValue(PROP_TAG(PT_STRING8, 0x6610), b'string8'), SPropValue(PROP_TAG(PT_UNICODE, 0x6611), u'こんにちは'), SPropValue(PROP_TAG(PT_SYSTIME, 0x6612), FileTime(120000000000000000)), SPropValue(PROP_TAG(PT_CLSID, 0x6613), b'1234567890123456'), SPropValue(PROP_TAG(PT_BINARY, 0x6614), b'binary')] message.SetProps(props) msgnew = root.CreateMessage(None, 0) message.CopyProps(tags, 0, None, IID_IMessage, msgnew, 0) results = msgnew.GetProps(tags, 0) assert results == props # move the props msgnew = root.CreateMessage(None, 0) message.CopyProps(tags, 0, None, IID_IMessage, msgnew, MAPI_MOVE) results = msgnew.GetProps(tags, 0) assert results == props results = message.GetProps(tags, 0) for i in results: assert PROP_TYPE(i.ulPropTag) == PT_ERROR
def test_types(store, message): props = [ SPropValue(PROP_TAG(PT_NULL, 0x6601), 0), SPropValue(PROP_TAG(PT_SHORT, 0x6602), 1), SPropValue(PROP_TAG(PT_LONG, 0x6603), 2), SPropValue(PROP_TAG(PT_FLOAT, 0x6604), 3), SPropValue(PROP_TAG(PT_DOUBLE, 0x6605), 4), SPropValue(PROP_TAG(PT_CURRENCY, 0x6606), 5), SPropValue(PROP_TAG(PT_APPTIME, 0x6607), 6), SPropValue(PROP_TAG(PT_BOOLEAN, 0x6608), True), SPropValue(PROP_TAG(PT_LONGLONG, 0x6609), 7), SPropValue(PROP_TAG(PT_STRING8, 0x6610), b'string8'), SPropValue(PROP_TAG(PT_UNICODE, 0x6611), u'こんにちは'), SPropValue(PROP_TAG(PT_SYSTIME, 0x6612), FileTime(120000000000000000)), SPropValue(PROP_TAG(PT_CLSID, 0x6613), b'1234567890123456'), SPropValue(PROP_TAG(PT_BINARY, 0x6614), b'binary')] message.SetProps(props) message.SaveChanges(0) entryidprops = message.GetProps([PR_ENTRYID], 0) entryid = entryidprops[0].Value message = store.OpenEntry(entryid, None, 0) results = message.GetProps([ PROP_TAG(PT_NULL, 0x6601), PROP_TAG(PT_SHORT, 0x6602), PROP_TAG(PT_LONG, 0x6603), PROP_TAG(PT_FLOAT, 0x6604), PROP_TAG(PT_DOUBLE, 0x6605), PROP_TAG(PT_CURRENCY, 0x6606), PROP_TAG(PT_APPTIME, 0x6607), PROP_TAG(PT_BOOLEAN, 0x6608), PROP_TAG(PT_LONGLONG, 0x6609), PROP_TAG(PT_STRING8, 0x6610), PROP_TAG(PT_UNICODE, 0x6611), PROP_TAG(PT_SYSTIME, 0x6612), PROP_TAG(PT_CLSID, 0x6613), PROP_TAG(PT_BINARY, 0x6614)], 0) props.remove(SPropValue(PROP_TAG(PT_NULL, 0x6601), 0)) props.insert(0, SPropValue(PROP_TAG(PT_ERROR, 0x6601), MAPI_E_NOT_FOUND)) assert results == props
def datetime_to_filetime(d): return FileTime(int(time.mktime(d.timetuple())) * 10000000 + NANOSECS_BETWEEN_EPOCH)
def rtime_to_datetime(r): return datetime.datetime.fromtimestamp(FileTime(r * 600000000).unixtime)
def datetime_to_filetime(d): return FileTime( int(datetime.datetime.timestamp(d)) * 10000000 + NANOSECS_BETWEEN_EPOCH)
def rtime_to_datetime(r): return datetime.datetime.fromtimestamp( FileTime(r * UnitsPerMinute).unixtime)