def findShare(self, view, collection, repoId, peerId):

        account = self.findAccount(view, peerId)

        acl = collection.getACL('p2p', None)
        if acl is None or not acl.verify(account.user, Permissions.READ):
            raise AccessDeniedError

        for share in SharedItem(collection).shares:
            if isinstance(share, self.shareClass):
                if share.repoId is None:
                    if (share.ackPending and share.contents is collection
                            and share.conduit.account is account
                            and share.conduit.peerId == peerId):
                        share.repoId = repoId
                        return share
                elif share.repoId == repoId:
                    return share

        share = self.shareClass(itsView=view,
                                account=view[self.client.account],
                                repoId=repoId,
                                peerId=peerId)
        share.contents = collection
        if not has_stamp(collection, SharedItem):
            SharedItem(collection).add()
        share.localVersion = view.itsVersion + 1
        view.commit()

        return share
Example #2
0
def getPeers(mailStamp):
    peers = mailStamp.getRecipients()

    # First, make sure we don't have peers with duplicate email addresses
    peerAddresses = set()
    filteredPeers = list()

    for peer in peers:
        address = getattr(peer, 'emailAddress', '')

        if address and address not in peerAddresses:
            # Note: shouldn't we also filter out "me" addresses?  I guess it's
            # harmless not to since we ignore incoming EIMML messages that are
            # "from me".
            peerAddresses.add(address)
            filteredPeers.append(peer)

    peers = filteredPeers

    # Next, for each peer already associated with the item, if any of them have
    # email addresses which match the 'peers' list, there is a chance that the
    # new peer is actually an EmailAddress item with same address but different
    # name.  We want to swap that peer out for the one already associated with
    # the item.
    item = mailStamp.itsItem
    view = item.itsView

    if has_stamp(item, SharedItem):
        shared = SharedItem(item)
        updatedPeers = list()

        # Build a set of email addresses already associated with this item
        associatedAddresses = set()
        addressMapping = {}

        for state in getattr(shared, "peerStates", []):
            peerUUID = shared.peerStates.getAlias(state)
            peer = view.findUUID(peerUUID)

            if peer is not None and getattr(peer, 'emailAddress', ''):
                associatedAddresses.add(peer.emailAddress)
                addressMapping[peer.emailAddress] = peer

        # Look for matches between already associated and new:
        for peer in peers:
            if peer.emailAddress in associatedAddresses:
                if shared.getPeerState(peer, create=False) is not None:
                    # We have a perfect match
                    updatedPeers.append(peer)
                else:
                    # address matches, but wrong email address item; switch
                    # to the already associated one
                    updatedPeers.append(addressMapping[peer.emailAddress])
            else:
                # No matching address; it's a new peer
                updatedPeers.append(peer)

        peers = updatedPeers

    return peers
Example #3
0
def getPeers(mailStamp):
    peers = mailStamp.getRecipients()

    # First, make sure we don't have peers with duplicate email addresses
    peerAddresses = set()
    filteredPeers = list()

    for peer in peers:
        address = getattr(peer, 'emailAddress', '')

        if address and address not in peerAddresses:
            # Note: shouldn't we also filter out "me" addresses?  I guess it's
            # harmless not to since we ignore incoming EIMML messages that are
            # "from me".
            peerAddresses.add(address)
            filteredPeers.append(peer)

    peers = filteredPeers

    # Next, for each peer already associated with the item, if any of them have
    # email addresses which match the 'peers' list, there is a chance that the
    # new peer is actually an EmailAddress item with same address but different
    # name.  We want to swap that peer out for the one already associated with
    # the item.
    item = mailStamp.itsItem
    view = item.itsView

    if has_stamp(item, SharedItem):
        shared = SharedItem(item)
        updatedPeers = list()

        # Build a set of email addresses already associated with this item
        associatedAddresses = set()
        addressMapping = {}

        for state in getattr(shared, "peerStates", []):
            peerUUID = shared.peerStates.getAlias(state)
            peer = view.findUUID(peerUUID)

            if peer is not None and getattr(peer, 'emailAddress', ''):
                associatedAddresses.add(peer.emailAddress)
                addressMapping[peer.emailAddress] = peer

        # Look for matches between already associated and new:
        for peer in peers:
            if peer.emailAddress in associatedAddresses:
                if shared.getPeerState(peer, create=False) is not None:
                    # We have a perfect match
                    updatedPeers.append(peer)
                else:
                    # address matches, but wrong email address item; switch
                    # to the already associated one
                    updatedPeers.append(addressMapping[peer.emailAddress])
            else:
                # No matching address; it's a new peer
                updatedPeers.append(peer)

        peers = updatedPeers

    return peers
Example #4
0
    def send(self, peerId, name):

        if not self.isLoggedIn():
            raise ValueError, "no mail client"

        view = self.itsView
        sidebar = schema.ns('osaf.app', view).sidebarCollection

        for collection in sidebar:
            if collection.displayName == name:
                for share in SharedItem(collection).shares:
                    conduit = share.conduit
                    if isinstance(conduit, MailConduit):
                        if conduit.peerId == peerId:
                            return self.client.send(share, None, None, 'sync')

        return self.client.send(None, peerId, name, 'send')
Example #5
0
 def testNote(self):
     self.checkStatus(0)
     self.note.changeEditState(Modification.edited)
     self.checkStatus(0) # edited has no effect till created
     self.note.changeEditState(Modification.created)
     self.checkStatus(0)
     self.note.changeEditState(Modification.edited)
     self.checkStatus(0, 'EDITED')
     
     si = SharedItem(self.note)
     si.add()
     si.generateConflicts()
     self.checkStatus(0, 'EDITED', 'ERROR')
    def subscribe(self, peerId, name):

        if not self.isLoggedIn():
            raise ValueError, "no connection"

        if '/' not in peerId:
            peerId += "/chandler"

        view = self.itsView
        sidebar = schema.ns('osaf.app', view).sidebarCollection
        share = None

        for collection in sidebar:
            if collection.displayName == name:
                for share in SharedItem(collection).shares:
                    conduit = share.conduit
                    if isinstance(conduit, JabberConduit):
                        if conduit.peerId == peerId:
                            return self.client.sync(share, None, None)

        return self.client.sync(None, peerId, name)