PonyConf/conversations/utils.py

32 lines
743 B
Python
Raw Normal View History

2016-06-13 00:00:30 +00:00
from django.conf import settings
2016-06-14 19:39:04 +00:00
from django.utils.crypto import get_random_string
import hashlib
2016-06-13 00:00:30 +00:00
2016-06-12 21:39:04 +00:00
def hexdigest_sha256(*args):
r = hashlib.sha256()
for arg in args:
r.update(str(arg).encode('utf-8'))
return r.hexdigest()
def get_reply_addr(message_id, dest):
if not hasattr(settings, 'REPLY_EMAIL'):
return []
addr = settings.REPLY_EMAIL
pos = addr.find('@')
name = addr[:pos]
domain = addr[pos:]
2016-06-14 19:39:04 +00:00
key = hexdigest_sha256(settings.SECRET_KEY, message_id, dest.pk)[0:12]
return ['%s+%s%s%s%s' % (name, dest.profile.email_token, message_id, key, domain)]
2016-06-12 21:39:04 +00:00
2016-06-14 19:39:04 +00:00
def generate_message_token():
return get_random_string(length=60, allowed_chars='abcdefghijklmnopqrstuvwxyz0123456789')