new parameter -t to 'post' command

This commit is contained in:
Romain Bignon 2011-02-24 21:37:35 +01:00
commit 2a964247e6

View file

@ -34,15 +34,15 @@ class MessageFormatter(IFormatter):
pass pass
def format_dict(self, item): def format_dict(self, item):
result = u'%sTitle:%s %s\n' % (ReplApplication.BOLD, result = u'%sTitle:%s %s\n' % (ReplApplication.BOLD,
ReplApplication.NC, item['title']) ReplApplication.NC, item['title'])
result += u'%sDate:%s %s\n' % (ReplApplication.BOLD, result += u'%sDate:%s %s\n' % (ReplApplication.BOLD,
ReplApplication.NC, item['date']) ReplApplication.NC, item['date'])
result += u'%sFrom:%s %s\n' % (ReplApplication.BOLD, result += u'%sFrom:%s %s\n' % (ReplApplication.BOLD,
ReplApplication.NC, item['sender']) ReplApplication.NC, item['sender'])
if item['receivers']: if item['receivers']:
result += u'%sTo:%s %s\n' % (ReplApplication.BOLD, result += u'%sTo:%s %s\n' % (ReplApplication.BOLD,
ReplApplication.NC, ReplApplication.NC,
', '.join(item['receivers'])) ', '.join(item['receivers']))
if item['flags'] & Message.IS_HTML: if item['flags'] & Message.IS_HTML:
@ -76,13 +76,13 @@ class MessagesListFormatter(IFormatter):
unread = ' ' unread = ' '
if self.interactive: if self.interactive:
backend = item['id'].split('@', 1)[1] backend = item['id'].split('@', 1)[1]
result = u'%s* (%d) %s %s (%s)%s' % (ReplApplication.BOLD, result = u'%s* (%d) %s %s (%s)%s' % (ReplApplication.BOLD,
self.count, unread, self.count, unread,
item['title'], backend, item['title'], backend,
ReplApplication.NC) ReplApplication.NC)
else: else:
result = u'%s* (%s) %s %s%s' % (ReplApplication.BOLD, item['id'], result = u'%s* (%s) %s %s%s' % (ReplApplication.BOLD, item['id'],
unread, item['title'], unread, item['title'],
ReplApplication.NC) ReplApplication.NC)
if item['date']: if item['date']:
result += u'\n %s' % item['date'] result += u'\n %s' % item['date']
@ -117,23 +117,24 @@ class MessagesListFormatter(IFormatter):
flags += ']' flags += ']'
if self.interactive: if self.interactive:
result = u'%s%s* (%d)%s %s <%s> %s (%s)\n' % (depth * ' ', result = u'%s%s* (%d)%s %s <%s> %s (%s)\n' % (depth * ' ',
ReplApplication.BOLD, ReplApplication.BOLD,
self.count, self.count,
ReplApplication.NC, ReplApplication.NC,
flags, flags,
message.sender, message.sender,
message.title, message.title,
backend) backend)
else: else:
result = u'%s%s* (%s@%s)%s %s <%s> %s\n' % (depth * ' ', result = u'%s%s* (%s.%s@%s)%s %s <%s> %s\n' % (depth * ' ',
ReplApplication.BOLD, ReplApplication.BOLD,
message.id, message.thread.id,
backend, message.id,
flags, backend,
ReplApplication.NC, flags,
message.sender, ReplApplication.NC,
message.title) message.sender,
message.title)
if message.children: if message.children:
if depth >= 0: if depth >= 0:
depth += 1 depth += 1
@ -159,11 +160,14 @@ class Boobmsg(ReplApplication):
def add_application_options(self, group): def add_application_options(self, group):
group.add_option('-e', '--skip-empty', action='store_true', group.add_option('-e', '--skip-empty', action='store_true',
help='Don\'t send messages with an empty body.') help='Don\'t send messages with an empty body.')
group.add_option('--to_file', action='store', group.add_option('--to_file', action='store',
help='File to export result', type="string", help='File to export result', type="string",
dest="filename") dest="filename")
group.add_option('-t', '--title', action='store',
help='For the "post" command, set a title to message',
type='string', dest='title')
def load_default_backends(self): def load_default_backends(self):
self.load_backends(ICapMessages, storage=self.create_storage()) self.load_backends(ICapMessages, storage=self.create_storage())
@ -180,8 +184,8 @@ class Boobmsg(ReplApplication):
backend_name = None backend_name = None
results = {} results = {}
for backend, field in self.do('get_account_status', for backend, field in self.do('get_account_status',
backends=backend_name, backends=backend_name,
caps=ICapAccount): caps=ICapAccount):
if backend.name in results: if backend.name in results:
results[backend.name].append(field) results[backend.name].append(field)
@ -220,7 +224,7 @@ class Boobmsg(ReplApplication):
return return
for receiver in receivers.strip().split(','): for receiver in receivers.strip().split(','):
receiver, backend_name = self.parse_id(receiver.strip(), receiver, backend_name = self.parse_id(receiver.strip(),
unique_backend=True) unique_backend=True)
if not backend_name and len(self.enabled_backends) > 1: if not backend_name and len(self.enabled_backends) > 1:
self.logger.warning(u'No backend specified for receiver "%s": message will be sent with all the ' self.logger.warning(u'No backend specified for receiver "%s": message will be sent with all the '
@ -229,15 +233,17 @@ class Boobmsg(ReplApplication):
if '.' in receiver: if '.' in receiver:
# It's a reply # It's a reply
thread_id, parent_id = receiver.split('.', 1) thread_id, parent_id = receiver.rsplit('.', 1)
else: else:
# It's an original message # It's an original message
thread_id = receiver thread_id = receiver
parent_id = None parent_id = None
thread = Thread(thread_id) thread = Thread(thread_id)
message = Message(thread, message = Message(thread,
0, 0,
title=self.options.title,
parent=Message(thread, parent_id) if parent_id else None, parent=Message(thread, parent_id) if parent_id else None,
content=text) content=text)
@ -285,9 +291,9 @@ class Boobmsg(ReplApplication):
self.threads.append(thread) self.threads.append(thread)
self.format(thread) self.format(thread)
self.flush() self.flush()
def do_export_thread(self, arg): def do_export_thread(self, arg):
""" """
export_thread export_thread
Export a thread Export a thread