adjust attachment saving

This commit is contained in:
Cyberes 2024-03-06 10:30:13 -07:00
parent 2c58ae30b8
commit b965538688
3 changed files with 4 additions and 4 deletions

View File

@ -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):

View File

@ -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():

2
run.py
View File

@ -10,7 +10,7 @@ import yaml
from iarchiver.database import EmailDatabase
from iarchiver.email import unix_timestamp_since_to_imap_timestamp
from iarchiver.mail import MailConnection
from iarchiver.mail_conn import MailConnection
def main(args):