Skip to content

Commit e300fbe

Browse files
Attempt to fix #417
1 parent 3b4fdea commit e300fbe

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
**v0.48.6**
2+
* [[TeamMsgExtractor #417](https://github.com/TeamMsgExtractor/msg-extractor/issues/417)] Fixed issues with `openMsg` where some corrupted MSG files could end up throwing an uncaught exception and leaving the file handle open.
3+
14
**v0.48.5**
25
* [[TeamMsgExtractor #414](https://github.com/TeamMsgExtractor/msg-extractor/issues/414)] Fixed typo in `message_signed_base.py`.
36

extract_msg/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2828

2929
__author__ = 'Destiny Peterson & Matthew Walker'
30-
__date__ = '2024-04-03'
31-
__version__ = '0.48.5'
30+
__date__ = '2024-07-06'
31+
__version__ = '0.48.6'
3232

3333
__all__ = [
3434
# Modules:

extract_msg/open_msg.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ def openMsg(path, **kwargs) -> MSGFile:
8989

9090
msg = MSGFile(path, **kwargs)
9191

92+
# Protect against corrupt MSG files.
93+
try:
94+
ct = msg.classType
95+
except:
96+
# All exceptions here mean we NEED to close the handle.
97+
msg.close()
98+
raise
99+
92100
# Restore the option in the kwargs so we don't have to worry about it.
93101
kwargs['delayAttachments'] = delayAttachments
94102

@@ -99,14 +107,14 @@ def openMsg(path, **kwargs) -> MSGFile:
99107
# other file types (like doc, ppt, etc.) might open but not return a class
100108
# type. If the stream is not found, classType returns None, which has no
101109
# lower function. So let's make sure we got a good return first.
102-
if not msg.classType:
110+
if not cy:
103111
if kwargs.get('strict', True):
104112
raise InvalidFileFormatError('File was confirmed to be an olefile, but was not an MSG file.')
105113
else:
106114
# If strict mode is off, we'll just return an MSGFile anyways.
107115
logger.critical('Received file that was an olefile but was not an MSG file. Returning MSGFile anyways because strict mode is off.')
108116
return msg
109-
classType = msg.classType.lower()
117+
classType = ct.lower()
110118
# Put the message class first as it is most common.
111119
if classType.startswith('ipm.note') or classType.startswith('report'):
112120
msg.close()
@@ -159,7 +167,6 @@ def openMsg(path, **kwargs) -> MSGFile:
159167
return msg
160168
elif kwargs.get('strict', True):
161169
# Because we are closing it, we need to store it in a variable first.
162-
ct = msg.classType
163170
msg.close()
164171
# Now we need to figure out exactly what we are going to be reporting to
165172
# the user.

0 commit comments

Comments
 (0)