adjust attachment saving
This commit is contained in:
parent
2c58ae30b8
commit
b965538688
|
@ -5,7 +5,7 @@ import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from iarchiver.mail import FileAttachment, FileAttachmentEncoder
|
from iarchiver.mail_conn import FileAttachment, FileAttachmentEncoder
|
||||||
|
|
||||||
|
|
||||||
def is_valid_table_name(table_name):
|
def is_valid_table_name(table_name):
|
||||||
|
|
|
@ -111,7 +111,7 @@ class MailConnection:
|
||||||
attachments = []
|
attachments = []
|
||||||
if email_message.is_multipart():
|
if email_message.is_multipart():
|
||||||
for part in email_message.walk():
|
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"))
|
content_disposition = str(part.get("Content-Disposition"))
|
||||||
if "attachment" in content_disposition:
|
if "attachment" in content_disposition:
|
||||||
filename = part.get_filename()
|
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.
|
# The filename of the file is the hash of its content, which should de-duplicate files.
|
||||||
filecontents = part.get_payload(decode=True)
|
filecontents = part.get_payload(decode=True)
|
||||||
filehash = md5_chunked(filecontents)
|
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
|
filepath = self.attachments_dir / filehash
|
||||||
file_obj = FileAttachment(filename, filehash)
|
file_obj = FileAttachment(filename, filehash)
|
||||||
if not filepath.is_file():
|
if not filepath.is_file():
|
||||||
|
|
2
run.py
2
run.py
|
@ -10,7 +10,7 @@ import yaml
|
||||||
|
|
||||||
from iarchiver.database import EmailDatabase
|
from iarchiver.database import EmailDatabase
|
||||||
from iarchiver.email import unix_timestamp_since_to_imap_timestamp
|
from iarchiver.email import unix_timestamp_since_to_imap_timestamp
|
||||||
from iarchiver.mail import MailConnection
|
from iarchiver.mail_conn import MailConnection
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
|
|
Loading…
Reference in New Issue