Skip to content

Commit

Permalink
Merge pull request #418 from TeamMsgExtractor/next-release
Browse files Browse the repository at this point in the history
Version 0.48.6
  • Loading branch information
TheElementalOfDestruction authored Jul 6, 2024
2 parents 6b1f0e0 + c06e566 commit 480d6f7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
**v0.48.6**
* [[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.

**v0.48.5**
* [[TeamMsgExtractor #414](https://github.com/TeamMsgExtractor/msg-extractor/issues/414)] Fixed typo in `message_signed_base.py`.

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ your access to the newest major version of extract-msg.
.. |License: GPL v3| image:: https://img.shields.io/badge/License-GPLv3-blue.svg
:target: LICENSE.txt

.. |PyPI3| image:: https://img.shields.io/badge/pypi-0.48.5-blue.svg
:target: https://pypi.org/project/extract-msg/0.48.5/
.. |PyPI3| image:: https://img.shields.io/badge/pypi-0.48.6-blue.svg
:target: https://pypi.org/project/extract-msg/0.48.6/

.. |PyPI2| image:: https://img.shields.io/badge/python-3.8+-brightgreen.svg
:target: https://www.python.org/downloads/release/python-3810/
Expand Down
4 changes: 2 additions & 2 deletions extract_msg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__author__ = 'Destiny Peterson & Matthew Walker'
__date__ = '2024-04-03'
__version__ = '0.48.5'
__date__ = '2024-07-06'
__version__ = '0.48.6'

__all__ = [
# Modules:
Expand Down
13 changes: 10 additions & 3 deletions extract_msg/open_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ def openMsg(path, **kwargs) -> MSGFile:

msg = MSGFile(path, **kwargs)

# Protect against corrupt MSG files.
try:
ct = msg.classType
except:
# All exceptions here mean we NEED to close the handle.
msg.close()
raise

# Restore the option in the kwargs so we don't have to worry about it.
kwargs['delayAttachments'] = delayAttachments

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

0 comments on commit 480d6f7

Please sign in to comment.