mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-09 22:38:19 +02:00
Close attachments
This commit is contained in:
parent
462fdd3e49
commit
7e250b2504
2 changed files with 18 additions and 19 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -14,3 +14,4 @@ dummy_project/*
|
||||||
messages
|
messages
|
||||||
*.sqlite3
|
*.sqlite3
|
||||||
.idea/
|
.idea/
|
||||||
|
venv/
|
||||||
|
|
@ -677,7 +677,6 @@ class Message(models.Model):
|
||||||
def _rehydrate(self, msg):
|
def _rehydrate(self, msg):
|
||||||
new = EmailMessage()
|
new = EmailMessage()
|
||||||
settings = utils.get_settings()
|
settings = utils.get_settings()
|
||||||
|
|
||||||
if msg.is_multipart():
|
if msg.is_multipart():
|
||||||
for header, value in msg.items():
|
for header, value in msg.items():
|
||||||
new[header] = value
|
new[header] = value
|
||||||
|
|
@ -696,10 +695,11 @@ class Message(models.Model):
|
||||||
if encoding and encoding.lower() == 'quoted-printable':
|
if encoding and encoding.lower() == 'quoted-printable':
|
||||||
# Cannot use `email.encoders.encode_quopri due to
|
# Cannot use `email.encoders.encode_quopri due to
|
||||||
# bug 14360: http://bugs.python.org/issue14360
|
# bug 14360: http://bugs.python.org/issue14360
|
||||||
|
with open(attachment.document.path, 'rb') as f:
|
||||||
output = BytesIO()
|
output = BytesIO()
|
||||||
encode_quopri(
|
encode_quopri(
|
||||||
BytesIO(
|
BytesIO(
|
||||||
attachment.document.read()
|
f.read()
|
||||||
),
|
),
|
||||||
output,
|
output,
|
||||||
quotetabs=True,
|
quotetabs=True,
|
||||||
|
|
@ -711,9 +711,8 @@ class Message(models.Model):
|
||||||
del new['Content-Transfer-Encoding']
|
del new['Content-Transfer-Encoding']
|
||||||
new['Content-Transfer-Encoding'] = 'quoted-printable'
|
new['Content-Transfer-Encoding'] = 'quoted-printable'
|
||||||
else:
|
else:
|
||||||
new.set_payload(
|
with open(attachment.document.path, 'rb') as f:
|
||||||
attachment.document.read()
|
new.set_payload(f.read())
|
||||||
)
|
|
||||||
del new['Content-Transfer-Encoding']
|
del new['Content-Transfer-Encoding']
|
||||||
encode_base64(new)
|
encode_base64(new)
|
||||||
except MessageAttachment.DoesNotExist:
|
except MessageAttachment.DoesNotExist:
|
||||||
|
|
@ -777,9 +776,8 @@ class Message(models.Model):
|
||||||
if self.eml.name.endswith('.gz'):
|
if self.eml.name.endswith('.gz'):
|
||||||
body = gzip.GzipFile(fileobj=self.eml).read()
|
body = gzip.GzipFile(fileobj=self.eml).read()
|
||||||
else:
|
else:
|
||||||
self.eml.open()
|
with self.eml.open():
|
||||||
body = self.eml.file.read()
|
body = self.eml.file.read()
|
||||||
self.eml.close()
|
|
||||||
else:
|
else:
|
||||||
body = self.get_body()
|
body = self.get_body()
|
||||||
flat = email.message_from_bytes(body)
|
flat = email.message_from_bytes(body)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue