Ejemplo n.º 1
0
def test_delegate_permissions_owner(publicfolder, session3, kind, rights,
                                    folder_access, message_access):
    print(kind)
    access = publicfolder.GetProps([PR_ACCESS], 0)[0].Value
    defaultAccess = MAPI_ACCESS_MODIFY | MAPI_ACCESS_READ | MAPI_ACCESS_DELETE | MAPI_ACCESS_CREATE_HIERARCHY | MAPI_ACCESS_CREATE_CONTENTS
    assert defaultAccess == access

    store = GetDefaultStore(session3)
    userid = session3.QueryIdentity()

    folderid = publicfolder.GetProps([PR_ENTRYID], 0)[0].Value
    acls = publicfolder.OpenProperty(PR_ACL_TABLE, IID_IExchangeModifyTable, 0,
                                     MAPI_MODIFY)
    rowlist = [
        ROWENTRY(ROW_ADD, [
            SPropValue(PR_MEMBER_ENTRYID, userid),
            SPropValue(PR_MEMBER_RIGHTS, rights)
        ])
    ]

    acls.ModifyTable(ROWLIST_REPLACE, rowlist)
    message = publicfolder.CreateMessage(None, 0)
    message.SetProps([SPropValue(PR_SUBJECT, b'acl test')])
    message.SaveChanges(0)
    eid = message.GetProps([PR_ENTRYID], 0)[0].Value
    access = message.GetProps([PR_ACCESS], 0)[0].Value
    assert access == MAPI_ACCESS_MODIFY | MAPI_ACCESS_READ | MAPI_ACCESS_DELETE

    # as user3, open public and get folder access
    public = GetPublicStore(session3)
    folder = public.OpenEntry(folderid, None, MAPI_BEST_ACCESS)
    access = folder.GetProps([PR_ACCESS], 0)[0].Value
    assert access == folder_access

    message = folder.OpenEntry(eid, None, 0)
    access = message.GetProps([PR_ACCESS], 0)[0].Value
    assert access == message_access
Ejemplo n.º 2
0
    def PreDelivery(self, session, addrbook, store, folder, message):
        """ Original code from movetopublic.py with call to self.publicfolder().
		Change type modification. """

        props = message.GetProps([PR_RECEIVED_BY_EMAIL_ADDRESS_W], 0)
        if props[0].ulPropTag != PR_RECEIVED_BY_EMAIL_ADDRESS_W:
            self.logger.logError("!--- Not received by emailaddress")
            return MP_CONTINUE,

        recipient = props[0].Value.lower()
        if not recipient:
            self.logger.logError("!--- No recipient in props {}".format(props))
            return MP_CONTINUE,

        recipfolder = self.publicfolder(recipient)
        if not recipfolder:
            self.logger.logDebug(
                ("*--- No public folder for recipient {}".format(
                    recipient.encode('utf-8'))))
            return MP_CONTINUE,

        publicstore = GetPublicStore(session)
        if not publicstore:
            storeprops = store.GetProps([PR_MAILBOX_OWNER_ENTRYID], 0)
            if storeprops[0].ulPropTag == PR_MAILBOX_OWNER_ENTRYID:
                user = addrbook.OpenEntry(storeprops[0].Value, None, 0)
                userprops = user.GetProps([PR_EC_COMPANY_NAME_W], 0)
                if userprops[0].ulPropTag == PR_EC_COMPANY_NAME_W:
                    companyname = userprops[0].Value
                else:
                    companyname = None

                if not companyname:
                    self.logger.logError(("!--- Cannot open a public store."
                                          ' Use "kopano-storeadm -P"'
                                          " to create one if it is missing."))
                    return MP_CONTINUE,

                ema = store.QueryInterface(IID_IExchangeManageStore)
                publicstoreid = ema.CreateStoreEntryID(None, companyname,
                                                       MAPI_UNICODE)
                publicstore = session.OpenMsgStore(0, publicstoreid, None,
                                                   MDB_WRITE)

        publicfolders = publicstore.OpenEntry(
            publicstore.GetProps([PR_IPM_PUBLIC_FOLDERS_ENTRYID], 0)[0].Value,
            None, MAPI_MODIFY)

        folderlist = recipfolder.split('/')
        folder = publicfolders
        for foldername in folderlist:
            if len(foldername) > 0:
                if hexversion >= 0x03000000:
                    folder = folder.CreateFolder(
                        0, foldername, "Create by Move to Public plugin", None,
                        OPEN_IF_EXISTS | MAPI_UNICODE)
                else:
                    folder = folder.CreateFolder(
                        0, foldername, "Create by Move to Public plugin", None,
                        OPEN_IF_EXISTS)

        msgnew = folder.CreateMessage(None, 0)
        tags = message.GetPropList(MAPI_UNICODE)
        message.CopyProps(tags, 0, None, IID_IMessage, msgnew, 0)

        msgnew.SaveChanges(0)
        folderid = folder.GetProps([PR_ENTRYID], 0)[0].Value
        msgid = msgnew.GetProps([PR_ENTRYID], 0)[0].Value

        publicstore.NotifyNewMail(
            NEWMAIL_NOTIFICATION(msgid, folderid, 0, None, 0))

        self.logger.logInfo(
            ("*--- Message moved to public folder {}".format(recipfolder)))

        return MP_STOP_SUCCESS,
