new Message attribute 'is_html'

This commit is contained in:
Romain Bignon 2010-04-12 13:45:33 +02:00
commit 2f297530a8
3 changed files with 16 additions and 7 deletions

View file

@ -119,19 +119,25 @@ class Monboob(ConsoleApplication):
date = time.strftime('%a, %d %b %Y %H:%M:%S +0000', mail.get_date().timetuple()) date = time.strftime('%a, %d %b %Y %H:%M:%S +0000', mail.get_date().timetuple())
msg_id = u'<%s.%s@%s>' % (backend.name, mail.get_full_id(), domain) msg_id = u'<%s.%s@%s>' % (backend.name, mail.get_full_id(), domain)
if self.config.get('html'): if self.config.get('html') and mail.is_html:
body = mail.get_content() body = mail.get_content()
content_type = 'html' content_type = 'html'
else: else:
body = html2text(mail.get_content()) if mail.is_html:
body = html2text(mail.get_content())
else:
body = mail.get_content()
content_type = 'plain' content_type = 'plain'
if mail.get_signature(): if mail.get_signature():
if self.config.get('html'): if self.config.get('html') and mail.is_html:
body += u'<p>-- <br />%s</p>' % mail.get_signature() body += u'<p>-- <br />%s</p>' % mail.get_signature()
else: else:
body += u'\n\n-- \n' body += u'\n\n-- \n'
body += html2text(mail.get_signature()) if mail.is_html:
body += html2text(mail.get_signature())
else:
body += mail.get_signature()
# Header class is smart enough to try US-ASCII, then the charset we # Header class is smart enough to try US-ASCII, then the charset we
# provide, then fall back to UTF-8. # provide, then fall back to UTF-8.

View file

@ -87,7 +87,8 @@ class DLFPBackend(Backend, ICapMessages, ICapMessagesReply):
thread.author, thread.author,
article.datetime, article.datetime,
content=''.join([thread.body, thread.part2]), content=''.join([thread.body, thread.part2]),
signature='URL: %s' % article.url) signature='URL: %s' % article.url,
is_html=True)
for comment in thread.iter_all_comments(): for comment in thread.iter_all_comments():
if not comment.id in seen[article.id]['comments']: if not comment.id in seen[article.id]['comments']:
@ -103,7 +104,8 @@ class DLFPBackend(Backend, ICapMessages, ICapMessagesReply):
comment.date, comment.date,
comment.reply_id, comment.reply_id,
comment.body, comment.body,
'Score: %d' % comment.score) 'Score: %d' % comment.score,
is_html=True)
self.storage.set('seen', what, seen) self.storage.set('seen', what, seen)
self.storage.save() self.storage.save()

View file

@ -24,7 +24,7 @@ import time
from .cap import ICap from .cap import ICap
class Message: class Message:
def __init__(self, thread_id, _id, title, sender, date=None, reply_id=u'', content=u'', signature=u''): def __init__(self, thread_id, _id, title, sender, date=None, reply_id=u'', content=u'', signature=u'', is_html=False):
self.thread_id = unicode(thread_id) self.thread_id = unicode(thread_id)
self.id = unicode(_id) self.id = unicode(_id)
self.reply_id = unicode(reply_id) self.reply_id = unicode(reply_id)
@ -37,6 +37,7 @@ class Message:
if date is None: if date is None:
date = datetime.datetime.utcnow() date = datetime.datetime.utcnow()
self.date = date self.date = date
self.is_html = is_html
def get_date_int(self): def get_date_int(self):
return int(time.strftime('%Y%m%d%H%M%S', self.get_date().timetuple())) return int(time.strftime('%Y%m%d%H%M%S', self.get_date().timetuple()))