Ejemplo n.º 1
0
def sendmail(collection):

    view = collection.itsView
    name = collection.displayName
    dialog = SendMailDialog(name, view)
    dialog.CenterOnScreen()

    if dialog.ShowModal() == wx.ID_OK:
        params = dialog.getParameters(view)
    else:
        params = None

    dialog.Destroy()

    if params is not None:
        account = params['account']
        commit = False
        if account is None:
            userid, server = params['to'].rsplit('@', 1)
            account = MailAccount(itsView=view, userid=userid, server=server,
                                  smtp=params['smtp'], imap=params['imap'])
            commit = True

        if collection.getACL('p2p', None) is None:
            acl = ACL()
            acl.append(ACE(schema.ns('p2p', view).all.itsUUID,
                           Permissions.READ))
            collection.setACL(acl, 'p2p')
            commit = True

        if commit:
            view.commit()
        account.login(setStatusMessage)
        account.send(params['to'], name)
Ejemplo n.º 2
0
    def on_p2p_AccessEvent(self, event):

        sidebar = Block.findBlockByName("Sidebar")
        collection = sidebar.contents.getFirstSelectedItem()
        view = self.itsView

        acl = collection.getACL('p2p', None)
        if acl is None:
            # for now, grant READ to everyone
            acl = ACL()
            acl.append(
                ACE(schema.ns('p2p', view).all.itsUUID, Permissions.READ))
            collection.setACL(acl, 'p2p')
        else:
            collection.removeACL('p2p')

        view.commit()
Ejemplo n.º 3
0
    def on_p2p_AccessEvent(self, event):

        sidebar = Block.findBlockByName("Sidebar")
        collection = sidebar.contents.getFirstSelectedItem()
        view = self.itsView

        acl = collection.getACL('p2p', None)
        if acl is None:
            # for now, grant READ to everyone
            acl = ACL()
            acl.append(ACE(schema.ns('p2p', view).all.itsUUID,
                           Permissions.READ))
            collection.setACL(acl, 'p2p')
        else:
            collection.removeACL('p2p')

        view.commit()
Ejemplo n.º 4
0
def sendmail(collection):

    view = collection.itsView
    name = collection.displayName
    dialog = SendMailDialog(name, view)
    dialog.CenterOnScreen()

    if dialog.ShowModal() == wx.ID_OK:
        params = dialog.getParameters(view)
    else:
        params = None

    dialog.Destroy()

    if params is not None:
        account = params['account']
        commit = False
        if account is None:
            userid, server = params['to'].rsplit('@', 1)
            account = MailAccount(itsView=view,
                                  userid=userid,
                                  server=server,
                                  smtp=params['smtp'],
                                  imap=params['imap'])
            commit = True

        if collection.getACL('p2p', None) is None:
            acl = ACL()
            acl.append(
                ACE(schema.ns('p2p', view).all.itsUUID, Permissions.READ))
            collection.setACL(acl, 'p2p')
            commit = True

        if commit:
            view.commit()
        account.login(setStatusMessage)
        account.send(params['to'], name)
Ejemplo n.º 5
0
    def _result_sync(self, view, iq, sync, args):

        try:
            view.refresh(None, None, False)

            if 'toRepoId' in args and UUID(args['toRepoId']) != self._repoId:
                raise RepositoryMismatchError, args['toRepoId']

            repoId = UUID(args['fromRepoId'])
            uuid = UUID(args['uuid'])
            version = int(args['version'])
            collection = view.find(uuid)

            if collection is None:
                collection = pim.SmartCollection(itsView=view,
                                                 _uuid=uuid,
                                                 displayName=args['name'])
                schema.ns("osaf.app", view).sidebarCollection.add(collection)

                # for now, grant READ to everyone
                acl = ACL()
                acl.append(
                    ACE(schema.ns('p2p', view).all.itsUUID, Permissions.READ))
                collection.setACL(acl, 'p2p')
                isNew = True
            else:
                isNew = False

            share = self.findShare(view, collection, repoId, iq['from'])
            format = share.format

            if isNew:
                share.localVersion = view.itsVersion + 1
            else:
                changes = self.computeChanges(view, share.localVersion,
                                              collection, share)
                if not changes:
                    share.localVersion = view.itsVersion + 1

            if sync.attributes.get('compressed') == 'true':
                dom = formats.ElementTreeDOM()
                input = StringIO(decompress(b64decode(sync.children[0])))
                data = ElementTree(file=input).getroot()
                input.close()
            else:
                dom = DomishDOM()
                data = sync.firstChildElement()

            share.remoteVersion = version
            view.deferDelete()

            for itemElement in dom.iterElements(data):
                attributes = dom.getAttributes(itemElement)
                status = attributes.get('status')
                if status == 'deleted':
                    item = view.findUUID(attributes['uuid'])
                    if item is not None:
                        item.delete()
                else:
                    child = dom.getFirstChildElement(itemElement)
                    if child is not None:
                        item = format.importProcess(dom, child)
                    else:
                        item = view.findUUID(attributes['uuid'])

                    if status == 'member':
                        collection.inclusions.add(item)

            # Kludge until masterEvents filter patch on bug 6970 is checked in
            for item in collection.inclusions:
                if pim.has_stamp(item, pim.EventStamp):
                    event = pim.EventStamp(item)
                    if event.rruleset is not None:
                        event.getMaster().getFirstOccurrence()

        except:
            view.cancel()
            raise

        share.established = True
        view.commit()
        self.client.output("'%s' synchronized" % (collection.displayName))

        to = iq['from']
        iq = client.IQ(self.client.xmlstream, 'result')
        iq.addElement(('jabber:x:chandler', 'query'))
        receipt = iq.query.addElement('receipt')
        receipt['fromRepoId'] = self._repoId.str64()
        receipt['toRepoId'] = repoId.str64()
        receipt['uuid'] = collection.itsUUID.str64()
        receipt['version'] = str(share.localVersion)
        reactor.callFromThread(iq.send, to)
