From c37da2360a5171c8671a1b82ed84d9973e5d79ba Mon Sep 17 00:00:00 2001 From: Mathias Rav Date: Sun, 30 Jul 2017 11:18:44 +0200 Subject: [PATCH] Copy definition of abbreviate_recipient_list (removed from emailtunnel?) --- tutormail/server.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tutormail/server.py b/tutormail/server.py index f8ae665..8efe037 100644 --- a/tutormail/server.py +++ b/tutormail/server.py @@ -19,6 +19,22 @@ from mftutor.tutor.models import Tutor, TutorGroup, RusClass, Rus +def abbreviate_recipient_list(recipients): + if all('@' in rcpt for rcpt in recipients): + parts = [rcpt.split('@', 1) for rcpt in recipients] + parts.sort(key=lambda x: (x[1].lower(), x[0].lower())) + by_domain = [ + (domain, [a[0] for a in aa]) + for domain, aa in itertools.groupby( + parts, key=lambda x: x[1]) + ] + return ', '.join( + '<%s@%s>' % (','.join(aa), domain) + for domain, aa in by_domain) + else: + return ', '.join('<%s>' % x for x in recipients) + + def now_string(): """Return the current date and time as a string.""" return datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S.%f") @@ -241,7 +257,7 @@ def log_receipt(self, peer, envelope): (str(message.subject), sender, recipients)) def log_delivery(self, message, recipients, sender): - recipients_string = emailtunnel.abbreviate_recipient_list(recipients) + recipients_string = abbreviate_recipient_list(recipients) logging.info('Subject: %r To: %s' % (str(message.subject), recipients_string))