extract-msg 0.58.0__tar.gz → 0.58.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. {extract_msg-0.58.0 → extract_msg-0.58.2}/CHANGELOG.md +9 -0
  2. {extract_msg-0.58.0 → extract_msg-0.58.2}/PKG-INFO +3 -3
  3. {extract_msg-0.58.0 → extract_msg-0.58.2}/README.rst +2 -2
  4. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/__init__.py +2 -2
  5. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/attachments/emb_msg_att.py +1 -1
  6. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/constants/re.py +13 -0
  7. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/message_base.py +20 -11
  8. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/msg.py +1 -1
  9. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_path.py +10 -1
  10. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/utils.py +22 -0
  11. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg.egg-info/PKG-INFO +3 -3
  12. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg_tests/util_tests.py +43 -0
  13. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg_tests/wk_tests.py +56 -0
  14. {extract_msg-0.58.0 → extract_msg-0.58.2}/setup.py +1 -1
  15. {extract_msg-0.58.0 → extract_msg-0.58.2}/LICENSE.txt +0 -0
  16. {extract_msg-0.58.0 → extract_msg-0.58.2}/MANIFEST.in +0 -0
  17. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/__main__.py +0 -0
  18. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/_rtf/__init__.py +0 -0
  19. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/_rtf/create_doc.py +0 -0
  20. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/_rtf/inject_rtf.py +0 -0
  21. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/_rtf/token.py +0 -0
  22. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/_rtf/tokenize_rtf.py +0 -0
  23. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/attachments/__init__.py +0 -0
  24. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/attachments/attachment.py +0 -0
  25. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/attachments/attachment_base.py +0 -0
  26. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/attachments/broken_att.py +0 -0
  27. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/attachments/custom_att.py +0 -0
  28. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/attachments/custom_att_handler/__init__.py +0 -0
  29. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/attachments/custom_att_handler/custom_handler.py +0 -0
  30. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/attachments/custom_att_handler/lnk_obj_att.py +0 -0
  31. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/attachments/custom_att_handler/outlook_image_dib.py +0 -0
  32. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/attachments/custom_att_handler/outlook_image_meta.py +0 -0
  33. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/attachments/signed_att.py +0 -0
  34. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/attachments/unsupported_att.py +0 -0
  35. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/attachments/web_att.py +0 -0
  36. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/constants/__init__.py +0 -0
  37. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/constants/ps.py +0 -0
  38. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/constants/st.py +0 -0
  39. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/data/logging-config/logging-nt.json +0 -0
  40. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/data/logging-config/logging-posix.json +0 -0
  41. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/encoding/__init__.py +0 -0
  42. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/encoding/_dt/__init__.py +0 -0
  43. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/encoding/_dt/_mac_ce.py +0 -0
  44. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/encoding/_dt/_mac_cyrillic.py +0 -0
  45. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/encoding/_dt/_mac_greek.py +0 -0
  46. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/encoding/_dt/_mac_iceland.py +0 -0
  47. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/encoding/_dt/_mac_turkish.py +0 -0
  48. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/encoding/_dt/_win874_dec.py +0 -0
  49. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/encoding/_dt/_win950_dec.py +0 -0
  50. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/encoding/utils.py +0 -0
  51. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/enums.py +0 -0
  52. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/exceptions.py +0 -0
  53. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/__init__.py +0 -0
  54. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/appointment.py +0 -0
  55. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/calendar.py +0 -0
  56. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/calendar_base.py +0 -0
  57. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/contact.py +0 -0
  58. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/journal.py +0 -0
  59. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/meeting_cancellation.py +0 -0
  60. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/meeting_exception.py +0 -0
  61. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/meeting_forward.py +0 -0
  62. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/meeting_related.py +0 -0
  63. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/meeting_request.py +0 -0
  64. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/meeting_response.py +0 -0
  65. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/message.py +0 -0
  66. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/message_signed.py +0 -0
  67. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/message_signed_base.py +0 -0
  68. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/post.py +0 -0
  69. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/sticky_note.py +0 -0
  70. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/task.py +0 -0
  71. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/msg_classes/task_request.py +0 -0
  72. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/null_date.py +0 -0
  73. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/ole_writer.py +0 -0
  74. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/open_msg.py +0 -0
  75. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/properties/__init__.py +0 -0
  76. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/properties/named.py +0 -0
  77. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/properties/prop.py +0 -0
  78. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/properties/properties_store.py +0 -0
  79. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/py.typed +0 -0
  80. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/recipient.py +0 -0
  81. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/__init__.py +0 -0
  82. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/_helpers.py +0 -0
  83. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/business_card.py +0 -0
  84. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/cfoas.py +0 -0
  85. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/contact_link_entry.py +0 -0
  86. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/dev_mode_a.py +0 -0
  87. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/dv_target_device.py +0 -0
  88. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/entry_id.py +0 -0
  89. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/misc_id.py +0 -0
  90. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/mon_stream.py +0 -0
  91. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/odt.py +0 -0
  92. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/ole_pres.py +0 -0
  93. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/ole_stream_struct.py +0 -0
  94. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/recurrence_pattern.py +0 -0
  95. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/report_tag.py +0 -0
  96. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/system_time.py +0 -0
  97. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/time_zone_definition.py +0 -0
  98. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/time_zone_struct.py +0 -0
  99. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/toc_entry.py +0 -0
  100. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg/structures/tz_rule.py +0 -0
  101. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg.egg-info/SOURCES.txt +0 -0
  102. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg.egg-info/dependency_links.txt +0 -0
  103. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg.egg-info/entry_points.txt +0 -0
  104. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg.egg-info/requires.txt +0 -0
  105. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg.egg-info/top_level.txt +0 -0
  106. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg_tests/__init__.py +0 -0
  107. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg_tests/attachment_tests.py +0 -0
  108. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg_tests/cmd_line_tests.py +0 -0
  109. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg_tests/constants.py +0 -0
  110. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg_tests/message_tests.py +0 -0
  111. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg_tests/msg_base_tests.py +0 -0
  112. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg_tests/ole_writer_tests.py +0 -0
  113. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg_tests/prop_tests.py +0 -0
  114. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg_tests/signed_tests.py +0 -0
  115. {extract_msg-0.58.0 → extract_msg-0.58.2}/extract_msg_tests/validation_tests.py +0 -0
  116. {extract_msg-0.58.0 → extract_msg-0.58.2}/requirements.txt +0 -0
  117. {extract_msg-0.58.0 → extract_msg-0.58.2}/setup.cfg +0 -0