Ejemplo n.º 6
0
    def _result_sync(self, view, uid, message, fromAddress):

        try:
            view.refresh(None, None, False)

            repoId = UUID(message['X-chandler-p2p-from'])
            uuid, version = message['X-chandler-p2p-item'].split('-')
            uuid = UUID(uuid)
            version = int(version)
            name = message['X-chandler-p2p-name']
            self.client.output("processing '%s'" %(name))

            collection = view.find(uuid)
            if collection is None:
                collection = pim.SmartCollection(itsView=view, _uuid=uuid,
                                                 displayName=name)
                schema.ns("osaf.app", view).sidebarCollection.add(collection)

                # for now, grant READ to everyone
                acl = ACL()
                acl.append(ACE(schema.ns('p2p', view).all.itsUUID,
                               Permissions.READ))
                collection.setACL(acl, 'p2p')
                isNew = True
            else:
                isNew = False

            share = self.findShare(view, collection, repoId, fromAddress)
            format = share.format

            if isNew:
                share.localVersion = view.itsVersion + 1
            else:
                changes = self.computeChanges(view, share.localVersion,
                                              collection, share)
                if not changes:
                    share.localVersion = view.itsVersion + 1

            payload = message.get_payload(1).get_payload()
            dom = ElementTreeDOM()
            input = StringIO(decompress(b64decode(payload)))
            data = ElementTree(file=input).getroot()
            input.close()

            share.remoteVersion = version
            view.deferDelete()

            for itemElement in dom.iterElements(data):
                attributes = dom.getAttributes(itemElement)
                status = attributes.get('status')
                if status == 'deleted':
                    item = view.findUUID(attributes['uuid'])
                    if item is not None:
                        item.delete()
                else:
                    child = dom.getFirstChildElement(itemElement)
                    if child is not None:
                        item = format.importProcess(dom, child)
                    else:
                        item = view.findUUID(attributes['uuid'])

                    if status == 'member':
                        collection.inclusions.add(item)

            # Kludge until masterEvents filter patch on bug 6970 is checked in
            for item in collection.inclusions:
                if pim.has_stamp(item, pim.EventStamp):
                    event = pim.EventStamp(item)
                    if event.rruleset is not None:
                        event.getMaster().getFirstOccurrence()

        except:
            view.cancel()
            raise

        share.established = True
        view.commit()
        self.client.output("'%s' synchronized" %(collection.displayName))

        replyTo = view[self.client.account].imap.replyToAddress.emailAddress

        receipt = MIMEText('Chandler sent a receipt for "%s"' %(name))
        receipt['From'] = replyTo
        receipt['Reply-To'] = replyTo
        receipt['To'] = message.get('replyTo') or fromAddress
        receipt['Subject'] = "Chandler sent a receipt"
        receipt['X-chandler'] = 'p2p'
        receipt['X-chandler-p2p-name'] = name
        receipt['X-chandler-p2p-from'] = self._repoId.str64()
        receipt['X-chandler-p2p-to'] = repoId.str64()
        receipt['X-chandler-p2p-item'] = "%s-%d" %(uuid.str64(),
                                                   share.localVersion)
        receipt['X-chandler-p2p-op'] = 'receipt'

        return receipt
