1
0
Fork 0

Merge pull request #273 from martinmanzo/master

Close attachments
This commit is contained in:
Pietro 2023-12-23 21:01:28 +01:00 committed by GitHub
commit dd37322a61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 19 deletions

1
.gitignore vendored
View file

@ -14,3 +14,4 @@ dummy_project/*
messages
*.sqlite3
.idea/
venv/

View file

@ -688,7 +688,6 @@ class Message(models.Model):
def _rehydrate(self, msg):
new = EmailMessage()
settings = utils.get_settings()
if msg.is_multipart():
for header, value in msg.items():
new[header] = value
@ -707,10 +706,11 @@ class Message(models.Model):
if encoding and encoding.lower() == 'quoted-printable':
# Cannot use `email.encoders.encode_quopri due to
# bug 14360: http://bugs.python.org/issue14360
with open(attachment.document.path, 'rb') as f:
output = BytesIO()
encode_quopri(
BytesIO(
attachment.document.read()
f.read()
),
output,
quotetabs=True,
@ -722,9 +722,8 @@ class Message(models.Model):
del new['Content-Transfer-Encoding']
new['Content-Transfer-Encoding'] = 'quoted-printable'
else:
new.set_payload(
attachment.document.read()
)
with open(attachment.document.path, 'rb') as f:
new.set_payload(f.read())
del new['Content-Transfer-Encoding']
encode_base64(new)
except MessageAttachment.DoesNotExist:
@ -788,9 +787,8 @@ class Message(models.Model):
if self.eml.name.endswith('.gz'):
body = gzip.GzipFile(fileobj=self.eml).read()
else:
self.eml.open()
with self.eml.open():
body = self.eml.file.read()
self.eml.close()
else:
body = self.get_body()
flat = email.message_from_bytes(body)