From dcae29a053866613612cfc5a74c8b3c5f3f88e8e Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Tue, 1 May 2012 21:43:46 -0300 Subject: added group email address, enabled by default --- askbot/lamson_handlers.py | 23 +++++++++++++++++++---- askbot/utils/mail.py | 6 +++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/askbot/lamson_handlers.py b/askbot/lamson_handlers.py index f121af06..5c86bc98 100644 --- a/askbot/lamson_handlers.py +++ b/askbot/lamson_handlers.py @@ -4,7 +4,7 @@ from lamson.server import Relay from django.utils.translation import ugettext as _ from django.core.files.uploadedfile import SimpleUploadedFile from django.conf import settings -from askbot.models import ReplyAddress +from askbot.models import ReplyAddress, Tag from askbot.utils import mail @@ -113,13 +113,28 @@ def get_parts(message): parts.append((part_type, part_content)) return parts -@route('ask@(host)') +@route('(addr)@(host)') @stateless -def ASK(message, host = None): +def ASK(message, host = None, addr = None): parts = get_parts(message) from_address = message.From subject = message['Subject']#why lamson does not give it normally? - mail.process_emailed_question(from_address, subject, parts) + if addr == 'ask': + mail.process_emailed_question(from_address, subject, parts) + else: + try: + group_tag = Tag.group_tags.get( + deleted = False, + name = addr + ) + mail.process_emailed_question( + from_address, subject, parts, tags = [group_tag.name, ] + ) + except Tag.DoesNotExist: + #do nothing because this handler will match all emails + return + except Tag.MultipleObjectsReturned: + return @route('reply-(address)@(host)', address='.+') @stateless diff --git a/askbot/utils/mail.py b/askbot/utils/mail.py index 744c54de..2d4d80b0 100644 --- a/askbot/utils/mail.py +++ b/askbot/utils/mail.py @@ -251,7 +251,7 @@ def process_parts(parts): return body_markdown.strip(), stored_files -def process_emailed_question(from_address, subject, parts): +def process_emailed_question(from_address, subject, parts, tags = None): """posts question received by email or bounces the message""" #a bunch of imports here, to avoid potential circular import issues from askbot.forms import AskByEmailForm @@ -275,6 +275,10 @@ def process_emailed_question(from_address, subject, parts): title = form.cleaned_data['title'] body_text = form.cleaned_data['body_text'] + #defect - here we might get "too many tags" issue + if tags: + tagnames += ' ' + ' '.join(tags) + user.post_question( title = title, tags = tagnames, -- cgit v1.2.3-1-g7c22