Enforce email check
This commit is contained in:
		
							parent
							
								
									3064dca6ca
								
							
						
					
					
						commit
						ad8c1cf115
					
				
					 2 changed files with 20 additions and 12 deletions
				
			
		| 
						 | 
					@ -45,6 +45,7 @@ class Processor(Thread):
 | 
				
			||||||
                    new_comment(msg['data'], msg.get('clientip', ''))
 | 
					                    new_comment(msg['data'], msg.get('clientip', ''))
 | 
				
			||||||
                elif msg['request'] == 'new_mail':
 | 
					                elif msg['request'] == 'new_mail':
 | 
				
			||||||
                    reply_comment_email(msg['data'])
 | 
					                    reply_comment_email(msg['data'])
 | 
				
			||||||
 | 
					                    send_delete_command(msg['data'])
 | 
				
			||||||
                elif msg['request'] == 'unsubscribe':
 | 
					                elif msg['request'] == 'unsubscribe':
 | 
				
			||||||
                    unsubscribe_reader(msg['data'])
 | 
					                    unsubscribe_reader(msg['data'])
 | 
				
			||||||
                elif msg['request'] == 'report':
 | 
					                elif msg['request'] == 'report':
 | 
				
			||||||
| 
						 | 
					@ -114,7 +115,7 @@ def new_comment(data, clientip):
 | 
				
			||||||
        client_ips[comment.id] = clientip
 | 
					        client_ips[comment.id] = clientip
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # send email
 | 
					    # send email
 | 
				
			||||||
    subject = '%s: [%d:%s]' % (site.name, comment.id, token)
 | 
					    subject = 'STACOSYS %s: [%d:%s]' % (site.name, comment.id, token)
 | 
				
			||||||
    mail(site.admin_email, subject, email_body)
 | 
					    mail(site.admin_email, subject, email_body)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Reader subscribes to further comments
 | 
					    # Reader subscribes to further comments
 | 
				
			||||||
| 
						 | 
					@ -146,7 +147,10 @@ def reply_comment_email(data):
 | 
				
			||||||
        comment = Comment.select().where(Comment.id == comment_id).get()
 | 
					        comment = Comment.select().where(Comment.id == comment_id).get()
 | 
				
			||||||
    except:
 | 
					    except:
 | 
				
			||||||
        logger.warn('unknown comment %d' % comment_id)
 | 
					        logger.warn('unknown comment %d' % comment_id)
 | 
				
			||||||
        send_delete_command(data)
 | 
					        return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if comment.published:
 | 
				
			||||||
 | 
					        logger.warn('ignore already published email. token %d' % comment_id)
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if comment.site.token != token:
 | 
					    if comment.site.token != token:
 | 
				
			||||||
| 
						 | 
					@ -157,9 +161,6 @@ def reply_comment_email(data):
 | 
				
			||||||
        logger.warn('ignore empty email')
 | 
					        logger.warn('ignore empty email')
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # accept email: request to delete
 | 
					 | 
				
			||||||
    send_delete_command(data)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # safe logic: no answer or unknown answer is a go for publishing
 | 
					    # safe logic: no answer or unknown answer is a go for publishing
 | 
				
			||||||
    if message[:2].upper() in ('NO','SP'):
 | 
					    if message[:2].upper() in ('NO','SP'):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,14 +12,21 @@ logger = logging.getLogger(__name__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def process_message(chan, method, properties, body):
 | 
					def process_message(chan, method, properties, body):
 | 
				
			||||||
    topic = method.routing_key
 | 
					 | 
				
			||||||
    data = json.loads(body)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if topic == 'mail.message':
 | 
					    try:
 | 
				
			||||||
        logger.info('new message => {}'.format(data))
 | 
					        topic = method.routing_key
 | 
				
			||||||
        processor.enqueue({'request': 'new_mail', 'data': data})
 | 
					        data = json.loads(body)
 | 
				
			||||||
    else:
 | 
					
 | 
				
			||||||
        logger.warn('unsupported message [topic={}]'.format(topic))
 | 
					        if topic == 'mail.message':
 | 
				
			||||||
 | 
					            if "STACOSYS" in data['subject']:
 | 
				
			||||||
 | 
					                logger.info('new message => {}'.format(data))
 | 
				
			||||||
 | 
					                processor.enqueue({'request': 'new_mail', 'data': data})
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                logger.info('ignore message => {}'.format(data))
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            logger.warn('unsupported message [topic={}]'.format(topic))
 | 
				
			||||||
 | 
					    except:
 | 
				
			||||||
 | 
					        logger.exception('cannot process message')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MessageConsumer(Thread):
 | 
					class MessageConsumer(Thread):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue