Skip to content

Commit

Permalink
Add headers to autoresponses in human-friendly order.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://open.inoi.fi/open-scalemail/trunk@128 b5f3cfec-f4e5-0310-a79a-9a52b1b86675
  • Loading branch information
tv committed Feb 3, 2005
1 parent e7de007 commit 3e2de28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
21 changes: 11 additions & 10 deletions scalemail/gone/respond.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ def prepare(msg,
recipientName=None,
subjectPrefix=None):
sender = goneutil.getSender(msg)

if ('From' not in reply
and recipient is not None):
if '@' in recipient:
local, host = recipient.split('@', 1)
box, domain = util.host_split(host)
if domain is not None:
host = domain
recipient = str(smtp.Address(local, host))
reply['From'] = email.Utils.formataddr((recipientName, recipient))

to = msg.get_all('Sender', None)
if to is None:
to = msg.get_all('From', None)
Expand All @@ -56,16 +67,6 @@ def prepare(msg,
subject = subjectPrefix + subject
reply['Subject'] = subject

if ('From' not in reply
and recipient is not None):
if '@' in recipient:
local, host = recipient.split('@', 1)
box, domain = util.host_split(host)
if domain is not None:
host = domain
recipient = str(smtp.Address(local, host))
reply['From'] = email.Utils.formataddr((recipientName, recipient))

msgid = msg.get('Message-ID', None)
if msgid is not None:
msgid = msgid.strip()
Expand Down
9 changes: 9 additions & 0 deletions scalemail/gone/test/test_respond.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,12 @@ def test_to_envelopeSender(self):
""")
r = respond.prepare(self.msg, reply, recipient='the-recipient')
self.assertEquals(r.get_all('To'), ['the-sender'])

def test_order(self):
"""Headers are added in human-friendly order, From/To/Subject."""
reply = email.message_from_string("""\
body
""")
r = respond.prepare(self.msg, reply, recipient='the-recipient')
self.assertEquals(r.keys(), ['From', 'To', 'Subject'])

0 comments on commit 3e2de28

Please sign in to comment.