gremmie@1: """ gremmie@1: This file contains various helper utility functions for the messages gremmie@1: application. gremmie@1: """ gremmie@1: gremmie@1: from django.utils.text import wrap gremmie@1: gremmie@1: gremmie@1: def reply_subject(subject): gremmie@1: """ gremmie@1: Builds a subject line for a reply. gremmie@1: If the subject already starts with Re: then return the subject. gremmie@1: Otherwise, prepend Re: to the subject and return it. gremmie@1: """ gremmie@1: if subject.startswith('Re: '): gremmie@1: return subject gremmie@1: return 'Re: ' + subject gremmie@1: gremmie@1: gremmie@1: def quote_message(who, date, message): gremmie@1: """ gremmie@1: Builds a message reply by quoting the existing message in a gremmie@1: typical email-like fashion. The quoting is compatible with Markdown. gremmie@1: """ gremmie@1: header = '> On %s, %s wrote:\n>\n' % (date.strftime('%a, %b %d %Y, %I:%M %p'), who) gremmie@1: lines = wrap(message, 55).split('\n') gremmie@1: for i, line in enumerate(lines): gremmie@1: lines[i] = '> ' + line gremmie@1: return header + '\n'.join(lines)