|
18 | 18 | from . import constants |
19 | 19 | from .constants import MSG_PATH |
20 | 20 | from .enums import Color, DirectoryEntryType |
21 | | -from .exceptions import TooManySectorsError |
| 21 | +from .exceptions import StandardViolationError, TooManySectorsError |
22 | 22 | from .utils import ceilDiv, dictGetCasedKey, inputToMsgPath |
23 | 23 | from olefile.olefile import OleDirectoryEntry, OleFileIO |
24 | 24 | from red_black_dict_mod import RedBlackTree |
@@ -804,9 +804,12 @@ def editEntry(self, path: MSG_PATH, **kwargs) -> None: |
804 | 804 | # Send it to be modified using the arguments given. |
805 | 805 | self.__modifyEntry(entry, **kwargs) |
806 | 806 |
|
807 | | - def fromMsg(self, msg: MSGFile) -> None: |
| 807 | + def fromMsg(self, msg: MSGFile, allowBadEmbed: bool = False) -> None: |
808 | 808 | """ |
809 | 809 | 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. |
810 | 813 | """ |
811 | 814 | # Get the root OLE entry's CLSID. |
812 | 815 | self.__rootEntry.clsid = _unClsid(msg._getOleEntry('/').clsid) |
@@ -834,7 +837,14 @@ def fromMsg(self, msg: MSGFile) -> None: |
834 | 837 | # Get the entry for the named properties directory and add it |
835 | 838 | # immediately if it exists. If it doesn't exist, this whole |
836 | 839 | # 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 |
838 | 848 |
|
839 | 849 | # Now that we know it exists, grab all the file inside and copy |
840 | 850 | # them to our root. |
|
0 commit comments