Beispiel #1
0
	def test_parse_command_address(self):
		for command in COMMANDS:
			actual = parse_command_address("*****@*****.**" % command)
			expected = ("list", command, "test.com")
			self.assertEqual(actual, expected)
		
		actual = parse_command_address("*****@*****.**")
		expected = ("list+ttt", None, "test.com")
		self.assertEqual(actual, expected)
		actual = parse_command_address("*****@*****.**")
		expected = ("list", None, "test.com")
		self.assertEqual(actual, expected)
Beispiel #2
0
def create_message_commands(msg):
	"""
	Given a message, creates and returns a list of commands for that message and target mailing lists.
	
	"""
	if msg.status != Message.UNPROCESSED:
		return
	
	pmsg = msg.get_processed()
	recipients = pmsg.to + pmsg.cc + pmsg.bcc
	if not recipients:
		return
	
	# Make a map of commands to recipient lists.
	cmd_recips = {}
	
	for recipient in recipients:
		local, cmd, domain = parse_command_address(recipient)
		# Default command is posting.
		cmd_recips.setdefault(cmd or "post", []).append('@'.join((local, domain)))
	
	try:
		with transaction.commit_on_success():
			for cmd in cmd_recips:
				lists = MailingList.objects.for_addresses(cmd_recips[cmd])
				list_cmds = [ListCommand.objects.create(message=msg, mailing_list=list_, command=cmd) for list_ in lists]
	except:
		msg.status = Message.FAILED
		msg.save()
		raise
	else:
		msg.status = Message.PROCESSED
		msg.save()
		return list_cmds
Beispiel #3
0
def validate_not_command(local_part):
	"""
	Validates that the email is not a command.
	
	"""
	local, command, domain = parse_command_address(local_part + "@")
	if command:
		raise ValidationError(u"`%s` is a command and cannot be used as part of an email address." % command)