summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-08-07 02:03:13 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-08-07 02:03:13 -0400
commitcb869efb70ca1a7b792d2981e95baaa1beaef330 (patch)
treee5089e0592680fe6a0583e226b294443b0728228
parent49f6175e1909584d15b9d995b078eecbed9775a7 (diff)
downloadaskbot-cb869efb70ca1a7b792d2981e95baaa1beaef330.tar.gz
askbot-cb869efb70ca1a7b792d2981e95baaa1beaef330.tar.bz2
askbot-cb869efb70ca1a7b792d2981e95baaa1beaef330.zip
added optional setting ASKBOT_DEBUG_INCOMING_EMAIL
-rw-r--r--askbot/mail/__init__.py19
-rw-r--r--askbot/mail/lamson_handlers.py20
2 files changed, 37 insertions, 2 deletions
diff --git a/askbot/mail/__init__.py b/askbot/mail/__init__.py
index 26bc7efd..4013a856 100644
--- a/askbot/mail/__init__.py
+++ b/askbot/mail/__init__.py
@@ -1,6 +1,9 @@
"""functions that send email in askbot
these automatically catch email-related exceptions
"""
+from django.conf import settings as django_settings
+DEBUG_EMAIL = getattr(django_settings, 'ASKBOT_DEBUG_INCOMING_EMAIL', False)
+
import logging
import os
import re
@@ -15,7 +18,6 @@ from askbot.utils.file_utils import store_file
from askbot.utils.html import absolutize_urls
from bs4 import BeautifulSoup
from django.core import mail
-from django.conf import settings as django_settings
from django.core.exceptions import PermissionDenied
from django.forms import ValidationError
from django.utils.translation import ugettext as _
@@ -332,18 +334,33 @@ def process_parts(parts, reply_code=None, from_address=None):
body_text = ''
stored_files = list()
attachments_markdown = ''
+
+ if DEBUG_EMAIL:
+ sys.stderr.write('--- MESSAGE PARTS:\n\n')
+
for (part_type, content) in parts:
if part_type == 'attachment':
+ if DEBUG_EMAIL:
+ sys.stderr.write('REGULAR ATTACHMENT:\n')
markdown, stored_file = process_attachment(content)
stored_files.append(stored_file)
attachments_markdown += '\n\n' + markdown
elif part_type == 'body':
+ if DEBUG_EMAIL:
+ sys.stderr.write('BODY:\n')
+ sys.stderr.write(content.encode('utf-8'))
+ sys.stderr.write('\n')
body_text += '\n\n' + content.strip('\n\t ')
elif part_type == 'inline':
+ if DEBUG_EMAIL:
+ sys.stderr.write('INLINE ATTACHMENT:\n')
markdown, stored_file = process_attachment(content)
stored_files.append(stored_file)
body_text += markdown
+ if DEBUG_EMAIL:
+ sys.stderr.write('--- THE END\n')
+
#if the response separator is present -
#split the body with it, and discard the "so and so wrote:" part
if reply_code:
diff --git a/askbot/mail/lamson_handlers.py b/askbot/mail/lamson_handlers.py
index e6414b7d..812e5a28 100644
--- a/askbot/mail/lamson_handlers.py
+++ b/askbot/mail/lamson_handlers.py
@@ -1,5 +1,6 @@
-import re
import functools
+import re
+import sys
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.urlresolvers import reverse
from django.conf import settings as django_settings
@@ -12,6 +13,7 @@ from askbot.models import ReplyAddress, Group, Tag
from askbot import mail
from askbot.conf import settings as askbot_settings
from askbot.utils.html import site_url
+from askbot.mail import DEBUG_EMAIL
#we might end up needing to use something like this
#to distinguish the reply text from the quoted original message
@@ -191,6 +193,13 @@ def ASK(message, host = None, addr = None):
parts = get_parts(message)
from_address = message.From
+
+ if DEBUG_EMAIL:
+ sys.stderr.write(
+ (u'Received email from %s\n' % from_address).encode('utf-8')
+ )
+
+
#why lamson does not give it normally?
subject = message['Subject'].strip('\n\t ')
body_text, stored_files, unused = mail.process_parts(parts)
@@ -228,6 +237,11 @@ def VALIDATE_EMAIL(
todo: go a step further and
"""
reply_code = reply_address_object.address
+
+ if DEBUG_EMAIL:
+ msg = u'Received email validation from %s\n' % from_address
+ sys.stderr.write(msg.encode('utf-8'))
+
try:
content, stored_files, signature = mail.process_parts(parts, reply_code)
@@ -273,6 +287,10 @@ def PROCESS(
"""handler to process the emailed message
and make a post to askbot based on the contents of
the email, including the text body and the file attachments"""
+ if DEBUG_EMAIL:
+ sys.stderr.write(
+ (u'Received reply from %s\n' % from_address).encode('utf-8')
+ )
#1) get actual email content
# todo: factor this out into the process_reply decorator
reply_code = reply_address_object.address