Skip to content

Commit 9b495a7

Browse files
Started work to allow more tolerant extraction
1 parent 3b44caa commit 9b495a7

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

extract_msg/ole_writer.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from . import constants
1919
from .constants import MSG_PATH
2020
from .enums import Color, DirectoryEntryType
21-
from .exceptions import TooManySectorsError
21+
from .exceptions import StandardViolationError, TooManySectorsError
2222
from .utils import ceilDiv, dictGetCasedKey, inputToMsgPath
2323
from olefile.olefile import OleDirectoryEntry, OleFileIO
2424
from red_black_dict_mod import RedBlackTree
@@ -804,9 +804,12 @@ def editEntry(self, path: MSG_PATH, **kwargs) -> None:
804804
# Send it to be modified using the arguments given.
805805
self.__modifyEntry(entry, **kwargs)
806806

807-
def fromMsg(self, msg: MSGFile) -> None:
807+
def fromMsg(self, msg: MSGFile, allowBadEmbed: bool = False) -> None:
808808
"""
809809
Copies the streams and stream information necessary from the MSG file.
810+
811+
:param allowBadEmbed: If true, attempts to skip steps that will fail if
812+
the embedded msg file violates standards.
810813
"""
811814
# Get the root OLE entry's CLSID.
812815
self.__rootEntry.clsid = _unClsid(msg._getOleEntry('/').clsid)
@@ -834,7 +837,14 @@ def fromMsg(self, msg: MSGFile) -> None:
834837
# Get the entry for the named properties directory and add it
835838
# immediately if it exists. If it doesn't exist, this whole
836839
# section will be skipped.
837-
self.addOleEntry('__nameid_version1.0', msg._getOleEntry('__nameid_version1.0', False), None)
840+
try:
841+
self.addOleEntry('__nameid_version1.0', msg._getOleEntry('__nameid_version1.0', False), None)
842+
except OSError as e:
843+
if str(e).startswith('Cannot add an entry'):
844+
if allowBadEmbed:
845+
return
846+
raise StandardViolationError('Embedded msg file attempted to be extracted that contains it\'s own named streams.')
847+
raise
838848

839849
# Now that we know it exists, grab all the file inside and copy
840850
# them to our root.

0 commit comments

Comments
 (0)