summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdolfo Fitoria <adolfo.fitoria@gmail.com>2012-09-18 09:03:01 -0600
committerAdolfo Fitoria <adolfo.fitoria@gmail.com>2012-09-18 09:03:01 -0600
commit715aea125ab7a9c0686929395f36d54f6434a899 (patch)
treea58e979ad06a1073da4d72f72f85604dc5fcb694
parent1766d1741969d51e1ebe76765c3a68939f29999e (diff)
downloadaskbot-715aea125ab7a9c0686929395f36d54f6434a899.tar.gz
askbot-715aea125ab7a9c0686929395f36d54f6434a899.tar.bz2
askbot-715aea125ab7a9c0686929395f36d54f6434a899.zip
buggy commit, error parsing signature from html emails
-rw-r--r--askbot/mail/__init__.py11
-rw-r--r--askbot/tests/reply_by_email_tests.py153
2 files changed, 133 insertions, 31 deletions
diff --git a/askbot/mail/__init__.py b/askbot/mail/__init__.py
index 739b147e..2629aa47 100644
--- a/askbot/mail/__init__.py
+++ b/askbot/mail/__init__.py
@@ -158,8 +158,8 @@ def mail_moderators(
try:
msg = mail.EmailMessage(
- subject_line,
- body_text,
+ subject_line,
+ body_text,
from_email,
recipient_list,
headers = headers or {}
@@ -287,10 +287,13 @@ def process_attachment(attachment):
def extract_user_signature(text, reply_code):
"""extracts email signature as text trailing
the reply code"""
- if reply_code in text:
+ #FIXME: buggy in html code
+ striped_text = clean_html_email(text.replace('<br>', '\n'))
+ #striped_text = strip_tags(text.replace('<br>', '\n'))
+ if reply_code in striped_text:
#extract the signature
tail = list()
- for line in reversed(text.splitlines()):
+ for line in reversed(striped_text.splitlines()):
#scan backwards from the end until the magic line
if reply_code in line:
break
diff --git a/askbot/tests/reply_by_email_tests.py b/askbot/tests/reply_by_email_tests.py
index 9248fc50..3336a3af 100644
--- a/askbot/tests/reply_by_email_tests.py
+++ b/askbot/tests/reply_by_email_tests.py
@@ -1,6 +1,7 @@
from django.utils.translation import ugettext as _
from askbot.models import ReplyAddress
from askbot.mail.lamson_handlers import PROCESS, VALIDATE_EMAIL, get_parts
+from askbot.mail import extract_user_signature
from askbot import const
@@ -146,7 +147,6 @@ class EmailSignatureDetectionTests(AskbotTestCase):
def setUp(self):
self.u1 = self.create_user('user1', status = 'a')
self.u2 = self.create_user('user2', status = 'a')
- self.u3 = self.create_user('user3', status = 'a')
def test_detect_signature_in_response(self):
question = self.post_question(user = self.u1)
@@ -194,31 +194,130 @@ class EmailSignatureDetectionTests(AskbotTestCase):
signature = self.reload_object(self.u2).email_signature
self.assertEqual(signature, 'Yours Truly')
- def test_detect_signature_in_html_welcome_response(self):
- reply_token = ReplyAddress.objects.create_new(
- user = self.u3,
- reply_action = 'validate_email'
- )
- self.u3.email_signature = ''
- self.u3.save()
- signature = 'Yours Truly'
-
- msg = MockMessage(
- 'some text',
- self.u3.email,
- signature = signature,
- response_code = reply_token.address
- )
-
- html_message = '<b>some text</b>' + signature
-
- msg.attach_alternative(html_message, 'text/html')
- VALIDATE_EMAIL(
- msg,
- address = reply_token.address
- )
-
- signature = self.reload_object(self.u3).email_signature
- self.assertEqual(signature, 'Yours Truly')
+class SignatureDetectionTests(AskbotTestCase):
+ '''Simple test to detect signature from text'''
+ def setUp(self):
+ self.u1 = self.create_user('user1', status = 'a')
+ self.u1.email_signature = '''--\nFoo Bar'''
+ self.u1.save()
+ self.plain_text = '''welcome!
+
+On Mon, Sep 17, 2012 at 9:01 AM, <foo@bar.com> wrote:
+
+> **
+> Welcome to Askbot!
+>
+> Important: *Please reply* to this message, without editing it. We need
+> this to determine your email signature and that the email address is valid
+> and was typed correctly.
+>
+> Until we receive the response from you, you will not be able ask or answer
+> questions on askbot by email.
+> ------------------------------
+>
+> Sincerely,
+> askbot Administrator
+>
+> ofqssnfqkvlw
+>
+
+
+
+--
+Foo Bar
+'''
+ self.html = '''welcome!<br><br><div class=3D"gmail_quote">On Mon, Sep 17, 2012 at 9:01 AM,=
+ <span dir=3D"ltr">&lt;<a href=3D"mailto:foo@bar.com" target=
+=3D"_blank">foo@bar.com</a>&gt;</span> wrote:<br><blockquote c=
+lass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;=
+padding-left:1ex">
+<u></u>=20
+
+
+ =20
+ =20
+ =20
+ =20
+
+ =20
+ =20
+
+ =20
+
+ =20
+
+<div>
+<table cellpadding=3D"0" cellspacing=3D"0" border=3D"0">
+ <tbody><tr>
+ <td>
+ <table border=3D"0" align=3D"center" cellspacing=3D"0" cellpadding=3D=
+"0" style=3D"background-color:#e7e8e8">
+ <tbody><tr height=3D"20">
+ <td valign=3D"top">=20
+ </td>
+ </tr>
+ <tr>
+ <td valign=3D"top">=20
+ <table border=3D"0" align=3D"center" cellspacing=3D"0" cellpadd=
+ing=3D"0" style=3D"background-color:#fff" width=3D"80%">
+ <tbody><tr>
+ <td valign=3D"top">=20
+ <table border=3D"0" align=3D"center" cellspacing=3D"0" ce=
+llpadding=3D"0" width=3D"80%">
+ <tbody><tr>
+ <td valign=3D"top">=20
+ <h1>Welcome to KnowledgePoint!</h1>
+ </td>
+ </tr>
+ <tr>
+ <td valign=3D"top">=20
+ =20
+
+<p>
+ Important: <em>Please reply</em> to this message, without editing it. W=
+e need this to determine your email signature and that the email address is=
+ valid and was typed correctly.
+</p>
+<p>
+ Until we receive the response from you, you will not be able ask or ans=
+wer questions on KnowledgePoint by email.
+</p>
+
+ </td>
+ </tr>
+ <tr>
+ <td valign=3D"top">=20
+ <hr>
+ =20
+<p>Sincerely,<br>KnowledgePoint Administrator</p>
+<p style=3D"font-size:8px;color:#aaa;margin-bottom:0px">ofqssnfqkvlw</p>
+
+ </td>
+ </tr>
+ </tbody></table>
+ </td>
+ </tr>
+ </tbody></table>
+ </td>
+ </tr>
+ <tr height=3D"20">
+ <td valign=3D"top">=20
+ </td>
+ </tr>
+ </tbody></table>
+ </td>
+ </tr>
+ </tbody></table> =20
+</div>
+</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br> Foo Bar
+<br>'''
+
+ def test_plain_text_parse(self):
+ signature = extract_user_signature(self.plain_text, 'ofqssnfqkvlw')
+ self.assertEquals(signature, self.u1.email_signature)
+
+ def test_html_parse(self):
+ signature = extract_user_signature(self.html, 'ofqssnfqkvlw')
+ self.assertEquals(signature, self.u1.email_signature)