mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Properly encode path components used to construct API URLs
Resolves #144 and similar potential issues
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime
|
||||
from email.utils import encode_rfc2231
|
||||
from six.moves.urllib.parse import quote_plus
|
||||
from six.moves.urllib.parse import quote
|
||||
|
||||
from requests import Request
|
||||
|
||||
@@ -82,12 +82,12 @@ class MailgunPayload(RequestsPayload):
|
||||
"Either provide valid `from_email`, "
|
||||
"or set `message.esp_extra={'sender_domain': 'example.com'}`",
|
||||
backend=self.backend, email_message=self.message, payload=self)
|
||||
if '/' in self.sender_domain or '%' in self.sender_domain:
|
||||
if '/' in self.sender_domain or '%2f' in self.sender_domain.lower():
|
||||
# Mailgun returns a cryptic 200-OK "Mailgun Magnificent API" response
|
||||
# if '/' (or even %-encoded '/') confuses it about the API endpoint.
|
||||
raise AnymailError("Invalid sender domain '%s'" % self.sender_domain,
|
||||
raise AnymailError("Invalid '/' in sender domain '%s'" % self.sender_domain,
|
||||
backend=self.backend, email_message=self.message, payload=self)
|
||||
return "%s/messages" % quote_plus(self.sender_domain)
|
||||
return "%s/messages" % quote(self.sender_domain, safe='')
|
||||
|
||||
def get_request_params(self, api_url):
|
||||
params = super(MailgunPayload, self).get_request_params(api_url)
|
||||
|
||||
Reference in New Issue
Block a user