diff options
author | David Rousselie <dax@happycoders.org> | 2008-07-26 00:05:59 +0400 |
---|---|---|
committer | David Rousselie <dax@happycoders.org> | 2008-07-26 00:05:59 +0400 |
commit | 717e4417331961f76cb41c722efa44693a13bceb (patch) | |
tree | 722e8b6a3434d9fa99938481de7e53809ecd6816 | |
parent | f920d6c5d271b626c31854699a0ff852e6cf161f (diff) |
Avoid crashing when parsing malformed mail header From
darcs-hash:20080725200559-86b55-48e00cc7822a2162159ba4bbe6386fbd3aea8bc0.gz
-rw-r--r-- | src/jmc/jabber/feeder.py | 23 | ||||
-rw-r--r-- | src/jmc/jabber/tests/component.py | 21 |
2 files changed, 33 insertions, 11 deletions
diff --git a/src/jmc/jabber/feeder.py b/src/jmc/jabber/feeder.py index 9b2377d..6e5ada0 100644 --- a/src/jmc/jabber/feeder.py +++ b/src/jmc/jabber/feeder.py @@ -157,17 +157,18 @@ class MailSender(HeadlineSender): """ message = MessageSender.create_message(self, to_account, (email_subject, email_body)) - msg_node = message.get_node() - addresses_node = msg_node.newChild(None, "addresses", None) - address_ns = addresses_node.newNs("http://jabber.org/protocol/address", - None) - addresses_node.setNs(address_ns) - replyto_address_node = addresses_node.newChild(address_ns, "address", - None) - replyto_address_node.setProp("type", "replyto") - replyto_jid = email_from.replace('@', '%', 1) + "@" \ - + unicode(JID(to_account.jid).domain) - replyto_address_node.setProp("jid", replyto_jid) + if email_from is not None: + msg_node = message.get_node() + addresses_node = msg_node.newChild(None, "addresses", None) + address_ns = addresses_node.newNs("http://jabber.org/protocol/address", + None) + addresses_node.setNs(address_ns) + replyto_address_node = addresses_node.newChild(address_ns, "address", + None) + replyto_address_node.setProp("type", "replyto") + replyto_jid = email_from.replace('@', '%', 1) + "@" \ + + unicode(JID(to_account.jid).domain) + replyto_address_node.setProp("jid", replyto_jid) return message def create_message(self, to_account, data): diff --git a/src/jmc/jabber/tests/component.py b/src/jmc/jabber/tests/component.py index 051a863..b7b54b6 100644 --- a/src/jmc/jabber/tests/component.py +++ b/src/jmc/jabber/tests/component.py @@ -1,3 +1,5 @@ + + # -*- coding: utf-8 -*- ## ## test_component.py @@ -1301,6 +1303,25 @@ class MailSender_TestCase(JCLTestCase): self.assertEquals(addresses[0].prop("jid"), "from%test.com@jmc.test.com") + def test_create_message_missing_email_from(self): + mail_sender = MailSender() + model.db_connect() + user1 = User(jid="test1@test.com") + account11 = IMAPAccount(user=user1, + name="account11", + jid="account11@jmc.test.com") + account11.online_action = MailAccount.RETRIEVE + account11.status = account.ONLINE + message = mail_sender.create_message(account11, (None, + "subject", + "message body")) + self.assertEquals(message.get_to(), user1.jid) + self.assertEquals(message.get_subject(), "subject") + self.assertEquals(message.get_body(), "message body") + addresses = message.xpath_eval("add:addresses/add:address", + {"add": "http://jabber.org/protocol/address"}) + self.assertEquals(addresses, []) + def test_create_message_digest(self): mail_sender = MailSender() model.db_connect() |