Ejemplo n.º 7
0
    def _result_sync(self, view, uid, message, fromAddress):

        try:
            view.refresh(None, None, False)

            repoId = UUID(message['X-chandler-p2p-from'])
            uuid, version = message['X-chandler-p2p-item'].split('-')
            uuid = UUID(uuid)
            version = int(version)
            name = message['X-chandler-p2p-name']
            self.client.output("processing '%s'" % (name))

            collection = view.find(uuid)
            if collection is None:
                collection = pim.SmartCollection(itsView=view,
                                                 _uuid=uuid,
                                                 displayName=name)
                schema.ns("osaf.app", view).sidebarCollection.add(collection)

                # for now, grant READ to everyone
                acl = ACL()
                acl.append(
                    ACE(schema.ns('p2p', view).all.itsUUID, Permissions.READ))
                collection.setACL(acl, 'p2p')
                isNew = True
            else:
                isNew = False

            share = self.findShare(view, collection, repoId, fromAddress)
            format = share.format

            if isNew:
                share.localVersion = view.itsVersion + 1
            else:
                changes = self.computeChanges(view, share.localVersion,
                                              collection, share)
                if not changes:
                    share.localVersion = view.itsVersion + 1

            payload = message.get_payload(1).get_payload()
            dom = ElementTreeDOM()
            input = StringIO(decompress(b64decode(payload)))
            data = ElementTree(file=input).getroot()
            input.close()

            share.remoteVersion = version
            view.deferDelete()

            for itemElement in dom.iterElements(data):
                attributes = dom.getAttributes(itemElement)
                status = attributes.get('status')
                if status == 'deleted':
                    item = view.findUUID(attributes['uuid'])
                    if item is not None:
                        item.delete()
                else:
                    child = dom.getFirstChildElement(itemElement)
                    if child is not None:
                        item = format.importProcess(dom, child)
                    else:
                        item = view.findUUID(attributes['uuid'])

                    if status == 'member':
                        collection.inclusions.add(item)

            # Kludge until masterEvents filter patch on bug 6970 is checked in
            for item in collection.inclusions:
                if pim.has_stamp(item, pim.EventStamp):
                    event = pim.EventStamp(item)
                    if event.rruleset is not None:
                        event.getMaster().getFirstOccurrence()

        except:
            view.cancel()
            raise

        share.established = True
        view.commit()
        self.client.output("'%s' synchronized" % (collection.displayName))

        replyTo = view[self.client.account].imap.replyToAddress.emailAddress

        receipt = MIMEText('Chandler sent a receipt for "%s"' % (name))
        receipt['From'] = replyTo
        receipt['Reply-To'] = replyTo
        receipt['To'] = message.get('replyTo') or fromAddress
        receipt['Subject'] = "Chandler sent a receipt"
        receipt['X-chandler'] = 'p2p'
        receipt['X-chandler-p2p-name'] = name
        receipt['X-chandler-p2p-from'] = self._repoId.str64()
        receipt['X-chandler-p2p-to'] = repoId.str64()
        receipt['X-chandler-p2p-item'] = "%s-%d" % (uuid.str64(),
                                                    share.localVersion)
        receipt['X-chandler-p2p-op'] = 'receipt'

        return receipt
Ejemplo n.º 8
0
    def _result_sync(self, view, iq, sync, args):

        try:
            view.refresh(None, None, False)

            if 'toRepoId' in args and UUID(args['toRepoId']) != self._repoId:
                raise RepositoryMismatchError, args['toRepoId']

            repoId = UUID(args['fromRepoId'])
            uuid = UUID(args['uuid'])
            version = int(args['version'])
            collection = view.find(uuid)

            if collection is None:
                collection = pim.SmartCollection(itsView=view, _uuid=uuid,
                                                 displayName=args['name'])
                schema.ns("osaf.app", view).sidebarCollection.add(collection)

                # for now, grant READ to everyone
                acl = ACL()
                acl.append(ACE(schema.ns('p2p', view).all.itsUUID,
                               Permissions.READ))
                collection.setACL(acl, 'p2p')
                isNew = True
            else:
                isNew = False

            share = self.findShare(view, collection, repoId, iq['from'])
            format = share.format

            if isNew:
                share.localVersion = view.itsVersion + 1
            else:
                changes = self.computeChanges(view, share.localVersion,
                                              collection, share)
                if not changes:
                    share.localVersion = view.itsVersion + 1

            if sync.attributes.get('compressed') == 'true':
                dom = formats.ElementTreeDOM()
                input = StringIO(decompress(b64decode(sync.children[0])))
                data = ElementTree(file=input).getroot()
                input.close()
            else:
                dom = DomishDOM()
                data = sync.firstChildElement()

            share.remoteVersion = version
            view.deferDelete()

            for itemElement in dom.iterElements(data):
                attributes = dom.getAttributes(itemElement)
                status = attributes.get('status')
                if status == 'deleted':
                    item = view.findUUID(attributes['uuid'])
                    if item is not None:
                        item.delete()
                else:
                    child = dom.getFirstChildElement(itemElement)
                    if child is not None:
                        item = format.importProcess(dom, child)
                    else:
                        item = view.findUUID(attributes['uuid'])

                    if status == 'member':
                        collection.inclusions.add(item)

            # Kludge until masterEvents filter patch on bug 6970 is checked in
            for item in collection.inclusions:
                if pim.has_stamp(item, pim.EventStamp):
                    event = pim.EventStamp(item)
                    if event.rruleset is not None:
                        event.getMaster().getFirstOccurrence()

        except:
            view.cancel()
            raise

        share.established = True
        view.commit()
        self.client.output("'%s' synchronized" %(collection.displayName))

        to = iq['from']
        iq = client.IQ(self.client.xmlstream, 'result')
        iq.addElement(('jabber:x:chandler', 'query'))
        receipt = iq.query.addElement('receipt')
        receipt['fromRepoId'] = self._repoId.str64()
        receipt['toRepoId'] = repoId.str64()
        receipt['uuid'] = collection.itsUUID.str64()
        receipt['version'] = str(share.localVersion)
        reactor.callFromThread(iq.send, to)