Skip to content

Commit

Permalink
starting to hate python3
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Mathie committed Apr 24, 2017
1 parent cca2128 commit f1d6479
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions flask_mailgun/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class MailGunAPI(object):
def __init__(self, config):
self.domain = config['MAILGUN_DOMAIN']
self.api_key = bytes(config['MAILGUN_API_KEY'])
self.api_key = config['MAILGUN_API_KEY'].encode('utf-8')
self.api_url = config.get('MAILGUN_API_URL',
MAILGUN_API_URL)
self.route = config.get('MAILGUN_ROUTE', 'uploads')
Expand Down Expand Up @@ -141,8 +141,9 @@ def verify_email(self, email):
if timestamp is None or token is None or signature is None:
raise MailGunException("Mailbox Error: credential verification failed.", "Not enough parameters")

message = '{}{}'.format(timestamp, token).encode('utf-8')
signature_calc = hmac.new(key=self.api_key,
msg=bytes('{}{}'.format(timestamp, token)),
msg=message,
digestmod=hashlib.sha256).hexdigest()
if signature != signature_calc:
raise MailGunException("Mailbox Error: credential verification failed.", "Signature doesn't match")
Expand Down
4 changes: 2 additions & 2 deletions flask_mailgun/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def attachment_decorator(f, email, filename):
"""Converts a file back into a FileStorage Object"""
with open(filename, 'r') as file:
attachment = FileStorage(stream=file,
filename=filename)
filename=filename.encode('utf-8'))
result = f(email, attachment)
return result

Expand Down Expand Up @@ -90,7 +90,7 @@ class Attachment(object):

def __init__(self, filename=None, content_type=None, data=None,
disposition=None, headers=None):
self.filename = filename
self.filename = filename.encode('utf-8')
self.content_type = content_type
self.data = data
self.disposition = disposition or 'attachment'
Expand Down
4 changes: 3 additions & 1 deletion tests/fixtures/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ def sign_email(email, mailgun):
token = random_string(50)
timestamp = int(time())
api_key = mailgun.mailgun_api.api_key
message = '{}{}'.format(timestamp, token).encode('utf-8')

signature = hmac.new(key=api_key,
msg=bytes('{}{}'.format(timestamp, token)),
msg=message,
digestmod=hashlib.sha256).hexdigest()
email.update(dict(token=token,
timestamp=timestamp,
Expand Down

0 comments on commit f1d6479

Please sign in to comment.