def optneg_mta(self, actions=SMFI_V2_ACTS, protocol=SMFI_V2_PROT, strict=True): """Perform the initial option negocation as a MTA. Returns a tuple of (actions, protocol) bitmasks for what we support. If strict is True (the default), raises MilterConvoError if the milter returns a SMFIR_OPTNEG that asks for things we told it that we do not support. Can optionally be passed more restrictive values for actions and protocol, but this is not recommended; milters may dislike it enough to disconnect abruptly on you.""" actions, protocol = codec.optneg_mta_capable(actions, protocol) self.sock.sendall(codec.encode_optneg(actions, protocol)) r = self.get_msg() if r[0] != SMFIC_OPTNEG: raise MilterConvoError("bad reply to SMFIR_OPTNEG, was: %s/%s" % (r[0], str(r[1]))) ract = r[1]['actions'] rprot = r[1]['protocol'] if strict: # There should be no bits outside what we claim to # support. if (ract & actions) != ract or \ (rprot & protocol) != rprot: raise MilterConvoError("SMFIR_OPTNEG reply with unsupported bits in actions or protocol: 0x%x/0x%x" % (ract, rprot)) else: ract = ract & actions rprot = rprot & protocol return ract, rprot
def testOptnegCap(self): """Test that optneg_mta_capable correctly masks things.""" for a, b in self.optneg_tests: r = codec.optneg_mta_capable(a[0], a[1]) self.assertEqual(r, b)