Changeset 95
- Timestamp:
- 06/19/07 17:05:57 (2 years ago)
- Files:
-
- src/jmc/jabber/component.py (modified) (4 diffs)
- src/jmc/jabber/tests/component.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/jmc/jabber/component.py
r94 r95 29 29 30 30 from pyxmpp.message import Message 31 from pyxmpp.jid import JID 31 32 32 33 from jcl.model.account import Account, PresenceAccount, LegacyJID … … 157 158 while mail_index is not None: 158 159 (body, email_from) = _account.get_mail(mail_index) 159 result.append((default_lang_class.new_mail_subject\ 160 result.append((email_from, 161 default_lang_class.new_mail_subject\ 160 162 % (email_from), 161 163 body)) … … 173 175 new_mail_count += 1 174 176 if body != "": 175 result.append((default_lang_class.new_digest_subject\ 177 result.append((None, 178 default_lang_class.new_digest_subject\ 176 179 % (new_mail_count), 177 180 body)) … … 192 195 return result 193 196 194 class MailSender( MessageSender,HeadlineSender):197 class MailSender(HeadlineSender): 195 198 """Send emails messages to jabber users""" 196 199 197 def send(self, to_account, subject, body): 200 def send(self, to_account, data): 201 """Call MessageSender send method""" 202 MessageSender.send(self, to_account, data) 203 204 def create_message(self, to_account, data): 198 205 """Send given emails (in data) as Jabber messages""" 206 email_from, subject, body = data 199 207 if to_account.action == MailAccount.RETRIEVE: 200 MessageSender.send(self, to_account, subject, body) 208 message = MessageSender.create_message(self, to_account, 209 (subject, body)) 210 msg_node = message.get_node() 211 addresses_node = msg_node.newChild(None, "addresses", None) 212 address_ns = addresses_node.newNs("http://jabber.org/protocol/address", None) 213 addresses_node.setNs(address_ns) 214 replyto_address_node = addresses_node.newChild(address_ns, "address", None) 215 replyto_address_node.setProp("type", "replyto") 216 replyto_jid = email_from.replace('@', '%', 1) + "@" \ 217 + unicode(JID(to_account.jid).domain) 218 replyto_address_node.setProp("jid", replyto_jid) 201 219 elif to_account.action == MailAccount.DIGEST: 202 HeadlineSender.send(self, to_account, subject, body) 220 message = HeadlineSender.create_message(self, to_account, 221 subject, body) 222 else: 223 message = None 224 return message 203 225 204 226 class MailHandler(Handler): src/jmc/jabber/tests/component.py
r94 r95 43 43 RootSendMailMessageHandler, MailHandler, MailSubscribeHandler, \ 44 44 MailUnsubscribeHandler, NoAccountError, MailFeederHandler, \ 45 MailPresenceHandler, MailAccountManager 45 MailPresenceHandler, MailAccountManager, MailSender 46 46 from jmc.lang import Lang 47 47 … … 146 146 def __init__(self): 147 147 self.default_from = "user1@test.com" 148 148 149 149 def create_email(self, from_email, to_email, subject, body): 150 150 return (from_email, to_email, subject, body) 151 151 152 152 def send_email(self, email): 153 153 self.email = email … … 340 340 def test_feed_retrieve_mail(self): 341 341 def mock_get_mail(index): 342 return [("body1", "from1@test.com"), \342 return [("body1", "from1@test.com"), 343 343 ("body2", "from2@test.com")][index] 344 344 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) 345 account11 = MockIMAPAccount(user_jid = "test1@test.com", \346 name = "account11", \347 jid ="account11@jmc.test.com")345 account11 = MockIMAPAccount(user_jid="test1@test.com", 346 name="account11", 347 jid="account11@jmc.test.com") 348 348 account11._action = MailAccount.RETRIEVE 349 349 account11.status = account.ONLINE … … 361 361 self.assertEquals(len(self.comp.stream.sent), 0) 362 362 self.assertEquals(len(result), 2) 363 self.assertEquals(result[0][0], \ 363 self.assertEquals(result[0][0], 364 "from1@test.com") 365 self.assertEquals(result[0][1], 364 366 account11.default_lang_class.new_mail_subject \ 365 367 % ("from1@test.com")) 366 self.assertEquals(result[0][1], "body1") 367 self.assertEquals(result[1][0], \ 368 self.assertEquals(result[0][2], "body1") 369 self.assertEquals(result[1][0], 370 "from2@test.com") 371 self.assertEquals(result[1][1], \ 368 372 account11.default_lang_class.new_mail_subject \ 369 373 % ("from2@test.com")) 370 self.assertEquals(result[1][ 1], "body2")374 self.assertEquals(result[1][2], "body2") 371 375 del account.hub.threadConnection 372 376 … … 415 419 self.assertEquals(len(self.comp.stream.sent), 0) 416 420 self.assertEquals(len(result), 1) 417 self.assertEquals(result[0][ 0], \421 self.assertEquals(result[0][1], \ 418 422 account11.default_lang_class.new_digest_subject \ 419 423 % (2)) 420 self.assertEquals(result[0][ 1], \424 self.assertEquals(result[0][2], \ 421 425 "body1\n----------------------------------\nbody2\n----------------------------------\n") 422 426 del account.hub.threadConnection … … 677 681 self.assertEquals(result[0].get_body(), 678 682 Lang.en.send_mail_error_no_to_header_body) 683 684 class MailSender_TestCase(unittest.TestCase): 685 def setUp(self): 686 if os.path.exists(DB_PATH): 687 os.unlink(DB_PATH) 688 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) 689 Account.createTable(ifNotExists=True) 690 PresenceAccount.createTable(ifNotExists=True) 691 MailAccount.createTable(ifNotExists=True) 692 IMAPAccount.createTable(ifNotExists=True) 693 POP3Account.createTable(ifNotExists=True) 694 del account.hub.threadConnection 695 696 def tearDown(self): 697 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) 698 POP3Account.dropTable(ifExists=True) 699 IMAPAccount.dropTable(ifExists=True) 700 MailAccount.dropTable(ifExists=True) 701 PresenceAccount.dropTable(ifExists=True) 702 Account.dropTable(ifExists=True) 703 del TheURIOpener.cachedURIs['sqlite://' + DB_URL] 704 account.hub.threadConnection.close() 705 del account.hub.threadConnection 706 if os.path.exists(DB_PATH): 707 os.unlink(DB_PATH) 708 709 def test_create_message(self): 710 mail_sender = MailSender() 711 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) 712 account11 = IMAPAccount(user_jid="test1@test.com", 713 name="account11", 714 jid="account11@jmc.test.com") 715 account11.online_action = MailAccount.RETRIEVE 716 account11.status = account.ONLINE 717 message = mail_sender.create_message(account11, ("from@test.com", 718 "subject", 719 "message body")) 720 self.assertEquals(message.get_to(), account11.user_jid) 721 del account.hub.threadConnection 722 self.assertEquals(message.get_subject(), "subject") 723 self.assertEquals(message.get_body(), "message body") 724 addresses = message.xpath_eval("add:addresses/add:address", 725 {"add": "http://jabber.org/protocol/address"}) 726 self.assertEquals(len(addresses), 1) 727 self.assertEquals(addresses[0].prop("type"), 728 "replyto") 729 self.assertEquals(addresses[0].prop("jid"), 730 "from%test.com@jmc.test.com") 679 731 680 732 class MailHandler_TestCase(unittest.TestCase): … … 928 980 suite.addTest(unittest.makeSuite(MailAccountManager_TestCase, 'test')) 929 981 suite.addTest(unittest.makeSuite(RootSendMailMessageHandler_TestCase, 'test')) 982 suite.addTest(unittest.makeSuite(MailSender_TestCase, 'test')) 930 983 suite.addTest(unittest.makeSuite(MailHandler_TestCase, 'test')) 931 984 suite.addTest(unittest.makeSuite(MailUnsubscribeHandler_TestCase, 'test'))
