summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-04-24 03:58:34 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-04-24 03:58:34 -0400
commit75050366da87747b7f7ec6a0c3213966c3bc8059 (patch)
tree671a5f0e48a5d241b42271b885e304adefdb9745
parentef2d4fc774f986e99d4443b651ae68961710e65c (diff)
downloadaskbot-75050366da87747b7f7ec6a0c3213966c3bc8059.tar.gz
askbot-75050366da87747b7f7ec6a0c3213966c3bc8059.tar.bz2
askbot-75050366da87747b7f7ec6a0c3213966c3bc8059.zip
improved handling of user signature extraction
-rw-r--r--askbot/mail/__init__.py20
-rw-r--r--askbot/mail/lamson_handlers.py22
2 files changed, 21 insertions, 21 deletions
diff --git a/askbot/mail/__init__.py b/askbot/mail/__init__.py
index 826e2b89..37d10f8b 100644
--- a/askbot/mail/__init__.py
+++ b/askbot/mail/__init__.py
@@ -298,6 +298,8 @@ def extract_user_signature(text, reply_code):
"""extracts email signature as text trailing
the reply code"""
stripped_text = strip_tags(text)
+
+ signature = ''
if reply_code in stripped_text:
#extract the signature
tail = list()
@@ -314,13 +316,10 @@ def extract_user_signature(text, reply_code):
signature = '\n'.join(tail)
- #patch signature to a sentinel value if it is truly empty, because we
- #cannot allow empty signature field, which indicates no
- #signature at all and in that case we ask user to create one
- if signature == '':
- signature = 'empty signature'
- else:
- return None
+ #patch signature to a sentinel value if it is truly empty, because we
+ #cannot allow empty signature field, which indicates no
+ #signature at all and in that case we ask user to create one
+ return signature or 'empty signature'
def process_parts(parts, reply_code=None):
@@ -388,12 +387,15 @@ def process_emailed_question(
stripped_body_text = user.strip_email_signature(body_text)
- signature_not_detected = (stripped_body_text == body_text)
+ #note that signature '' means it is unset and 'empty signature' is a sentinel
+ #because there is no other way to indicate unset signature without adding
+ #another field to the user model
+ signature_changed = (stripped_body_text == body_text and user.email_signature)
need_new_signature = (
user.email_isvalid is False or
user.email_signature == '' or
- signature_not_detected
+ signature_changed
)
#ask for signature response if user's email has not been
diff --git a/askbot/mail/lamson_handlers.py b/askbot/mail/lamson_handlers.py
index 5008918e..728203e6 100644
--- a/askbot/mail/lamson_handlers.py
+++ b/askbot/mail/lamson_handlers.py
@@ -278,21 +278,19 @@ def PROCESS(
#2) process body text and email signature
user = reply_address_object.user
- if signature is not None:#if there, then it was stripped
- if signature != user.email_signature:
- user.email_signature = signature
- else:#try to strip signature
- stripped_body_text = user.strip_email_signature(body_text)
- #todo: add test cases for emails without the signature
- if stripped_body_text == body_text and user.email_signature:
- #todo: send an email asking to update the signature
- raise ValueError('email signature changed or unknown')
- body_text = stripped_body_text
-
- #3) validate email address and save user
+
+ if signature != user.email_signature:
+ user.email_signature = signature
+
+ #3) validate email address and save user along with maybe new signature
user.email_isvalid = True
user.save()#todo: actually, saving is not necessary, if nothing changed
+ #here we might be in danger of chomping off some of the
+ #message is body text ends with a legitimate text coinciding with
+ #the user's email signature
+ body_text = user.strip_email_signature(body_text)
+
#4) actually make an edit in the forum
robj = reply_address_object
add_post_actions = ('post_comment', 'post_answer', 'auto_answer_or_comment')