Complete publishing process by email

pull/6/head
Yax 10 years ago
parent 8c1366ffaa
commit 2f48340547

@ -35,8 +35,8 @@ class Processor(Thread):
msg = queue.get() msg = queue.get()
if msg['request'] == 'new_comment': if msg['request'] == 'new_comment':
new_comment(msg['data']) new_comment(msg['data'])
#elif msg['type'] == 'reply_comment_email': elif msg['request'] == 'new_mail':
# reply_comment_email(req['From'], req['Subject'], req['Body']) reply_comment_email(msg['data'])
#elif req['type'] == 'unsubscribe': #elif req['type'] == 'unsubscribe':
# unsubscribe_reader(req['email'], req['article']) # unsubscribe_reader(req['email'], req['article'])
else: else:
@ -87,7 +87,7 @@ def new_comment(data):
# send email # send email
# TODO subject should embed a key # TODO subject should embed a key
subject = '%s: [%d]' % (site.name, comment.id) subject = '%s: [%s:%d]' % (site.name, token, comment.id)
mail(site.admin_email, subject, email_body) mail(site.admin_email, subject, email_body)
# TODO support subscription # TODO support subscription
@ -98,50 +98,57 @@ def new_comment(data):
logger.debug("new comment processed ") logger.debug("new comment processed ")
def reply_comment_email(from_email, subject, message): def reply_comment_email(data):
try:
m = re.search('\[(\d+)\-(\w+)\]', subject) email_address = data['from']
branch_name = m.group(1) subject = data['subject']
article = m.group(2) message = ''
for part in data['parts']:
message = decode_best_effort(message) if part['content-type'] == 'text/plain':
message = part['content']
# safe logic: no answer or unknown answer is a go for publishing break
if message[:2].upper() == 'NO':
logger.info('discard comment: %s' % branch_name) m = re.search('\[(\w+)\:(\d+)\]', subject)
email_body = get_template('drop_comment').render(original=message) token = m.group(1)
mail(pecosys.get_config('post', 'from_email'), comment_id = int(m.group(2))
pecosys.get_config('post', 'to_email'),
'Re: ' + subject, email_body) # retrieve site and comment rows
else: comment = Comment.select().where(Comment.id == comment_id).get()
if pecosys.get_config("git", "disabled"): if comment.site.token != token:
logger.debug("GIT usage disabled (debug mode)") logger.warn('ignore corrupted email')
else: return
git.merge(branch_name)
if pecosys.get_config("git", "remote"): # TODO validate chardet decoding is no more needed
git.push() #message = decode_best_effort(message)
logger.info('commit comment: %s' % branch_name) if not message:
logger.warn('ignore empty email')
# send approval confirmation email to admin return
email_body = get_template('approve_comment').render(original=message)
mail(pecosys.get_config('post', 'from_email'), # safe logic: no answer or unknown answer is a go for publishing
pecosys.get_config('post', 'to_email'), if message[:2].upper() == 'NO':
'Re: ' + subject, email_body) logger.info('discard comment: %d' % comment_id)
comment.delete_instance()
# notify reader once comment is published email_body = get_template('drop_comment').render(original=message)
reader_email, article_url = get_email_metadata(message) mail(email_address, 'Re: ' + subject, email_body)
if reader_email: else:
notify_reader(reader_email, article_url) # update Comment row
comment.published = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# notify subscribers every time a new comment is published comment.save()
notify_subscribers(article)
logger.info('commit comment: %d' % comment_id)
if pecosys.get_config("git", "disabled"):
logger.debug("GIT usage disabled (debug mode)") # send approval confirmation email to admin
else: email_body = get_template('approve_comment').render(original=message)
git.branch("-D", branch_name) mail(email_address, 'Re: ' + subject, email_body)
except:
logger.exception("new email failure") # TODO manage subscriptions
# notify reader once comment is published
#reader_email, article_url = get_email_metadata(message)
#if reader_email:
# notify_reader(reader_email, article_url)
# notify subscribers every time a new comment is published
#notify_subscribers(article)
def get_email_metadata(message): def get_email_metadata(message):

Loading…
Cancel
Save