def __init__(self, mail_id, mailbox_name, headers=None, tags=set(), flags=set(), body=None, attachments=[]): self._mail_id = mail_id self._mailbox_name = mailbox_name self._headers = headers if headers is not None else {} self._body = to_unicode(body) self.tags = set(tags) # TODO test that asserts copy self._flags = set(flags) # TODO test that asserts copy self._attachments = attachments
def render_GET(self, request): query, window_size, page = request.args.get('q')[0], request.args.get('w')[0], request.args.get('p')[0] unicode_query = to_unicode(query) d = self._mail_service.mails(unicode_query, window_size, page) d.addCallback(lambda (mails, total): { "stats": { "total": total, }, "mails": [mail.as_dict() for mail in mails] }) d.addCallback(lambda res: respond_json_deferred(res, request)) def error_handler(error): print error d.addErrback(error_handler) return NOT_DONE_YET
def _index_mail(self, writer, mail): mdict = mail.as_dict() header = mdict['header'] tags = set(mdict.get('tags', {})) tags.add(mail.mailbox_name.lower()) index_data = { 'sender': self._empty_string_to_none(header.get('from', '')), 'subject': self._empty_string_to_none(header.get('subject', '')), 'date': self._format_utc_integer(header.get('date', '')), 'to': self._format_recipient(header, 'to'), 'cc': self._format_recipient(header, 'cc'), 'bcc': self._format_recipient(header, 'bcc'), 'tag': u','.join(unique(tags)), 'body': to_unicode(mdict.get('textPlainBody', mdict.get('body', ''))), 'ident': unicode(mdict['ident']), 'flags': unicode(','.join(unique(mail.flags))), 'raw': unicode(mail.raw) } writer.update_document(**index_data)
def test_to_unicode_empty_string(self): text = '' self.assertEqual(text, to_unicode(text))
def test_to_unicode_self(self): text = u'already unicode' self.assertEqual(text, to_unicode(text))
def test_to_unicode_guesses_encoding_and_unicode_text(self): text = 'coração' self.assertEqual(u'coração', to_unicode(text))