Skip to content

Commit

Permalink
Use Django file storage API to store documents.
Browse files Browse the repository at this point in the history
fix #34
  • Loading branch information
tonioo committed Dec 3, 2015
1 parent f5ed509 commit b33378e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions modoboa_webmail/lib/imapemail.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from rfc6266 import parse_headers

from django.conf import settings
from django.core.files.base import ContentFile
from django.core.files.storage import default_storage
from django.utils.translation import ugettext as _

from modoboa.lib import parameters, u2u_decode
Expand Down Expand Up @@ -170,20 +172,20 @@ def _find_attachments(self):
self.attachments[att["pnum"]] = attname

def _fetch_inlines(self):
"""Store inline images on filesystem to display them."""
for cid, params in self.bs.inlines.iteritems():
if re.search(r"\.\.", cid):
continue
fname = "modoboa_webmail/%s_%s" % (self.mailid, cid)
path = os.path.join(settings.MEDIA_ROOT, fname)
params["fname"] = os.path.join(settings.MEDIA_URL, fname)
if os.path.exists(path):
if default_storage.exists(path):
continue

params["fname"] = os.path.join(settings.MEDIA_URL, fname)
pdef, content = self.imapc.fetchpart(
self.mailid, self.mbox, params["pnum"]
)
with open(path, "wb") as fpo:
fpo.write(decode_payload(params["encoding"], content))
default_storage.save(
path, ContentFile(decode_payload(params["encoding"], content)))

def map_cid(self, url):
m = re.match(".*cid:(.+)", url)
Expand Down

0 comments on commit b33378e

Please sign in to comment.