def encode(self, encoding=None):
		name_string = None
		
		if encoding is None:
			encoding = self.encoding
		
		if encoding != 'ascii':
			try:  # This nonsense is to preserve Python 2 behaviour. Python 3 utf-8 encodes when asked for ascii!
				self.name.encode('ascii', errors='strict')
			except UnicodeError:
				pass
			else:
				name_string = self.name
		
		if name_string is None:
			name_string = Header(self.name, encoding).encode()
		
		# Encode punycode for internationalized domains.
		localpart, domain = self.address.split('@', 1)
		domain = domain.encode('idna').decode()
		address = '@'.join((localpart, domain))

		return formataddr((name_string, address)).replace('\n', '').encode(encoding)
dataset/ETHPy150Open marrow/mailer/marrow/mailer/address.py/Address.encode/original