Skip to content

Commit

Permalink
Enable indexing of encrypted message content
Browse files Browse the repository at this point in the history
  • Loading branch information
BjarniRunar committed Dec 29, 2013
1 parent edc15f0 commit b0b2926
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
8 changes: 6 additions & 2 deletions mailpile/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class Rescan(Command):
SERIALIZE = 'Rescan'

def command(self):
session, config = self.session, self.session.config
session, config, idx = self.session, self.session.config, self._idx()

delay = play_nice_with_threads()
if delay > 0:
Expand All @@ -595,7 +595,11 @@ def command(self):
msg_idxs = self._choose_messages(self.args)
if msg_idxs:
session.ui.warning(_('FIXME: rescan messages: %s') % msg_idxs)
return False
for msg_idx_pos in msg_idxs:
e = Email(idx, msg_idx_pos)
session.ui.mark('Re-indexing %s' % e.msg_mid())
idx.index_email(self.session, e)
return {'messages': len(msg_idxs)}
else:
# FIXME: Need a lock here?
if 'rescan' in config._running:
Expand Down
24 changes: 21 additions & 3 deletions mailpile/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from mailpile.util import *
from mailpile.mailutils import MBX_ID_LEN, NoSuchMailboxError
from mailpile.mailutils import ExtractEmails, ExtractEmailAndName
from mailpile.mailutils import ParseMessage, HeaderPrint
from mailpile.mailutils import Email, ParseMessage, HeaderPrint
from mailpile.postinglist import GlobalPostingList
from mailpile.ui import *

Expand Down Expand Up @@ -381,7 +381,8 @@ def scan_mailbox(self, session, mailbox_idx, mailbox_fn, mailbox_opener):

# Message new or modified, let's parse it.
msg_fd = mbox.get_file(i)
msg = ParseMessage(msg_fd, pgpmime=False)
msg = ParseMessage(msg_fd,
pgpmime=session.config.prefs.index_encrypted)
msg_size = msg_fd.tell()
msg_id = self.get_msg_id(msg, msg_ptr)
if msg_id in self.MSGIDS:
Expand Down Expand Up @@ -665,11 +666,15 @@ def _loader(p):
if textpart:
# FIXME: Does this lowercase non-ASCII characters correctly?
# FIXME: What about encrypted content?
keywords.extend(re.findall(WORD_REGEXP, textpart.lower()))
# FIXME: Do this better.
if ('-----BEGIN PGP' in textpart and
'-----END PGP' in textpart):
keywords.append('pgp:has')
if '-----BEGIN PGP ENCRYPTED' in textpart:
keywords.append('pgp-encrypted-text:has')
else:
keywords.append('pgp-signed-text:has')
keywords.extend(re.findall(WORD_REGEXP, textpart.lower()))
for extract in plugins.get_text_kw_extractors():
keywords.extend(extract(self, msg, ctype,
lambda: textpart))
Expand All @@ -681,6 +686,19 @@ def _loader(p):
keywords.extend(extract(self, msg, ctype, att, part,
lambda: _loader(part)))

if (session.config.prefs.index_encrypted and
'pgp-encrypted-text:has' in keywords):
e = Email(None, -1)
e.msg_parsed = msg
e.msg_info = ['' for i in range(0, 11)]
tree = e.get_message_tree(want=['text_parts'])
for text in [t['data'] for t in tree['text_parts']]:
print 'OOO, INLINE PGP, PARSING, WOOT'
keywords.extend(re.findall(WORD_REGEXP, text.lower()))
for extract in plugins.get_text_kw_extractors():
keywords.extend(extract(self, msg, 'text/plain',
lambda: text))

keywords.append('%s:id' % msg_id)
keywords.extend(re.findall(WORD_REGEXP,
self.hdr(msg, 'subject').lower()))
Expand Down

0 comments on commit b0b2926

Please sign in to comment.