Skip to content

Commit

Permalink
allow message search for html-only messages
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingDiver committed Oct 10, 2018
1 parent 2f39911 commit d6434dc
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions BetterEmail.indigoPlugin/Contents/Server Plugin/IMAPServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,28 @@ def checkMsgs(self):
try:
if message.is_multipart():
self.logger.threaddebug(self.device.name + u": checkMsgs: Decoding multipart message")

# look for text/plain or text/html, with text/plain preferred (break after finding plain type)

use_part = None
for part in message.walk():
type = part.get_content_type()
self.logger.threaddebug('\tfound type: %s' % type)
if type == "text/plain":
use_part = part
break
elif type == "text/html":
use_part = part

else:
raise Exception("No plain text segment found in multipart message")
if not use_part:
raise Exception("No searchable text segment found in multipart message")

charset = part.get_content_charset()
charset = use_part.get_content_charset()
if charset:
messageText = part.get_payload(decode=True).decode(charset)
messageText = use_part.get_payload(decode=True).decode(charset)
else:
messageText = part.get_payload()
messageText = use_part.get_payload()
else:
self.logger.threaddebug('checkMsgs: Decoding simple message')
charset = message.get_content_charset()
Expand Down

0 comments on commit d6434dc

Please sign in to comment.