Beispiel #1
0
    def _save_rule(store, userids, deletion):
        # remove existing rule # XXX update
        for rule in store.inbox.rules():
            if rule.mapirow[PR_RULE_PROVIDER_W] == u'Schedule+ EMS Interface' and \
               PR_RULE_ID in rule.mapirow:
                pr_rule_id = rule.mapirow[PR_RULE_ID]

                rulerows = [
                    ROWENTRY(ROW_REMOVE, [SPropValue(PR_RULE_ID, pr_rule_id)])
                ]
                table = store.inbox.mapiobj.OpenProperty(
                    PR_RULES_TABLE, IID_IExchangeModifyTable, 0, 0)
                table.ModifyTable(0, rulerows)

        # create new rule
        row = [
            SPropValue(PR_RULE_LEVEL, 0),
            SPropValue(PR_RULE_NAME_W, u"Delegate Meetingrequest service"),
            SPropValue(PR_RULE_PROVIDER_W, u"Schedule+ EMS Interface"),
            SPropValue(PR_RULE_SEQUENCE, 0),
            SPropValue(PR_RULE_STATE, 1),
            SPropValue(PR_RULE_PROVIDER_DATA, b''),
        ]

        actions = []
        userprops = []
        for userid in userids:
            user = store.server.gab.OpenEntry(userid, None, MAPI_BEST_ACCESS)
            props = user.GetProps(USERPROPS, MAPI_UNICODE)
            # Hardcode recipient type to TO
            props.append(SPropValue(PR_RECIPIENT_TYPE, MAPI_TO))
            userprops.append(props)

        actions.append(
            ACTION(ACTTYPE.OP_DELEGATE, 0, None, None, 0,
                   actFwdDelegate(userprops)))
        if deletion:
            actions.append(ACTION(ACTTYPE.OP_DELETE, 0, None, None, 0, None))
        row.append(SPropValue(PR_RULE_ACTIONS, ACTIONS(1, actions)))

        cond = SAndRestriction([
            SContentRestriction(
                FL_PREFIX, PR_MESSAGE_CLASS_W,
                SPropValue(PR_MESSAGE_CLASS_W, u"IPM.Schedule.Meeting")),
            SNotRestriction(SExistRestriction(PR_DELEGATED_BY_RULE)),
            SOrRestriction([
                SNotRestriction(SExistRestriction(PR_SENSITIVITY)),
                SPropertyRestriction(RELOP_NE, PR_SENSITIVITY,
                                     SPropValue(PR_SENSITIVITY, 2))
            ])
        ])
        row.append(SPropValue(PR_RULE_CONDITION, cond))
        rulerows = [ROWENTRY(ROW_ADD, row)]
        table = store.inbox.mapiobj.OpenProperty(PR_RULES_TABLE,
                                                 IID_IExchangeModifyTable, 0,
                                                 0)
        table.ModifyTable(0, rulerows)
Beispiel #2
0
    def PreRuleProcess(self, session, addrbook, store, rulestable):
        props = store.GetProps([PR_ENTRYID, PR_IPM_WASTEBASKET_ENTRYID], 0)
        storeid = props[0].Value
        folderid = props[1].Value

        rowlist = [
            ROWENTRY(ROW_ADD, [
                SPropValue(PR_RULE_LEVEL, 0),
                SPropValue(PR_RULE_NAME, "dagenttest"),
                SPropValue(PR_RULE_PROVIDER, "RuleOrganizer"),
                SPropValue(PR_RULE_STATE, ST_ENABLED),
                SPropValue(PR_RULE_SEQUENCE, 1),
                SPropValue(
                    PR_RULE_ACTIONS,
                    ACTIONS(EDK_RULES_VERSION, [
                        ACTION(ACTTYPE.OP_MOVE, 0x00000000, None, None,
                               0x00000000, actMoveCopy(storeid, folderid))
                    ])),
                SPropValue(
                    PR_RULE_CONDITION,
                    SContentRestriction(FL_SUBSTRING | FL_IGNORECASE,
                                        PR_SUBJECT,
                                        SPropValue(PR_SUBJECT, 'rulestest')))
            ])
        ]
        rulestable.ModifyTable(0, rowlist)

        return MP_CONTINUE
Beispiel #3
0
def test_reply_rule(lmtpclient, inbox, outbox, rules, sink, reply_template,
                    create_test_email):
    '''Reply to a mail matching subject to KOPANO_TEST_USER with a template message in the inbox assoicated messages'''
    subject = 'reply rule'
    sender = '*****@*****.**'
    receiver = os.getenv('KOPANO_TEST_EMAIL')

    condition = SContentRestriction(FL_SUBSTRING | FL_IGNORECASE, PR_SUBJECT,
                                    SPropValue(PR_SUBJECT, subject.encode()))
    ruleaction = ACTIONS(EDK_RULES_VERSION, [
        ACTION(ACTTYPE.OP_REPLY, 0x00000000, None, None, 0x00000000,
               actReply(reply_template, b'\0' * 16))
    ])
    add_rule(rules, condition, ruleaction)

    msg = create_test_email(sender, receiver, subject, '')
    lmtpclient.sendmail(sender, receiver, msg.as_string())

    sink.WaitForNotification(60)

    table = inbox.GetContentsTable(0)
    rowcount = table.GetRowCount(0)
    assert rowcount == 1

    table = outbox.GetContentsTable(0)
    rowcount = table.GetRowCount(0)
    assert rowcount == 1
Beispiel #4
0
def create_forward_rule(rules, subject, gab_user, flavor=0x00000000):
    condition = SContentRestriction(FL_SUBSTRING | FL_IGNORECASE, PR_SUBJECT,
                                    SPropValue(PR_SUBJECT, subject.encode()))
    ruleaction = ACTIONS(EDK_RULES_VERSION, [
        ACTION(ACTTYPE.OP_FORWARD, flavor, None, None, 0x00000000,
               actFwdDelegate(gab_user))
    ])
    add_rule(rules, condition, ruleaction)
Beispiel #5
0
def create_copymove_rule(rules, action, subject, storeid, wasteid):
    condition = SContentRestriction(FL_SUBSTRING | FL_IGNORECASE, PR_SUBJECT,
                                    SPropValue(PR_SUBJECT, subject.encode()))
    ruleaction = ACTIONS(EDK_RULES_VERSION, [
        ACTION(action, 0x00000000, None, None, 0x00000000,
               actMoveCopy(storeid, wasteid))
    ])
    add_rule(rules, condition, ruleaction)
Beispiel #6
0
    def create_action(self, type_, folder=None):
        if type_ == 'move':  # TODO other types
            action = ACTION(
                1, 0, None, None, 0x0,
                actMoveCopy(_bdec(folder.store.entryid),
                            _bdec(folder.entryid)))

            row = []
            found = False
            for proptag, value in self.mapirow.items():
                if proptag == PR_RULE_ACTIONS:
                    found = True
                    value.lpAction.append(action)
                row.append(SPropValue(proptag, value))
            if not found:
                row.append(SPropValue(PR_RULE_ACTIONS, ACTIONS(1, [action])))

            self.table.ModifyTable(0, [ROWENTRY(ROW_MODIFY, row)])

        return Action(action)