Closed ragebear00 closed 1 month ago
I'll see if I can replicate the issue you're experiencing, but I can't really think of a reason for it to be going wrong except that maybe your python interpreter isn't actually releasing the file handles when they are closed (something I don't think I'd be able to fix).
In the meantime, can you tell me if replacing this in the second code segment:
msg = extract_msg.openMsg(filename)
meta = msg.body
msg.close()
with
del msg
would also resolve the issue for you? If so, then it would suggest that a reference attached to the msg file is not getting garbage collected and is what is breaking things.
try del msg, but does not work.
However, I test the same code in a different computer (same version number), msg.close() can close the file in the exception process (after error raised) and os.remove successfully.
The error may be caused by something else. At present, let's assume it is solved.
My best guess then is that python is not actually releasing the file handle on that machine when close is called, for whatever reason.
Bug Metadata
Describe the bug Email not closed after error and os.remove failed
Traceback (most recent call last): File "C:/Extract_Msg.py", line 73, in
print(ErrorTest(r"C:_a\18.msg"))
File "C:/Extract_Msg.py", line 37, in ErrorTest
msg.saveAttachments(customPath=r'C:_a')
File "C:\Users\z\AppData\Local\Programs\Python\Python310\lib\site-packages\extract_msg\msg_classes\msg.py", line 808, in saveAttachments
attachment.save(skipHidden = skipHidden, kwargs)
File "C:\Users\z\AppData\Local\Programs\Python\Python310\lib\site-packages\extract_msg\attachments\emb_msg_att.py", line 121, in save
return self.data.save(kwargs)
File "C:\Users\z\AppData\Local\Programs\Python\Python310\lib\site-packages\extract_msg\msg_classes\message_base.py", line 792, in save
raise DataNotFoundError('Plain text body could not be found.')
extract_msg.exceptions.DataNotFoundError: Plain text body could not be found.
Add the following can close the email and os.remove succeeds
def msgAttachment(filename):
~ time.sleep(1)