コード例 #1
0
    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', date.mail_date_now())),
            '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)
コード例 #2
0
 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
コード例 #3
0
    def render_GET(self, request):
        _mail_service = self.mail_service(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 = _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
コード例 #4
0
 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
コード例 #5
0
    def render_GET(self, request):

        _mail_service = self.mail_service(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 = _mail_service.mails(unicode_query, window_size, page)

        d.addCallback(self._build_mails_response)
        d.addCallback(lambda res: respond_json_deferred(res, request))

        def error_handler(error):
            print error

        d.addErrback(error_handler)

        return NOT_DONE_YET
コード例 #6
0
    def render_GET(self, request):

        _mail_service = self.mail_service(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 = _mail_service.mails(unicode_query, window_size, page)

        d.addCallback(self._build_mails_response)
        d.addCallback(lambda res: respond_json_deferred(res, request))

        def error_handler(error):
            print error

        d.addErrback(error_handler)

        return NOT_DONE_YET
コード例 #7
0
    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', date.mail_date_now())),
            '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)
コード例 #8
0
    def render_GET(self, request):
        start = time.clock()

        def log_after_completion(result, start):
            end = time.clock()
            log.info('Needed %f ms to render response' % (end - start))
            return result

        _mail_service = self.mail_service(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 = _mail_service.mails(unicode_query, window_size, page)

        d.addCallback(self._build_mails_response)
        d.addCallback(lambda res: respond_json_deferred(res, request))
        d.addCallback(log_after_completion, start=start)

        def error_handler(error):
            print error

        d.addErrback(error_handler)

        return NOT_DONE_YET
コード例 #9
0
    def render_GET(self, request):
        start = time.clock()

        def log_after_completion(result, start):
            end = time.clock()
            log.info('Needed %f ms to render response' % (end - start))
            return result

        _mail_service = self.mail_service(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 = _mail_service.mails(unicode_query, window_size, page)

        d.addCallback(self._build_mails_response)
        d.addCallback(lambda res: respond_json_deferred(res, request))
        d.addCallback(log_after_completion, start=start)

        def error_handler(error):
            print error

        d.addErrback(error_handler)

        return NOT_DONE_YET
コード例 #10
0
 def test_to_unicode_empty_string(self):
     text = ''
     self.assertEqual(text, to_unicode(text))
コード例 #11
0
 def test_to_unicode_self(self):
     text = u'already unicode'
     self.assertEqual(text, to_unicode(text))
コード例 #12
0
 def test_to_unicode_guesses_encoding_and_unicode_text(self):
     text = 'coração'
     self.assertEqual(u'coração', to_unicode(text))
コード例 #13
0
 def test_to_unicode_empty_string(self):
     text = ''
     self.assertEqual(text, to_unicode(text))
コード例 #14
0
 def test_to_unicode_self(self):
     text = u'already unicode'
     self.assertEqual(text, to_unicode(text))
コード例 #15
0
 def test_to_unicode_guesses_encoding_and_unicode_text(self):
     text = 'coração'
     self.assertEqual(u'coração', to_unicode(text))