[go: nahoru, domu]

Skip to content

Commit

Permalink
olevba: add a try.. finally clause around monkey patch of email lib
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieuxyz committed Sep 3, 2020
1 parent a7fcbcc commit 13a7373
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions oletools/olevba.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@
import os
import logging
import struct
from copy import copy
from io import BytesIO, StringIO
import math
import zipfile
Expand Down Expand Up @@ -2945,15 +2944,17 @@ def open_mht(self, data):
# TODO: quick and dirty fix: insert a standard line with MIME-Version header?
# monkeypatch email to fix issue #32:
# allow header lines without ":"
oldHeaderRE = copy(email.feedparser.headerRE)
oldHeaderRE = email.feedparser.headerRE
loosyHeaderRE = re.compile(r'^(From |[\041-\071\073-\176]{1,}:?|[\t ])')
email.feedparser.headerRE = loosyHeaderRE
if PYTHON2:
mhtml = email.message_from_string(stripped_data)
else:
# on Python 3, need to use message_from_bytes instead:
mhtml = email.message_from_bytes(stripped_data)
email.feedparser.headerRE = oldHeaderRE
try:
if PYTHON2:
mhtml = email.message_from_string(stripped_data)
else:
# on Python 3, need to use message_from_bytes instead:
mhtml = email.message_from_bytes(stripped_data)
finally:
email.feedparser.headerRE = oldHeaderRE
# find all the attached files:
for part in mhtml.walk():
content_type = part.get_content_type() # always returns a value
Expand Down

0 comments on commit 13a7373

Please sign in to comment.