@@ -1,3 +1,12 @@
1
+ **v0.58.2**
2
+ * [[Advisory GHSA-6p33-92hw-4v86](https://github.com/TeamMsgExtractor/msg-extractor/security/advisories/GHSA-6p33-92hw-4v86)] [[Advisory GHSA-cxpg-prmv-g4pp](https://github.com/TeamMsgExtractor/msg-extractor/security/advisories/GHSA-cxpg-prmv-g4pp)] Fixed further attack vectors regarding the original advisory that were previously undiscovered. Most changes suggested in the new advisory were accepted as is, however a change was made to the handling of `srcset` to prevent it from being used at all if external files are not allowed.
3
+ * Changed `setup.py` to exclude `extract_msg_tests` from installed packages.
4
+ * Fixed an issue where the code for `MSGPath` was using a feature added in 3.9.
5
+
6
+ **v0.58.1**
7
+ * [[TeamMsgExtractor #493](https://github.com/TeamMsgExtractor/msg-extractor/issues/493)] Fixed unable to open embedded msg files due to `MSGBase.prefixList` still being used after it was removed.
8
+ * Corrected the typing signature of `MSGBase.prefix`.
9
+
1
10
  **v0.58.0**
2
11
  * Changed module to primarily use `MSGPath` for pathing. All functions still except string paths or list paths, they now just also accept `MSGPath` and use it under the hood for path conversions. With this, some functions have been changed to specifically return `MSGPath` rather than list and string versions of paths. Removed: `MSGBase.prefixList`, `utils.inputToMsgPath()`, and `utils.msgPathToString()`. Modified: `*.fixPath()`, `*.listDir()`, and `MSGBase.prefix`.
3
12
  * Changed setup to use `find_packages()` to try and get ahead of deprecation and ensure all files are distributed correctly.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: extract_msg
3
- Version: 0.58.0
3
+ Version: 0.58.2
4
4
  Summary: Extracts emails and attachments saved in Microsoft Outlook's .msg files
5
5
  Home-page: https://github.com/TeamMsgExtractor/msg-extractor
6
6
  Download-URL: https://github.com/TeamMsgExtractor/msg-extractor/archives/master
@@ -287,8 +287,8 @@ your access to the newest major version of extract-msg.
287
287
  .. |License: GPL v3| image:: https://img.shields.io/badge/License-GPLv3-blue.svg
288
288
  :target: LICENSE.txt
289
289
 
290
- .. |PyPI3| image:: https://img.shields.io/badge/pypi-0.58.0-blue.svg
291
- :target: https://pypi.org/project/extract-msg/0.58.0/
290
+ .. |PyPI3| image:: https://img.shields.io/badge/pypi-0.58.2-blue.svg
291
+ :target: https://pypi.org/project/extract-msg/0.58.2/
292
292
 
293
293
  .. |PyPI2| image:: https://img.shields.io/badge/python-3.8+-brightgreen.svg
294
294
  :target: https://www.python.org/downloads/release/python-3810/
@@ -268,8 +268,8 @@ your access to the newest major version of extract-msg.
268
268
  .. |License: GPL v3| image:: https://img.shields.io/badge/License-GPLv3-blue.svg
269
269
  :target: LICENSE.txt
270
270
 
271
- .. |PyPI3| image:: https://img.shields.io/badge/pypi-0.58.0-blue.svg
272
- :target: https://pypi.org/project/extract-msg/0.58.0/
271
+ .. |PyPI3| image:: https://img.shields.io/badge/pypi-0.58.2-blue.svg
272
+ :target: https://pypi.org/project/extract-msg/0.58.2/
273
273
 
274
274
  .. |PyPI2| image:: https://img.shields.io/badge/python-3.8+-brightgreen.svg
275
275
  :target: https://www.python.org/downloads/release/python-3810/
@@ -27,8 +27,8 @@ https://github.com/TeamMsgExtractor/msg-extractor
27
27
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
28
28
 
29
29
  __author__ = 'Destiny Peterson & Matthew Walker'
30
- __date__ = '2026-10-28'
31
- __version__ = '0.58.0'
30
+ __date__ = '2026-11-05'
31
+ __version__ = '0.58.2'
32
32
 
33
33
  __all__ = [
34
34
  # Modules:
@@ -34,7 +34,7 @@ class EmbeddedMsgAttachment(AttachmentBase):
34
34
 
35
35
  def __init__(self, msg: MSGFile, dir_: str, propStore: PropertiesStore):
36
36
  super().__init__(msg, dir_, propStore)
37
- self.__prefix = msg.prefixList + [dir_, '__substg1.0_3701000D']
37
+ self.__prefix = msg.prefix / dir_ / '__substg1.0_3701000D'
38
38
  self.__data = openMsg(self.msg.path, prefix = self.__prefix, parentMsg = self.msg, treePath = self.treePath, **self.msg.kwargs)
39
39
 
40
40
  def getFilename(self, **kwargs) -> str:
@@ -4,7 +4,9 @@ Regular expression constants.
4
4
 
5
5
 
6
6
  __all__ = [
7
+ 'CSS_IMPORT_EXTERNAL',
7
8
  'CSS_URL',
9
+ 'EXTERNAL_URL_IGNORED_CHARS',
8
10
  'HTML_BODY_START',
9
11
  'HTML_SAN_SPACE',
10
12
  'INVALID_FILENAME_CHARS',
@@ -56,3 +58,14 @@ RTF_BODY_STRIP_PRE_OPEN: Final[_RE_BYTES_TYPE] = re.compile(rb'\\htmlrtf1? ?{[^{
56
58
 
57
59
  # Used for stripping urls from CSS.
58
60
  CSS_URL: Final[_RE_STR_TYPE] = re.compile(r'url\(\s*["\']?(https?:\/\/[^"\')\s]+)["\']?\s*\)', re.I)
61
+ # Used for stripping external @import rules from CSS. An @import that pulls in
62
+ # an external http(s) resource causes wkhtmltopdf to fetch it, so the whole
63
+ # at-rule is removed. This matches both the string form (@import "http://...";)
64
+ # and the url() form (@import url(http://...);), including any media-query list,
65
+ # up to the terminating semicolon. CSS_URL alone does not catch the string form.
66
+ CSS_IMPORT_EXTERNAL: Final[_RE_STR_TYPE] = re.compile(r'@import\b[^;]*?https?:\/\/[^;]*;?', re.I)
67
+ # Characters that HTML URL parsing ignores: leading C0 controls and spaces, and
68
+ # interior tab/CR/LF. These are removed before testing an attribute's scheme so
69
+ # a value like " http://..." or "ht\ttp://..." cannot smuggle a URL past the
70
+ # external-file check.
71
+ EXTERNAL_URL_IGNORED_CHARS: Final[_RE_STR_TYPE] = re.compile(r'^[\x00-\x20]+|[\t\r\n]')
@@ -48,9 +48,9 @@ from ..structures.report_tag import ReportTag
48
48
  from ..recipient import Recipient
49
49
  from ..utils import (
50
50
  addNumToDir, addNumToZipDir, createZipOpen, decodeRfc2047, findWk,
51
- htmlSanitize, inputToBytes, inputToString, isEncapsulatedRtf, patchCss,
52
- prepareFilename, rtfSanitizeHtml, rtfSanitizePlain, stripRtf,
53
- validateHtml
51
+ htmlSanitize, inputToBytes, inputToString, isEncapsulatedRtf,
52
+ isExternalUrl, patchCss, prepareFilename, rtfSanitizeHtml,
53
+ rtfSanitizePlain, stripRtf, validateHtml
54
54
  )
55
55
 
56
56
 
@@ -612,15 +612,24 @@ class MessageBase(MSGFile):
612
612
  # Always decompose these, there is no good reason for these.
613
613
  if tag.name.lower() in ('iframe', 'script'):
614
614
  tag.decompose()
615
- # Strip external files away only if they are not allowed.
615
+
616
+ # Strip external files away only if they are not allowed. Each
617
+ # URL-bearing attribute is checked independently (not as an
618
+ # elif chain, which only ever stripped one per tag), the value
619
+ # is normalized first so a leading space or interior tab/newline
620
+ # cannot smuggle a URL past the check.
616
621
  elif not wkAllowExternalFiles:
617
- if tag.get('href', '').lower().startswith('http'):
618
- tag['href'] = ''
619
- elif tag.get('src', '').lower().startswith('http'):
620
- tag['src'] = ''
621
- elif tag.get('data', '').lower().startswith('http'):
622
- if tag.name.lower() == 'object':
623
- tag['data'] = ''
622
+ # If anyone can show me a legitimate way for this to appear
623
+ # in an email with attachments and not just external URLs,
624
+ # then this can be restored. Extract-msg has no support for
625
+ # converting these to data source types anyways.
626
+ if tag.get('srcset'):
627
+ tag['srcset'] = ''
628
+ for attr in ('href', 'src', 'data', 'poster', 'background'):
629
+ if attr == 'data' and tag.name.lower() != 'object':
630
+ continue
631
+ if isExternalUrl(tag.get(attr, '')):
632
+ tag[attr] = ''
624
633
 
625
634
  # SECURITY: Last step, we need to go over all of the css data to ensure
626
635
  # no tracking images ONLY if images are disabled.
@@ -1130,7 +1130,7 @@ class MSGFile:
1130
1130
  return self.__path
1131
1131
 
1132
1132
  @property
1133
- def prefix(self) -> str:
1133
+ def prefix(self) -> MSGPath:
1134
1134
  """
1135
1135
  The prefix of the ``MSGFile`` instance.
1136
1136
 
@@ -82,4 +82,13 @@ class MSGPath(PurePosixPath):
82
82
  """
83
83
  Adds the tail to the last item in the path, without a separator.
84
84
  """
85
- return self.__class__(str(self) + tail)
85
+ return self.__class__(str(self) + tail)
86
+
87
+ if sys.version_info[1] == 8:
88
+ # Basically just use the future feature from pathlib.
89
+ def is_relative_to(self, *other) -> bool:
90
+ try:
91
+ self.relative_to(*other)
92
+ return True
93
+ except ValueError:
94
+ return False
@@ -28,6 +28,7 @@ __all__ = [
28
28
  'inputToBytes',
29
29
  'inputToString',
30
30
  'isEncapsulatedRtf',
31
+ 'isExternalUrl',
31
32
  'makeWeakRef',
32
33
  'parseType',
33
34
  'patchCss',
@@ -830,10 +831,31 @@ def parseType(_type: int, stream: Union[int, bytes], encoding: str, extras: Sequ
830
831
  return value
831
832
 
832
833
 
834
+ def isExternalUrl(value: Optional[str]) -> bool:
835
+ """
836
+ Whether a URL attribute value points at an external http(s) resource.
837
+
838
+ The leading whitespace and control characters, and the interior tab/CR/LF,
839
+ that HTML URL parsing discards are removed before the scheme is tested, so a
840
+ value such as ``" http://..."`` (a leading space defeats a plain
841
+ ``startswith('http')``) is still detected as external.
842
+ """
843
+ if not value:
844
+ return False
845
+ normalized = constants.re.EXTERNAL_URL_IGNORED_CHARS.sub('', value)
846
+ return normalized.lower().startswith(('http://', 'https://'))
847
+
848
+
833
849
  def patchCss(cssData: str) -> str:
834
850
  """
835
851
  Takes the css data and patches out urls from it for security.
852
+
853
+ Both external ``@import`` rules and external ``url()`` references are
854
+ removed, as either can make wkhtmltopdf fetch an attacker-chosen resource.
855
+ ``@import`` is handled first because its string form (``@import "http://..."``)
856
+ has no ``url()`` wrapper and would otherwise survive.
836
857
  """
858
+ cssData = constants.re.CSS_IMPORT_EXTERNAL.sub('', cssData)
837
859
  return constants.re.CSS_URL.sub('none', cssData)
838
860
 
839
861
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: extract-msg
3
- Version: 0.58.0
3
+ Version: 0.58.2
4
4
  Summary: Extracts emails and attachments saved in Microsoft Outlook's .msg files
5
5
  Home-page: https://github.com/TeamMsgExtractor/msg-extractor
6
6
  Download-URL: https://github.com/TeamMsgExtractor/msg-extractor/archives/master
@@ -287,8 +287,8 @@ your access to the newest major version of extract-msg.
287
287
  .. |License: GPL v3| image:: https://img.shields.io/badge/License-GPLv3-blue.svg
288
288
  :target: LICENSE.txt
289
289
 
290
- .. |PyPI3| image:: https://img.shields.io/badge/pypi-0.58.0-blue.svg
291
- :target: https://pypi.org/project/extract-msg/0.58.0/
290
+ .. |PyPI3| image:: https://img.shields.io/badge/pypi-0.58.2-blue.svg
291
+ :target: https://pypi.org/project/extract-msg/0.58.2/
292
292
 
293
293
  .. |PyPI2| image:: https://img.shields.io/badge/python-3.8+-brightgreen.svg
294
294
  :target: https://www.python.org/downloads/release/python-3810/
@@ -21,6 +21,49 @@ class UtilTests(unittest.TestCase):
21
21
  with self.assertRaises(KeyError):
22
22
  utils.dictGetCasedKey(caseDict, 'jjjjj')
23
23
 
24
+ def test_patchCss(self):
25
+ # External url() references are neutralized (pre-existing behavior).
26
+ self.assertNotIn('http', utils.patchCss('body{background:url("http://evil/x")}').lower())
27
+ self.assertNotIn('http', utils.patchCss('@font-face{src:url(http://evil/x)}').lower())
28
+ # External @import rules are neutralized in every form, including the
29
+ # bare-string form that has no url() wrapper (the fixed gap).
30
+ for css in (
31
+ '@import "http://evil/x";',
32
+ "@import 'http://evil/x';",
33
+ '@import url("http://evil/x");',
34
+ '@import "http://evil/x" screen and (min-width: 1px);',
35
+ '@IMPORT "HTTP://EVIL/x" ;',
36
+ ):
37
+ self.assertNotIn('http', utils.patchCss(css).lower(), css)
38
+ # Local/relative references and ordinary text content are preserved;
39
+ # a text string that merely mentions a URL is not a fetch.
40
+ self.assertEqual(utils.patchCss('@import "theme.css";'), '@import "theme.css";')
41
+ self.assertEqual(utils.patchCss('p::after{content:"see http://x"}'),
42
+ 'p::after{content:"see http://x"}')
43
+
44
+ def test_isExternalUrl(self):
45
+ externalUrls = (
46
+ 'http://evil/x',
47
+ 'https://evil/x',
48
+ 'HTTP://EVIL/x',
49
+ ' http://evil/x', # leading space (the fixed gap)
50
+ '\t\n http://evil/x', # leading control characters
51
+ 'ht\ttp://evil/x', # interior tab, discarded by URL parsing
52
+ )
53
+ nonExternal = (
54
+ '',
55
+ 'cid:logo',
56
+ 'image.png',
57
+ '/relative/path',
58
+ 'data:image/png;base64,AAAA',
59
+ 'mailto:a@b.c',
60
+ )
61
+
62
+ for value in externalUrls:
63
+ self.assertTrue(utils.isExternalUrl(value), value)
64
+ for value in nonExternal:
65
+ self.assertFalse(utils.isExternalUrl(value), value)
66
+
24
67
  def test_divide(self):
25
68
  inputString = '12345678901234567890'
26
69
  expectedOutputs = {
@@ -75,6 +75,22 @@ class WkTests(unittest.TestCase):
75
75
  f'</body></html>'
76
76
  ).encode(),
77
77
  ),
78
+ (
79
+ "img-srcset",
80
+ (
81
+ f'<html><body>'
82
+ f'<img srcset="http://127.0.0.1:{port}/ssrf-srcset 1x">'
83
+ f'</body></html>'
84
+ ).encode(),
85
+ ),
86
+ (
87
+ "src-leading-space",
88
+ (
89
+ f'<html><body>'
90
+ f'<img src=" http://127.0.0.1:{port}/ssrf-leading-space">'
91
+ f'</body></html>'
92
+ ).encode(),
93
+ ),
78
94
  (
79
95
  "link-css",
80
96
  (
@@ -98,6 +114,46 @@ class WkTests(unittest.TestCase):
98
114
  f'<body style="background-image: url(http://127.0.0.1:{port}/ssrf-css-tag)">test</body></html>'
99
115
  ).encode(),
100
116
  ),
117
+ (
118
+ "css-import-string",
119
+ (
120
+ f'<html><head>'
121
+ f'<style>@import "http://127.0.0.1:{port}/ssrf-import-string";</style>'
122
+ f'</head><body>test</body></html>'
123
+ ).encode(),
124
+ ),
125
+ (
126
+ "css-import-url",
127
+ (
128
+ f'<html><head>'
129
+ f'<style>@import url("http://127.0.0.1:{port}/ssrf-import-url");</style>'
130
+ f'</head><body>test</body></html>'
131
+ ).encode(),
132
+ ),
133
+ (
134
+ "css-font-face",
135
+ (
136
+ f'<html><head>'
137
+ f'<style>@font-face{{font-family:x;src:url("http://127.0.0.1:{port}/ssrf-font-face")}}</style>'
138
+ f'</head><body>test</body></html>'
139
+ ).encode(),
140
+ ),
141
+ (
142
+ "css-image-set",
143
+ (
144
+ f'<html><head>'
145
+ f'<style>body{{background-image:image-set("http://127.0.0.1:{port}/ssrf-image-set-string" 1x)}}</style>'
146
+ f'</head><body>test</body></html>'
147
+ ).encode(),
148
+ ),
149
+ (
150
+ "css-no-quote",
151
+ (
152
+ f'<html><head></head><body>'
153
+ f'<p style="background:url(http://127.0.0.1:{port}/attr-bg-url)">x</p>'
154
+ f'</body></html>'
155
+ ).encode(),
156
+ ),
101
157
  ]
102
158
 
103
159
  # We want to run all of the tests really quickly and then evaluate
@@ -39,7 +39,7 @@ setup(
39
39
  author='Destiny Peterson & Matthew Walker',
40
40
  author_email='arceusthe@gmail.com, mattgwwalker@gmail.com',
41
41
  license='GPL',
42
- packages=find_packages('.'),
42
+ packages=find_packages('.', exclude = 'extract_msg_tests'),
43
43
  py_modules=[main_module],
44
44
  entry_points={
45
45
  'console_scripts': ['extract_msg = extract_msg.__main__:main',]
File without changes
File without changes
File without changes