Mercurial > public > sg101
comparison gpp/messages/utils.py @ 566:4b9970ad0edb
For bitbucket issue #6, try to improve quoting messages.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 04 Mar 2012 14:52:24 -0600 |
parents | 538a1bd2f1f4 |
children |
comparison
equal
deleted
inserted
replaced
565:6a265b5768ca | 566:4b9970ad0edb |
---|---|
1 """ | 1 """ |
2 This file contains various helper utility functions for the messages | 2 This file contains various helper utility functions for the messages |
3 application. | 3 application. |
4 | |
4 """ | 5 """ |
5 | |
6 from django.utils.text import wrap | |
7 | 6 |
8 | 7 |
9 def reply_subject(subject): | 8 def reply_subject(subject): |
10 """ | 9 """ |
11 Builds a subject line for a reply. | 10 Builds a subject line for a reply. |
12 If the subject already starts with Re: then return the subject. | 11 If the subject already starts with Re: then return the subject. |
13 Otherwise, prepend Re: to the subject and return it. | 12 Otherwise, prepend Re: to the subject and return it. |
14 """ | 13 """ |
15 if subject.startswith('Re: '): | 14 if subject.startswith('Re: '): |
16 return subject | 15 return subject |
17 return 'Re: ' + subject | 16 return 'Re: ' + subject |
18 | |
19 | |
20 def quote_message(who, date, message): | |
21 """ | |
22 Builds a message reply by quoting the existing message in a | |
23 typical email-like fashion. The quoting is compatible with Markdown. | |
24 """ | |
25 header = '> On %s, %s wrote:\n>\n' % (date.strftime('%a, %b %d %Y, %I:%M %p'), who) | |
26 lines = wrap(message, 55).split('\n') | |
27 for i, line in enumerate(lines): | |
28 lines[i] = '> ' + line | |
29 return header + '\n'.join(lines) + '\n\n' |