diff options
author | Bruno Wagner <bwagner@thoughtworks.com> | 2014-10-15 16:37:13 +0200 |
---|---|---|
committer | Bruno Wagner <bwagner@thoughtworks.com> | 2014-10-15 16:37:23 +0200 |
commit | c526bab6a5cc91182481d2565b0e762a66572bef (patch) | |
tree | 2d518b533a6b5fe4411e2257d0a76019a046b16d | |
parent | 3ec8dbee135fe67ede676f3c0a882b1ff4fb9701 (diff) |
#101 Raw is now the default search field
-rw-r--r-- | service/pixelated/adapter/mail.py | 58 | ||||
-rw-r--r-- | service/pixelated/adapter/search.py | 8 |
2 files changed, 31 insertions, 35 deletions
diff --git a/service/pixelated/adapter/mail.py b/service/pixelated/adapter/mail.py index cd345f13..513a07d8 100644 --- a/service/pixelated/adapter/mail.py +++ b/service/pixelated/adapter/mail.py @@ -43,6 +43,31 @@ class Mail: def date(self): return self.headers['Date'] + @property + def status(self): + return Status.from_flags(self.flags) + + @property + def flags(self): + return self.fdoc.content.get('flags') + + @property + def _mime_multipart(self): + if self._mime: + return self._mime + mime = MIMEMultipart() + for key, value in self.headers.items(): + mime[str(key)] = str(value) + mime.attach(MIMEText(self.body, 'plain')) + self._mime = mime + return mime + + def raw(self): + return self._mime_multipart.as_string() + + def _get_chash(self): + return sha256.SHA256(self.raw()).hexdigest() + def as_dict(self): return { 'header': {k.lower(): v for k, v in self.headers.items()}, @@ -66,30 +91,9 @@ class InputMail(Mail): self._chash = None @property - def _mime_multipart(self): - if self._mime: - return self._mime - mime = MIMEMultipart() - for key, value in self.headers.items(): - mime[str(key)] = str(value) - mime.attach(MIMEText(self.body, 'plain')) - self._mime = mime - return mime - - @property def ident(self): return self._get_chash() - def _raw(self): - if not self._raw_message: - self._raw_message = self._mime_multipart.as_string() - return self._raw_message - - def _get_chash(self): - if not self._chash: - self._chash = sha256.SHA256(self._raw()).hexdigest() - return self._chash - def _get_for_save(self, next_uid, mailbox): docs = [self._fdoc(next_uid, mailbox), self._hdoc()] docs.extend([m for m in self._cdocs()]) @@ -103,7 +107,7 @@ class InputMail(Mail): fd[fields.MBOX_KEY] = mailbox fd[fields.UID_KEY] = next_uid fd[fields.CONTENT_HASH_KEY] = self._get_chash() - fd[fields.SIZE_KEY] = len(self._raw()) + fd[fields.SIZE_KEY] = len(self.raw()) fd[fields.MULTIPART_KEY] = True fd[fields.RECENT_KEY] = True fd[fields.TYPE_KEY] = fields.TYPE_FLAGS_VAL @@ -192,9 +196,7 @@ class PixelatedMail(Mail): for header in ['From', 'Subject']: _headers[header] = self.hdoc.content['headers'].get(header) - _headers['Date'] = self._get_date() - return _headers def _get_date(self): @@ -204,14 +206,6 @@ class PixelatedMail(Mail): return dateparser.parse(date).isoformat() @property - def status(self): - return Status.from_flags(self.flags) - - @property - def flags(self): - return self.fdoc.content.get('flags') - - @property def security_casing(self): return {} diff --git a/service/pixelated/adapter/search.py b/service/pixelated/adapter/search.py index 859497bb..72e714e9 100644 --- a/service/pixelated/adapter/search.py +++ b/service/pixelated/adapter/search.py @@ -75,7 +75,8 @@ class SearchEngine(object): subject=TEXT(stored=False), body=TEXT(stored=False), tag=KEYWORD(stored=False, commas=True), - flags=KEYWORD(stored=False, commas=True)) + flags=KEYWORD(stored=False, commas=True), + raw=TEXT(stored=False)) def _create_index(self): return whoosh.index.create_in(self.INDEX_FOLDER, self._mail_schema(), indexname='mails') @@ -98,7 +99,8 @@ class SearchEngine(object): 'tag': u','.join(tags), 'body': unicode(mdict['body']), 'ident': unicode(mdict['ident']), - 'flags': unicode(','.join(mail.flags)) + 'flags': unicode(','.join(mail.flags)), + 'raw': unicode(mail.raw) } writer.update_document(**index_data) @@ -110,7 +112,7 @@ class SearchEngine(object): def _search_with_options(self, options, query): with self._index.searcher() as searcher: - query = QueryParser('body', self._index.schema).parse(query) + query = QueryParser('raw', self._index.schema).parse(query) results = searcher.search(query, **options) return results |