Skip to content

Commit deec504

Browse files
Merge pull request #410 from TeamMsgExtractor/next-release
Version 0.48.3
2 parents 076cb0a + 9e10c2c commit deec504

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
**v0.48.3**
2+
* [[TeamMsgExtractor #409](https://github.com/TeamMsgExtractor/msg-extractor/issues/409)] Added missing private method to `SignedAttachment`.
3+
* Fixed some missing typing information.
4+
15
**v0.48.2**
26
* Fixed bugs with `MessageBase.asEmailMessage()`. Numerous improvements to how it handles the data.
37

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ your access to the newest major version of extract-msg.
260260
.. |License: GPL v3| image:: https://img.shields.io/badge/License-GPLv3-blue.svg
261261
:target: LICENSE.txt
262262

263-
.. |PyPI3| image:: https://img.shields.io/badge/pypi-0.48.2-blue.svg
264-
:target: https://pypi.org/project/extract-msg/0.48.2/
263+
.. |PyPI3| image:: https://img.shields.io/badge/pypi-0.48.3-blue.svg
264+
:target: https://pypi.org/project/extract-msg/0.48.3/
265265

266266
.. |PyPI2| image:: https://img.shields.io/badge/python-3.8+-brightgreen.svg
267267
:target: https://www.python.org/downloads/release/python-3810/

extract_msg/__init__.py

+2-2
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-03-09'
31-
__version__ = '0.48.2'
30+
__date__ = '2024-03-20'
31+
__version__ = '0.48.3'
3232

3333
__all__ = [
3434
# Modules:

extract_msg/attachments/attachment_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def _getTypedStream(self, filename: MSG_PATH, _type = None):
152152
raise ReferenceError('The MSGFile for this Attachment instance has been garbage collected.')
153153
return msg._getTypedStream([self.__dir, msgPathToString(filename)], True, _type)
154154

155-
def _handleFnc(self, _zip, filename, customPath, kwargs) -> pathlib.Path:
155+
def _handleFnc(self, _zip, filename, customPath: pathlib.Path, kwargs) -> pathlib.Path:
156156
"""
157157
"Handle Filename Conflict"
158158

extract_msg/attachments/signed_att.py

+42
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,48 @@ def __init__(self, msg, data: bytes, name: str, mimetype: str, node: email.messa
6262
if self.__data is None:
6363
self.__data = data
6464

65+
def _handleFnc(self, _zip, filename, customPath: pathlib.Path, kwargs) -> pathlib.Path:
66+
"""
67+
"Handle Filename Conflict"
68+
69+
Internal function for use in determining how to modify the saving path
70+
when a file with the same name already exists. This is mainly because
71+
any save function that uses files will need to do this functionality.
72+
73+
:returns: A ``pathlib.Path`` object to where the file should be saved.
74+
"""
75+
fullFilename = customPath / filename
76+
77+
overwriteExisting = kwargs.get('overwriteExisting', False)
78+
79+
if _zip:
80+
# If we are writing to a zip file and are not overwriting.
81+
if not overwriteExisting:
82+
name, ext = os.path.splitext(filename)
83+
nameList = _zip.namelist()
84+
if str(fullFilename).replace('\\', '/') in nameList:
85+
for i in range(2, 100):
86+
testName = customPath / f'{name} ({i}){ext}'
87+
if str(testName).replace('\\', '/') not in nameList:
88+
return testName
89+
else:
90+
# If we couldn't find one that didn't exist.
91+
raise FileExistsError(f'Could not create the specified file because it already exists ("{fullFilename}").')
92+
else:
93+
if not overwriteExisting and fullFilename.exists():
94+
# Try to split the filename into a name and extension.
95+
name, ext = os.path.splitext(filename)
96+
# Try to add a number to it so that we can save without overwriting.
97+
for i in range(2, 100):
98+
testName = customPath / f'{name} ({i}){ext}'
99+
if not testName.exists():
100+
return testName
101+
else:
102+
# If we couldn't find one that didn't exist.
103+
raise FileExistsError(f'Could not create the specified file because it already exists ("{fullFilename}").')
104+
105+
return fullFilename
106+
65107
def save(self, **kwargs) -> constants.SAVE_TYPE:
66108
"""
67109
Saves the attachment data.

0 commit comments

Comments
 (0)