Skip to content

Commit

Permalink
Copy definition of abbreviate_recipient_list (removed from emailtunnel?)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mortal committed Jul 30, 2017
1 parent 060697d commit c37da23
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tutormail/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit c37da23

Please sign in to comment.