diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-05-24 15:56:10 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-05-24 15:56:10 -0400 |
commit | 88ca6ed037d3d7f2c36fe38532b718e432487b46 (patch) | |
tree | c4620a69af235576eafb8e16374a04986a628926 | |
parent | eee3ec8b7d78a04f4b3f8a56c7f73797318c9dd0 (diff) | |
download | askbot-88ca6ed037d3d7f2c36fe38532b718e432487b46.tar.gz askbot-88ca6ed037d3d7f2c36fe38532b718e432487b46.tar.bz2 askbot-88ca6ed037d3d7f2c36fe38532b718e432487b46.zip |
added signature extraction to processing of all responses
-rw-r--r-- | askbot/lamson_handlers.py | 24 | ||||
-rw-r--r-- | askbot/models/__init__.py | 9 | ||||
-rw-r--r-- | 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 += '<p style="font-size:8px;color:#aaa'> + reply_code + '</p>' + return subject_line, template.render(Context(update_data)) #todo: action @@ -2730,8 +2736,8 @@ def send_instant_notifications_about_activity_in_post( #TODO check user reputation headers = mail.thread_headers(post, origin_post, update_activity.activity_type) reply_to_with_comment = None#only used for questions in some cases + reply_addr = "noreply" if askbot_settings.REPLY_BY_EMAIL: - reply_addr = "noreply" if user.reputation >= 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': |