RFC: Omezení počtu adres v mailech z testwebu #27
					 1 changed files with 11 additions and 3 deletions
				
			
		|  | @ -7,6 +7,11 @@ Used to distinguish testing emails from production ones.""" | |||
| from django.core.mail.backends.smtp import EmailBackend as DjangoSMTPBackend | ||||
| from django.conf import settings | ||||
| 
 | ||||
| def omezovatko_poctu_mailu(maily:list, maximum:int) -> str: | ||||
| 	if len(maily) <= maximum: return str(maily) | ||||
| 	# Aspoň zhruba simulujeme tisk pole… | ||||
| 	return '[' + ", ".join(f"'{mail}'" for mail in maily[:maximum - 1]) + f', … ({len(maily)} e-mailů) ]' | ||||
| 
 | ||||
| class PrefixingMailBackend(DjangoSMTPBackend): | ||||
| 	# method _send is not probably meant to be monkey_patched, so we patch send_messages instead. | ||||
| 	def send_messages(self, messages): | ||||
|  | @ -16,10 +21,13 @@ class PrefixingMailBackend(DjangoSMTPBackend): | |||
| 
 | ||||
| 			if message.from_email != settings.SERVER_EMAIL: | ||||
| 				message.subject = prefix + ' ' + message.subject | ||||
| 				to = omezovatko_poctu_mailu(message.to, 3) | ||||
| 				cc = omezovatko_poctu_mailu(message.cc, 3) | ||||
| 				bcc = omezovatko_poctu_mailu(message.bcc, 3) | ||||
| 				message.body = f"""Bylo by posláno na e-maily: | ||||
| 	To: {message.to} | ||||
| 	Cc: {message.cc} | ||||
| 	Bcc: {message.bcc} | ||||
| 	To: {to} | ||||
| 	Cc: {cc} | ||||
| 	Bcc: {bcc} | ||||
| """+ "\n\n" + message.body | ||||
| 				message.to = settings.TESTOVACI_EMAILOVA_KONFERENCE | ||||
| 				message.cc = [] | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue