From 88ca6ed037d3d7f2c36fe38532b718e432487b46 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Thu, 24 May 2012 15:56:10 -0400 Subject: added signature extraction to processing of all responses --- askbot/lamson_handlers.py | 24 +++++------------------- askbot/models/__init__.py | 9 ++++++++- askbot/models/reply_by_email.py | 27 +++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/askbot/lamson_handlers.py b/askbot/lamson_handlers.py index d7dc7e13..3b6aefd7 100644 --- a/askbot/lamson_handlers.py +++ b/askbot/lamson_handlers.py @@ -221,27 +221,13 @@ def VALIDATE_EMAIL( todo: go a step further and """ content, stored_files = mail.process_parts(parts) + #save the signature and mark email as valid reply_code = reply_address_object.address + user = reply_address_object.user if reply_code in content: - - #extract the signature - tail = list() - for line in reversed(content.splitlines()): - #scan backwards from the end until the magic line - if reply_code in line: - break - tail.insert(0, line) - - #strip off the leading quoted lines, there could be one or two - #also strip empty lines - while tail[0].startswith('>') or tail[0].strip() == '': - tail.pop(0) - - signature = '\n'.join(tail) - - #save the signature and mark email as valid - user = reply_address_object.user - user.email_signature = signature + user.email_signature = reply_address_object.extract_user_signature( + content + ) user.email_isvalid = True user.save() diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index d7b838d5..6e662b24 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -2578,6 +2578,7 @@ def format_instant_notification_email( from_user = None, post = None, reply_with_comment_address = None, + reply_code = None, update_type = None, template = None, ): @@ -2694,6 +2695,11 @@ def format_instant_notification_email( 'reply_separator': reply_separator } subject_line = _('"%(title)s"') % {'title': origin_post.thread.title} + + content = template.render(Context(update_data)) + if can_reply: + content += '

= askbot_settings.MIN_REP_TO_POST_BY_EMAIL: reply_args = { @@ -2771,6 +2777,7 @@ def send_instant_notifications_about_activity_in_post( from_user = update_activity.user, post = post, reply_with_comment_address = reply_to_with_comment, + reply_code = reply_addr, update_type = update_type, template = get_template('instant_notification.html') ) diff --git a/askbot/models/reply_by_email.py b/askbot/models/reply_by_email.py index 786b38a5..3940709d 100644 --- a/askbot/models/reply_by_email.py +++ b/askbot/models/reply_by_email.py @@ -74,6 +74,25 @@ class ReplyAddress(models.Model): """True if was used""" return self.used_at != None + def extract_user_signature(self, text): + if self.address in text: + #extract the signature + tail = list() + for line in reversed(text.splitlines()): + #scan backwards from the end until the magic line + if self.address in line: + break + tail.insert(0, line) + + #strip off the leading quoted lines, there could be one or two + #also strip empty lines + while tail[0].startswith('>') or tail[0].strip() == '': + tail.pop(0) + + return '\n'.join(tail) + else: + return '' + def edit_post(self, parts): """edits the created post upon repeated response to the same address""" @@ -95,6 +114,14 @@ class ReplyAddress(models.Model): result = None #todo: delete stored files if this function fails content, stored_files = mail.process_parts(parts) + + if self.address in content: + new_signature = self.extract_user_signature(content) + if new_signature != self.user.email_signature: + self.user.email_signature = new_signature + self.user.email_isvalid = True + self.user.save() + content = self.user.strip_email_signature(content) if self.post.post_type == 'answer': -- cgit v1.2.3-1-g7c22