adjust attachment saving
This commit is contained in:
parent
2c58ae30b8
commit
b965538688
|
@ -5,7 +5,7 @@ import time
|
|||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from iarchiver.mail import FileAttachment, FileAttachmentEncoder
|
||||
from iarchiver.mail_conn import FileAttachment, FileAttachmentEncoder
|
||||
|
||||
|
||||
def is_valid_table_name(table_name):
|
||||
|
|
|
@ -111,7 +111,7 @@ class MailConnection:
|
|||
attachments = []
|
||||
if email_message.is_multipart():
|
||||
for part in email_message.walk():
|
||||
content_type = part.get_content_type()
|
||||
# content_type = part.get_content_type()
|
||||
content_disposition = str(part.get("Content-Disposition"))
|
||||
if "attachment" in content_disposition:
|
||||
filename = part.get_filename()
|
||||
|
@ -119,7 +119,7 @@ class MailConnection:
|
|||
# The filename of the file is the hash of its content, which should de-duplicate files.
|
||||
filecontents = part.get_payload(decode=True)
|
||||
filehash = md5_chunked(filecontents)
|
||||
part.set_payload(filehash) # replace the attachment with its hash
|
||||
part.set_payload(f'MD5:{filehash}') # replace the attachment with its hash
|
||||
filepath = self.attachments_dir / filehash
|
||||
file_obj = FileAttachment(filename, filehash)
|
||||
if not filepath.is_file():
|
||||
|
|
Loading…
Reference in New Issue