Example #1
0
	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 testOptnegMilterEncode(self):
		"""Test encode_optneg() with is_milter=True, which should
		not clamp protocol to SMFI_V2_PROT."""
		r = codec.encode_optneg(actions=0xff, protocol=0x180,
					is_milter = True)
		rcmd, rdict, data = codec.decode_msg(r)
		self.assertEqual(rdict['actions'], SMFI_V2_ACTS)
		self.assertEqual(rdict['protocol'], 0x180)
	def testOptnegEncode(self):
		"""Test that encode_optneg() works right."""
		return
		for a, b in self.optneg_tests:
			r = codec.encode_optneg(actions=a[0], protocol=a[1])
			rcmd, rdict, data = codec.decode_msg(r)
			self.assertEqual(data, '')
			self.assertEqual(rcmd, SMFIC_OPTNEG)
			rpair = (rdict['actions'], rdict['protocol'])
			self.assertEqual(rpair, b)
Example #4
0
	def optneg_milter(self, actions=SMFI_V2_ACTS, protocol=0):
		"""Perform the initial option negotiation as a milter,
		reading the MTA's SMFIR_OPTNEG and replying with ours.
		Returns a tuple of (actions, protocol) bitmasks for what
		both we and the MTA will do."""
		r = self.get_msg()
		if r[0] != SMFIC_OPTNEG:
			raise MilterConvoError("first message not SMFIR_OPTNEG, was: %s/%s" % (r[0], str(r[1])))
		ract, rprot =  codec.optneg_milter_capable(r[1]['actions'],
							   r[1]['protocol'],
							   actions, protocol)
		self.sock.sendall(codec.encode_optneg(ract, rprot,
						      is_milter=True))
		return (ract, rprot)