def item(self, entryid=None, guid=None): """Return :class:`Item` with given entryid.""" item = _item.Item() # XXX copy-pasting.. item.store = self item.server = self.server if guid is not None: # 01 -> entryid format version, 05 -> object type (message) entryid = '00000000' + self.guid + '0100000005000000' + guid + '00000000' if entryid is not None: eid = _utils._bdec_eid(entryid) else: raise ArgumentError("no guid or entryid specified") try: item.mapiobj = _utils.openentry_raw(self.mapiobj, eid, 0) # XXX soft-deleted item? except MAPIErrorNotFound: raise NotFoundError("no item with entryid '%s'" % entryid) except MAPIErrorInvalidEntryid: raise ArgumentError("invalid entryid: %r" % entryid) return item
def item(self, entryid=None, sourcekey=None): """ Return :class:`Item` with given entryid or sourcekey :param entryid: item entryid :param sourcekey: item sourcekey """ if entryid is not None: eid = _utils._bdec_eid(entryid) elif sourcekey is not None: # TODO this is horribly slow with nothing cached.. 1 SQL per row!? try: restriction = SPropertyRestriction( RELOP_EQ, PR_SOURCE_KEY, SPropValue(PR_SOURCE_KEY, _bdec(sourcekey))) except: raise ArgumentError("invalid sourcekey: %r" % sourcekey) table = self.mapiobj.GetContentsTable(MAPI_DEFERRED_ERRORS) table.SetColumns([PR_ENTRYID, PR_SOURCE_KEY], 0) table.Restrict(restriction, 0) rows = list(table.QueryRows(-1, 0)) if not rows: raise NotFoundError("no item with sourcekey '%s'" % sourcekey) eid = rows[0][0].Value # open message with entryid try: mapiobj = _utils.openentry_raw(self.store.mapiobj, eid, self.content_flag) except MAPIErrorNotFound: if sourcekey is not None: raise NotFoundError("no item with sourcekey '%s'" % sourcekey) else: raise NotFoundError("no item with entryid '%s'" % entryid) except MAPIErrorInvalidEntryid: raise ArgumentError("invalid entryid: %r" % entryid) item = _item.Item(self, mapiobj=mapiobj) return item