summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVasil Vangelovski <vvangelovski@gmail.com>2012-01-18 23:13:58 +0100
committerVasil Vangelovski <vvangelovski@gmail.com>2012-01-18 23:13:58 +0100
commitb8e6e0f93ff70f7d846604969c38c54697ad448a (patch)
tree4bb6c41a63af8779bfa3aa21e8d930127c6196ad
parentdef1cb19113690a1dac93b42d457ec4279dd61f3 (diff)
downloadaskbot-b8e6e0f93ff70f7d846604969c38c54697ad448a.tar.gz
askbot-b8e6e0f93ff70f7d846604969c38c54697ad448a.tar.bz2
askbot-b8e6e0f93ff70f7d846604969c38c54697ad448a.zip
Separating quoted text in reply by email feature
-rw-r--r--askbot/models/reply_by_email.py31
-rw-r--r--askbot/tests/reply_by_email_tests.py5
2 files changed, 34 insertions, 2 deletions
diff --git a/askbot/models/reply_by_email.py b/askbot/models/reply_by_email.py
index 8ec43974..43d5905d 100644
--- a/askbot/models/reply_by_email.py
+++ b/askbot/models/reply_by_email.py
@@ -57,6 +57,36 @@ class ReplyAddress(models.Model):
return result
+#we might end up needing to use something like this
+#to distinguish the reply text from the quoted original message
+"""
+def _strip_message_qoute(message_text):
+ import re
+ result = message_text
+ pattern = "(?P<qoute>" + \
+ "On ([a-zA-Z0-9, :/<>@\.\"\[\]]* wrote:.*)|" + \
+ "From: [\w@ \.]* \[mailto:[\w\.]*@[\w\.]*\].*|" + \
+ "From: [\w@ \.]*(\n|\r\n)+Sent: [\*\w@ \.,:/]*(\n|\r\n)+To:.*(\n|\r\n)+.*|" + \
+ "[- ]*Forwarded by [\w@ \.,:/]*.*|" + \
+ "From: [\w@ \.<>\-]*(\n|\r\n)To: [\w@ \.<>\-]*(\n|\r\n)Date: [\w@ \.<>\-:,]*\n.*|" + \
+ "From: [\w@ \.<>\-]*(\n|\r\n)To: [\w@ \.<>\-]*(\n|\r\n)Sent: [\*\w@ \.,:/]*(\n|\r\n).*|" + \
+ "From: [\w@ \.<>\-]*(\n|\r\n)To: [\w@ \.<>\-]*(\n|\r\n)Subject:.*|" + \
+ "(-| )*Original Message(-| )*.*)"
+ groups = re.search(pattern, email_text, re.IGNORECASE + re.DOTALL)
+ qoute = None
+ if not groups is None:
+ if groups.groupdict().has_key("qoute"):
+ qoute = groups.groupdict()["qoute"]
+ if qoute:
+ result = reslut.split(qoute)[0]
+ #if the last line contains an email message remove that one too
+ lines = result.splitlines(True)
+ if re.search(r'[\w\.]*@[\w\.]*\].*', lines[-1]):
+ result = '\n'.join(lines[:-1])
+ return result
+"""
+
+
#TODO move this function to a more appropriate module
def process_reply_email(message, address, host):
@@ -70,6 +100,7 @@ def process_reply_email(message, address, host):
the original notification you received at the end of your reply.")
else:
reply_part = parts[0]
+ reply_part = '\n'.join(reply_part.splitlines(True)[:-3])
reply_address.create_reply(reply_part.strip())
except ReplyAddress.DoesNotExist:
error = _("You were replying to an email address\
diff --git a/askbot/tests/reply_by_email_tests.py b/askbot/tests/reply_by_email_tests.py
index 4efa440b..68aeda35 100644
--- a/askbot/tests/reply_by_email_tests.py
+++ b/askbot/tests/reply_by_email_tests.py
@@ -43,10 +43,11 @@ class EmailProcessingTests(AskbotTestCase):
def test_process_correct_answer_comment(self):
addr = ReplyAddress.objects.create_new( self.answer, self.u1).address
separator = _("======= Reply above this line. ====-=-=")
- msg = MockMessage("This is a test reply \n%s\nlorem ipsum"%(separator), "user1@domain.com")
+ msg = MockMessage("This is a test reply \n\nOn such and such someone\
+ wrote something \n\n%s\nlorem ipsum "%(separator), "user1@domain.com")
process_reply_email(msg, addr, '')
self.assertEquals(self.answer.comments.count(), 2)
- self.assertEquals(self.answer.comments.all().order_by('-pk')[0].text, "This is a test reply")
+ self.assertEquals(self.answer.comments.all().order_by('-pk')[0].text.strip(), "This is a test reply")