From c6105f36c41b39012a2c9edae193de24b0a9a176 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Tue, 6 Nov 2012 23:02:23 -0300 Subject: code for stripping email client quote separator and the corresponding test cases for some most common email clients --- askbot/tests/email_parsing_tests.py | 48 ++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'askbot/tests/email_parsing_tests.py') diff --git a/askbot/tests/email_parsing_tests.py b/askbot/tests/email_parsing_tests.py index c1cea215..c8f3a057 100644 --- a/askbot/tests/email_parsing_tests.py +++ b/askbot/tests/email_parsing_tests.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from django.conf import settings as django_settings from askbot.skins.loaders import get_template from django.template import Context @@ -5,7 +6,7 @@ from askbot import mail from askbot import models from askbot.tests import utils -class EmailParseTests(utils.AskbotTestCase): +class EmailParsingTests(utils.AskbotTestCase): def setUp(self): self.template_name = 'email/welcome_lamson_on.html' @@ -22,29 +23,38 @@ class EmailParseTests(utils.AskbotTestCase): print '==================================================' print cleaned_body print "CLEANED BODY" - self.assertEquals(cleaned_body, self.expected_output) + self.assertEqual(cleaned_body, self.expected_output) def test_gmail_rich_text_response_stripped(self): text = u'\n\nthis is my reply!\n\nOn Wed, Oct 31, 2012 at 1:45 AM, wrote:\n\n> **\n> ' - self.assertEqual(mail.extract_body(text), 'this is my reply!') + self.assertEqual(mail.extract_reply(text), 'this is my reply!') - def test_gmail_plain_text_response_stripped(text): + def test_gmail_plain_text_response_stripped(self): text = u'\n\nthis is my another reply!\n\nOn Wed, Oct 31, 2012 at 1:45 AM, wrote:\n>\n> ' - self.assertEqual(mail.extract_body(text), 'this is my another reply!') + self.assertEqual(mail.extract_reply(text), 'this is my another reply!') def test_yahoo_mail_response_stripped(self): text = u'\n\nthis is my reply!\n\n\n\n________________________________\n From: "kp@kp-dev.askbot.com" \nTo: fadeev@rocketmail.com \nSent: Wednesday, October 31, 2012 2:41 AM\nSubject: "This is my test question"\n \n\n \n \n \n' - self.assertEqual(mail.extract_body(text), 'this is my reply!') - - def test_kmail_plain_text_response_stripped(text): - text = u'On Monday 01 October 2012 21:22:44 you wrote: \n\nSecond try, no HTML kmail does weird things.' - self.assertEqual(mail.extract_body(text), 'this is my reply!') - - -u'outlook.com (new hotmail) with RTF on \n\nSubject: "Posting a question by email." \nFrom: kp@kp-dev.askbot.com \nTo: aj_fitoria@hotmail.com \nDate: Thu, 1 Nov 2012 16:30:27 +0000' - -u'reply from hotmail without RTF \n________________________________ \n> Subject: "test with recovered signature" \n> From: kp@kp-dev.askbot.com \n> To: aj_fitoria@hotmail.com \n> Date: Thu, 1 Nov 2012 16:44:35 +0000' - -u'Reply from squirremail \n' - -""" + self.assertEqual(mail.extract_reply(text), 'this is my reply!') + + def test_kmail_plain_text_response_stripped(self): + text = u'On Monday 01 October 2012 21:22:44 you wrote: \n\nthis is my reply!' + self.assertEqual(mail.extract_reply(text), 'this is my reply!') + + def test_outlook_com_with_rtf_response_stripped(self): + text = u'outlook.com (new hotmail) with RTF on \n\nSubject: "Posting a question by email." \nFrom: kp@kp-dev.askbot.com \nTo: aj_fitoria@hotmail.com \nDate: Thu, 1 Nov 2012 16:30:27 +0000' + self.assertEqual( + mail.extract_reply(text), + 'outlook.com (new hotmail) with RTF on' + ) + self.assertEqual( + mail.extract_reply(text), + 'outlook.com (new hotmail) with RTF on' + ) + + def test_outlook_com_plain_text_response_stripped(self): + text = u'reply from hotmail without RTF \n________________________________ \n> Subject: "test with recovered signature" \n> From: kp@kp-dev.askbot.com \n> To: aj_fitoria@hotmail.com \n> Date: Thu, 1 Nov 2012 16:44:35 +0000' + self.assertEqual( + mail.extract_reply(text), + u'reply from hotmail without RTF' + ) -- cgit v1.2.3-1-g7c22