Ejemplo n.º 3
0
    def PreDelivery(self, session, addrbook, store, folder, message):

        props = message.GetProps([PR_RECEIVED_BY_EMAIL_ADDRESS_W], 0)
        if props[0].ulPropTag != PR_RECEIVED_BY_EMAIL_ADDRESS_W:
            self.logger.logError("!--- No received by emailaddress")
            return MP_CONTINUE,

        recipient = props[0].Value.lower()

        if recipient not in self.rulelist:
            self.logger.logInfo("*--- No rule for recipient '%s'" %
                                recipient.encode('utf-8'))
            return MP_CONTINUE,

        publicstore = GetPublicStore(session)
        if publicstore is None:
            # check for company public
            companyname = None

            storeprops = store.GetProps([PR_MAILBOX_OWNER_ENTRYID], 0)
            if storeprops[0].ulPropTag == PR_MAILBOX_OWNER_ENTRYID:
                user = addrbook.OpenEntry(storeprops[0].Value, None, 0)
                userprops = user.GetProps([PR_EC_COMPANY_NAME_W], 0)
                if userprops[0].ulPropTag == PR_EC_COMPANY_NAME_W:
                    companyname = userprops[0].Value

                if companyname is None:
                    self.logger.logError("!--- Can not open a public store")
                    return MP_CONTINUE,

                ema = store.QueryInterface(IID_IExchangeManageStore)
                publicstoreid = ema.CreateStoreEntryID(None, companyname,
                                                       MAPI_UNICODE)
                publicstore = session.OpenMsgStore(0, publicstoreid, None,
                                                   MDB_WRITE)

        publicfolders = publicstore.OpenEntry(
            publicstore.GetProps([PR_IPM_PUBLIC_FOLDERS_ENTRYID], 0)[0].Value,
            None, MAPI_MODIFY)

        folderlist = self.rulelist[recipient].split('/')
        if len(folderlist) == 0:
            self.logger.logWarn(
                "!--- No folders in the rule of recipient '%s'" %
                recipient.encode('utf-8'))
            return MP_CONTINUE,

        folder = publicfolders
        for foldername in folderlist:
            if len(foldername) > 0:
                if hexversion >= 0x03000000:
                    folder = folder.CreateFolder(
                        0, foldername, "Create by Move to Public plugin", None,
                        OPEN_IF_EXISTS | MAPI_UNICODE)
                else:
                    folder = folder.CreateFolder(
                        0, foldername, "Create by Move to Public plugin", None,
                        OPEN_IF_EXISTS)

        msgnew = folder.CreateMessage(None, 0)
        tags = message.GetPropList(MAPI_UNICODE)
        message.CopyProps(tags, 0, None, IID_IMessage, msgnew, 0)

        msgnew.SaveChanges(0)
        folderid = folder.GetProps([PR_ENTRYID], 0)[0].Value
        msgid = msgnew.GetProps([PR_ENTRYID], 0)[0].Value

        publicstore.NotifyNewMail(
            NEWMAIL_NOTIFICATION(msgid, folderid, 0, None, 0))

        self.logger.logInfo("*--- Message moved to public folder '%s'" %
                            (self.rulelist[recipient].encode('utf-8')))

        return MP_STOP_SUCCESS,