Commit f7762145 authored by Romain Bignon's avatar Romain Bignon

send messages returned by ICapMessagesReply.post_reply()

parent 5fb975a3
......@@ -98,7 +98,8 @@ class Monboob(ConsoleApplication):
return 1
thread_id, msg_id = id.rsplit('.', 1)
backend.post_reply(thread_id, msg_id, title, content)
for m in backend.post_reply(thread_id, msg_id, title, content):
self.send_email(backend, m)
@ConsoleApplication.command("run daemon")
def command_run(self):
......@@ -46,17 +46,12 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesReply, ICapDating):
# Private
_browser = None
_profiles_walker = None
_queue_messages = None
def __getattr__(self, name):
if name == 'browser':
if not self._browser:
self._browser = AdopteUnMec(self.config['username'], self.config['password'])
return self._browser
if name == 'queue_messages':
if self._queue_messages is None:
self._queue_messages = []
return self._queue_messages
raise AttributeError, name
def iter_messages(self, thread=None):
......@@ -64,11 +59,6 @@ def iter_messages(self, thread=None):
yield message
def iter_new_messages(self, thread=None):
for message in self.queue_messages:
if not thread or message.get_thread_id() == thread:
yield message
self.queue_messages = []
for message in self._iter_messages(thread, True):
yield message
......@@ -101,26 +91,25 @@ def _iter_messages(self, thread, only_new):
def post_reply(self, thread_id, reply_id, title, message):
# Enqueue current awaiting messages
for mail in self._iter_messages(thread_id, True):
yield mail
with self.browser:
try:, message)
except AdopteCantPostMail, e:
mail = Message(thread_id,
yield Message(thread_id,
'Unable to send mail to %s' % thread_id,
content=u'Unable to send message to %s:\n\t%s\n\n---\n%s' (thread_id, unicode(e), message),
# Enqueue my messages and every next messages.
mails = self.browser.get_thread_mails(thread_id)
my_name = self.browser.get_my_name()
for mail in mails:
yield mail
if mail.get_from() == my_name:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment