From 3deedb3d64a93991e1d5dacb4ef1c107eb92b16b Mon Sep 17 00:00:00 2001 From: TheElementalOfDestruction Date: Sat, 16 Jul 2022 03:41:05 -0700 Subject: [PATCH 1/3] Started version 0.37.0. Added ability to skip `UnsupportedAttachment`s --- CHANGELOG.md | 3 +++ README.rst | 4 ++-- extract_msg/__init__.py | 4 ++-- extract_msg/__main__.py | 7 +++++++ extract_msg/attachment.py | 10 ++++++++++ extract_msg/msg.py | 1 + extract_msg/utils.py | 7 +++++-- 7 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87877f55..ecdac6e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +**v0.37.0** +* Added new option to allow messages with `NotImplementedError` attachments to at least save everything not related to them. From the command line this would be `--skip-not-implemented` or `--skip-ni`. From the save function, this would be the `skipNotImplemented` option. + **v0.36.0** * Improved type hints to tell when a function may not return anything. * Added support for the `reportTag` property to `MessageBase`. I noticed this was one of the properties for `IPM.Outlook.Recall` so I decided to implement it. I'll work on ensuring all of `[MS-OXOMSG]` and `[MS-OXCMSG]` are implemented at a later date, including splitting off `REPORT` into it's own class, because it is it's own class. diff --git a/README.rst b/README.rst index 91390260..75a0fe8a 100644 --- a/README.rst +++ b/README.rst @@ -226,8 +226,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.36.0-blue.svg - :target: https://pypi.org/project/extract-msg/0.36.0/ +.. |PyPI3| image:: https://img.shields.io/badge/pypi-0.37.0-blue.svg + :target: https://pypi.org/project/extract-msg/0.37.0/ .. |PyPI2| image:: https://img.shields.io/badge/python-3.6+-brightgreen.svg :target: https://www.python.org/downloads/release/python-367/ diff --git a/extract_msg/__init__.py b/extract_msg/__init__.py index 1add2b95..122ebddf 100644 --- a/extract_msg/__init__.py +++ b/extract_msg/__init__.py @@ -27,8 +27,8 @@ # along with this program. If not, see . __author__ = 'Destiny Peterson & Matthew Walker' -__date__ = '2022-07-15' -__version__ = '0.36.0' +__date__ = '2022-07-16' +__version__ = '0.37.0' import logging diff --git a/extract_msg/__main__.py b/extract_msg/__main__.py index 91c245cf..bfda71d6 100644 --- a/extract_msg/__main__.py +++ b/extract_msg/__main__.py @@ -5,6 +5,7 @@ import zipfile from extract_msg import __doc__, utils +from extract_msg.enums import AttachErrorBehavior def main() -> None: @@ -67,6 +68,7 @@ def main() -> None: 'preparedHtml': args.preparedHtml, 'rtf': args.rtf, 'skipEmbedded': args.skipEmbedded, + 'skipNotImplemented': args.skipNotImplemented, 'useMsgFilename': args.useFilename, 'wkOptions': args.wkOptions, 'wkPath': args.wkPath, @@ -77,6 +79,11 @@ def main() -> None: 'ignoreRtfDeErrors': args.ignoreRtfDeErrors, } + # If we are skipping the NotImplementedError attachments, we need to + # suppress the error. + if args.skipNotImplemented: + openKwargs['attachmentErrorBehavior'] = AttachErrorBehavior.NOT_IMPLEMENTED + def strSanitize(inp): """ Small function to santize parts of a string when failing to print diff --git a/extract_msg/attachment.py b/extract_msg/attachment.py index 5e2f3aa6..f1e0cd45 100644 --- a/extract_msg/attachment.py +++ b/extract_msg/attachment.py @@ -264,6 +264,16 @@ class UnsupportedAttachment(AttachmentBase): An attachment whose type is not currently supported. """ + def save(self, **kwargs) -> None: + """ + Raises a NotImplementedError unless :param skipNotImplemented: is set to + True. If it is, returns None to signify the attachment was skipped. This + allows for the easy implementation of the option to skip this type of + attachment. + """ + if not kwargs.get('skipNotImplemented', False): + raise NotImplementedError('Unsupported attachments cannot be saved.') + @property def type(self) -> AttachmentType: """ diff --git a/extract_msg/msg.py b/extract_msg/msg.py index 53910fad..8bd39366 100644 --- a/extract_msg/msg.py +++ b/extract_msg/msg.py @@ -581,6 +581,7 @@ def attachments(self) -> List: try: self._attachments.append(self.attachmentClass(self, attachmentDir)) except (NotImplementedError, UnrecognizedMSGTypeError) as e: + print("Hello") if self.attachmentErrorBehavior != AttachErrorBehavior.THROW: logger.error(f'Error processing attachment at {attachmentDir}') logger.exception(e) diff --git a/extract_msg/utils.py b/extract_msg/utils.py index d8624403..4404c798 100644 --- a/extract_msg/utils.py +++ b/extract_msg/utils.py @@ -301,9 +301,12 @@ def getCommandArgs(args) -> argparse.Namespace: # --no-folders parser.add_argument('--no-folders', dest='noFolders', action='store_true', help='Stores everything in the location specified by --out. Requires --attachments-only and is incompatible with --out-name.') - - parser.add_argument('--skip-embedded', dest = 'skipEmbedded', action='store_true', + # --skip-embedded + parser.add_argument('--skip-embedded', dest='skipEmbedded', action='store_true', help='Skips all embedded MSG files when saving attachments.') + # --skip-not-implemented + parser.add_argument('--skip-not-implemented', '--skip-ni', dest='skipNotImplemented', action='store_true', + help='Skips any attachments that are not implemented, allowing saving of the rest of the message.') # --out-name NAME inputFormat.add_argument('--out-name', dest='outName', help='Name to be used with saving the file output. Cannot be used if you are saving more than one file.') From 0ff3e81d2eb44d89cb680232c522da190248d7e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Wed, 20 Jul 2022 11:18:41 +0200 Subject: [PATCH 2/3] new: expose typing --- extract_msg/py.typed | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 extract_msg/py.typed diff --git a/extract_msg/py.typed b/extract_msg/py.typed new file mode 100644 index 00000000..e69de29b From d1b9af3d01352948e0fb0d0f5da47c21d79be9c1 Mon Sep 17 00:00:00 2001 From: TheElementalOfDestruction Date: Wed, 20 Jul 2022 02:32:29 -0700 Subject: [PATCH 3/3] Move version down to 0.36.1 for minor release. --- CHANGELOG.md | 3 ++- README.rst | 4 ++-- extract_msg/__init__.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecdac6e2..6d84d0b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ -**v0.37.0** +**v0.36.1** +* [[TeamMsgExtractor #283](https://github.com/TeamMsgExtractor/msg-extractor/issues/283)] Added file for typing recognition. * Added new option to allow messages with `NotImplementedError` attachments to at least save everything not related to them. From the command line this would be `--skip-not-implemented` or `--skip-ni`. From the save function, this would be the `skipNotImplemented` option. **v0.36.0** diff --git a/README.rst b/README.rst index 75a0fe8a..200d83e8 100644 --- a/README.rst +++ b/README.rst @@ -226,8 +226,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.37.0-blue.svg - :target: https://pypi.org/project/extract-msg/0.37.0/ +.. |PyPI3| image:: https://img.shields.io/badge/pypi-0.36.1-blue.svg + :target: https://pypi.org/project/extract-msg/0.36.1/ .. |PyPI2| image:: https://img.shields.io/badge/python-3.6+-brightgreen.svg :target: https://www.python.org/downloads/release/python-367/ diff --git a/extract_msg/__init__.py b/extract_msg/__init__.py index 122ebddf..5d75405c 100644 --- a/extract_msg/__init__.py +++ b/extract_msg/__init__.py @@ -27,8 +27,8 @@ # along with this program. If not, see . __author__ = 'Destiny Peterson & Matthew Walker' -__date__ = '2022-07-16' -__version__ = '0.37.0' +__date__ = '2022-07-20' +__version__ = '0.36.1' import logging