From: Magnus Hagander Date: Fri, 1 Apr 2022 14:00:50 +0000 (+0200) Subject: Fix bytes/str handling of secondary text parts in messages X-Git-Url: http://git.postgresql.org/gitweb/edit?a=commitdiff_plain;h=55f23a7b991d5ce3661e8685c4bd667efe09b10d;p=pgarchives.git Fix bytes/str handling of secondary text parts in messages This was broken in the python 2->3 migration, but is apparently an uncommon enough case that it wasn't properly spotted until now. Reported and pointers in the right direction from Andres Freund --- diff --git a/loader/lib/parser.py b/loader/lib/parser.py index 171f197..8b9c87a 100644 --- a/loader/lib/parser.py +++ b/loader/lib/parser.py @@ -384,15 +384,17 @@ class ArchivesParser(object): # However, this will also *always* catch the MIME part added # by majordomo with the footer. So if that one is present, # we need to explicitly exclude it again. + # For this reason, we need it in both bytes and string format, so we can apply the regexp try: b = container.get_payload(decode=True) + s = self.get_payload_as_unicode(container) except AssertionError: # Badly encoded data can throw an exception here, where the python # libraries fail to handle it and enters a cannot-happen path. # In which case we just ignore this attachment. return - if isinstance(b, str) and not self._re_footer.match(b): + if isinstance(b, bytes) and isinstance(s, str) and not self._re_footer.match(s): # We know there is no name for this one self.attachments.append((None, container.get_content_type(), b)) return