summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2015-05-26 14:17:18 +0200
committerThomas Bruederli <bruederli@kolabsys.com>2015-05-26 14:17:18 +0200
commita1a7c5fdb86c513b43deb2496f0d1c604ec52f14 (patch)
tree35e5c91f64d3a03c70abdd3f10ab97f95991f773
parent0c072d69d677fa7cdad65af563994f6a0098003f (diff)
downloadpykolab-a1a7c5fdb86c513b43deb2496f0d1c604ec52f14.tar.gz
Limit number of retries to send an update notification; fix the smtplib.SMTP.sendmail() mock to also return success status
-rw-r--r--tests/unit/test-012-wallace_invitationpolicy.py1
-rw-r--r--wallace/module_invitationpolicy.py10
2 files changed, 9 insertions, 2 deletions
diff --git a/tests/unit/test-012-wallace_invitationpolicy.py b/tests/unit/test-012-wallace_invitationpolicy.py
index b612a52..189f3c6 100644
--- a/tests/unit/test-012-wallace_invitationpolicy.py
+++ b/tests/unit/test-012-wallace_invitationpolicy.py
@@ -104,6 +104,7 @@ class TestWallaceInvitationpolicy(unittest.TestCase):
def _mock_smtp_sendmail(self, from_addr, to_addr, message, mail_options=None, rcpt_options=None):
self.smtplog.append((from_addr, to_addr, message))
+ return True
def test_001_itip_events_from_message(self):
itips = pykolab.itip.events_from_message(message_from_string(itip_multipart))
diff --git a/wallace/module_invitationpolicy.py b/wallace/module_invitationpolicy.py
index edd23a9..f401b0d 100644
--- a/wallace/module_invitationpolicy.py
+++ b/wallace/module_invitationpolicy.py
@@ -1209,15 +1209,21 @@ def send_update_notification(object, receiving_user, old=None, reply=True):
smtp.set_debuglevel(True)
success = False
+ retries = 5
- while not success:
+ while not success and retries > 0:
try:
success = smtp.sendmail(orgemail, receiving_user['mail'], msg.as_string())
log.debug(_("Sent update notification to %r: %r") % (receiving_user['mail'], success), level=8)
smtp.quit()
+ break
except Exception, e:
log.error(_("SMTP sendmail error: %r") % (e))
- time.sleep(10)
+
+ time.sleep(10)
+ retries -= 1
+
+ return success
def send_cancel_notification(object, receiving_user, deleted=False):