From f42cd7d32dfc1598b1c3d207cdddf0abbc2dac55 Mon Sep 17 00:00:00 2001 From: Arnaud Fribault Date: Thu, 10 May 2012 09:21:57 +0200 Subject: [PATCH 1/8] verify-sender.json is obsolete. Removed sender verification step --- djrill/mail/backends/djrill.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/djrill/mail/backends/djrill.py b/djrill/mail/backends/djrill.py index 6c9e3a8..e6c75a0 100644 --- a/djrill/mail/backends/djrill.py +++ b/djrill/mail/backends/djrill.py @@ -34,19 +34,20 @@ class DjrillBackend(BaseEmailBackend): def open(self, sender): """ """ - self.connection = None - - valid_sender = requests.post( - self.api_verify, data={"key": self.api_key, "email": sender}) - - if valid_sender.status_code == 200: - data = json.loads(valid_sender.content) - if data["is_enabled"]: - self.connection = True - return True - else: - if not self.fail_silently: - raise + self.connection = True + # self.connection = None + # + # valid_sender = requests.post( + # self.api_verify, data={"key": self.api_key, "email": sender}) + # + # if valid_sender.status_code == 200: + # data = json.loads(valid_sender.content) + # if data["is_enabled"]: + # self.connection = True + # return True + # else: + # if not self.fail_silently: + # raise def send_messages(self, email_messages): if not email_messages: From 99a9bd2c6ea7d833b107b3993d2493a08cdd9908 Mon Sep 17 00:00:00 2001 From: Arnaud Fribault Date: Wed, 16 May 2012 16:02:12 +0200 Subject: [PATCH 2/8] Raise a valid exception if failedSilently is false --- djrill/mail/backends/djrill.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/djrill/mail/backends/djrill.py b/djrill/mail/backends/djrill.py index e6c75a0..08476d4 100644 --- a/djrill/mail/backends/djrill.py +++ b/djrill/mail/backends/djrill.py @@ -6,7 +6,21 @@ from django.utils import simplejson as json import requests +class DjrillBackendHTTPError(Exception): + """An exception that will turn into an HTTP error response.""" + def __init__(self, status_code, log_message=None, *args): + self.status_code = status_code + self.log_message = log_message + self.args = args + def __str__(self): + message = "DjrillBackendHTTP %d: %s" % ( + self.status_code, httplib.responses[self.status_code]) + if self.log_message: + return message + " (" + (self.log_message % self.args) + ")" + else: + return message + class DjrillBackend(BaseEmailBackend): """ Mandrill API Email Backend @@ -92,7 +106,7 @@ class DjrillBackend(BaseEmailBackend): if djrill_it.status_code != 200: if not self.fail_silently: - raise + raise DjrillBackendHTTPError(status_code=djrill_it.status_code, "Failed to send a message to %s, from %s" % (self.recipients, self.sender)) return False return True From 0394df47a0d28a1217ad491c1fedd07df15e5002 Mon Sep 17 00:00:00 2001 From: Arnaud Fribault Date: Wed, 16 May 2012 16:43:01 +0200 Subject: [PATCH 3/8] Fixes error message formatting --- djrill/mail/backends/djrill.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djrill/mail/backends/djrill.py b/djrill/mail/backends/djrill.py index 08476d4..7843a4f 100644 --- a/djrill/mail/backends/djrill.py +++ b/djrill/mail/backends/djrill.py @@ -106,7 +106,7 @@ class DjrillBackend(BaseEmailBackend): if djrill_it.status_code != 200: if not self.fail_silently: - raise DjrillBackendHTTPError(status_code=djrill_it.status_code, "Failed to send a message to %s, from %s" % (self.recipients, self.sender)) + raise DjrillBackendHTTPError(status_code=djrill_it.status_code, log_message="Failed to send a message to %s, from %s" % (self.recipients, self.sender)) return False return True From 9ee197ac71460bcd210a7a4619ddfc44e4fb46e8 Mon Sep 17 00:00:00 2001 From: medmunds Date: Thu, 12 Jul 2012 17:30:16 -0700 Subject: [PATCH 4/8] Backend: fix exception messaging --- djrill/mail/backends/djrill.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/djrill/mail/backends/djrill.py b/djrill/mail/backends/djrill.py index 7843a4f..3b2e951 100644 --- a/djrill/mail/backends/djrill.py +++ b/djrill/mail/backends/djrill.py @@ -7,20 +7,20 @@ from django.utils import simplejson as json import requests class DjrillBackendHTTPError(Exception): - """An exception that will turn into an HTTP error response.""" - def __init__(self, status_code, log_message=None, *args): - self.status_code = status_code - self.log_message = log_message - self.args = args + """An exception that will turn into an HTTP error response.""" + def __init__(self, status_code, log_message=None): + super(DjrillBackendHTTPError, self).__init__() + self.status_code = status_code + self.log_message = log_message - def __str__(self): - message = "DjrillBackendHTTP %d: %s" % ( - self.status_code, httplib.responses[self.status_code]) - if self.log_message: - return message + " (" + (self.log_message % self.args) + ")" - else: + def __str__(self): + message = "DjrillBackendHTTP %d" % self.status_code + if self.log_message: + return message + " " + self.log_message + else: return message - + + class DjrillBackend(BaseEmailBackend): """ Mandrill API Email Backend From 5b359880346b4fe5e14a77fa587cae975cfca89f Mon Sep 17 00:00:00 2001 From: Arnaud Fribault Date: Wed, 16 May 2012 16:02:12 +0200 Subject: [PATCH 5/8] Raise a valid exception if failedSilently is false --- djrill/mail/backends/djrill.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/djrill/mail/backends/djrill.py b/djrill/mail/backends/djrill.py index 70cb6ab..cffb3e1 100644 --- a/djrill/mail/backends/djrill.py +++ b/djrill/mail/backends/djrill.py @@ -6,7 +6,21 @@ from django.utils import simplejson as json import requests +class DjrillBackendHTTPError(Exception): + """An exception that will turn into an HTTP error response.""" + def __init__(self, status_code, log_message=None, *args): + self.status_code = status_code + self.log_message = log_message + self.args = args + def __str__(self): + message = "DjrillBackendHTTP %d: %s" % ( + self.status_code, httplib.responses[self.status_code]) + if self.log_message: + return message + " (" + (self.log_message % self.args) + ")" + else: + return message + class DjrillBackend(BaseEmailBackend): """ Mandrill API Email Backend @@ -89,7 +103,7 @@ class DjrillBackend(BaseEmailBackend): if djrill_it.status_code != 200: if not self.fail_silently: - raise + raise DjrillBackendHTTPError(status_code=djrill_it.status_code, "Failed to send a message to %s, from %s" % (self.recipients, self.sender)) return False return True From 96b5733e9d0aacc20feab04378aef1ff8f11be15 Mon Sep 17 00:00:00 2001 From: Arnaud Fribault Date: Wed, 16 May 2012 16:43:01 +0200 Subject: [PATCH 6/8] Fixes error message formatting --- djrill/mail/backends/djrill.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djrill/mail/backends/djrill.py b/djrill/mail/backends/djrill.py index cffb3e1..53c7794 100644 --- a/djrill/mail/backends/djrill.py +++ b/djrill/mail/backends/djrill.py @@ -103,7 +103,7 @@ class DjrillBackend(BaseEmailBackend): if djrill_it.status_code != 200: if not self.fail_silently: - raise DjrillBackendHTTPError(status_code=djrill_it.status_code, "Failed to send a message to %s, from %s" % (self.recipients, self.sender)) + raise DjrillBackendHTTPError(status_code=djrill_it.status_code, log_message="Failed to send a message to %s, from %s" % (self.recipients, self.sender)) return False return True From c1e577c6f53954381be9b44e15cdfdb44f9bf746 Mon Sep 17 00:00:00 2001 From: medmunds Date: Thu, 12 Jul 2012 17:30:16 -0700 Subject: [PATCH 7/8] Backend: fix exception messaging --- djrill/mail/backends/djrill.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/djrill/mail/backends/djrill.py b/djrill/mail/backends/djrill.py index 53c7794..fb26bd5 100644 --- a/djrill/mail/backends/djrill.py +++ b/djrill/mail/backends/djrill.py @@ -7,20 +7,20 @@ from django.utils import simplejson as json import requests class DjrillBackendHTTPError(Exception): - """An exception that will turn into an HTTP error response.""" - def __init__(self, status_code, log_message=None, *args): - self.status_code = status_code - self.log_message = log_message - self.args = args + """An exception that will turn into an HTTP error response.""" + def __init__(self, status_code, log_message=None): + super(DjrillBackendHTTPError, self).__init__() + self.status_code = status_code + self.log_message = log_message - def __str__(self): - message = "DjrillBackendHTTP %d: %s" % ( - self.status_code, httplib.responses[self.status_code]) - if self.log_message: - return message + " (" + (self.log_message % self.args) + ")" - else: + def __str__(self): + message = "DjrillBackendHTTP %d" % self.status_code + if self.log_message: + return message + " " + self.log_message + else: return message - + + class DjrillBackend(BaseEmailBackend): """ Mandrill API Email Backend From 5602fc5314dc8355b75fc16ec8b8c3795ce220c1 Mon Sep 17 00:00:00 2001 From: medmunds Date: Wed, 31 Oct 2012 11:51:47 -0700 Subject: [PATCH 8/8] Backend: Remove obsolete api_verify altogether. Remove connection management (remnant of sender verification, and didn't match Django email backend signatures). Reformat inherited patch to 80-char line width. Consistent int return type from send_messages. --- djrill/mail/backends/djrill.py | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/djrill/mail/backends/djrill.py b/djrill/mail/backends/djrill.py index fb26bd5..d9997cf 100644 --- a/djrill/mail/backends/djrill.py +++ b/djrill/mail/backends/djrill.py @@ -33,7 +33,6 @@ class DjrillBackend(BaseEmailBackend): super(DjrillBackend, self).__init__(**kwargs) self.api_key = getattr(settings, "MANDRILL_API_KEY", None) self.api_url = getattr(settings, "MANDRILL_API_URL", None) - self.connection = None if not self.api_key: raise ImproperlyConfigured("You have not set your mandrill api key " @@ -43,35 +42,14 @@ class DjrillBackend(BaseEmailBackend): "url to your settings.py") self.api_action = self.api_url + "/messages/send.json" - self.api_verify = self.api_url + "/users/ping.json" - - def open(self, sender): - """ - """ - self.connection = None - - valid_sender = requests.post( - self.api_verify, data={"key": self.api_key}) - - if valid_sender.status_code == 200: - self.connection = True - return True - else: - if not self.fail_silently: - raise def send_messages(self, email_messages): if not email_messages: - return + return 0 num_sent = 0 for message in email_messages: - self.open(message.from_email) - if not self.connection: - return - sent = self._send(message) - if sent: num_sent += 1 @@ -103,7 +81,10 @@ class DjrillBackend(BaseEmailBackend): if djrill_it.status_code != 200: if not self.fail_silently: - raise DjrillBackendHTTPError(status_code=djrill_it.status_code, log_message="Failed to send a message to %s, from %s" % (self.recipients, self.sender)) + raise DjrillBackendHTTPError( + status_code=djrill_it.status_code, + log_message="Failed to send a message to %s, from %s" % + (self.recipients, self.sender)) return False return True