Skip to content

Commit

Permalink
Merge pull request #273 from martinmanzo/master
Browse files Browse the repository at this point in the history
Close attachments
  • Loading branch information
Pietro395 authored Dec 23, 2023
2 parents 997bed0 + 7e250b2 commit dd37322
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ dummy_project/*
messages
*.sqlite3
.idea/
venv/
36 changes: 17 additions & 19 deletions django_mailbox/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,6 @@ def html(self):
def _rehydrate(self, msg):
new = EmailMessage()
settings = utils.get_settings()

if msg.is_multipart():
for header, value in msg.items():
new[header] = value
Expand All @@ -707,24 +706,24 @@ def _rehydrate(self, msg):
if encoding and encoding.lower() == 'quoted-printable':
# Cannot use `email.encoders.encode_quopri due to
# bug 14360: http://bugs.python.org/issue14360
output = BytesIO()
encode_quopri(
BytesIO(
attachment.document.read()
),
output,
quotetabs=True,
header=False,
)
new.set_payload(
output.getvalue().decode().replace(' ', '=20')
)
with open(attachment.document.path, 'rb') as f:
output = BytesIO()
encode_quopri(
BytesIO(
f.read()
),
output,
quotetabs=True,
header=False,
)
new.set_payload(
output.getvalue().decode().replace(' ', '=20')
)
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:
Expand Down Expand Up @@ -788,9 +787,8 @@ def get_email_object(self):
if self.eml.name.endswith('.gz'):
body = gzip.GzipFile(fileobj=self.eml).read()
else:
self.eml.open()
body = self.eml.file.read()
self.eml.close()
with self.eml.open():
body = self.eml.file.read()
else:
body = self.get_body()
flat = email.message_from_bytes(body)
Expand Down

0 comments on commit dd37322

Please sign in to comment.