handle errors

This commit is contained in:
Romain Bignon 2010-11-09 20:56:57 +01:00
commit f4747ca9d7

View file

@ -207,8 +207,8 @@ class Monboob(ReplApplication):
def process(self): def process(self):
try: try:
for backend, message in self.weboob.do('iter_unread_messages'): for backend, message in self.weboob.do('iter_unread_messages'):
self.send_email(backend, message) if self.send_email(backend, message):
backend.set_message_read(message) backend.set_message_read(message)
except CallErrors, e: except CallErrors, e:
for backend, error, backtrace in e.errors: for backend, error, backtrace in e.errors:
print >>sys.stderr, u'Error(%s): %s' % (backend.name, error) print >>sys.stderr, u'Error(%s): %s' % (backend.name, error)
@ -298,10 +298,16 @@ class Monboob(ReplApplication):
p.stdin.close() p.stdin.close()
if p.wait() != 0: if p.wait() != 0:
self.logger.error('Unable to deliver mail: %s' % p.stdout.read().strip()) self.logger.error('Unable to deliver mail: %s' % p.stdout.read().strip())
return False
else: else:
# Send the message via SMTP to localhost:25 # Send the message via SMTP to localhost:25
smtp = SMTP(self.config.get('smtp')) try:
smtp.sendmail(sender, recipient, msg.as_string()) smtp = SMTP(self.config.get('smtp'))
smtp.quit() smtp.sendmail(sender, recipient, msg.as_string())
except Exception, e:
self.logger.error('Unable to deliver mail: %s' % e)
return False
else:
smtp.quit()
return msg['Message-Id'] return True